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


C# VowpalWabbit.SaveModel方法代码示例

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


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

示例1: TestID

        public void TestID()
        {
            using (var vw = new VowpalWabbit("--id abc"))
            {
                Assert.AreEqual("abc", vw.ID);

                vw.SaveModel("model");

                vw.ID = "def";
                vw.SaveModel("model.1");
            }

            using (var vw = new VowpalWabbit("-i model"))
            {
                Assert.AreEqual("abc", vw.ID);
            }

            using (var vw = new VowpalWabbit("-i model.1"))
            {
                Assert.AreEqual("def", vw.ID);
            }

            using (var vwm = new VowpalWabbitModel("-i model.1"))
            {
                Assert.AreEqual("def", vwm.ID);
                using (var vw = new VowpalWabbit(new VowpalWabbitSettings(model: vwm)))
                {
                    Assert.AreEqual("def", vw.ID);
                    Assert.AreEqual(vwm.ID, vw.ID);
                }
            }
        }
开发者ID:adgaudio,项目名称:vowpal_wabbit,代码行数:32,代码来源:TestModelLoading.cs

示例2: TestArguments

        public void TestArguments()
        {
            using (var vw = new VowpalWabbit(new VowpalWabbitSettings("--cb_explore_adf --epsilon 0.3 --interact ud") { Verbose = true }))
            {
                // --cb_explore_adf --epsilon 0.3 --interact ud --cb_adf--csoaa_ldf multiline --csoaa_rank
                Console.WriteLine(vw.Arguments.CommandLine);
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--cb_explore_adf"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--epsilon 0.3"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--interact ud"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--csoaa_ldf multiline"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--csoaa_rank"));
                vw.SaveModel("args.model");
            }

            using (var vw = new VowpalWabbit(new VowpalWabbitSettings { ModelStream = File.Open("args.model", FileMode.Open) }))
            {
                Console.WriteLine(vw.Arguments.CommandLine);
                // --no_stdin--bit_precision 18--cb_explore_adf--epsilon 0.300000--cb_adf--cb_type ips --csoaa_ldf multiline--csoaa_rank--interact ud

                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--no_stdin"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--bit_precision 18"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--cb_explore_adf"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--epsilon 0.3"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--interact ud"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--csoaa_ldf multiline"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--csoaa_rank"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--cb_type ips"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--csoaa_ldf multiline"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--interact ud"));
                Assert.IsTrue(vw.Arguments.CommandLine.Contains("--csoaa_rank"));
            }
        }
开发者ID:arielf,项目名称:vowpal_wabbit,代码行数:32,代码来源:TestArguments.cs

示例3: BasicExample

        public void BasicExample()
        {
            using (var vw = new VowpalWabbit("--quiet"))
            {
                vw.Learn("1 |f 13:3.9656971e-02 24:3.4781646e-02 69:4.6296168e-02");

                var prediction = vw.Predict("|f 13:3.9656971e-02 24:3.4781646e-02 69:4.6296168e-02", VowpalWabbitPredictionType.Scalar);
                vw.SaveModel("output.model");
            }
        }
开发者ID:XkhldY,项目名称:vowpal_wabbit,代码行数:10,代码来源:NIPS2015Tutorial.cs

示例4: TestLoadModelInMemory

        public void TestLoadModelInMemory()
        {
            using (var vw = new VowpalWabbit(@"-i model-sets\8.0.1_rcv1_ok.model"))
            {
                var memStream = new MemoryStream();
                vw.SaveModel(memStream);

                vw.SaveModel("native.model");

                using (var file = File.Create("managed.file.model"))
                {
                    vw.SaveModel(file);
                }

                var nativeModel = File.ReadAllBytes("native.model");
                var managedFileModel = File.ReadAllBytes("managed.file.model");
                var managedModel = memStream.ToArray();

                Assert.IsTrue(nativeModel.SequenceEqual(managedModel));
                Assert.IsTrue(nativeModel.SequenceEqual(managedFileModel));
            }
        }
开发者ID:adgaudio,项目名称:vowpal_wabbit,代码行数:22,代码来源:TestModelLoading.cs

示例5: TestEmptyID

        public void TestEmptyID()
        {
            using (var vw = new VowpalWabbit("-l 1"))
            {
                Assert.AreEqual(string.Empty, vw.ID);

                vw.SaveModel("model");
            }

            using (var vw = new VowpalWabbit("-f model"))
            {
                Assert.AreEqual(string.Empty, vw.ID);
            }
        }
开发者ID:KaiWeiChang,项目名称:vowpal_wabbit,代码行数:14,代码来源:TestModelLoading.cs

