• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# VowpalWabbit类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



VowpalWabbit类属于命名空间,在下文中一共展示了VowpalWabbit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: TestNull1

        public void TestNull1()
        {
            using (var vw = new VowpalWabbit<Context, ADF>("--cb_adf --rank_all --interact ab"))
            {
                var ctx = new Context()
                {
                    ID = 25,
                    Vector = null,
                    ActionDependentFeatures = new[] {
                        new ADF {
                            ADFID = "23"
                        }
                    }.ToList()
                };

                vw.Learn(ctx, ctx.ActionDependentFeatures, 0, new ContextualBanditLabel()
                {
                    Action = 1,
                    Cost = 1,
                    Probability = 0.2f
                });
                var result = vw.Predict(ctx, ctx.ActionDependentFeatures);
                Assert.AreEqual(1, result.Length);
            }
        }
开发者ID:KaiWeiChang,项目名称:vowpal_wabbit,代码行数:25,代码来源:TestNull.cs


示例3: TestNull3

        public void TestNull3()
        {
            using (var vw = new VowpalWabbit<Context, ADF>("--cb_adf --rank_all --interact ac"))
            {
                var ctx = new Context()
                {
                    ID = 25,
                    Vector = new float[] { 3 },
                    VectorC = new float[] { 2, 2, 3 },
                    ActionDependentFeatures = new[] {
                        new ADF {
                            ADFID = "23",
                        }
                    }.ToList()
                };

                var label = new ContextualBanditLabel() {
                                Action = 1,
                                Cost= 1,
                                Probability = 0.2f
                            };

                vw.Learn(ctx, ctx.ActionDependentFeatures, 0, label);

                ctx.Vector = null;
                vw.Learn(ctx, ctx.ActionDependentFeatures, 0, label);

                ctx.Vector = new float[] { 2 };
                ctx.VectorC = null;
                vw.Learn(ctx, ctx.ActionDependentFeatures, 0, label);

                ctx.Vector = null;
                vw.Learn(ctx, ctx.ActionDependentFeatures, 0, label);
            }
        }
开发者ID:KaiWeiChang,项目名称:vowpal_wabbit,代码行数:35,代码来源:TestNull.cs


示例4: TestExampleCacheForLearning

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


示例5: Test87

        public void Test87()
        {
            using (var vw = new VowpalWabbit<DataString, DataStringADF>("--cb_adf --rank_all"))
            {
                var sampleData = CreateSampleCbAdfData();

                var example = sampleData[0];

                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];

                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];
                result = vw.Predict(example, example.ActionDependentFeatures);

                ReferenceEquals(example.ActionDependentFeatures[0], result[1]);
                ReferenceEquals(example.ActionDependentFeatures[1], result[0]);
            }
        }
开发者ID:nguyenhailong,项目名称:vowpal_wabbit,代码行数:27,代码来源:TestCbAdf.cs


示例6: Post

        public async Task<HttpResponseMessage> Post()
        {
            var header = this.Request.Headers.SingleOrDefault(x => x.Key == "Authorization");

            if (header.Value == null)
                throw new UnauthorizedAccessException("AuthorizationToken missing");

            var userToken = header.Value.First();

            if (string.IsNullOrWhiteSpace(userToken) || userToken != ConfigurationManager.AppSettings["UserToken"])
                return Request.CreateResponse(HttpStatusCode.Unauthorized);

            if (this.metaData == null || lastDownload + TimeSpan.FromMinutes(1) < DateTime.Now)
            {
                var url = ConfigurationManager.AppSettings["DecisionServiceSettingsUrl"];
                this.metaData = ApplicationMetadataUtil.DownloadMetadata<ApplicationClientMetadata>(url);
                lastDownload = DateTime.Now;
            }

            using (var vw = new VowpalWabbit(new VowpalWabbitSettings(metaData.TrainArguments)
            {
                EnableStringExampleGeneration = true,
                EnableStringFloatCompact = true
            }))
            using (var serializer = new VowpalWabbitJsonSerializer(vw))
            using (var example = serializer.ParseAndCreate(new JsonTextReader(new StreamReader(await Request.Content.ReadAsStreamAsync()))))
            {
                return Request.CreateResponse(HttpStatusCode.OK, example.VowpalWabbitString);
            }
        }
开发者ID:xornand,项目名称:mwt-ds-web-api,代码行数:30,代码来源:VowpalWabbitValidationController.cs


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


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


