Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Weibull.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(Weibull);
51
55 public override string[] DefaultArgumentNames
56 {
57 get { return new string[] { "shape", "scale", "N" }; }
58 }
59
67 {
68 switch (Arguments.Length)
69 {
70 case 2:
71 double Shape = Expression.ToDouble(Arguments[0].AssociatedObjectValue);
72 double Scale = Expression.ToDouble(Arguments[1].AssociatedObjectValue);
73
74 return new DoubleNumber(NextDouble(Shape, Scale));
75
76 case 3:
77 default:
78 Shape = 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(Scale, Shape);
90
91 return new DoubleVector(v);
92 }
93 }
94
101 public static double NextDouble(double Shape, double Scale)
102 {
103 if (Shape <= 0)
104 throw new ArgumentOutOfRangeException("Must be positive.", nameof(Shape));
105
106 if (Scale <= 0)
107 throw new ArgumentOutOfRangeException("Must be positive.", nameof(Scale));
108
109 return Math.Pow(-Math.Log(Uniform.NextDouble()), 1 / Shape) * Scale;
110 }
111
112 }
113
114}
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 uniform distribution.
Definition: Uniform.cs:15
static double NextDouble()
Gets a random value in [0,1).
Definition: Uniform.cs:159
Generates a random number using the weibull distribution.
Definition: Weibull.cs:16
override string[] DefaultArgumentNames
Default Argument names
Definition: Weibull.cs:56
Weibull(ScriptNode Shape, ScriptNode Scale, ScriptNode N, int Start, int Length, Expression Expression)
Generates a random number using the weibull distribution.
Definition: Weibull.cs:29
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: Weibull.cs:66
static double NextDouble(double Shape, double Scale)
Gets a weibull distributed random value.
Definition: Weibull.cs:101
Weibull(ScriptNode Shape, ScriptNode Scale, int Start, int Length, Expression Expression)
Generates a random number using the weibull distribution.
Definition: Weibull.cs:42
override string FunctionName
Name of the function
Definition: Weibull.cs:50
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