示例6: TestArguments

        public void TestArguments()
        {
            using (var vw = new VowpalWabbit(new VowpalWabbitSettings("--cb_adf --rank_all --interact ud") { Verbose = true }))
            {
                Assert.AreEqual("--cb_adf --rank_all --interact ud --csoaa_ldf multiline --csoaa_rank", vw.Arguments.CommandLine);

                vw.SaveModel("args.model");
            }

            using (var vw = new VowpalWabbit(new VowpalWabbitSettings { ModelStream = File.Open("args.model", FileMode.Open) }))
            {
                Assert.AreEqual("--no_stdin --max_prediction 1 --bit_precision 18 --cb_adf --cb_type ips --rank_all --csoaa_ldf multiline --interact ud --csoaa_rank",
                    vw.Arguments.CommandLine);
            }
        }
开发者ID:vjeranc,项目名称:vowpal_wabbit,代码行数:15,代码来源:TestArguments.cs

示例7: TestQuietAndTestArguments

        public void TestQuietAndTestArguments()
        {
            using (var vw = new VowpalWabbit("--quiet -t"))
            {
                vw.SaveModel("args.model");
            }

            using (var vw = new VowpalWabbitModel(new VowpalWabbitSettings { ModelStream = File.Open("args.model", FileMode.Open) }))
            {
                Assert.IsFalse(vw.Arguments.CommandLine.Contains("--quiet"));
                Assert.IsFalse(vw.Arguments.CommandLine.Contains("-t"));

                using (var vwSub = new VowpalWabbit(new VowpalWabbitSettings("-t") { Model = vw }))
                {
                    Assert.IsTrue(vwSub.Arguments.CommandLine.Contains("--quiet"));
                    Assert.IsTrue(vwSub.Arguments.CommandLine.Contains("-t"));
                }
            }

            using (var vw = new VowpalWabbit(""))
            {
                vw.SaveModel("args.model");
            }

            using (var vw = new VowpalWabbitModel(new VowpalWabbitSettings { ModelStream = File.Open("args.model", FileMode.Open) }))
            {
                Assert.IsFalse(vw.Arguments.CommandLine.Contains("--quiet"));
                Assert.IsFalse(vw.Arguments.CommandLine.Contains("-t"));

                using (var vwSub = new VowpalWabbit(new VowpalWabbitSettings("-t") { Model = vw }))
                {
                    Assert.IsTrue(vwSub.Arguments.CommandLine.Contains("--quiet"));
                    Assert.IsTrue(vwSub.Arguments.CommandLine.Contains("-t"));
                }
            }
        }
开发者ID:arielf,项目名称:vowpal_wabbit,代码行数:36,代码来源:TestArguments.cs

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

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

示例10: TestConfigADFParsing

        public void TestConfigADFParsing()
        {
            var schemaShared = ConfigInspector.CreateSchema(typeof(ConfigShared), "f1", msg => Assert.Fail(msg));
            var schemaADF = ConfigInspector.CreateSchema(typeof(ConfigADF), "f2(Enumerize=true)", msg => Assert.Fail(msg));

            using (var vw = new VowpalWabbit<ConfigShared, ConfigADF>(new VowpalWabbitSettings("--cb_adf", schema: schemaShared, actionDependentSchema: schemaADF)))
            using (var vwNative = new VowpalWabbit("--cb_adf"))
            {
                vw.Learn(
                    new ConfigShared { f1 = 2, ignore_me = 3 },
                    new[]
                    {
                        new ConfigADF { f2 = 3 },
                        new ConfigADF { f2 = 4 },
                    }, 0, new ContextualBanditLabel { Action = 0, Cost = 1, Probability = .5f });

                vwNative.Learn(
                    new[]
                    {
                        "shared | f1:2",
                        "0:1:.5 | f23",
                        " | f24"
                    });

                vw.Native.SaveModel("config-actual.model");
                vwNative.SaveModel("config-expected.model");
            }

            var actual = File.ReadAllBytes("config-actual.model");
            var expected = File.ReadAllBytes("config-expected.model");

            CollectionAssert.AreEqual(expected, actual);
        }
开发者ID:KaiWeiChang,项目名称:vowpal_wabbit,代码行数:33,代码来源:TestConfigInspector.cs

示例11: TestReload

        public void TestReload()
        {
            using (var vw = new VowpalWabbit(""))
            {
                vw.SaveModel("model");
                vw.Reload();
            }

            using (var vw = new VowpalWabbit(""))
            {
                vw.ID = "def";
                vw.SaveModel("model.1");

                vw.Reload();

                Assert.AreEqual("def", vw.ID);
            }
        }
