@@ -10,26 +10,6 @@ namespace Microsoft.ML.Auto
10
10
{
11
11
internal sealed class SweeperProbabilityUtils
12
12
{
13
- public SweeperProbabilityUtils ( )
14
- {
15
- }
16
-
17
- public static double Sum ( double [ ] a )
18
- {
19
- double total = 0 ;
20
- foreach ( double d in a )
21
- total += d ;
22
- return total ;
23
- }
24
-
25
- public static double NormalCdf ( double x , double mean , double variance )
26
- {
27
- double centered = x - mean ;
28
- double ztrans = centered / ( Math . Sqrt ( variance ) * Math . Sqrt ( 2 ) ) ;
29
-
30
- return 0.5 * ( 1 + ProbabilityFunctions . Erf ( ztrans ) ) ;
31
- }
32
-
33
13
public static double StdNormalPdf ( double x )
34
14
{
35
15
return 1 / Math . Sqrt ( 2 * Math . PI ) * Math . Exp ( - Math . Pow ( x , 2 ) / 2 ) ;
@@ -63,45 +43,6 @@ public double[] NormalRVs(int numRVs, double mu, double sigma)
63
43
return rvs . ToArray ( ) ;
64
44
}
65
45
66
- /// <summary>
67
- /// This performs (slow) roulette-wheel sampling of a categorical distribution. Should be swapped for other
68
- /// method as soon as one is available.
69
- /// </summary>
70
- /// <param name="numSamples">Number of samples to draw.</param>
71
- /// <param name="weights">Weights for distribution (should sum to 1).</param>
72
- /// <returns>A set of indicies indicating which element was chosen for each sample.</returns>
73
- public int [ ] SampleCategoricalDistribution ( int numSamples , double [ ] weights )
74
- {
75
- // Normalize weights if necessary.
76
- double total = Sum ( weights ) ;
77
- if ( Math . Abs ( 1.0 - total ) > 0.0001 )
78
- weights = Normalize ( weights ) ;
79
-
80
- // Build roulette wheel.
81
- double [ ] rw = new double [ weights . Length ] ;
82
- double cs = 0.0 ;
83
- for ( int i = 0 ; i < weights . Length ; i ++ )
84
- {
85
- cs += weights [ i ] ;
86
- rw [ i ] = cs ;
87
- }
88
-
89
- // Draw samples.
90
- int [ ] results = new int [ numSamples ] ;
91
- for ( int i = 0 ; i < results . Length ; i ++ )
92
- {
93
- double u = AutoMlUtils . Random . NextDouble ( ) ;
94
- results [ i ] = BinarySearch ( rw , u , 0 , rw . Length - 1 ) ;
95
- }
96
-
97
- return results ;
98
- }
99
-
100
- public double SampleUniform ( )
101
- {
102
- return AutoMlUtils . Random . NextDouble ( ) ;
103
- }
104
-
105
46
/// <summary>
106
47
/// Simple binary search method for finding smallest index in array where value
107
48
/// meets or exceeds what you're looking for.
@@ -120,36 +61,6 @@ private int BinarySearch(double[] a, double u, int low, int high)
120
61
return a [ mid ] >= u ? BinarySearch ( a , u , low , mid ) : BinarySearch ( a , u , mid , high ) ;
121
62
}
122
63
123
- public static double [ ] Normalize ( double [ ] weights )
124
- {
125
- double total = Sum ( weights ) ;
126
-
127
- // If all weights equal zero, set to 1 (to avoid divide by zero).
128
- if ( total <= Double . Epsilon )
129
- {
130
- Console . WriteLine ( $ "{ total } { Double . Epsilon } ") ;
131
- for ( var i = 0 ; i < weights . Length ; i ++ )
132
- {
133
- weights [ i ] = 1 ;
134
- }
135
- total = weights . Length ;
136
- }
137
-
138
- for ( int i = 0 ; i < weights . Length ; i ++ )
139
- weights [ i ] /= total ;
140
- return weights ;
141
- }
142
-
143
- public static double [ ] InverseNormalize ( double [ ] weights )
144
- {
145
- weights = Normalize ( weights ) ;
146
-
147
- for ( int i = 0 ; i < weights . Length ; i ++ )
148
- weights [ i ] = 1 - weights [ i ] ;
149
-
150
- return Normalize ( weights ) ;
151
- }
152
-
153
64
public static Float [ ] ParameterSetAsFloatArray ( IValueGenerator [ ] sweepParams , ParameterSet ps , bool expandCategoricals = true )
154
65
{
155
66
AutoMlUtils . Assert ( ps . Count == sweepParams . Length ) ;
0 commit comments