@@ -31,7 +31,7 @@ public UniformNumericOption(double min, double max, bool logBase = false)
31
31
32
32
public override int ? [ ] Step => new int ? [ ] { null } ;
33
33
34
- public override double [ ] MappingToFeatureSpace ( Parameter param )
34
+ public override double [ ] MappingToFeatureSpace ( IParameter param )
35
35
{
36
36
var x = param . AsType < double > ( ) ;
37
37
Contract . Requires ( x <= this . Max && x >= this . Min , $ "{ x } is not within [{ this . Min } , { this . Max } ]") ;
@@ -49,20 +49,21 @@ public override double[] MappingToFeatureSpace(Parameter param)
49
49
}
50
50
}
51
51
52
- public override Parameter SampleFromFeatureSpace ( double [ ] values )
52
+ public override IParameter SampleFromFeatureSpace ( double [ ] values )
53
53
{
54
54
Contract . Requires ( values . Length == 1 , "values length must be 1" ) ;
55
55
var value = values [ 0 ] ;
56
56
Contract . Requires ( value <= 1 && value >= 0 , $ "{ value } must be between [0,1]") ;
57
57
58
58
if ( this . LogBase )
59
59
{
60
- var order = Math . Log ( this . Min ) + Math . Log ( this . Max / this . Min ) * value ;
61
- return new Parameter ( Math . Exp ( order ) ) ;
60
+ var order = Math . Pow ( this . Max / this . Min , value ) ;
61
+ var res = this . Min * order ;
62
+ return Parameter . FromDouble ( res ) ;
62
63
}
63
64
else
64
65
{
65
- return new Parameter ( ( this . Min + ( this . Max - this . Min ) * value ) ) ;
66
+ return Parameter . FromDouble ( ( this . Min + ( this . Max - this . Min ) * value ) ) ;
66
67
}
67
68
}
68
69
}
@@ -74,7 +75,7 @@ public UniformDoubleOption(double min, double max, bool logBase = false, double?
74
75
{
75
76
if ( defaultValue != null )
76
77
{
77
- this . Default = this . MappingToFeatureSpace ( new Parameter ( defaultValue ) ) ;
78
+ this . Default = this . MappingToFeatureSpace ( Parameter . FromDouble ( defaultValue . Value ) ) ;
78
79
}
79
80
}
80
81
}
@@ -86,22 +87,22 @@ public UniformSingleOption(float min, float max, bool logBase = false, float? de
86
87
{
87
88
if ( defaultValue != null )
88
89
{
89
- this . Default = this . MappingToFeatureSpace ( new Parameter ( defaultValue ) ) ;
90
+ this . Default = this . MappingToFeatureSpace ( Parameter . FromFloat ( defaultValue . Value ) ) ;
90
91
}
91
92
}
92
93
93
- public override double [ ] MappingToFeatureSpace ( Parameter param )
94
+ public override double [ ] MappingToFeatureSpace ( IParameter param )
94
95
{
95
96
var singleValue = param . AsType < float > ( ) ;
96
97
var doubleValue = Convert . ToDouble ( singleValue ) ;
97
- return base . MappingToFeatureSpace ( new Parameter ( doubleValue ) ) ;
98
+ return base . MappingToFeatureSpace ( Parameter . FromDouble ( doubleValue ) ) ;
98
99
}
99
100
100
- public override Parameter SampleFromFeatureSpace ( double [ ] values )
101
+ public override IParameter SampleFromFeatureSpace ( double [ ] values )
101
102
{
102
103
var doubleValue = base . SampleFromFeatureSpace ( values ) . AsType < double > ( ) ;
103
104
var singleValue = Convert . ToSingle ( doubleValue ) ;
104
- return new Parameter ( singleValue ) ;
105
+ return Parameter . FromFloat ( singleValue ) ;
105
106
}
106
107
}
107
108
@@ -112,23 +113,23 @@ public UniformIntOption(int min, int max, bool logBase = false, int? defaultValu
112
113
{
113
114
if ( defaultValue != null )
114
115
{
115
- this . Default = this . MappingToFeatureSpace ( new Parameter ( defaultValue ) ) ;
116
+ this . Default = this . MappingToFeatureSpace ( Parameter . FromInt ( defaultValue . Value ) ) ;
116
117
}
117
118
}
118
119
119
- public override Parameter SampleFromFeatureSpace ( double [ ] values )
120
+ public override IParameter SampleFromFeatureSpace ( double [ ] values )
120
121
{
121
122
var param = base . SampleFromFeatureSpace ( values ) ;
122
123
var intValue = Convert . ToInt32 ( Math . Floor ( param . AsType < double > ( ) + 1e-6 ) ) ;
123
124
124
- return new Parameter ( intValue ) ;
125
+ return Parameter . FromInt ( intValue ) ;
125
126
}
126
127
127
- public override double [ ] MappingToFeatureSpace ( Parameter param )
128
+ public override double [ ] MappingToFeatureSpace ( IParameter param )
128
129
{
129
130
var value = param . AsType < int > ( ) ;
130
131
var valueAsDouble = Convert . ToDouble ( value ) ;
131
- return base . MappingToFeatureSpace ( new Parameter ( valueAsDouble ) ) ;
132
+ return base . MappingToFeatureSpace ( Parameter . FromDouble ( valueAsDouble ) ) ;
132
133
}
133
134
}
134
135
}
0 commit comments