-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResCompTaskConfig.cs
153 lines (136 loc) · 5.56 KB
/
ResCompTaskConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using EasyMLCore.MLP;
using System;
using System.Linq;
using System.Xml.Linq;
namespace EasyMLCore.TimeSeries
{
/// <summary>
/// Configuration of the ResCompTask.
/// </summary>
[Serializable]
public class ResCompTaskConfig : ConfigBase, IModelConfig
{
//Constants
/// <summary>
/// Name of an associated xsd type.
/// </summary>
public const string XsdTypeName = "ResCompTaskConfig";
//Attribute properties
/// <summary>
/// ResCompTask name.
/// </summary>
public string Name { get; }
/// <inheritdoc cref="OutputTaskType"/>
public OutputTaskType TaskType { get; }
/// <summary>
/// Input sections configuration.
/// </summary>
public ResCompTaskInputSectionsConfig InputSectionsCfg { get; }
/// <summary>
/// Output features configuration.
/// </summary>
public FeaturesConfig OutputFeaturesCfg { get; }
/// <summary>
/// Model configuration.
/// </summary>
public IModelConfig ModelCfg { get; }
//Constructors
/// <summary>
/// Creates an initialized instance.
/// </summary>
/// <param name="name">ResCompTask name.</param>
/// <param name="taskType">Computation output task type.</param>
/// <param name="inputSectionsCfg">Input sections configuration.</param>
/// <param name="outputFeaturesCfg">Output features configuration.</param>
/// <param name="modelCfg">Model configuration.</param>
public ResCompTaskConfig(string name,
OutputTaskType taskType,
ResCompTaskInputSectionsConfig inputSectionsCfg,
FeaturesConfig outputFeaturesCfg,
IModelConfig modelCfg
)
{
Name = name;
TaskType = taskType;
InputSectionsCfg = (ResCompTaskInputSectionsConfig)inputSectionsCfg.DeepClone();
OutputFeaturesCfg = (FeaturesConfig)outputFeaturesCfg.DeepClone();
ModelCfg = (IModelConfig)modelCfg.DeepClone();
Check();
return;
}
/// <summary>
/// The deep copy constructor.
/// </summary>
/// <param name="source">The source instance.</param>
public ResCompTaskConfig(ResCompTaskConfig source)
: this(source.Name, source.TaskType, source.InputSectionsCfg,
source.OutputFeaturesCfg, source.ModelCfg)
{
return;
}
/// <summary>
/// Creates an initialized instance.
/// </summary>
/// <param name="elem">A xml element containing the configuration data.</param>
public ResCompTaskConfig(XElement elem)
{
//Validation
XElement validatedElem = Validate(elem, XsdTypeName);
//Parsing
Name = validatedElem.Attribute("name").Value;
TaskType = (OutputTaskType)Enum.Parse(typeof(OutputTaskType), validatedElem.Attribute("taskType").Value, true);
InputSectionsCfg = new ResCompTaskInputSectionsConfig(validatedElem.Elements("inputSections").First());
OutputFeaturesCfg = new FeaturesConfig(validatedElem.Elements("outputFeatures").First());
//Model configuration
XElement modelElem = validatedElem.Elements().Last();
ModelCfg = modelElem.Name.LocalName switch
{
"networkModel" => new NetworkModelConfig(modelElem),
"crossValModel" => new CrossValModelConfig(modelElem),
"stackingModel" => new StackingModelConfig(modelElem),
"bhsModel" => new BHSModelConfig(modelElem),
"rvflModel" => new RVFLModelConfig(modelElem),
"compositeModel" => new CompositeModelConfig(modelElem),
_ => throw new ArgumentException($"Unknown model element name {modelElem.Name.LocalName}.", nameof(elem)),
};
Check();
return;
}
//Properties
/// <inheritdoc/>
public override bool ContainsOnlyDefaults { get { return false; } }
//Methods
/// <inheritdoc/>
protected override void Check()
{
if (Name.Length == 0)
{
throw new ArgumentException($"Task name cannot be empty.", nameof(Name));
}
return;
}
/// <inheritdoc/>
public override ConfigBase DeepClone()
{
return new ResCompTaskConfig(this);
}
/// <inheritdoc/>
public override XElement GetXml(string rootElemName, bool suppressDefaults)
{
XElement rootElem = new XElement(rootElemName,
new XAttribute("name", Name),
new XAttribute("taskType", TaskType.ToString()),
InputSectionsCfg.GetXml(suppressDefaults),
OutputFeaturesCfg.GetXml("outputFeatures", suppressDefaults),
ModelCfg.GetXml(suppressDefaults)
);
Validate(rootElem, XsdTypeName);
return rootElem;
}
/// <inheritdoc/>
public override XElement GetXml(bool suppressDefaults)
{
return GetXml("task", suppressDefaults);
}
}//ResCompTaskConfig
}//Namespace