Formatting
This commit is contained in:
parent
8cc4c3c1e9
commit
8676c3f9a7
@ -25,7 +25,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return System.Double.NaN;
|
return double.NaN;
|
||||||
|
|
||||||
return await this.Random.NextNumber(new Gamma{ Shape = 0.5 * this.DegreesOfFreedom, Scale = 2.0 }, token);
|
return await this.Random.NextNumber(new Gamma{ Shape = 0.5 * this.DegreesOfFreedom, Scale = 2.0 }, token);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return System.Double.NaN;
|
return double.NaN;
|
||||||
|
|
||||||
if(this.Mean == 1.0)
|
if(this.Mean == 1.0)
|
||||||
return -Math.Log(await this.Random.GetUniform(token));
|
return -Math.Log(await this.Random.GetUniform(token));
|
||||||
|
@ -29,7 +29,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return System.Double.NaN;
|
return double.NaN;
|
||||||
|
|
||||||
// Implementation based on "A Simple Method for Generating Gamma Variables"
|
// Implementation based on "A Simple Method for Generating Gamma Variables"
|
||||||
// by George Marsaglia and Wai Wan Tsang. ACM Transactions on Mathematical Software
|
// by George Marsaglia and Wai Wan Tsang. ACM Transactions on Mathematical Software
|
||||||
|
@ -27,7 +27,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return System.Double.NaN;
|
return double.NaN;
|
||||||
|
|
||||||
var gammaDist = new Gamma{ Shape = this.Shape, Scale = 1.0 / this.Scale };
|
var gammaDist = new Gamma{ Shape = this.Shape, Scale = 1.0 / this.Scale };
|
||||||
return 1.0 / await this.Random.NextNumber(gammaDist, token);
|
return 1.0 / await this.Random.NextNumber(gammaDist, token);
|
||||||
|
@ -15,7 +15,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return System.Double.NaN;
|
return double.NaN;
|
||||||
|
|
||||||
var value = await this.Random.GetUniform(token);
|
var value = await this.Random.GetUniform(token);
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return System.Double.NaN;
|
return double.NaN;
|
||||||
|
|
||||||
var normal = await this.Random.NextNumber(new Normal {Mean = this.Mu, StandardDeviation = this.Sigma}, token);
|
var normal = await this.Random.NextNumber(new Normal {Mean = this.Mu, StandardDeviation = this.Sigma}, token);
|
||||||
return Math.Exp(normal);
|
return Math.Exp(normal);
|
||||||
|
@ -27,7 +27,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return System.Double.NaN;
|
return double.NaN;
|
||||||
|
|
||||||
var u1 = await this.Random.GetUniform(token);
|
var u1 = await this.Random.GetUniform(token);
|
||||||
var u2 = await this.Random.GetUniform(token);
|
var u2 = await this.Random.GetUniform(token);
|
||||||
|
@ -26,7 +26,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return System.Double.NaN;
|
return double.NaN;
|
||||||
|
|
||||||
var normal = await this.Random.NextNumber(NORMAL_DISTRIBUTED, token);
|
var normal = await this.Random.NextNumber(NORMAL_DISTRIBUTED, token);
|
||||||
var chiSquare = await this.Random.NextNumber(new ChiSquare {DegreesOfFreedom = this.DegreesOfFreedom}, token);
|
var chiSquare = await this.Random.NextNumber(new ChiSquare {DegreesOfFreedom = this.DegreesOfFreedom}, token);
|
||||||
|
@ -7,6 +7,6 @@ namespace FastRng.Double.Distributions
|
|||||||
{
|
{
|
||||||
public IRandom Random { get; set; }
|
public IRandom Random { get; set; }
|
||||||
|
|
||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token = default) => this.Random == null ? System.Double.NaN : await this.Random.GetUniform(token);
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default) => this.Random == null ? double.NaN : await this.Random.GetUniform(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -38,7 +38,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return System.Double.NaN;
|
return double.NaN;
|
||||||
|
|
||||||
var value = await this.Random.GetUniform(token);
|
var value = await this.Random.GetUniform(token);
|
||||||
return this.Scale * Math.Pow(-Math.Log(value), 1.0 / this.Shape);
|
return this.Scale * Math.Pow(-Math.Log(value), 1.0 / this.Shape);
|
||||||
|
Loading…
Reference in New Issue
Block a user