Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
StandardDeviation.cs
1using System;
2using System.Numerics;
8
10{
15 {
25 {
26 }
27
31 public override string FunctionName => nameof(StandardDeviation);
32
36 public override string[] Aliases
37 {
38 get { return new string[] { "stddev" }; }
39 }
40
48 {
49 return new DoubleNumber(CalcStandardDeviation(Argument.Values, this));
50 }
51
58 public static double CalcStandardDeviation(double[] Values, ScriptNode Node)
59 {
60 double Avg = Average.CalcAverage(Values, Node);
61 double Result = 0;
62 double d;
63 int i, c = Values.Length;
64
65 if (c == 1)
66 return 0;
67
68 for (i = 0; i < c; i++)
69 {
70 d = (Values[i] - Avg);
71 Result += d * d;
72 }
73
74 Result /= (c - 1);
75
76 return Math.Sqrt(Result);
77 }
78
86 {
87 return new ComplexNumber(CalcStandardDeviation(Argument.Values, this));
88 }
89
96 public static Complex CalcStandardDeviation(Complex[] Values, ScriptNode Node)
97 {
98 Complex Avg = Average.CalcAverage(Values, Node);
99 Complex Result = 0;
100 Complex d;
101 int i, c = Values.Length;
102
103 if (c == 1)
104 return Complex.Zero;
105
106 for (i = 0; i < c; i++)
107 {
108 d = (Values[i] - Avg);
109 Result += d * d;
110 }
111
112 Result /= (c - 1);
113
114 return Complex.Sqrt(Result);
115 }
116
124 {
125 throw new ScriptRuntimeException("Expected a numeric vector.", this);
126 }
127
128 }
129}
Class managing a script expression.
Definition: Expression.cs:39
static double CalcAverage(double[] Values, ScriptNode Node)
Calculates the average of a set of double values.
Definition: Average.cs:68
override IElement EvaluateVector(IVector Argument, Variables Variables)
Evaluates the function on a vector argument.
static Complex CalcStandardDeviation(Complex[] Values, ScriptNode Node)
Calculates the standard deviation of a set of complex values.
static double CalcStandardDeviation(double[] Values, ScriptNode Node)
Calculates the standard deviation of a set of double values.
override string FunctionName
Name of the function
override string[] Aliases
Optional aliases. If there are no aliases for the function, null is returned.
override IElement EvaluateVector(DoubleVector Argument, Variables Variables)
Evaluates the function on a vector argument.
StandardDeviation(ScriptNode Argument, int Start, int Length, Expression Expression)
StandardDeviation(v), StdDev(v)
override IElement EvaluateVector(ComplexVector Argument, Variables Variables)
Evaluates the function on a vector argument.
ScriptNode Argument
Function argument.
Base class for funcions of one vector variable.
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
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 vectors.
Definition: IVector.cs:9