Exemple #1
0
        public void TestString()
        {
            using (var vw = new VowpalWabbitExampleValidator <ExampleString>(string.Empty))
            {
                vw.Validate("|abc London", new ExampleString()
                {
                    Location = "London"
                });
                vw.Validate("", new ExampleString()
                {
                });
                vw.Validate("", new ExampleString()
                {
                    Location = ""
                });
            }

            using (var vw = new VowpalWabbitExampleValidator <ExampleString4>(string.Empty))
            {
                vw.Validate("| VideoTitleRich_Homie_Quan_-_\"Blah_Blah_Blah\"___Behind_The_Scenes", new ExampleString4 {
                    Value = "VideoTitleRich Homie Quan - \"Blah Blah Blah\" | Behind The Scenes"
                });
                vw.Validate("| VideoTitleIt's_Official__Your_vibrator_Can_be_Hacked", new ExampleString4 {
                    Value = "VideoTitleIt's Official: Your vibrator Can be Hacked"
                });
            }
        }
 public void TestJsonDirectMulti()
 {
     using (var vw = new VowpalWabbitExampleValidator <JsonShared>(new VowpalWabbitSettings(featureDiscovery: VowpalWabbitFeatureDiscovery.Json)))
     {
         vw.Validate(new[]
         {
             "shared | Ageteen",
             " | Id:1",
             " | Id:2"
         },
                     new JsonShared
         {
             Age       = "teen",
             Documents = new []
             {
                 new JsonADF {
                     Id = 1
                 },
                 new JsonADF {
                     Id = 2
                 }
             }
         });
     }
 }
 public void TestNumericUInt64Overflow()
 {
     using (var vw = new VowpalWabbitExampleValidator<NumericExampleUInt64>(string.Empty))
     {
         vw.Validate("| Value:1.844674E+19", new NumericExampleUInt64() { Value = UInt64.MaxValue});
     }
 }
        public void TestJsonDirect()
        {
            using (var vw = new VowpalWabbitExampleValidator<JsonContext>(new VowpalWabbitSettings(featureDiscovery:VowpalWabbitFeatureDiscovery.Json)))
            {
                vw.Validate("| Clicks:5 |a Bar:1 Age25_old |b Marker", new JsonContext()
                {
                    Ns1 = new Namespace1
                    {
                        Foo = 1,
                        Age = "25 old",
                        DontConsider = "XXX"
                    },
                    Ns2 = new Namespace2
                    {
                        FeatureA = true
                    },
                    Clicks = 5
                });

                vw.Validate("| Clicks:5 |a Bar:1", new JsonContext() {
                    Ns1 = new Namespace1
                    {
                        Foo = 1,
                        DontConsider = "XXX"
                    },
                    Clicks = 5,
                    IgnoreMe = "true"
                });
            }
        }
Exemple #5
0
 public void TestJsonDirectMulti()
 {
     using (var vw = new VowpalWabbitExampleValidator <JsonShared>(new VowpalWabbitSettings("--cb_adf")
     {
         TypeInspector = JsonTypeInspector.Default
     }))
     {
         vw.Validate(new[]
         {
             "shared | Ageteen",
             " | Id:1",
             " | Id:2"
         },
                     new JsonShared
         {
             Age       = "teen",
             Documents = new[]
             {
                 new JsonADF {
                     Id = 1
                 },
                 new JsonADF {
                     Id = 2
                 }
             }
         });
     }
 }
 public void TestStringFeatureGroup()
 {
     using (var vw = new VowpalWabbitExampleValidator<ExampleString2>(string.Empty))
     {
         vw.Validate("|a London", new ExampleString2() { Location = "London" });
     }
 }
Exemple #7
0
        public void Test87()
        {
            using (var vw = new VowpalWabbit <DataString, DataStringADF>("--cb_adf --rank_all"))
                using (var vwSharedValidation = new VowpalWabbitExampleValidator <DataString>("--cb_adf --rank_all"))
                    using (var vwADFValidation = new VowpalWabbitExampleValidator <DataStringADF>("--cb_adf --rank_all"))
                    {
                        var sampleData = CreateSampleCbAdfData();

                        var example = sampleData[0];
                        Validate(vwSharedValidation, vwADFValidation, example);

                        var result = vw.LearnAndPredict(example, example.ActionDependentFeatures, example.SelectedActionIndex, example.Label);
                        ReferenceEquals(example.ActionDependentFeatures[0], result[0]);
                        ReferenceEquals(example.ActionDependentFeatures[1], result[1]);
                        ReferenceEquals(example.ActionDependentFeatures[2], result[2]);

                        example = sampleData[1];
                        Validate(vwSharedValidation, vwADFValidation, example);

                        result = vw.LearnAndPredict(example, example.ActionDependentFeatures, example.SelectedActionIndex, example.Label);
                        ReferenceEquals(example.ActionDependentFeatures[0], result[1]);
                        ReferenceEquals(example.ActionDependentFeatures[1], result[0]);

                        example = sampleData[2];
                        Validate(vwSharedValidation, vwADFValidation, example);

                        result = vw.Predict(example, example.ActionDependentFeatures);

                        ReferenceEquals(example.ActionDependentFeatures[0], result[1]);
                        ReferenceEquals(example.ActionDependentFeatures[1], result[0]);
                    }
        }
 public void TestNumericUInt64OverflowArray()
 {
     using (var vw = new VowpalWabbitExampleValidator<NumericExampleUInt64Array>(string.Empty))
     {
         vw.Validate("| 0:1.844674E+19", new NumericExampleUInt64Array() { Value = new[] { UInt64.MaxValue } });
     }
 }
