6using System.Collections.Generic;
9using System.Threading.Tasks;
42 throw new Exception(
"The dataset '" + desc.
Name +
"' has not been saved to the database and cannot be loaded. The data layer should be configured to use a database dataset, but may be configured to use an .NPY file as a source.");
62 schema.Data.StaticNum.Add(
new Field(vsd));
64 schema.Data.StaticCat.Add(
new Field(vsd));
69 schema.Data.ObservedNum.Add(
new Field(vsd));
71 schema.Data.ObservedCat.Add(
new Field(vsd));
76 schema.Data.KnownNum.Add(
new Field(vsd));
78 schema.Data.KnownCat.Add(
new Field(vsd));
106 XmlDocument xmlDoc =
new XmlDocument();
107 xmlDoc.Load(strFile);
109 XmlNode node = xmlDoc.SelectSingleNode(
"Schema");
113 XmlNode dataNode = node.SelectSingleNode(
"Data");
114 XmlAttribute colAtt = dataNode.Attributes[
"Columns"];
115 schema.
Data.Columns =
int.Parse(colAtt.Value);
117 XmlNode syncNode = dataNode.SelectSingleNode(
"Sync");
118 schema.m_data.LoadSync(syncNode);
120 XmlNode observedNode = dataNode.SelectSingleNode(
"Observed");
121 XmlNode observedNumNode = observedNode.SelectSingleNode(
"Numeric");
122 schema.m_data.LoadObservedNum(observedNumNode);
123 XmlNode observedCatNode = observedNode.SelectSingleNode(
"Categorical");
124 schema.m_data.LoadObservedCat(observedCatNode);
126 XmlNode knownNode = dataNode.SelectSingleNode(
"//Known");
127 XmlNode knownNumNode = knownNode.SelectSingleNode(
"Numeric");
128 schema.m_data.LoadKnownNum(knownNumNode);
129 XmlNode knownCatNode = knownNode.SelectSingleNode(
"Categorical");
130 schema.m_data.LoadKnownCat(knownCatNode);
132 XmlNode staticNode = dataNode.SelectSingleNode(
"Static");
133 XmlNode staticNumNode = staticNode.SelectSingleNode(
"Numeric");
134 schema.m_data.LoadStaticNum(staticNumNode);
135 XmlNode staticCatNode = staticNode.SelectSingleNode(
"Categorical");
136 schema.m_data.LoadStaticCat(staticCatNode);
138 XmlNode lookupsNode = node.SelectSingleNode(
"Lookups");
149 get {
return m_data; }
157 get {
return m_lookups; }
167 FieldCollection m_sync =
new FieldCollection();
168 FieldCollection m_numKnown =
new FieldCollection();
169 FieldCollection m_catKnown =
new FieldCollection();
170 FieldCollection m_numObserved =
new FieldCollection();
171 FieldCollection m_catObserved =
new FieldCollection();
172 FieldCollection m_numStatic =
new FieldCollection();
173 FieldCollection m_catStatic =
new FieldCollection();
186 public void LoadSync(XmlNode node)
188 m_sync = FieldCollection.Load(node);
195 public void LoadKnownNum(XmlNode node)
197 m_numKnown = FieldCollection.Load(node);
204 public void LoadKnownCat(XmlNode node)
206 m_catKnown = FieldCollection.Load(node);
213 public void LoadObservedNum(XmlNode node)
215 m_numObserved = FieldCollection.Load(node);
222 public void LoadObservedCat(XmlNode node)
224 m_catObserved = FieldCollection.Load(node);
231 public void LoadStaticNum(XmlNode node)
233 m_numStatic = FieldCollection.Load(node);
240 public void LoadStaticCat(XmlNode node)
242 m_catStatic = FieldCollection.Load(node);
248 public int TargetIndex
250 get {
return m_numObserved.FindFieldIndex(Field.INPUT_TYPE.TARGET); }
258 get {
return m_nColumns; }
259 set { m_nColumns = value; }
265 public FieldCollection Sync
267 get {
return m_sync; }
273 public FieldCollection KnownNum
275 get {
return m_numKnown; }
281 public FieldCollection KnownCat
283 get {
return m_catKnown; }
289 public FieldCollection ObservedNum
291 get {
return m_numObserved; }
297 public int ObservedNumExplicitCount
302 foreach (Field field
in m_numObserved)
304 if ((field.InputType & Field.INPUT_TYPE.OBSERVED) == Field.INPUT_TYPE.OBSERVED)
317 public bool IsObservedNum(
int nIdx)
319 if (nIdx < 0 || nIdx >= m_numObserved.Count)
322 return ((m_numObserved[nIdx].InputType & Field.INPUT_TYPE.OBSERVED) == Field.INPUT_TYPE.OBSERVED);
328 public FieldCollection ObservedCat
330 get {
return m_catObserved; }
336 public FieldCollection StaticNum
338 get {
return m_numStatic; }
344 public FieldCollection StaticCat
346 get {
return m_catStatic; }
355 Dictionary<string, Lookup> m_rgLookups =
new Dictionary<string, Lookup>();
373 XmlNodeList lookupNodes = node.SelectNodes(
"Lookup");
374 foreach (XmlNode lookupNode
in lookupNodes)
389 m_rgLookups.Add(lookup.
Name, lookup);
399 if (!m_rgLookups.ContainsKey(strName))
402 return m_rgLookups[strName];
412 get {
return m_rgLookups.ElementAt(nIdx).Value; }
420 get {
return m_rgLookups.Count; }
430 Dictionary<string, LookupItem> m_rgLookupNameToId =
new Dictionary<string, LookupItem>();
431 Dictionary<int, LookupItem> m_rgLookupIdToName =
new Dictionary<int, LookupItem>();
449 lookup.m_strName = node.Attributes[
"Name"].Value;
451 XmlNodeList itemNodes = node.SelectNodes(
"Item");
452 foreach (XmlNode itemNode
in itemNodes)
465 get {
return m_rgLookupIdToName.Count; }
473 m_rgLookupIdToName.Clear();
474 m_rgLookupNameToId.Clear();
483 foreach (KeyValuePair<int, LookupItem> kv
in l.m_rgLookupIdToName)
487 if (m_rgLookupIdToName.ContainsKey(kv.Key))
489 if (!m_rgLookupIdToName[kv.Key].Compare(kv.Value))
491 m_rgLookupIdToName.Remove(kv.Key);
492 m_rgLookupNameToId.Remove(kv.Value.Name);
502 m_rgLookupIdToName.Add(kv.Key, kv.Value);
503 m_rgLookupNameToId.Add(kv.Value.Name, kv.Value);
514 m_rgLookupIdToName.Add(item.
ID, item);
515 m_rgLookupNameToId.Add(item.
Name, item);
523 get {
return m_strName; }
533 if (!m_rgLookupNameToId.ContainsKey(strName))
536 return m_rgLookupNameToId[strName].ID;
546 if (!m_rgLookupIdToName.ContainsKey(nID))
549 return m_rgLookupIdToName[nID].Name;
559 get {
return m_rgLookupIdToName.ElementAt(nIdx).Value; }
570 int m_nValidRangeStartIndex = -1;
571 int m_nValidRangeEndIndex = -1;
591 public LookupItem(
string strName,
int nIndex,
int nValidRangeStart,
int nValidRangeEnd)
595 m_nValidRangeStartIndex = nValidRangeStart;
596 m_nValidRangeEndIndex = nValidRangeEnd;
606 string strName = node.FirstChild.Value;
607 int nIndex =
int.Parse(node.Attributes[
"Index"].Value);
608 int nValidRangeStart = -1;
609 int nValidRangeEnd = -1;
611 if (node.Attributes[
"ValidRangeStartIdx"] !=
null)
612 nValidRangeStart =
int.Parse(node.Attributes[
"ValidRangeStartIdx"].Value);
614 if (node.Attributes[
"ValidRangeEndIdx"] !=
null)
615 nValidRangeEnd =
int.Parse(node.Attributes[
"ValidRangeEndIdx"].Value);
617 return new LookupItem(strName, nIndex, nValidRangeStart, nValidRangeEnd);
644 get {
return m_strName; }
652 get {
return m_nIndex; }
660 get {
return m_nValidRangeStartIndex; }
668 get {
return m_nValidRangeEndIndex; }
676 get {
return (m_nValidRangeStartIndex == -1) ? -1 : (m_nValidRangeEndIndex - m_nValidRangeStartIndex) + 1; }
685 return m_strName +
" @" + m_nIndex.ToString() +
" (" + m_nValidRangeStartIndex.ToString() +
"," + m_nValidRangeEndIndex.ToString() +
")";
695 List<Field> m_rgFields =
new List<Field>();
713 XmlNode nodeFile = node.SelectSingleNode(
"File");
714 if (nodeFile !=
null)
715 col.m_strFile = nodeFile.FirstChild.Value;
717 XmlNodeList nodes = node.SelectNodes(
"Field");
718 foreach (XmlNode node1
in nodes)
734 for (
int i = 0; i < m_rgFields.Count; i++)
736 if ((m_rgFields[i].InputType & type) == type)
749 m_rgFields.Add(field);
758 return m_rgFields.GetEnumerator();
765 IEnumerator IEnumerable.GetEnumerator()
767 return m_rgFields.GetEnumerator();
777 get {
return m_rgFields[nIdx]; }
789 foreach (
Field field
in m_rgFields)
791 if (field.
Name == strName)
804 get {
return m_rgFields.Count; }
812 get {
return m_strFile; }
887 m_dataType = dataType;
888 m_inputType = inputType;
897 m_strName = vsd.
Name;
924 string strName = node.FirstChild.Value;
925 int nIdx =
int.Parse(node.Attributes[
"Index"].Value);
926 string strDataType = node.Attributes[
"DataType"].Value;
927 string strInputType = node.Attributes[
"InputType"].Value;
932 if (strDataType ==
"REAL")
934 else if (strDataType ==
"CATEGORICAL")
937 if (strInputType ==
"TIME")
939 else if (strInputType ==
"ID")
941 else if (strInputType ==
"KNOWN")
943 else if (strInputType ==
"STATIC")
947 if (strInputType.Contains(
"OBSERVED"))
949 if (strInputType.Contains(
"TARGET"))
953 return new Field(strName, nIdx, dataType, inputType);
961 get {
return m_strName; }
969 get {
return m_nIdx; }
977 get {
return m_dataType; }
985 get {
return m_inputType; }
994 return m_strName +
" @" + m_nIdx.ToString() +
" (" + m_dataType.ToString() +
"," + m_inputType.ToString() +
")";
The ProjectEx class manages a project containing the solver description, model description,...
DatasetDescriptor Dataset
Return the descriptor of the dataset used.
int ID
Get/set the database ID of the item.
string Name
Get/set the name of the item.
The DatasetDescriptor class describes a dataset which contains both a training data source and testin...
SourceDescriptor TrainingSource
Get/set the training data source.
SourceDescriptor TestingSource
Get/set the testing data source.
TemporalDescriptor TemporalDescriptor
Get/set the temporal descriptor (if any).
The TemporalDescriptor is used to describe a temporal aspects of the data source.
List< ValueStreamDescriptor > ValueStreamDescriptors
Returns the value stream descriptor.
The value stream descriptor describes a single value stream within a value item.
STREAM_CLASS_TYPE ClassType
Returns the value stream class type.
int Ordering
Returns the value stream ordering.
STREAM_VALUE_TYPE ValueType
Returns the value stream value type.
STREAM_CLASS_TYPE
Defines the stream class type.
STREAM_VALUE_TYPE
Defines the stream value type.
string Name
Return the value stream name.
The DatasetLoader is used to load descriptors from the database.
DatasetDescriptor LoadDatasetFromDb(string strDs)
Load a dataset with the specified name from the database.
The DataSchema class is used by the DataTemporalLayer to load the data schema describing the NPY file...
Data Data
Returns the data portion of the schema.
static DataSchema Load(string strFile)
Loads the data schema from the XML schema file produced by the AiDesigner.TFT data creator.
DataSchema()
The constructor.
static DataSchema LoadFromDatasetDescriptor(DatasetDescriptor desc, Phase phase)
Loads the data schema from a dataset descriptor.
static DataSchema LoadFromProject(ProjectEx prj, Phase phase=Phase.TRAIN)
Loads the data schema from a project.
LookupCollection Lookups
Returns the lookups portion of the schema.
The FieldCollection manages a collection of fields.
int FindFieldIndex(Field.INPUT_TYPE type)
Locates the index of the field by its type.
int Count
Returns the number of fields in the collection.
FieldCollection()
The constructor.
void Add(Field field)
Add a new field to the collection.
static FieldCollection Load(XmlNode node)
Loads a collection of fields from an XML node.
IEnumerator< Field > GetEnumerator()
Return the enumeration of the fields.
string File
Returns the NPY file for which the fields are associated with.
The Field class manages a single field.
static Field Load(XmlNode node)
Loads a new field from an XML node.
int Index
Returns the Index of the field within the numpy file.
DATA_TYPE DataType
Returns the data type of the field.
INPUT_TYPE InputType
Returns the input type of the field.
override string ToString()
Returns a string representation of the field.
INPUT_TYPE
Defines the input type of the field.
Field(ValueStreamDescriptor vsd)
Create a new field from the ValueStreamDescriptor specified.
DATA_TYPE
Defines the Data Type of the field.
Field(string strName, int nIdx, DATA_TYPE dataType, INPUT_TYPE inputType)
The constructor.
string Name
Returns the name of the field.
The LookupCollection class contains a collection of Lookup objects.
static LookupCollection Load(XmlNode node)
Loads the LookupCollection from a node.
int Count
Specifies the number of lookups in the collection.
Lookup Find(string strName)
Locates a lookup by name.
LookupCollection()
The constructor.
void Add(Lookup lookup)
Adds a new lookup to the collection.
The Lookup class is used to manage a single lookup table.
void Add(LookupItem item)
Add a new item to the lookup table.
void Clear()
Clear the entries from the lookup table.
int FindID(string strName)
Find a given lookup ID by name.
string Name
Specifies the lookup item name.
int Count
Returns the the number of lookup items.
static Lookup Load(XmlNode node)
Load a lookup table from an XML node.
void Add(Lookup l)
Add a lookup table to this lookup table.
string FindName(int nID)
Find a given lookup name by ID.
The lookup item manages a single lookup item used to map a name to an ID.
LookupItem(string strName, int nIndex, int nValidRangeStart, int nValidRangeEnd)
The constructor.
int ValidRangeEndIndex
Returns the valid data range end index or -1 to ignore.
static LookupItem Load(XmlNode node)
Load a LookupItem from an XML node.
int? ValidRangeCount
Returns the number of valid data items in the range or -1 if the range is not set.
LookupItem(string strName, int nIndex)
The constructor.
int ID
Specifies the lookup ID.
bool Compare(LookupItem item)
Compare two LookupItems and return whether or not they are the same.
override string ToString()
Returns a string representation of the lookup item.
int ValidRangeStartIndex
Returns the valid data range start index or -1 to ignore.
string Name
Specifies the lookup name.
The descriptors namespace contains all descriptor used to describe various items stored within the da...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Phase
Defines the Phase under which to run a Net.
@ NONE
No training category specified.
The MyCaffe.db.temporal namespace contains all classes used to create the MyCaffeTemporalDatabase in-...
The MyCaffe.layers.tft namespace contains all TFT related layers.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...