Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Cauchy.cs
1using System;
2using System.Collections.Generic;
3using System.Security.Cryptography;
9
11{
16 {
17 private static readonly ArgumentType[] argumentTypes3Parameters = new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar };
18 private static readonly ArgumentType[] argumentTypes2Parameters = new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, };
19
30 : base(new ScriptNode[] { Shape, Scale, N }, argumentTypes3Parameters, Start, Length, Expression)
31 {
32 }
33
43 : base(new ScriptNode[] { Shape, Scale }, argumentTypes2Parameters, Start, Length, Expression)
44 {
45 }
46
50 public override string FunctionName => nameof(Cauchy);
51
55 public override string[] DefaultArgumentNames
56 {
57 get { return new string[] { "median", "scale", "N" }; }
58 }
59
67 {
68 switch (Arguments.Length)
69 {
70 case 2:
71 double Median = Expression.ToDouble(Arguments[0].AssociatedObjectValue);
72 double Scale = Expression.ToDouble(Arguments[1].AssociatedObjectValue);
73
74 return new DoubleNumber(NextDouble(Median, Scale));
75
76 case 3:
77 default:
78 Median = Expression.ToDouble(Arguments[0].AssociatedObjectValue);
79 Scale = Expression.ToDouble(Arguments[1].AssociatedObjectValue);
80 double d = Expression.ToDouble(Arguments[2].AssociatedObjectValue);
81 int N = (int)Math.Round(d);
82 if (N < 0 || N != d)
83 throw new ScriptRuntimeException("N must be a non-negative integer.", this);
84
85 double[] v = new double[N];
86 int i;
87
88 for (i = 0; i < N; i++)
89 v[i] = NextDouble(Median, Scale);
90
91 return new DoubleVector(v);
92 }
93 }
94
101 public static double NextDouble(double Median, double Scale)
102 {
103 if (Scale <= 0)
104 throw new ArgumentOutOfRangeException("Must be positive.", nameof(Scale));
105
106 return Math.Tan(Math.PI * (Uniform.NextDouble() - 0.5)) * Scale + Median;
107 }
108
109 }
110
111}
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 cauchy distribution.
Definition: Cauchy.cs:16
override string FunctionName
Name of the function
Definition: Cauchy.cs:50
Cauchy(ScriptNode Shape, ScriptNode Scale, int Start, int Length, Expression Expression)
Generates a random number using the cauchy distribution.
Definition: Cauchy.cs:42
override string[] DefaultArgumentNames
Default Argument names
Definition: Cauchy.cs:56
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: Cauchy.cs:66
Cauchy(ScriptNode Shape, ScriptNode Scale, ScriptNode N, int Start, int Length, Expression Expression)
Generates a random number using the cauchy distribution.
Definition: Cauchy.cs:29
static double NextDouble(double Median, double Scale)
Gets a cauchy distributed random value.
Definition: Cauchy.cs:101
Generates a random number using the uniform distribution.
Definition: Uniform.cs:15
static double NextDouble()
Gets a random value in [0,1).
Definition: Uniform.cs:159
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