Exemple #9
0
        public void TestJsonDictionaryStringFloat()
        {
            using (var vw = new VowpalWabbitExampleValidator <POCODict>(new VowpalWabbitSettings {
                TypeInspector = JsonTypeInspector.Default
            }))
            {
                vw.Validate("|Features Feature1:2.1 Feature2:3.2", new POCODict {
                    Features = new Dictionary <string, float> {
                        { "Feature1", 2.1f }, { "Feature2", 3.2f }
                    }
                });
            }

            // test serialzier caching too
            using (var vw = new VowpalWabbitExampleValidator <POCODict>(new VowpalWabbitSettings {
                TypeInspector = TypeInspector.All
            }))
            {
                vw.Validate("| Abc:2.1 def:3.2", new POCODict {
                    Features = new Dictionary <string, float> {
                        { "Abc", 2.1f }, { "def", 3.2f }
                    }
                });
            }
        }
Exemple #10
0
 public void TestJsonDirectMultiEmpty()
 {
     using (var vw = new VowpalWabbitExampleValidator <JsonSharedEmpty>(new VowpalWabbitSettings {
         TypeInspector = JsonTypeInspector.Default
     }))
     {
         vw.Validate(new[]
         {
             " | Id:1",
             " | Id:2"
         },
                     new JsonSharedEmpty
         {
             Age    = "ignored",
             _multi = new[]
             {
                 new JsonADF {
                     Id = 1
                 },
                 new JsonADF {
                     Id = 2
                 }
             }
         });
     }
 }
Exemple #11
0
        public void TestJsonDirect()
        {
            using (var vw = new VowpalWabbitExampleValidator <JsonContext>(new VowpalWabbitSettings {
                TypeInspector = JsonTypeInspector.Default
            }))
            {
                vw.Validate("| Clicks:5 |a Bar:1 Age25_old |b Marker", new JsonContext()
                {
                    Ns1 = new Namespace1
                    {
                        Foo          = 1,
                        Age          = "25 old",
                        DontConsider = "XXX"
                    },
                    Ns2 = new Namespace2
                    {
                        FeatureA = true
                    },
                    Clicks = 5
                });

                vw.Validate("| Clicks:5 |a Bar:1", new JsonContext()
                {
                    Ns1 = new Namespace1
                    {
                        Foo          = 1,
                        DontConsider = "XXX"
                    },
                    Clicks   = 5,
                    IgnoreMe = "true"
                });
            }
        }
 public void TestJsonConvertibleMulti()
 {
     using (var vw = new VowpalWabbitExampleValidator <JsonRawAdfString>(new VowpalWabbitSettings("--cb_adf")
     {
         TypeInspector = JsonTypeInspector.Default
     }))
     {
         vw.Validate(new[] {
             "shared | Bar:5",
             " | Foo:1 |Value test:1.2",
             " | Foo:2 |Value test:2.3",
         },
                     new JsonRawAdfString
         {
             Bar    = 5,
             _multi = new []
             {
                 new JsonRawString
                 {
                     Foo   = 1,
                     Value = JsonConvert.SerializeObject(new { test = 1.2 })
                 },
                 new JsonRawString
                 {
                     Foo   = 2,
                     Value = JsonConvert.SerializeObject(new { test = 2.3 })
                 }
             }
         });
     }
 }
