Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleLittleCloud committed Feb 28, 2023
1 parent e1d5c8f commit cb3083b
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override void Write(Utf8JsonWriter writer, UniformNumericOption value, Js
UniformIntOption intOption => new Schema
{
Type = "int",
Default = intOption.SampleFromFeatureSpace(intOption.Default).AsType<double>(),
Default = intOption.SampleFromFeatureSpace(intOption.Default).AsType<int>(),
Min = Convert.ToInt32(intOption.Min),
Max = Convert.ToInt32(intOption.Max),
LogBase = intOption.LogBase,
Expand All @@ -70,7 +70,7 @@ public override void Write(Utf8JsonWriter writer, UniformNumericOption value, Js
UniformSingleOption singleOption => new Schema
{
Type = "float",
Default = singleOption.SampleFromFeatureSpace(singleOption.Default).AsType<double>(),
Default = singleOption.SampleFromFeatureSpace(singleOption.Default).AsType<Single>(),
Min = Convert.ToSingle(singleOption.Min),
Max = Convert.ToSingle(singleOption.Max),
LogBase = singleOption.LogBase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"LearningRate": {
"type": "float",
"default": 1,
"min": 0.0001,
"min": 0.00010,
"max": 1,
"log_base": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
},
"OptimizationTolerance": {
"type": "float",
"default": 0.0001,
"min": 1E-07,
"default": 0.00010,
"min": 0.0000001,
"max": 0.1,
"log_base": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
},
"OptimizationTolerance": {
"type": "float",
"default": 0.0001,
"min": 1E-07,
"default": 0.00010,
"min": 0.0000001,
"max": 0.1,
"log_base": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
},
"OptimizationTolerance": {
"type": "float",
"default": 0.0001,
"min": 1E-07,
"default": 0.00010,
"min": 0.0000001,
"max": 0.1,
"log_base": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@
},
"LambdaW": {
"type": "float",
"default": 0.0001,
"min": 0.0001,
"default": 0.00010,
"min": 0.00010,
"max": 1,
"log_base": true
},
"LambdaTheta": {
"type": "float",
"default": 0.0001,
"min": 0.0001,
"default": 0.00010,
"min": 0.00010,
"max": 1,
"log_base": true
},
"LambdaThetaprime": {
"type": "float",
"default": 0.0001,
"min": 0.0001,
"default": 0.00010,
"min": 0.00010,
"max": 1,
"log_base": true
},
"Sigma": {
"type": "float",
"default": 0.0001,
"min": 0.0001,
"default": 0.00010,
"min": 0.00010,
"max": 1,
"log_base": true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Lambda": {
"type": "float",
"default": 0.0001,
"min": 1E-06,
"default": 0.00010,
"min": 0.0000010,
"max": 1,
"log_base": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"LearningRate": {
"type": "float",
"default": 1,
"min": 0.0001,
"min": 0.00010,
"max": 1,
"log_base": true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"L2Regularization": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 32768,
"log_base": true
},
"L1Regularization": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 32768,
"log_base": true
},
"ConvergenceTolerance": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 1,
"log_base": true
},
Expand All @@ -29,8 +29,8 @@
},
"BiasLearningRate": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 1,
"log_base": true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"L2Regularization": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 32768,
"log_base": true
},
"L1Regularization": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 32768,
"log_base": true
},
"ConvergenceTolerance": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 1,
"log_base": true
},
Expand All @@ -29,8 +29,8 @@
},
"BiasLearningRate": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 1,
"log_base": true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"L2Regularization": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 32768,
"log_base": true
},
"L1Regularization": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 32768,
"log_base": true
},
"ConvergenceTolerance": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 1,
"log_base": true
},
Expand All @@ -29,8 +29,8 @@
},
"BiasLearningRate": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 1,
"log_base": true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"L2Regularization": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 32768,
"log_base": true
},
"L1Regularization": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 32768,
"log_base": true
},
"ConvergenceTolerance": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 1,
"log_base": true
},
Expand All @@ -29,8 +29,8 @@
},
"BiasLearningRate": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 1,
"log_base": true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"L2Regularization": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 32768,
"log_base": true
},
"L1Regularization": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 32768,
"log_base": true
},
"ConvergenceTolerance": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 1,
"log_base": true
},
Expand All @@ -29,8 +29,8 @@
},
"BiasLearningRate": {
"type": "float",
"default": 1E-07,
"min": 1E-07,
"default": 0.0000001,
"min": 0.0000001,
"max": 1,
"log_base": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"ConvergenceTolerance": {
"type": "double",
"default": 0.1,
"min": 1E-06,
"min": 0.000001,
"max": 0.1,
"log_base": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"ConvergenceTolerance": {
"type": "double",
"default": 0.1,
"min": 1E-06,
"min": 0.000001,
"max": 0.1,
"log_base": true
},
Expand Down
26 changes: 26 additions & 0 deletions test/Microsoft.ML.SearchSpace.Tests/SearchSpaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Buffers.Text;
using System.Buffers;
using System.Text.Json;
using System.Text.Json.Serialization;
using ApprovalTests;
Expand All @@ -29,6 +31,8 @@ public class SearchSpaceTest : TestBase
public SearchSpaceTest(ITestOutputHelper output)
: base(output)
{
_settings.Converters.Add(new DoubleConverter());
_settings.Converters.Add(new SingleConverter());
}

[Fact]
Expand Down Expand Up @@ -357,5 +361,27 @@ private class NestSearchSpace
[Range(-1000.0f, 1000, init: 0)]
public float UniformFloat { get; set; }
}

class DoubleConverter : JsonConverter<double>
{
public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
=> Convert.ToDouble(reader.GetDecimal());

public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options)
{
writer.WriteNumberValue(Math.Round(Convert.ToDecimal(value), 6));
}
}

class SingleConverter : JsonConverter<float>
{
public override float Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
=> Convert.ToSingle(reader.GetDecimal());

public override void Write(Utf8JsonWriter writer, float value, JsonSerializerOptions options)
{
writer.WriteNumberValue(Convert.ToDecimal(value));
}
}
}
}

0 comments on commit cb3083b

Please sign in to comment.