当前位置: 首页>>代码示例>>C#>>正文


C# VowpalWabbit.ReadExample方法代码示例

本文整理汇总了C#中VowpalWabbit.ReadExample方法的典型用法代码示例。如果您正苦于以下问题:C# VowpalWabbit.ReadExample方法的具体用法?C# VowpalWabbit.ReadExample怎么用?C# VowpalWabbit.ReadExample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VowpalWabbit的用法示例。


在下文中一共展示了VowpalWabbit.ReadExample方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test9

        public void Test9()
        {
            var sampleData = TrainSetCs_testLdf.CreateSampleCbAdfData();

            //            # Test 9: label-dependent features with csoaa_ldf
            //{VW} -k -c -d train-sets/cs_test.ldf -p cs_test.ldf.csoaa.predict --passes 10 --invariant --csoaa_ldf multiline --holdout_off
            //    train-sets/ref/cs_test.ldf.csoaa.stderr
            //    train-sets/ref/cs_test.ldf.csoaa.predict
            using (var vw = new VowpalWabbit<Cs_TestData>("-k -c -p cs_test.ldf.csoaa.predict --passes 10 --invariant --csoaa_ldf multiline --holdout_off"))
            {
                foreach (var d in sampleData)
                {
                    using (var ex = vw.ReadExample(d))
                    {
                        ex.Learn();
                    }
                }

                vw.RunMultiPass();

                VWTestHelper.AssertEqual(@"train-sets\ref\cs_test.ldf.csoaa.stderr", vw.PerformanceStatistics);
            }

            Assert.AreEqual(
                File.ReadAllText(@"train-sets\ref\cs_test.ldf.csoaa.predict"),
                File.ReadAllText("cs_test.ldf.csoaa.predict"));
        }
开发者ID:qingqingqing,项目名称:vowpal_wabbit,代码行数:27,代码来源:Test3.cs

示例2: TestExampleCache

        public void TestExampleCache()
        {
            var random = new Random(123);
            var examples = new List<CachedData>();

            for (int i = 0; i < 1000; i++)
            {
                examples.Add(new CachedData
                {
                    Label = new SimpleLabel { Label = 1 },
                    Feature = random.NextDouble()
                });
            }

            for (int i = 0; i < 1000; i++)
            {
                var cachedData = new CachedData
                {
                    Label = new SimpleLabel { Label = 2 },
                    Feature = 10 + random.NextDouble()
                };

                examples.Add(cachedData);
                examples.Add(cachedData);
            }

            using (var vw = new VowpalWabbit<CachedData>("-k -c --passes 10", new VowpalWabbitSerializerSettings
            {
                EnableExampleCaching = false
            }))
            {
                foreach (var example in examples)
                {
                    using (var vwExample = vw.ReadExample(example))
                    {
                        vwExample.Learn();
                    }
                }

                vw.RunMultiPass();
                vw.SaveModel("model1");
            }

            using (var vwModel = new VowpalWabbitModel("-t", File.OpenRead("model1")))
            using (var vwCached = new VowpalWabbit<CachedData>(vwModel, new VowpalWabbitSerializerSettings { EnableExampleCaching = true, MaxExampleCacheSize = 5 }))
            using (var vw = new VowpalWabbit<CachedData>(vwModel, new VowpalWabbitSerializerSettings { EnableExampleCaching = false }))
            {
                foreach (var example in examples)
                {
                    using (var vwCachedExample = vwCached.ReadExample(example))
                    using (var vwExample = vw.ReadExample(example))
                    {
                        var cachedPrediction = vwCachedExample.Predict<VowpalWabbitScalarPrediction>();
                        var prediction = vwExample.Predict<VowpalWabbitScalarPrediction>();

                        Assert.AreEqual(prediction.Value, cachedPrediction.Value);
                        Assert.AreEqual(example.Label.Label, Math.Round(prediction.Value));
                    }
                }
            }
        }
开发者ID:qingqingqing,项目名称:vowpal_wabbit,代码行数:61,代码来源:TestExampleCache.cs

示例3: TestExampleCacheDisabledForLearning

 public void TestExampleCacheDisabledForLearning()
 {
     using (var vw = new VowpalWabbit<CachedData>(string.Empty, new VowpalWabbitSerializerSettings
         {
             EnableExampleCaching = false
         }))
     {
         using (var example = vw.ReadExample(new CachedData()))
         {
             example.Learn();
         }
     }
 }
开发者ID:qingqingqing,项目名称:vowpal_wabbit,代码行数:13,代码来源:TestExampleCache.cs

示例4: TestExampleCacheForLearning

 public void TestExampleCacheForLearning()
 {
     using (var vw = new VowpalWabbit<CachedData>(string.Empty))
     {
         using (var example = vw.ReadExample(new CachedData()))
         {
             example.Learn();
         }
     }
 }
开发者ID:qingqingqing,项目名称:vowpal_wabbit,代码行数:10,代码来源:TestExampleCache.cs

示例5: Test1and2

        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>(" -k -c test1and2 --passes 8 -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);

                        var expected = vwStr.Learn<VowpalWabbitScalarPrediction>(data.Line);

                        using (var example = vw.ReadExample(data))
                        {
                            var actual = example.LearnAndPredict<VowpalWabbitScalarPrediction>();

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

                        lineNr++;
                    }));

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

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

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

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

            using (var vwModel = new VowpalWabbitModel("-k -t --invariant", File.OpenRead("models/0001.model")))
            using (var vwInMemoryShared1 = new VowpalWabbit(vwModel))
            using (var vwInMemoryShared2 = new VowpalWabbit<Test1>(vwModel))
            using (var vwInMemory = new VowpalWabbit("-k -t --invariant", File.OpenRead("models/0001.model")))
            using (var vwStr = new VowpalWabbit("-k -t -i models/str0001.model --invariant"))
            using (var vw = new VowpalWabbit<Test1>("-k -t -i models/0001.model --invariant"))
            {
                for (var i = 0; i < input.Count; i++)
                {
                    var actualStr = vwStr.Predict<VowpalWabbitScalarPrediction>(input[i].Line);
                    var actualShared1 = vwInMemoryShared1.Predict<VowpalWabbitScalarPrediction>(input[i].Line);
                    var actualInMemory = vwInMemory.Predict<VowpalWabbitScalarPrediction>(input[i].Line);

                    using (var example = vw.ReadExample(input[i]))
                    using (var exampleInMemory2 = vwInMemoryShared2.ReadExample(input[i]))
                    {
                        var actual = example.Predict<VowpalWabbitScalarPrediction>();
                        var actualShared2 = exampleInMemory2.Predict<VowpalWabbitScalarPrediction>();

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

                // VWTestHelper.AssertEqual(@"test-sets\ref\0001.stderr", vwInMemoryShared2.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.PerformanceStatistics);
            }
        }
开发者ID:keisks,项目名称:vowpal_wabbit,代码行数:74,代码来源:Test1and2.cs


注:本文中的VowpalWabbit.ReadExample方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。