Exemple #13
0
        public void Test87()
        {
            using (var vw = new VowpalWabbit<DataString, DataStringADF>("--cb_adf --rank_all"))
            using (var vwSharedValidation = new VowpalWabbitExampleValidator<DataString>("--cb_adf --rank_all"))
            using (var vwADFValidation = new VowpalWabbitExampleValidator<DataStringADF>("--cb_adf --rank_all"))
            {
                var sampleData = CreateSampleCbAdfData();

                var example = sampleData[0];
                Validate(vwSharedValidation, vwADFValidation, example);

                var result = vw.LearnAndPredict(example, example.ActionDependentFeatures, example.SelectedActionIndex, example.Label);
                ReferenceEquals(example.ActionDependentFeatures[0], result[0]);
                ReferenceEquals(example.ActionDependentFeatures[1], result[1]);
                ReferenceEquals(example.ActionDependentFeatures[2], result[2]);

                example = sampleData[1];
                Validate(vwSharedValidation, vwADFValidation, example);

                result = vw.LearnAndPredict(example, example.ActionDependentFeatures, example.SelectedActionIndex, example.Label);
                ReferenceEquals(example.ActionDependentFeatures[0], result[1]);
                ReferenceEquals(example.ActionDependentFeatures[1], result[0]);

                example = sampleData[2];
                Validate(vwSharedValidation, vwADFValidation, example);

                result = vw.Predict(example, example.ActionDependentFeatures);

                ReferenceEquals(example.ActionDependentFeatures[0], result[1]);
                ReferenceEquals(example.ActionDependentFeatures[1], result[0]);
            }
        }
 public void TestExpansion()
 {
     using (var vw = new VowpalWabbitExampleValidator<ExpansionContext>(string.Empty))
     {
         vw.Validate("| 3:.1 4:.2 5:.3", new ExpansionContext() { Features = new[] { .1f, .2f, .3f }, Offset = 3 });
     }
 }
 public void TestStringSplit()
 {
     using (var vw = new VowpalWabbitExampleValidator<ExampleStringSplit>(string.Empty))
     {
         vw.Validate("| New York State", new ExampleStringSplit() { Value = "New York State" });
     }
 }
        public void TestConfigParsing()
        {
            var str = @"
f1
ns1.f2(FeatureGroup = 'a')
ns1.f3(Namespace = ""a"",Enumerize=true, FeatureGroup = 'g'  )
ns1.f4(Enumerize=true , FeatureGroup ='f', Order=3,AddAnchor=true)
ns1.ns2.f5
            ";

            var schema = ConfigInspector.CreateSchema(typeof(ConfigSample), str, msg => Assert.Fail(msg));

            using (var vw = new VowpalWabbitExampleValidator <ConfigSample>(new VowpalWabbitSettings {
                Schema = schema
            }))
            {
                vw.Validate("| f1:1 f5:5 |a abc |ga f33 |f f44 ",
                            new ConfigSample
                {
                    f1  = 1,
                    ns1 = new ConfigSampleNamespace
                    {
                        f2  = "abc",
                        f3  = 3,
                        f4  = 4,
                        ns2 = new ConfigSampleNamespaceSub
                        {
                            f5 = 5
                        }
                    }
                });
            }
        }
Exemple #17
0
        public void TestJsonConvertibleMulti()
        {
            using (var vw = new VowpalWabbitExampleValidator <JsonRawAdfString>(new VowpalWabbitSettings("--cb_adf")
            {
                TypeInspector = JsonTypeInspector.Default
            }))
            {
                vw.Validate(new[] {
                    "shared | Bar:5",
                    " | Foo:1 |Value test:1.2",
                    " | Foo:2 |Value test:2.3",
                    " | Foo:3 |Value titleabc\"def",
                },
                            new JsonRawAdfString
                {
                    Bar    = 5,
                    _multi = new[]
                    {
                        new JsonRawString
                        {
                            Foo   = 1,
                            Value = JsonConvert.SerializeObject(new { test = 1.2 })
                        },
                        new JsonRawString
                        {
                            Foo   = 2,
                            Value = JsonConvert.SerializeObject(new { test = 2.3 })
                        },
                        new JsonRawString
                        {
                            Foo   = 3,
                            Value = JsonConvert.SerializeObject(new { title = "abc\"def", _ignoreMe = 1 })
                        },
                    }
                });

                var adf = new JsonRawString
                {
                    Foo    = 1,
                    Value  = JsonConvert.SerializeObject(new { A = new { test = 1.2 }, B = new { bar = 2 } }),
                    Values = new[]
                    {
                        JsonConvert.SerializeObject(new { D = new { d = 1.2 } }),
                        JsonConvert.SerializeObject(new { E = new { e = true } }),
                    }.ToList()
                };

                var ctx = new JsonRawAdfString
                {
                    Bar    = 5,
                    _multi = new[] { adf }
                };

                vw.Validate(new[] {
                    "shared | Bar:5",
                    " | Foo:1 |A test:1.2 |B bar:2 |D d:1.2 |E e"
                }, ctx);
            }
        }
 public void TestStringEscape()
 {
     using (var vw = new VowpalWabbitExampleValidator<ExampleStringEscape>(string.Empty))
     {
         vw.Validate("| New_York_State", new ExampleStringEscape() { Value = "New York State" });
         vw.Validate("| new_York_state", new ExampleStringEscape() { Value = "new York state" });
     }
 }
 public void TestNumericDoubleOverflowArray()
 {
     using (var vw = new VowpalWabbitExampleValidator<NumericExampleDoubleArray>(string.Empty))
     {
         vw.Validate("| 0:1.79769313486231570000E+308", new NumericExampleDoubleArray() { Value = new [] { double.MaxValue } });
         vw.Validate("| 0:-1.79769313486231570000E+308", new NumericExampleDoubleArray() { Value = new [] {  double.MinValue } });
     }
 }
 public void TestNumericInt64OverflowArray()
 {
     using (var vw = new VowpalWabbitExampleValidator<NumericExampleInt64Array>(string.Empty))
     {
         vw.Validate("| 0:9.22337203685477580700E+018", new NumericExampleInt64Array() { Value = new [] { Int64.MaxValue } });
         vw.Validate("| 0:-9.22337203685477580700E+018", new NumericExampleInt64Array() { Value = new[] { Int64.MinValue } });
     }
 }
 public void TestEnumerize()
 {
     using(var vw = new VowpalWabbitExampleValidator<ExampleEnum>(string.Empty))
     {
         vw.Validate("| AgeEnumerize25", new ExampleEnum() { AgeEnumerize = 25 });
         vw.Validate("| AgeEnumerize0 AgeNumeric:25", new ExampleEnum() { AgeNumeric = 25 });
         vw.Validate("| AgeEnumerize0 AgeNumeric:23 AgeEnumChild", new ExampleEnum() { AgeNumeric = 23, AgeEnum = Age.Child });
     }
 }
