Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Chi.cs
1using System;
2using System.Text;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
8
10{
14 public class Chi : Distribution
15 {
19 protected double t0;
20
24 protected double k;
25
29 protected double kHalf;
30
34 protected double c;
35
42 : base(Parent, Model)
43 {
44 }
45
49 public override string LocalName => nameof(Chi);
50
58 {
59 return new Chi(Parent, Model);
60 }
61
66 public override Task FromXml(XmlElement Definition)
67 {
68 this.t0 = XML.Attribute(Definition, "t0", 0.0);
69 this.k = XML.Attribute(Definition, "k", 0.0);
70
71 this.kHalf = this.k / 2;
72 this.c = 1.0 / StatMath.Γ(this.kHalf);
73
74 return base.FromXml(Definition);
75 }
76
83 protected override double GetCumulativeProbability(double t, int NrCycles)
84 {
85 t -= this.t0;
86 if (t < 0)
87 return 0;
88 else
89 return StatMath.γ(this.kHalf, t * t / 2) * this.c;
90 }
91
96 public override void ExportPdfBody(StringBuilder Output)
97 {
98 Output.Append("t<");
99 Output.Append(CommonTypes.Encode(this.t0));
100 Output.Append("?0:");
101 Output.Append(CommonTypes.Encode(this.c * Math.Pow(2, 1 - this.kHalf)));
102 Output.Append("*(t-");
103 Output.Append(CommonTypes.Encode(this.t0));
104 Output.Append(").^");
105 Output.Append(CommonTypes.Encode(this.k - 1));
106 Output.Append(".*exp(-(t-");
107 Output.Append(CommonTypes.Encode(this.t0));
108 Output.Append(").^2/2)");
109 }
110 }
111}
Root node of a simulation model
Definition: Model.cs:49
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
Definition: Chi.cs:66
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
Definition: Chi.cs:57
Chi(ISimulationNode Parent, Model Model)
Chi distribution
Definition: Chi.cs:41
double t0
Time of start of distribution
Definition: Chi.cs:19
override void ExportPdfBody(StringBuilder Output)
Exports the PDF function body.
Definition: Chi.cs:96
override string LocalName
Local name of XML element defining contents of class.
Definition: Chi.cs:49
override double GetCumulativeProbability(double t, int NrCycles)
The Cumulative Distribution Function (CDF) of the distribution, excluding intensity (Distribution....
Definition: Chi.cs:83
Abstract base class for distributions
Definition: Distribution.cs:13
ISimulationNode Parent
Parent node in the simulation model.
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:594
Helps with common XML-related tasks.
Definition: XML.cs:19
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Definition: XML.cs:914
Contains Numerical Methods to compute mathematical functions needed for probabilistic computations.
Definition: StatMath.cs:12
static double Γ(double x)
Gamma function Γ(x), for real-valued arguments.
Definition: StatMath.cs:80
static double γ(double a, double x)
Incomplete gamma function γ(a,x)→Γ(a),x→∞
Definition: StatMath.cs:149
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...