Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
QuadraticVariation.cs
4
6{
11 {
12 private readonly double[] cx;
13 private readonly double[] cy;
14
19 : base(new ScriptNode[] { Coefficients }, argumentTypes1Matrix, Start, Length, Expression)
20 {
21 this.cx = new double[6];
22 this.cy = new double[6];
23 }
24
28 public QuadraticVariation(ScriptNode XCoefficients, ScriptNode YCoefficients, int Start, int Length, Expression Expression)
29 : base(new ScriptNode[] { XCoefficients, YCoefficients }, new ArgumentType[] { ArgumentType.Vector, ArgumentType.Vector },
31 {
32 this.cx = new double[6];
33 this.cy = new double[6];
34 }
35
40 ScriptNode cx4, ScriptNode cx5, ScriptNode cx6,
41 ScriptNode cy1, ScriptNode cy2, ScriptNode cy3,
42 ScriptNode cy4, ScriptNode cy5, ScriptNode cy6,
44 : base(new ScriptNode[] { cx1, cx2, cx3, cx4, cx5, cx6, cy1, cy2, cy3, cy4, cy5, cy6 },
45 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
46 ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
47 ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
48 ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar },
50 {
51 this.cx = new double[6];
52 this.cy = new double[6];
53 }
54
58 public QuadraticVariation(double cx1, double cx2, double cx3, double cx4, double cx5, double cx6,
59 double cy1, double cy2, double cy3, double cy4, double cy5, double cy6,
61 : base(Arguments, ArgumentTypes, Start, Length, Expression)
62 {
63 this.cx = new double[] { cx1, cx2, cx3, cx4, cx5, cx6 };
64 this.cy = new double[] { cy1, cy2, cy3, cy4, cy5, cy6 };
65 }
66
71 {
72 switch (Arguments.Length)
73 {
74 case 12:
75 break;
76
77 case 1:
78 if (!(Arguments[0] is IMatrix M) || M.Rows != 2 || M.Columns != 6)
79 throw new ScriptRuntimeException("Expected a 2x6 matrix.", this);
80
81 Arguments = new IElement[]
82 {
83 M.GetElement(0, 0),
84 M.GetElement(1, 0),
85 M.GetElement(2, 0),
86 M.GetElement(3, 0),
87 M.GetElement(4, 0),
88 M.GetElement(5, 0),
89 M.GetElement(0, 1),
90 M.GetElement(1, 1),
91 M.GetElement(2, 1),
92 M.GetElement(3, 1),
93 M.GetElement(4, 1),
94 M.GetElement(5, 1)
95 };
96 break;
97
98 case 2:
99 if (!(Arguments[0] is IVector CX) || CX.Dimension != 6 ||
100 !(Arguments[1] is IVector CY) || CY.Dimension != 6)
101 {
102 throw new ScriptRuntimeException("Expected vectors of 6 dimensions.", this);
103 }
104
105 Arguments = new IElement[]
106 {
107 CX.GetElement(0),
108 CX.GetElement(1),
109 CX.GetElement(2),
110 CX.GetElement(3),
111 CX.GetElement(4),
112 CX.GetElement(5),
113 CY.GetElement(0),
114 CY.GetElement(1),
115 CY.GetElement(2),
116 CY.GetElement(3),
117 CY.GetElement(4),
118 CY.GetElement(5)
119 };
120 break;
121
122 default:
123 throw new ScriptRuntimeException("Invalid number of arguments.", this);
124 }
125
138
139 return new QuadraticVariation(cx1, cx2, cx3, cx4, cx5, cx6, cy1, cy2, cy3, cy4, cy5, cy6,
140 this.Arguments, this.ArgumentTypes, Start, Length, Expression);
141 }
142
146 public override string[] DefaultArgumentNames
147 {
148 get
149 {
150 return new string[]
151 {
152 "cx1", "cx2", "cx2", "cx4", "cx5", "cx6",
153 "cx7", "cx8", "cx9", "cx10", "cx11", "cx12"
154 };
155 }
156 }
157
161 public override void Operate(ref double x, ref double y)
162 {
163 double x2 = x * x;
164 double y2 = y * y;
165 double xy = x * y;
166
167 double NextX = this.cx[0] + this.cx[1] * x + this.cx[2] * x2 +
168 this.cx[3] * xy + this.cx[4] * y + this.cx[5] * y2;
169
170 y = this.cy[0] + this.cy[1] * x + this.cy[2] * x2 +
171 this.cy[3] * xy + this.cy[4] * y + this.cy[5] * y2;
172 x = NextX;
173 }
174
178 public override string FunctionName => nameof(QuadraticVariation);
179 }
180}
Class managing a script expression.
Definition: Expression.cs:39
static double ToDouble(object Object)
Converts an object to a double value.
Definition: Expression.cs:4824
QuadraticVariation(ScriptNode XCoefficients, ScriptNode YCoefficients, int Start, int Length, Expression Expression)
TODO
override void Operate(ref double x, ref double y)
TODO
QuadraticVariation(ScriptNode Coefficients, int Start, int Length, Expression Expression)
TODO
override IElement Evaluate(IElement[] Arguments, Variables Variables)
TODO
QuadraticVariation(ScriptNode cx1, ScriptNode cx2, ScriptNode cx3, ScriptNode cx4, ScriptNode cx5, ScriptNode cx6, ScriptNode cy1, ScriptNode cy2, ScriptNode cy3, ScriptNode cy4, ScriptNode cy5, ScriptNode cy6, int Start, int Length, Expression Expression)
TODO
QuadraticVariation(double cx1, double cx2, double cx3, double cx4, double cx5, double cx6, double cy1, double cy2, double cy3, double cy4, double cy5, double cy6, ScriptNode[] Arguments, ArgumentType[] ArgumentTypes, int Start, int Length, Expression Expression)
TODO
static readonly ArgumentType[] argumentTypes1Matrix
One matrix parameter.
ScriptNode[] Arguments
Function arguments.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
Basic interface for matrices.
Definition: IMatrix.cs:9
Basic interface for vectors.
Definition: IVector.cs:9
ArgumentType
Type of parameter used in a function definition or a lambda definition.
Definition: IFunction.cs:9