Exemple #22
0
 private void Validate(VowpalWabbitExampleValidator<DataString> vwSharedValidation, VowpalWabbitExampleValidator<DataStringADF> vwADFValidation, DataString example)
 {
     vwSharedValidation.Validate(example.Line, example, SharedLabel.Instance);
     for (int i = 0; i < example.ActionDependentFeatures.Count; i++)
     {
         var adf = example.ActionDependentFeatures[i];
         vwADFValidation.Validate(adf.Line, adf, i == example.SelectedActionIndex ? example.Label : null);
     }
 }
 public void TestFeatureDiscoveryAll()
 {
     using (var vw = new VowpalWabbitExampleValidator <POCO>(new VowpalWabbitSettings(featureDiscovery: VowpalWabbitFeatureDiscovery.All)))
     {
         vw.Validate("| Feature1 Feature2:5", new POCO {
             Feature1 = true, Feature2 = 5
         });
     }
 }
Exemple #24
0
 private void Validate(VowpalWabbitExampleValidator <DataString> vwSharedValidation, VowpalWabbitExampleValidator <DataStringADF> vwADFValidation, DataString example)
 {
     vwSharedValidation.Validate(example.Line, example, SharedLabel.Instance);
     for (int i = 0; i < example.ActionDependentFeatures.Count; i++)
     {
         var adf = example.ActionDependentFeatures[i];
         vwADFValidation.Validate(adf.Line, adf, i == example.SelectedActionIndex ? example.Label : null);
     }
 }
 public void TestString()
 {
     using (var vw = new VowpalWabbitExampleValidator<ExampleString>(string.Empty))
     {
         vw.Validate("|abc London", new ExampleString() { Location = "London" });
         vw.Validate("", new ExampleString() { });
         vw.Validate("", new ExampleString() { Location = "" });
     }
 }
Exemple #26
0
 public void TestJsonByte()
 {
     using (var vw = new VowpalWabbitExampleValidator <JsonContextByte>(new VowpalWabbitSettings(featureDiscovery: VowpalWabbitFeatureDiscovery.Json)))
     {
         vw.Validate("| Feature:25", new JsonContextByte {
             Feature = 25
         });
     }
 }
 public void TestNumericUInt64Overflow()
 {
     using (var vw = new VowpalWabbitExampleValidator <NumericExampleUInt64>(string.Empty))
     {
         vw.Validate("| Value:1.844674E+19", new NumericExampleUInt64()
         {
             Value = UInt64.MaxValue
         });
     }
 }
 public void TestNumericUInt64OverflowArray()
 {
     using (var vw = new VowpalWabbitExampleValidator <NumericExampleUInt64Array>(string.Empty))
     {
         vw.Validate("| 0:1.844674E+19", new NumericExampleUInt64Array()
         {
             Value = new[] { UInt64.MaxValue }
         });
     }
 }
 public void TestExpansion()
 {
     using (var vw = new VowpalWabbitExampleValidator <ExpansionContext>(string.Empty))
     {
         vw.Validate("| 3:.1 4:.2 5:.3", new ExpansionContext()
         {
             Features = new[] { .1f, .2f, .3f }, Offset = 3
         });
     }
 }
 public void TestStringFeatureGroup()
 {
     using (var vw = new VowpalWabbitExampleValidator <ExampleString2>(string.Empty))
     {
         vw.Validate("|a London", new ExampleString2()
         {
             Location = "London"
         });
     }
 }
 public void TestStringSplit()
 {
     using (var vw = new VowpalWabbitExampleValidator <ExampleStringSplit>(string.Empty))
     {
         vw.Validate("| New York State", new ExampleStringSplit()
         {
             Value = "New York State"
         });
     }
 }
 public void TestStringIncludeName()
 {
     using (var vw = new VowpalWabbitExampleValidator <ExampleStringInclude>(string.Empty))
     {
         vw.Validate("| AgeTeenager", new ExampleStringInclude()
         {
             Age = "Teenager"
         });
     }
 }