示例9: VowpalWabbitJsonSerializer

        /// <summary>
        /// Initializes a new instance of the <see cref="VowpalWabbitJson"/> class.
        /// </summary>
        /// <param name="vw">The VW native instance.</param>
        public VowpalWabbitJsonSerializer(VowpalWabbit vw)
        {
            Contract.Requires(vw != null);

            this.vw = vw;
            this.defaultMarshaller = new VowpalWabbitDefaultMarshaller();
            this.jsonSerializer = new JsonSerializer();
        }
开发者ID:xiongxiongufl,项目名称:vowpal_wabbit,代码行数:12,代码来源:VowpalWabbitJsonSerializer.cs


示例10: TestExampleCacheDisabledForLearning

        public void TestExampleCacheDisabledForLearning()
        {
            using (var vw = new VowpalWabbit<CachedData>(new VowpalWabbitSettings(enableExampleCaching: false)))
            {
                vw.Learn(new CachedData(), new SimpleLabel());

            }
        }
开发者ID:KaiWeiChang,项目名称:vowpal_wabbit,代码行数:8,代码来源:TestExampleCache.cs


示例11: VowpalWabbitMultiworldTesting

        /// <summary>
        ///
        /// </summary>
        /// <param name="vwModel">Optional model to see multiworld testing</param>
        public VowpalWabbitMultiworldTesting(Stream vwModel = null)
        {
            var settings = vwModel == null ?
                new VowpalWabbitSettings("--multiworld_test f") :
                new VowpalWabbitSettings { ModelStream = vwModel };

            this.vw = new VowpalWabbit<LearnedVsConstantPolicy>(settings);
        }
开发者ID:vjeranc,项目名称:vowpal_wabbit,代码行数:12,代码来源:VowpalWabbitMultiworldTesting.cs


示例12: DisclaimerPredict

 public DisclaimerPredict(string modelName, string dictionary, int dictionarySize, float cutoff)
 {
     //--quiet
     // _vw = new VowpalWabbit(string.Format("-t -i {0} --quiet", modelName));
     _vw = new VowpalWabbit(string.Format("-f {0} --loss_function logistic --passes 25 -c -l2", modelName));
     _dictionary = new WordDictionary(dictionary, dictionarySize);
     _cutoff = cutoff;
 }
开发者ID:BhargavUppalapu,项目名称:DotNetNLPTools,代码行数:8,代码来源:DisclaimerPredict.cs


示例13: Validate

 internal static void Validate(string line, VowpalWabbitExample ex, IVowpalWabbitLabelComparator comparator, string args = null)
 {
     using (var vw = new VowpalWabbit(args))
     using (var strExample = vw.ParseLine(line))
     {
         var diff = strExample.Diff(vw, ex, comparator);
         Assert.IsNull(diff, diff + " generated string: '" + ex.VowpalWabbitString + "'");
     }
 }
开发者ID:XkhldY,项目名称:vowpal_wabbit,代码行数:9,代码来源:VowpalWabbitExampleValidator.cs


示例14: TestDynamic

        public void TestDynamic()
        {
            // TODO: look into friend assemblies and how to figure if one is a friend
            using (var vw = new VowpalWabbit("--cb_adf --rank_all"))
            using (var vwDynamic = new VowpalWabbitDynamic(new VowpalWabbitSettings("--cb_adf --rank_all") { TypeInspector = JsonTypeInspector.Default }))
            {
                var expected = vw.Learn(new[] { "| q:1", "2:-3:0.9 | q:2", "| q:3" }, VowpalWabbitPredictionType.ActionScore);
                var actual = vwDynamic.Learn(
                    new
                    {
                        _multi = new[]
                        {
                            new { q = 1 },
                            new { q = 2 },
                            new { q = 3 }
                        }
                    },
                    VowpalWabbitPredictionType.ActionScore,
                    new ContextualBanditLabel(0, -3, 0.9f),
                    1);
                AssertAreEqual(expected, actual);

                expected = vw.Learn(new[] { "| q:1", "2:-5:0.9 | q:2", "| q:3" }, VowpalWabbitPredictionType.ActionScore);
                actual = vwDynamic.Learn(
                    new
                    {
                        _multi = new[]
                        {
                            new { q = 1 },
                            new { q = 2 },
                            new { q = 3 }
                        }
                    },
                    VowpalWabbitPredictionType.ActionScore,
                    new ContextualBanditLabel(0, -5, 0.9f),
                    1);
                AssertAreEqual(expected, actual);

                expected = vw.Learn(new[] { "| q:1", "| q:2", "3:-2:0.8 | q:3" }, VowpalWabbitPredictionType.ActionScore);
                actual = vwDynamic.Learn(
                    new
                    {
                        _multi = new[]
                        {
                            new { q = 1 },
                            new { q = 2 },
                            new { q = 3 }
                        },
                        _labelIndex = 2,
                        _label_Action = 3,
                        _label_Cost = -2,
                        _label_Probability = 0.8
                    },
                    VowpalWabbitPredictionType.ActionScore);
                AssertAreEqual(expected, actual);
            }
        }
