Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
StudentT.cs
1using System;
2using System.Collections.Generic;
3using System.Security.Cryptography;
9
11{
16 {
17 private static readonly ArgumentType[] argumentTypes2Parameters = new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar };
18 private static readonly ArgumentType[] argumentTypes1Parameters = new ArgumentType[] { ArgumentType.Scalar, };
19
29 : base(new ScriptNode[] { Degrees, N }, argumentTypes2Parameters, Start, Length, Expression)
30 {
31 }
32
41 : base(new ScriptNode[] { Degrees }, argumentTypes1Parameters, Start, Length, Expression)
42 {
43 }
44
48 public override string FunctionName => nameof(StudentT);
49
53 public override string[] DefaultArgumentNames
54 {
55 get { return new string[] { "degrees", "N" }; }
56 }
57
65 {
66 switch (Arguments.Length)
67 {
68 case 1:
69 double Degrees = Expression.ToDouble(Arguments[0].AssociatedObjectValue);
70
71 return new DoubleNumber(NextDouble(Degrees));
72
73 case 2:
74 default:
75 Degrees = Expression.ToDouble(Arguments[0].AssociatedObjectValue);
76 double d = Expression.ToDouble(Arguments[1].AssociatedObjectValue);
77 int N = (int)Math.Round(d);
78 if (N < 0 || N != d)
79 throw new ScriptRuntimeException("N must be a non-negative integer.", this);
80
81 double[] v = new double[N];
82 int i;
83
84 for (i = 0; i < N; i++)
85 v[i] = NextDouble(Degrees);
86
87 return new DoubleVector(v);
88 }
89 }
90
96 public static double NextDouble(double Degrees)
97 {
98 if (Degrees <= 0)
99 throw new ArgumentOutOfRangeException("Must be positive.", nameof(Degrees));
100
101 return Normal.NextDouble() / Math.Sqrt(Chi2.NextDouble(Degrees) / Degrees);
102 }
103
104 }
105
106}
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
Base class for multivariate funcions.
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
Generates a random number using the chi squared distribution.
Definition: Chi2.cs:16
static double NextDouble(double Degrees)
Gets a chi squared distributed random value.
Definition: Chi2.cs:96
Generates a random number using the normal distribution.
Definition: Normal.cs:16
static double NextDouble()
Gets a normally distributed random value. Distribution has a mean of 0 and standard deviation of 1.
Definition: Normal.cs:140
Generates a random number using the student-T distribution.
Definition: StudentT.cs:16
StudentT(ScriptNode Degrees, int Start, int Length, Expression Expression)
Generates a random number using the student-T distribution.
Definition: StudentT.cs:40
StudentT(ScriptNode Degrees, ScriptNode N, int Start, int Length, Expression Expression)
Generates a random number using the student-T distribution.
Definition: StudentT.cs:28
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: StudentT.cs:64
static double NextDouble(double Degrees)
Gets a student-T distributed random value.
Definition: StudentT.cs:96
override string FunctionName
Name of the function
Definition: StudentT.cs:48
override string[] DefaultArgumentNames
Default Argument names
Definition: StudentT.cs:54
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
ArgumentType
Type of parameter used in a function definition or a lambda definition.
Definition: IFunction.cs:9