Exemple #33
0
 public void TestJsonByte()
 {
     using (var vw = new VowpalWabbitExampleValidator <JsonContextByte>(new VowpalWabbitSettings {
         TypeInspector = JsonTypeInspector.Default
     }))
     {
         vw.Validate("| Feature:25", new JsonContextByte {
             Feature = 25
         });
     }
 }
        public void TestEnumerableString()
        {
            using (var vw = new VowpalWabbitExampleValidator <ExampleEnumerable>(string.Empty))
            {
                vw.Validate("| A New_York B", new ExampleEnumerable {
                    Value = new[] { "A", "New_York", "B" }
                });

                vw.Validate("", new ExampleEnumerable());
            }
        }
 public void TestCustomType()
 {
     using (var vw = new VowpalWabbitExampleValidator <ExampleCustomType>(string.Empty))
     {
         vw.Validate("| Custom2", new ExampleCustomType {
             Custom = new CustomType {
                 value = 2
             }
         });
     }
 }
 public void TestBool()
 {
     using (var vw = new VowpalWabbitExampleValidator <ExampleBoolean>(string.Empty))
     {
         vw.Validate("| OnOff", new ExampleBoolean {
             OnOff = true
         });
         vw.Validate("| ", new ExampleBoolean {
             OnOff = false
         });
     }
 }
 public void TestEnumerizePosition()
 {
     using (var vw = new VowpalWabbitExampleValidator <ExampleEnumerize>(string.Empty))
     {
         vw.Validate("| Position0", new ExampleEnumerize {
             Position = 0
         });
         vw.Validate("| Position2", new ExampleEnumerize {
             Position = 2
         });
     }
 }
 public void TestJsonDirectWithLabel()
 {
     using (var vw = new VowpalWabbitExampleValidator<JsonContext>(new VowpalWabbitSettings(featureDiscovery: VowpalWabbitFeatureDiscovery.Json)))
     {
         vw.Validate("13 | Clicks:5 MoreClicks:3", new JsonContext()
         {
             Label = new SimpleLabel { Label = 13 },
             Clicks = 5,
             MoreClicks = 3,
             IgnoreMe2 = "YYY"
         });
     }
 }
Exemple #39
0
 public void TestJsonArray()
 {
     using (var vw = new VowpalWabbitExampleValidator <JsonContextArray>(new VowpalWabbitSettings(featureDiscovery: VowpalWabbitFeatureDiscovery.Json)))
     {
         vw.Validate("1:2:.5 | :.1 :.2 :.3", new JsonContextArray()
         {
             Label = new ContextualBanditLabel {
                 Action = 1, Cost = 2, Probability = .5f
             },
             Data = new[] { .1f, .2f, .3f }
         });
     }
 }
 public void TestNumericDoubleOverflowArray()
 {
     using (var vw = new VowpalWabbitExampleValidator <NumericExampleDoubleArray>(string.Empty))
     {
         vw.Validate("| 0:1.79769313486231570000E+308", new NumericExampleDoubleArray()
         {
             Value = new [] { double.MaxValue }
         });
         vw.Validate("| 0:-1.79769313486231570000E+308", new NumericExampleDoubleArray()
         {
             Value = new [] { double.MinValue }
         });
     }
 }
 public void TestNumericInt64OverflowArray()
 {
     using (var vw = new VowpalWabbitExampleValidator <NumericExampleInt64Array>(string.Empty))
     {
         vw.Validate("| 0:9.22337203685477580700E+018", new NumericExampleInt64Array()
         {
             Value = new [] { Int64.MaxValue }
         });
         vw.Validate("| 0:-9.22337203685477580700E+018", new NumericExampleInt64Array()
         {
             Value = new[] { Int64.MinValue }
         });
     }
 }
 public void TestStringEscape()
 {
     using (var vw = new VowpalWabbitExampleValidator <ExampleStringEscape>(string.Empty))
     {
         vw.Validate("| New_York_State", new ExampleStringEscape()
         {
             Value = "New York State"
         });
         vw.Validate("| new_York_state", new ExampleStringEscape()
         {
             Value = "new York state"
         });
     }
 }
 public void TestJsonOptIn()
 {
     using (var vw = new VowpalWabbitExampleValidator<JsonContextOptIn>(new VowpalWabbitSettings(featureDiscovery: VowpalWabbitFeatureDiscovery.Json)))
     {
         vw.Validate("| Clicked |Ns2 Marker", new JsonContextOptIn()
         {
             Clicked = true,
             IgnoredNamespace = new Namespace1 {  Foo = 3 },
             Ns2 = new Namespace2
             {
                 FeatureA = true
             }
         });
     }
 }