开发者ID:arielf,项目名称:vowpal_wabbit,代码行数:57,代码来源:TestDynamic.cs


示例15: Ingest

        private static void Ingest(VowpalWabbit vw, IEnumerable<List<string>> blocks)
        {
            foreach (var block in blocks)
            {
                vw.Learn(block);
            }

            vw.EndOfPass();
        }
开发者ID:XkhldY,项目名称:vowpal_wabbit,代码行数:9,代码来源:TestAllReduce.cs


示例16: SetupVW

        private VowpalWabbit SetupVW()
        {
            var vw = new VowpalWabbit(" --probabilities --loss_function=logistic --oaa 3");

            vw.Learn("1 | a b");
            vw.Learn("2 | a c");
            vw.Learn("3 | c b e");

            return vw;
        }
开发者ID:gramhagen,项目名称:vowpal_wabbit,代码行数:10,代码来源:TestMultiClassPredictionFactory.cs


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


示例18: VowpalWabbitJsonSerializer

        /// <summary>
        /// Initializes a new instance of the <see cref="VowpalWabbitJson"/> class.
        /// </summary>
        /// <param name="vw">The VW native instance.</param>
        public VowpalWabbitJsonSerializer(VowpalWabbit vw)
        {
            Contract.Requires(vw != null);

            this.vw = vw;
            this.defaultMarshaller = new VowpalWabbitDefaultMarshaller();
            this.jsonSerializer = new JsonSerializer();

            this.Context = new VowpalWabbitMarshalContext(this.vw);
            this.DefaultNamespaceContext = new VowpalWabbitMarshalContext(this.vw, this.Context.ExampleBuilder);
        }
开发者ID:qqgeogor,项目名称:vowpal_wabbit,代码行数:15,代码来源:VowpalWabbitJsonSerializer.cs


示例19: MyListener

            public MyListener(VowpalWabbit<Data> vw)
            {
                this.vw = vw;

                // re-use example object
                this.example = new Data()
                {
                    Features = new List<KeyValuePair<string, float>>()
                };

                this.stopwatch = new Stopwatch();
            }
开发者ID:nguyenhailong,项目名称:vowpal_wabbit,代码行数:12,代码来源:Rcv1Test.cs


示例20: TestJsonFeatureExtraction

        public void TestJsonFeatureExtraction()
        {
            string json = "{\"ns1\":{\"location\":\"New York\", \"f2\":3.4}}";

            using (var vw = new VowpalWabbit("-b 3 --noconstant"))
            using (var serializer = new VowpalWabbitJsonSerializer(vw))
            using (var result = serializer.ParseAndCreate(json))
            {
                var singleExample = result as VowpalWabbitSingleLineExampleCollection;
                Assert.IsNotNull(singleExample);
                if (singleExample != null)
                {
                    foreach (var ns in singleExample.Example)
                    {
                        Console.WriteLine(ns.Index);

                        foreach (var feature in ns)
                        {
                            Console.WriteLine("{0}:{1}", feature.WeightIndex, feature.X);
                        }
                    }

                    var ns1 = singleExample.Example.ToArray();
                    Assert.AreEqual(1, ns1.Length);
                    Assert.AreEqual((byte)'n', ns1[0].Index);
                    CollectionAssert.AreEqual(
                            new[] {
                                new VowpalWabbitFeature(1, 12),
                                new VowpalWabbitFeature(3.4f, 28)
                            },
                            ns1[0].ToArray());
                }

                // for documentation purpose only
                var multiExample = result as VowpalWabbitMultiLineExampleCollection;
                Assert.IsNull(multiExample);
                if (multiExample != null)
                {
                    foreach (var example in multiExample.Examples)
                    {
                        foreach (var ns in example)
                        {
                            Console.WriteLine(ns.Index);

                            foreach (var feature in ns)
                            {
                                Console.WriteLine("{0}:{1}", feature.WeightIndex, feature.X);
                            }
                        }
                    }
                }
            }
        }
开发者ID:G453,项目名称:vowpal_wabbit,代码行数:53,代码来源:TestFeatureExtraction.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Voxel类代码示例发布时间:2022-05-24
下一篇:
C# VolunteerService类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap