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


C# VowpalWabbit.RunMultiPass方法代码示例

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


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

示例1: ExecuteTest

        public static void ExecuteTest(int testCaseNr, string args, string input, string stderr, string predictFile)
        {
            using (var vw = new VowpalWabbit(args))
            {
                var multiline = IsMultilineData(input);
                using (var streamReader = Open(input))
                {
                    if (multiline)
                    {
                        var lines = new List<string>();

                        string dataLine;
                        while ((dataLine = streamReader.ReadLine()) != null)
                        {
                            if (string.IsNullOrWhiteSpace(dataLine))
                            {
                                if (lines.Count > 0)
                                {
                                    if (args.Contains("-t")) // test only
                                        vw.Predict(lines);
                                    else
                                        vw.Learn(lines);
                                }

                                lines.Clear();
                                continue;
                            }

                            lines.Add(dataLine);
                        }
                    }
                    else
                    {
                        string dataLine;
                        while ((dataLine = streamReader.ReadLine()) != null)
                        {
                            if (!string.IsNullOrWhiteSpace(predictFile) && File.Exists(predictFile))
                            {
                                float actualValue;
                                if (args.Contains("-t")) // test only
                                    actualValue = vw.Predict(dataLine, VowpalWabbitPredictionType.Scalar);
                                else
                                    actualValue = vw.Learn(dataLine, VowpalWabbitPredictionType.Scalar);
                            }
                            else
                                vw.Learn(dataLine);
                        }
                    }

                    if (vw.Arguments.NumPasses > 1)
                        vw.RunMultiPass();
                    else
                        vw.EndOfPass();

                    if (!string.IsNullOrWhiteSpace(stderr) && File.Exists(stderr))
                        VWTestHelper.AssertEqual(stderr, vw.PerformanceStatistics);
                }
            }
        }
开发者ID:danmelamed,项目名称:vowpal_wabbit,代码行数:59,代码来源:RunTestsHelper.cs

示例2: 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>(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);
            }
        }
开发者ID:gramhagen,项目名称:vowpal_wabbit,代码行数:80,代码来源:Test1and2.cs

示例3: RunAllTest


//.........这里部分代码省略.........
                    ExtractArgument(argsBuilder, @"-p\s+(\S+)");

                    var model = ExtractArgument(argsBuilder, @"-f\s+(\S+)");
                    var multiPass = args.Contains("--passes");

                    List<float> expectedPredictions = null;
                    if (File.Exists(predict))
                    {
                        expectedPredictions = File.ReadLines(predict)
                            .Select(l => float.Parse(l.Split(' ')[0], CultureInfo.InvariantCulture))
                            .ToList();
                    }
                    else
                    {
                        if (testing)
                        {
                            Console.WriteLine("Skipping inconsistent test -t without .predict file");
                            Reset();
                            continue;
                        }
                    }

                    Console.WriteLine("Running test {0}: {1} using {2}", nr, comment, argsBuilder);

                    var lineNr = 0;
                    // TODO: check for -p predict
                    // TODO: need to check which prediction label it will be
                    using (var vw = new VowpalWabbit(argsBuilder.ToString()))
                    {
                        foreach (var dataLine in File.ReadLines(dataFile))
                        {
                            if (expectedPredictions != null)
                            {
                                var expectedValue = expectedPredictions[lineNr++];

                                float actualValue;
                                if (testing)
                                {
                                    actualValue = vw.Predict(dataLine, VowpalWabbitPredictionType.Scalar);
                                }
                                else
                                {
                                    actualValue = vw.Learn(dataLine, VowpalWabbitPredictionType.Scalar);
                                }

                                //Assert.AreEqual(
                                //    expectedValue,
                                //    actualValue,
                                //    1e-5,
                                //    string.Format("Test {0}", nr));
                            }
                            else
                            {
                                vw.Learn(dataLine);
                            }
                        }

                        if (multiPass)
                        {
                            vw.RunMultiPass();
                        }

                        if (model != null)
                        {
                            vw.SaveModel(model);
                        }

                        VWTestHelper.AssertEqual(stderr, vw.PerformanceStatistics);
                    }

                    // reset
                    Reset();
                }
                else if ((match = Regex.Match(line, @"^# Test (?<nr>\d+):(?<comment>.*)?$")).Success)
                {
                    nr = match.Groups["nr"].Value;
                    comment = match.Groups["comment"].Value;
                }
                else if ((match = Regex.Match(line, @"^\{VW\} (?<args>.*)$")).Success)
                {
                    args = match.Groups["args"].Value;
                }
                else if (line.EndsWith(".stdout"))
                {
                    stderr = line.Trim();
                }
                else if (line.EndsWith(".stderr"))
                {
                    stderr = line.Trim();
                }
                else if (line.EndsWith(".predict"))
                {
                    predict = line.Trim();
                }
                else if (line.StartsWith("#") && line.Contains("SkipC#"))
                {
                    skipTest = true;
                }
            }
        }