Exemple #44
0
 public void TestJsonDirectWithLabel()
 {
     using (var vw = new VowpalWabbitExampleValidator <JsonContext>(new VowpalWabbitSettings(featureDiscovery: VowpalWabbitFeatureDiscovery.Json)))
     {
         vw.Validate("13 | Clicks:5 MoreClicks:3", new JsonContext()
         {
             Label = new SimpleLabel {
                 Label = 13
             },
             Clicks     = 5,
             MoreClicks = 3,
             IgnoreMe2  = "YYY"
         });
     }
 }
Exemple #45
0
 public void TestJsonArray()
 {
     using (var vw = new VowpalWabbitExampleValidator <JsonContextArray>(new VowpalWabbitSettings {
         TypeInspector = JsonTypeInspector.Default
     }))
     {
         vw.Validate("1:2:.5 |Data :.1 :.2 :.3", new JsonContextArray()
         {
             Label = new ContextualBanditLabel {
                 Action = 1, Cost = 2, Probability = .5f
             },
             Data = new[] { .1f, .2f, .3f }
         });
     }
 }
        public void TestStringNamespace()
        {
            try
            {
                using (var vw = new VowpalWabbitExampleValidator<ExampleString3>(string.Empty))
                {
                    vw.Validate("|bc London", new ExampleString3() { Location = "London" });
                }

                Assert.Fail("Expected ArgumentException");
            }
            catch (ArgumentException)
            {
            }
        }
        public void TestLabels()
        {
            using (var vw = new VowpalWabbitExampleValidator<SimpleContext>(string.Empty))
            {
                vw.Validate("3.2 | Feature:25",
                    new SimpleContext
                    {
                        Feature = 25,
                        Label = new SimpleLabel { Label = 3.2f }
                    });

                vw.Validate("| Feature:25",
                    new SimpleContext
                    {
                        Feature = 25,
                    });
            }
        }
 public void TestJsonByte()
 {
     using (var vw = new VowpalWabbitExampleValidator<JsonContextByte>(new VowpalWabbitSettings(featureDiscovery: VowpalWabbitFeatureDiscovery.Json)))
     {
         vw.Validate("| Feature:25", new JsonContextByte { Feature = 25 });
     }
 }
Exemple #49
0
        public void TestDictionaryUInt16String()
        {
            using(var vw = new VowpalWabbitExampleValidator<DictionaryExampleUInt16String>(string.Empty))
            {
                var example = new DictionaryExampleUInt16String() { Dict = new Dictionary<System.UInt16, string>() };

                example.Dict.Add(15, "0.5");
                example.Dict.Add(5, "0.3");
                example.Dict.Add(20, "123.2");

                vw.Validate("| 15:0.5 5:0.3 20:123.2", example);

                example.Dict = null;
                vw.Validate("", example);
            }
        }
 public void TestJsonArray()
 {
     using (var vw = new VowpalWabbitExampleValidator<JsonContextArray>(new VowpalWabbitSettings(featureDiscovery: VowpalWabbitFeatureDiscovery.Json)))
     {
         vw.Validate("1:2:.5 | :.1 :.2 :.3", new JsonContextArray()
         {
             Label = new ContextualBanditLabel { Action =1 , Cost = 2, Probability = .5f },
             Data = new[] { .1f, .2f, .3f }
         });
     }
 }
 public void TestJsonDirectText()
 {
     using (var vw = new VowpalWabbitExampleValidator<JsonText>(new VowpalWabbitSettings(featureDiscovery: VowpalWabbitFeatureDiscovery.Json)))
     {
         vw.Validate("| a b c |a d e f", new JsonText
         {
             Text = "a b c",
             AuxInfo = "Foo",
             A = new JsonText
             {
                 Text = "d e f",
                 AuxInfo = "Bar"
             }
         });
     }
 }
