Skip to content

Commit ea2dcf9

Browse files
committed
Extreme Value distribution
1 parent 2d66127 commit ea2dcf9

21 files changed

+616
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Extreme Value distribution.
13+
1014
## [1.3.1] - 2021-07-23
1115

1216
### Fixed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ They wrap generators and provide unique and shared instances of them.
7979
[Wikipedia](https://en.wikipedia.org/wiki/Bates_distribution);
8080
- [Exponential](Runtime/ContinuousDistributions/ExponentialDistribution) -
8181
[Wikipedia](https://en.wikipedia.org/wiki/Exponential_distribution);
82+
- [Extreme Value](Runtime/ContinuousDistributions/ExtremeValueDistribution) -
83+
[Wikipedia](https://en.wikipedia.org/wiki/Generalized_extreme_value_distribution);
8284
- [Func\<float\> Random Generator Wrapper](Runtime/ContinuousDistributions/FuncDistribution);
8385
- [Gamma](Runtime/ContinuousDistributions/GammaDistribution) -
8486
[Wikipedia](https://en.wikipedia.org/wiki/Gamma_distribution);

Runtime/ContinuousDistributions/ExponentialDistribution/GeneratorProviders/ExponentialGeneratorDependentProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public ExponentialGeneratorDependent<IContinuousGenerator> exponentialGenerator
5252
}
5353

5454
/// <summary>
55-
/// Returns a shared <see cref="ExponentialGenerator"/>.
55+
/// Returns a shared <see cref="ExponentialGeneratorDependent{T}"/>.
5656
/// </summary>
5757
[NotNull]
5858
public ExponentialGeneratorDependent<IContinuousGenerator> sharedExponentialGenerator

Runtime/ContinuousDistributions/ExtremeValueDistribution.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) 2020-2023 Vladimir Popov [email protected] https://github.com/ZorPastaman/Random-Generators
2+
3+
using System;
4+
using System.Runtime.CompilerServices;
5+
using JetBrains.Annotations;
6+
using UnityEngine;
7+
8+
namespace Zor.RandomGenerators.ContinuousDistributions
9+
{
10+
/// <summary>
11+
/// Collection of methods that generate a random value using Extreme value distribution algorithms.
12+
/// </summary>
13+
public static class ExtremeValueDistribution
14+
{
15+
public const float DefaultLocation = 0f;
16+
public const float DefaultScale = 1f;
17+
18+
/// <summary>
19+
/// Generates a random value using <see cref="UnityGeneratorStruct.DefaultExclusive"/> as an iid source.
20+
/// </summary>
21+
/// <param name="location">Location.</param>
22+
/// <param name="scale">Scale. Must be more than 0.</param>
23+
/// <returns>Generated value.</returns>
24+
/// <remarks><paramref name="scale"/> must be more than 0.</remarks>
25+
[MethodImpl(MethodImplOptions.AggressiveInlining), Pure]
26+
public static float Generate(float location, float scale)
27+
{
28+
return Generate(UnityGeneratorStruct.DefaultExclusive, location, scale);
29+
}
30+
31+
/// <summary>
32+
/// Generates a random value using <paramref name="iidFunc"/> as an iid source.
33+
/// </summary>
34+
/// <param name="iidFunc">
35+
/// Function that returns an independent and identically distributed random value in range [0, 1).
36+
/// </param>
37+
/// <param name="location">Location.</param>
38+
/// <param name="scale">Scale. Must be more than 0.</param>
39+
/// <returns>Generated value.</returns>
40+
/// <remarks><paramref name="scale"/> must be more than 0.</remarks>
41+
[MethodImpl(MethodImplOptions.AggressiveInlining), Pure]
42+
public static float Generate([NotNull] Func<float> iidFunc, float location, float scale)
43+
{
44+
return Generate(new FuncGeneratorStruct(iidFunc), location, scale);
45+
}
46+
47+
/// <summary>
48+
/// Generates a random value using <paramref name="iidGenerator"/> as an iid source.
49+
/// </summary>
50+
/// <param name="iidGenerator">
51+
/// Random generator that returns an independent and identically distributed random value in range [0, 1).
52+
/// </param>
53+
/// <param name="location">Location.</param>
54+
/// <param name="scale">Scale. Must be more than 0.</param>
55+
/// <returns>Generated value.</returns>
56+
/// <remarks><paramref name="scale"/> must be more than 0.</remarks>
57+
[Pure]
58+
public static float Generate<T>([NotNull] T iidGenerator, float location, float scale)
59+
where T : IContinuousGenerator
60+
{
61+
float iid = 1f - iidGenerator.Generate();
62+
return location - scale * Mathf.Log(-Mathf.Log(iid));
63+
}
64+
}
65+
}

Runtime/ContinuousDistributions/ExtremeValueDistribution/ExtremeValueDistribution.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/ContinuousDistributions/ExtremeValueDistribution/GeneratorProviders.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Copyright (c) 2020-2023 Vladimir Popov [email protected] https://github.com/ZorPastaman/Random-Generators
2+
3+
using System.Runtime.CompilerServices;
4+
using JetBrains.Annotations;
5+
using UnityEngine;
6+
using Zor.RandomGenerators.PropertyDrawerAttributes;
7+
8+
namespace Zor.RandomGenerators.ContinuousDistributions.GeneratorProviders
9+
{
10+
/// <summary>
11+
/// Provides <see cref="ExtremeValueGeneratorDependent{T}"/>.
12+
/// </summary>
13+
[CreateAssetMenu(
14+
menuName = CreateAssetMenuConstants.ExtremeValueDistributionFolder + "Extreme Value Generator Dependent Provider",
15+
fileName = "ExtremeValueGeneratorDependentProvider",
16+
order = CreateAssetMenuConstants.DistributionOrder
17+
)]
18+
public sealed class ExtremeValueGeneratorDependentProvider : ContinuousGeneratorProvider
19+
{
20+
[SerializeField, Tooltip("Random generator that returns an independent and identically distributed random value in range [0, 1).")]
21+
private ContinuousGeneratorProviderReference m_DependedGeneratorProvider;
22+
[SerializeField] private float m_Location = ExtremeValueDistribution.DefaultLocation;
23+
[SerializeField, SimpleRangeFloat(NumberConstants.NormalEpsilon, float.MaxValue)]
24+
private float m_Scale = ExtremeValueDistribution.DefaultScale;
25+
26+
private ExtremeValueGeneratorDependent<IContinuousGenerator> m_sharedGenerator;
27+
28+
/// <summary>
29+
/// Creates a new <see cref="ExtremeValueGeneratorDependent{T}"/>
30+
/// and returns it as <see cref="IContinuousGenerator"/>.
31+
/// </summary>
32+
public override IContinuousGenerator generator
33+
{
34+
[Pure]
35+
get => extremeValueGenerator;
36+
}
37+
38+
/// <summary>
39+
/// Returns a shared <see cref="ExtremeValueGeneratorDependent{T}"/> as <see cref="IContinuousGenerator"/>.
40+
/// </summary>
41+
public override IContinuousGenerator sharedGenerator => sharedExtremeValueGenerator;
42+
43+
/// <summary>
44+
/// Creates a new <see cref="ExtremeValueGeneratorDependent{T}"/> and returns it.
45+
/// </summary>
46+
[NotNull]
47+
public ExtremeValueGeneratorDependent<IContinuousGenerator> extremeValueGenerator
48+
{
49+
[Pure]
50+
get => new(m_DependedGeneratorProvider.generator, m_Location, m_Scale);
51+
}
52+
53+
/// <summary>
54+
/// Returns a shared <see cref="ExtremeValueGeneratorDependent{T}"/>.
55+
/// </summary>
56+
[NotNull]
57+
public ExtremeValueGeneratorDependent<IContinuousGenerator> sharedExtremeValueGenerator =>
58+
m_sharedGenerator ??= extremeValueGenerator;
59+
60+
/// <summary>
61+
/// Random generator that returns an independent and identically distributed random value in range [0, 1).
62+
/// </summary>
63+
public ContinuousGeneratorProviderReference dependedGeneratorProvider
64+
{
65+
[MethodImpl(MethodImplOptions.AggressiveInlining), Pure]
66+
get => m_DependedGeneratorProvider;
67+
set
68+
{
69+
if (m_DependedGeneratorProvider == value)
70+
{
71+
return;
72+
}
73+
74+
m_DependedGeneratorProvider = value;
75+
m_sharedGenerator = null;
76+
}
77+
}
78+
79+
public float location
80+
{
81+
[MethodImpl(MethodImplOptions.AggressiveInlining), Pure]
82+
get => m_Location;
83+
set
84+
{
85+
if (m_Location == value)
86+
{
87+
return;
88+
}
89+
90+
m_Location = value;
91+
m_sharedGenerator = null;
92+
}
93+
}
94+
95+
/// <remarks>Must be more than 0.</remarks>
96+
public float scale
97+
{
98+
[MethodImpl(MethodImplOptions.AggressiveInlining), Pure]
99+
get => m_Scale;
100+
set
101+
{
102+
if (m_Scale == value)
103+
{
104+
return;
105+
}
106+
107+
m_Scale = value;
108+
m_sharedGenerator = null;
109+
}
110+
}
111+
112+
/// <inheritdoc/>
113+
public override void DropSharedGenerator()
114+
{
115+
m_sharedGenerator = null;
116+
}
117+
118+
private void OnValidate()
119+
{
120+
m_sharedGenerator = null;
121+
}
122+
}
123+
}

Runtime/ContinuousDistributions/ExtremeValueDistribution/GeneratorProviders/ExtremeValueGeneratorDependentProvider.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright (c) 2020-2023 Vladimir Popov [email protected] https://github.com/ZorPastaman/Random-Generators
2+
3+
using System.Runtime.CompilerServices;
4+
using JetBrains.Annotations;
5+
using UnityEngine;
6+
using Zor.RandomGenerators.PropertyDrawerAttributes;
7+
8+
namespace Zor.RandomGenerators.ContinuousDistributions.GeneratorProviders
9+
{
10+
/// <summary>
11+
/// Provides <see cref="ExtremeValueGenerator"/>.
12+
/// </summary>
13+
[CreateAssetMenu(
14+
menuName = CreateAssetMenuConstants.ExtremeValueDistributionFolder + "Extreme Value Generator Provider",
15+
fileName = "ExtremeValueGeneratorProvider",
16+
order = CreateAssetMenuConstants.DistributionOrder
17+
)]
18+
public sealed class ExtremeValueGeneratorProvider : ContinuousGeneratorProvider
19+
{
20+
[SerializeField] private float m_Location = ExtremeValueDistribution.DefaultLocation;
21+
[SerializeField, SimpleRangeFloat(NumberConstants.NormalEpsilon, float.MaxValue)]
22+
private float m_Scale = ExtremeValueDistribution.DefaultScale;
23+
24+
private ExtremeValueGenerator m_sharedGenerator;
25+
26+
/// <summary>
27+
/// Creates a new <see cref="ExtremeValueGenerator"/> and returns it as <see cref="IContinuousGenerator"/>.
28+
/// </summary>
29+
public override IContinuousGenerator generator
30+
{
31+
[Pure]
32+
get => extremeValueGenerator;
33+
}
34+
35+
/// <summary>
36+
/// Returns a shared <see cref="ExtremeValueGenerator"/> as <see cref="IContinuousGenerator"/>.
37+
/// </summary>
38+
public override IContinuousGenerator sharedGenerator => sharedExtremeValueGenerator;
39+
40+
/// <summary>
41+
/// Creates a new <see cref="ExtremeValueGenerator"/> and returns it.
42+
/// </summary>
43+
[NotNull]
44+
public ExtremeValueGenerator extremeValueGenerator
45+
{
46+
[Pure]
47+
get => new ExtremeValueGenerator(m_Location, m_Scale);
48+
}
49+
50+
/// <summary>
51+
/// Returns a shared <see cref="ExtremeValueGeneratorDependent{T}"/>.
52+
/// </summary>
53+
[NotNull]
54+
public ExtremeValueGenerator sharedExtremeValueGenerator => m_sharedGenerator ??= extremeValueGenerator;
55+
56+
public float location
57+
{
58+
[MethodImpl(MethodImplOptions.AggressiveInlining), Pure]
59+
get => m_Location;
60+
set
61+
{
62+
if (m_Location == value)
63+
{
64+
return;
65+
}
66+
67+
m_Location = value;
68+
m_sharedGenerator = null;
69+
}
70+
}
71+
72+
/// <remarks>Must be more than 0.</remarks>
73+
public float scale
74+
{
75+
[MethodImpl(MethodImplOptions.AggressiveInlining), Pure]
76+
get => m_Scale;
77+
set
78+
{
79+
if (m_Scale == value)
80+
{
81+
return;
82+
}
83+
84+
m_Scale = value;
85+
m_sharedGenerator = null;
86+
}
87+
}
88+
89+
/// <inheritdoc/>
90+
public override void DropSharedGenerator()
91+
{
92+
m_sharedGenerator = null;
93+
}
94+
95+
private void OnValidate()
96+
{
97+
m_sharedGenerator = null;
98+
}
99+
}
100+
}

Runtime/ContinuousDistributions/ExtremeValueDistribution/GeneratorProviders/ExtremeValueGeneratorProvider.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/ContinuousDistributions/ExtremeValueDistribution/Generators.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)