开发者ID:nguyenhailong,项目名称:vowpal_wabbit,代码行数:101,代码来源:RunTests.cs

示例4: 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

示例5: 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

示例6: ExecuteTest

        public static void ExecuteTest(int testCaseNr, string args, string input, string stderr, string predictFile)
        {
            using (var vw = new VowpalWabbit(args))
            {
                var multiline = IsMultilineData(input);
                using (var streamReader = Open(input))
                {
                    if (multiline)
                    {
                        var lines = new List<string>();

                        string dataLine;
                        while ((dataLine = streamReader.ReadLine()) != null)
                        {
                            if (string.IsNullOrWhiteSpace(dataLine))
                            {
                                if (lines.Count > 0)
                                {
                                    if (args.Contains("-t")) // test only
                                        vw.Predict(lines);
                                    else
                                        vw.Learn(lines);
                                }

                                lines.Clear();
                                continue;
                            }

                            lines.Add(dataLine);
                        }
                    }
                    else
                    {
                        int lineNr = 0;
                        string[] predictions = null;
                        if (File.Exists(predictFile))
                            predictions = File.ReadAllLines(predictFile);

                        string dataLine;
                        while ((dataLine = streamReader.ReadLine()) != null)
                        {
                            if (!string.IsNullOrWhiteSpace(predictFile) && File.Exists(predictFile))
                            {
                                object actualValue;
                                if (args.Contains("-t")) // test only
                                    actualValue = vw.Predict(dataLine, VowpalWabbitPredictionType.Dynamic);
                                else
                                    actualValue = vw.Learn(dataLine, VowpalWabbitPredictionType.Dynamic);

                                if (predictions != null)
                                {
                                    // validate predictions
                                    var actualFloat = actualValue as float?;
                                    if (actualFloat != null)
                                    {
                                        var expectedPrediction = float.Parse(predictions[lineNr].Split(' ').First(), CultureInfo.InvariantCulture);
                                        VWTestHelper.FuzzyEqual(expectedPrediction, (float)actualFloat, 1e-4, "Prediction mismatch");
                                    }

                                    var actualScalar = actualValue as VowpalWabbitScalar?;
                                    if (actualScalar != null)
                                    {
                                        var expectedPredictions = predictions[lineNr]
                                            .Split(' ')
                                            .Select(field => float.Parse(field, CultureInfo.InvariantCulture))
                                            .ToArray();

                                        Assert.AreEqual(2, expectedPredictions.Length);
                                        VWTestHelper.FuzzyEqual(expectedPredictions[0], actualScalar.Value.Value, 1e-4, "Prediction value mismatch");
                                        VWTestHelper.FuzzyEqual(expectedPredictions[1], actualScalar.Value.Confidence, 1e-4, "Prediction confidence mismatch");
                                    }
                                }
                            }
                            else
                                vw.Learn(dataLine);

                            lineNr++;
                        }
                    }

                    if (vw.Arguments.NumPasses > 1)
                        vw.RunMultiPass();
                    else
                        vw.EndOfPass();

                    if (!string.IsNullOrWhiteSpace(stderr) && File.Exists(stderr))
                        VWTestHelper.AssertEqual(stderr, vw.PerformanceStatistics);
                }
            }
        }
开发者ID:gramhagen,项目名称:vowpal_wabbit,代码行数:90,代码来源:RunTestsHelper.cs

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