Exemple #52
0
        public void TestDictionarySByte()
        {
            using(var vw = new VowpalWabbitExampleValidator<DictionaryExampleSByte>(string.Empty))
            {
                var example = new DictionaryExampleSByte() { Dict = new Dictionary<System.SByte, float>() };

                example.Dict.Add(15, .5f);
                example.Dict.Add(5, .3f);
                example.Dict.Add(20, 123.2f);

                vw.Validate("| 15:0.5 5:0.3 20:123.2", example);

                example.Dict = null;
                vw.Validate("", example);
            }
        }
Exemple #53
0
        public void TestDictionaryInt32Int32()
        {
            using(var vw = new VowpalWabbitExampleValidator<DictionaryExampleInt32Int32>(string.Empty))
            {
                var example = new DictionaryExampleInt32Int32() { Dict = new Dictionary<System.Int32, Int32>() };

                example.Dict.Add(15, (Int32)3);
                example.Dict.Add(5, (Int32)4);
                example.Dict.Add(20, (Int32)5);

                vw.Validate("| 15:3 5:4 20:5", example);

                example.Dict = null;
                vw.Validate("", example);
            }
        }
Exemple #54
0
        public void TestDictionarySByteSingle()
        {
            using(var vw = new VowpalWabbitExampleValidator<DictionaryExampleSByteSingle>(string.Empty))
            {
                var example = new DictionaryExampleSByteSingle() { Dict = new Dictionary<System.SByte, Single>() };

                example.Dict.Add(15, (Single)3);
                example.Dict.Add(5, (Single)4);
                example.Dict.Add(20, (Single)5);

                vw.Validate("| 15:3 5:4 20:5", example);

                example.Dict = null;
                vw.Validate("", example);
            }
        }
        public void TestLabelsNoAnnotation()
        {
            using (var vw = new VowpalWabbitExampleValidator<SimpleContextNoAnnotation>(
                new VowpalWabbitSettings(featureDiscovery: VowpalWabbitFeatureDiscovery.All)))
            {
                vw.Validate("3.2 | Feature:25",
                    new SimpleContextNoAnnotation
                    {
                        Feature = 25,
                        Label = new SimpleLabel { Label = 3.2f }
                    });

                vw.Validate("| Feature:25",
                    new SimpleContextNoAnnotation
                    {
                        Feature = 25,
                    });
            }
        }
Exemple #56
0
 public void TestNumericSingleArray()
 {
     using(var vw = new VowpalWabbitExampleValidator<NumericExampleSingleArray>(string.Empty))
     {
         vw.Validate("| :4 :2 :3", new NumericExampleSingleArray() { Value = new System.Single[] { 4, 2, 3 } });
         vw.Validate("", new NumericExampleSingleArray());
     }
 }
Exemple #57
0
 public void TestNumericUInt64()
 {
     using(var vw = new VowpalWabbitExampleValidator<NumericExampleUInt64>(string.Empty))
     {
         vw.Validate("| Value:25", new NumericExampleUInt64() { Value = 25 });
     }
 }
Exemple #58
0
 public void TestNumericUInt64ArrayAnchor()
 {
     using(var vw = new VowpalWabbitExampleValidator<NumericExampleUInt64ArrayAnchor>(string.Empty))
     {
         vw.Validate("| :1 :4 :2 :3", new NumericExampleUInt64ArrayAnchor() { Value = new System.UInt64[] { 4, 2, 3 } });
         vw.Validate("", new NumericExampleUInt64ArrayAnchor());
     }
 }