开发者ID:adgaudio,项目名称:vowpal_wabbit,代码行数:18,代码来源:TestModelLoading.cs

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

示例13: TestAllReduceInternal

        internal async Task TestAllReduceInternal()
        {
            var data = Enumerable.Range(1, 1000).Select(_ => Generator.GenerateShared(10)).ToList();

            var stringSerializerCompiler = (VowpalWabbitSingleExampleSerializerCompiler<CbAdfShared>)
                VowpalWabbitSerializerFactory.CreateSerializer<CbAdfShared>(new VowpalWabbitSettings { EnableStringExampleGeneration = true });
            var stringSerializerAdfCompiler = (VowpalWabbitSingleExampleSerializerCompiler<CbAdfAction>)
                VowpalWabbitSerializerFactory.CreateSerializer<CbAdfAction>(new VowpalWabbitSettings { EnableStringExampleGeneration = true });

            var stringData = new List<List<string>>();

            VowpalWabbitPerformanceStatistics statsExpected;
            using (var spanningTree = new SpanningTreeClr())
            {
                spanningTree.Start();

                using (var vw1 = new VowpalWabbit(new VowpalWabbitSettings(@"--total 2 --node 1 --unique_id 0 --span_server localhost --cb_adf --rank_all --interact xy") { EnableStringExampleGeneration = true }))
                using (var vw2 = new VowpalWabbit(new VowpalWabbitSettings(@"--total 2 --node 0 --unique_id 0 --span_server localhost --cb_adf --rank_all --interact xy") { EnableStringExampleGeneration = true } ))
                {
                    var stringSerializer = stringSerializerCompiler.Func(vw1);
                    var stringSerializerAdf = stringSerializerAdfCompiler.Func(vw1);

                    // serialize
                    foreach (var d in data)
                    {
                        var block = new List<string>();

                        using (var context = new VowpalWabbitMarshalContext(vw1))
                        {
                            stringSerializer(context, d.Item1, SharedLabel.Instance);
                            block.Add(context.ToString());
                        }

                        block.AddRange(d.Item2.Select((a, i) =>
                            {
                                using (var context = new VowpalWabbitMarshalContext(vw1))
                                {
                                    stringSerializerAdf(context, a, i == d.Item3.Action ? d.Item3 : null);
                                    return context.ToString();
                                }
                            }));

                        stringData.Add(block);
                    }

                    await Task.WhenAll(
                        Task.Factory.StartNew(() => Ingest(vw1, stringData.Take(500))),
                        Task.Factory.StartNew(() => Ingest(vw2, stringData.Skip(500))));

                    vw1.SaveModel("expected.1.model");
                    vw2.SaveModel("expected.2.model");

                    statsExpected = vw1.PerformanceStatistics;
                }
            }

            // skip header
            var expected1Model = File.ReadAllBytes("expected.1.model").Skip(0x15).ToList();
            var expected2Model = File.ReadAllBytes("expected.2.model").Skip(0x15).ToList();

            var settings = new VowpalWabbitSettings("--cb_adf --rank_all --interact xy")
            {
                ParallelOptions = new ParallelOptions
                {
                    MaxDegreeOfParallelism = 2
                },
                ExampleCountPerRun = 2000,
                ExampleDistribution = VowpalWabbitExampleDistribution.RoundRobin
            };

            using (var vw = new VowpalWabbitThreadedLearning(settings))
            {
                await Task.WhenAll(
                    Task.Factory.StartNew(() => Ingest(vw, stringData.Take(500))),
                    Task.Factory.StartNew(() => Ingest(vw, stringData.Skip(500))));

                // important to enqueue the request before Complete() is called
                var statsTask = vw.PerformanceStatistics;
                var modelSave = vw.SaveModel("actual.model");

                await vw.Complete();

                var statsActual = await statsTask;
                VWTestHelper.AssertEqual(statsExpected, statsActual);

                await modelSave;

                // skip header
                var actualModel = File.ReadAllBytes("actual.model").Skip(0x15).ToList();

                CollectionAssert.AreEqual(expected1Model, actualModel);
                CollectionAssert.AreEqual(expected2Model, actualModel);
            }

            using (var vw = new VowpalWabbitThreadedLearning(settings))
            {
                var vwManaged = vw.Create<CbAdfShared, CbAdfAction>();

                await Task.WhenAll(
                    Task.Factory.StartNew(() => Ingest(vwManaged, data.Take(500))),
//.........这里部分代码省略.........
开发者ID:XkhldY,项目名称:vowpal_wabbit,代码行数:101,代码来源:TestAllReduce.cs

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