-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReservoirConfig.cs
115 lines (100 loc) · 3.7 KB
/
ReservoirConfig.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
using System;
using System.Linq;
using System.Xml.Linq;
namespace EasyMLCore.TimeSeries
{
/// <summary>
/// Configuration of a reservoir.
/// </summary>
[Serializable]
public class ReservoirConfig : ConfigBase
{
//Constants
/// <summary>
/// Name of an associated xsd type.
/// </summary>
public const string XsdTypeName = "ReservoirConfig";
//Attribute properties
/// <inheritdoc cref="ReservoirInputConfig"/>
public ReservoirInputConfig InputCfg { get; }
/// <inheritdoc cref="ReservoirHiddenLayerConfig"/>
public ReservoirHiddenLayerConfig HiddenLayerCfg { get; }
//Constructors
/// <summary>
/// Creates an initialized instance.
/// </summary>
/// <param name="inputCfg">Configuration of the reservoir's input.</param>
/// <param name="hiddenLayerCfg">Configuration of the reservoir's hidden layer.</param>
public ReservoirConfig(ReservoirInputConfig inputCfg,
ReservoirHiddenLayerConfig hiddenLayerCfg
)
{
InputCfg = (ReservoirInputConfig)inputCfg.DeepClone();
HiddenLayerCfg = (ReservoirHiddenLayerConfig)hiddenLayerCfg.DeepClone();
Check();
return;
}
/// <summary>
/// The deep copy constructor.
/// </summary>
/// <param name="source">The source instance.</param>
public ReservoirConfig(ReservoirConfig source)
: this(source.InputCfg, source.HiddenLayerCfg)
{
return;
}
/// <summary>
/// Creates an initialized instance.
/// </summary>
/// <param name="elem">A xml element containing the configuration data.</param>
public ReservoirConfig(XElement elem)
{
//Validation
XElement validatedElem = Validate(elem, XsdTypeName);
//Parsing
XElement inputElem = validatedElem.Elements("input").FirstOrDefault();
InputCfg = new ReservoirInputConfig(inputElem);
XElement hiddenLayerElem = validatedElem.Elements("hiddenLayer").FirstOrDefault();
HiddenLayerCfg = new ReservoirHiddenLayerConfig(hiddenLayerElem);
Check();
return;
}
//Properties
/// <summary>
/// Checks the defaults.
/// </summary>
public bool IsDefaultInputCfg { get { return InputCfg.ContainsOnlyDefaults; } }
/// <summary>
/// Checks the defaults.
/// </summary>
public bool IsDefaultHiddenLayerCfg { get { return HiddenLayerCfg.ContainsOnlyDefaults; } }
/// <inheritdoc/>
public override bool ContainsOnlyDefaults { get { return false; } }
//Methods
/// <inheritdoc/>
protected override void Check()
{
return;
}
/// <inheritdoc/>
public override ConfigBase DeepClone()
{
return new ReservoirConfig(this);
}
/// <inheritdoc/>
public override XElement GetXml(string rootElemName, bool suppressDefaults)
{
XElement rootElem = new XElement(rootElemName,
InputCfg.GetXml(suppressDefaults),
HiddenLayerCfg.GetXml(suppressDefaults)
);
Validate(rootElem, XsdTypeName);
return rootElem;
}
/// <inheritdoc/>
public override XElement GetXml(bool suppressDefaults)
{
return GetXml("reservoir", suppressDefaults);
}
}//ReservoirConfig
}//Namespace