Exemple #59
0
        public void Test1and2()
        {
            var references = File.ReadAllLines(@"pred-sets\ref\0001.predict").Select(l => float.Parse(l, CultureInfo.InvariantCulture)).ToArray();

            var input = new List<Test1>();

            using (var vwStr = new VowpalWabbit(" -k -c test1and2.str --passes 8 -l 20 --power_t 1 --initial_t 128000  --ngram 3 --skips 1 --invariant --holdout_off"))
            using (var vw = new VowpalWabbit<Test1>(new VowpalWabbitSettings(" -k -c test1and2 --passes 8 -l 20 --power_t 1 --initial_t 128000  --ngram 3 --skips 1 --invariant --holdout_off")
                { EnableExampleCaching = false }))
            using (var vwValidate = new VowpalWabbitExampleValidator<Test1>("-l 20 --power_t 1 --initial_t 128000  --ngram 3 --skips 1 --invariant --holdout_off"))
            {
                var lineNr = 0;
                VWTestHelper.ParseInput(
                    File.OpenRead(@"train-sets\0001.dat"),
                    new MyListener(data =>
                    {
                        input.Add(data);

                        vwValidate.Validate(data.Line, data, data.Label);

                        var expected = vwStr.Learn(data.Line, VowpalWabbitPredictionType.Dynamic);
                        Assert.IsInstanceOfType(expected, typeof(float));
                        var actual = vw.Learn(data, data.Label, VowpalWabbitPredictionType.Scalar);

                        Assert.AreEqual((float)expected, actual, 1e-6, "Learn output differs on line: " + lineNr);

                        lineNr++;
                    }));

                vwStr.RunMultiPass();
                vw.Native.RunMultiPass();

                vwStr.SaveModel("models/str0001.model");
                vw.Native.SaveModel("models/0001.model");

                VWTestHelper.AssertEqual(@"train-sets\ref\0001.stderr", vwStr.PerformanceStatistics);
                VWTestHelper.AssertEqual(@"train-sets\ref\0001.stderr", vw.Native.PerformanceStatistics);
            }

            Assert.AreEqual(input.Count, references.Length);

            using (var vwModel = new VowpalWabbitModel(new VowpalWabbitSettings("-k -t --invariant") { ModelStream = File.OpenRead("models/0001.model") }))
            using (var vwInMemoryShared1 = new VowpalWabbit(new VowpalWabbitSettings { Model = vwModel }))
            using (var vwInMemoryShared2 = new VowpalWabbit<Test1>(new VowpalWabbitSettings { Model = vwModel }))
            using (var vwInMemory = new VowpalWabbit(new VowpalWabbitSettings("-k -t --invariant") { ModelStream = File.OpenRead("models/0001.model") }))
            using (var vwStr = new VowpalWabbit("-k -t -i models/str0001.model --invariant"))
            using (var vwNative = new VowpalWabbit("-k -t -i models/0001.model --invariant"))
            using (var vw = new VowpalWabbit<Test1>("-k -t -i models/0001.model --invariant"))
            using (var vwModel2 = new VowpalWabbitModel("-k -t --invariant -i models/0001.model"))
            using (var vwInMemoryShared3 = new VowpalWabbit<Test1>(new VowpalWabbitSettings { Model = vwModel2 }))
            {
                for (var i = 0; i < input.Count; i++)
                {
                    var actualStr = vwStr.Predict(input[i].Line, VowpalWabbitPredictionType.Scalar);
                    var actualNative = vwNative.Predict(input[i].Line, VowpalWabbitPredictionType.Scalar);
                    var actualInMemory = vwInMemory.Predict(input[i].Line, VowpalWabbitPredictionType.Scalar);

                    var actual = vw.Predict(input[i], VowpalWabbitPredictionType.Scalar, input[i].Label);
                    var actualShared1 = vwInMemoryShared1.Predict(input[i].Line, VowpalWabbitPredictionType.Scalar);
                    var actualShared2 = vwInMemoryShared2.Predict(input[i], VowpalWabbitPredictionType.Scalar, input[i].Label);
                    var actualShared3 = vwInMemoryShared3.Predict(input[i], VowpalWabbitPredictionType.Scalar, input[i].Label);

                    Assert.AreEqual(references[i], actualStr, 1e-5);
                    Assert.AreEqual(references[i], actualNative, 1e-5);
                    Assert.AreEqual(references[i], actualInMemory, 1e-5);
                    Assert.AreEqual(references[i], actual, 1e-5);
                    Assert.AreEqual(references[i], actualShared1, 1e-5);
                    Assert.AreEqual(references[i], actualShared2, 1e-5);
                    Assert.AreEqual(references[i], actualShared3, 1e-5);
                }

                // due to shared usage the counters don't match up
                //VWTestHelper.AssertEqual(@"test-sets\ref\0001.stderr", vwInMemoryShared2.Native.PerformanceStatistics);
                //VWTestHelper.AssertEqual(@"test-sets\ref\0001.stderr", vwInMemoryShared1.PerformanceStatistics);

                VWTestHelper.AssertEqual(@"test-sets\ref\0001.stderr", vwInMemory.PerformanceStatistics);
                VWTestHelper.AssertEqual(@"test-sets\ref\0001.stderr", vwStr.PerformanceStatistics);
                VWTestHelper.AssertEqual(@"test-sets\ref\0001.stderr", vw.Native.PerformanceStatistics);
            }
        }
Exemple #60
0
        public void TestDictionaryUInt16UInt64()
        {
            using(var vw = new VowpalWabbitExampleValidator<DictionaryExampleUInt16UInt64>(string.Empty))
            {
                var example = new DictionaryExampleUInt16UInt64() { Dict = new Dictionary<System.UInt16, UInt64>() };

                example.Dict.Add(15, (UInt64)3);
                example.Dict.Add(5, (UInt64)4);
                example.Dict.Add(20, (UInt64)5);

                vw.Validate("| 15:3 5:4 20:5", example);

                example.Dict = null;
                vw.Validate("", example);
            }
        }