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>(new VowpalWabbitSettings("-k -c --passes 10", enableExampleCaching: false)))
            {
                foreach (var example in examples)
                {
                    vw.Learn(example, example.Label);
                }

                vw.Native.RunMultiPass();
                vw.Native.SaveModel("models/model1");
            }

            using (var vwModel = new VowpalWabbitModel(new VowpalWabbitSettings("-t", modelStream: File.OpenRead("models/model1"))))
            using (var vwCached = new VowpalWabbit<CachedData>(new VowpalWabbitSettings(model: vwModel, enableExampleCaching: true, maxExampleCacheSize: 5 )))
            using (var vw = new VowpalWabbit<CachedData>(new VowpalWabbitSettings(model: vwModel, enableExampleCaching: false )))
            {
                foreach (var example in examples)
                {
                    var cachedPrediction = vwCached.Predict(example, VowpalWabbitPredictionType.Scalar);
                    var prediction = vw.Predict(example, VowpalWabbitPredictionType.Scalar);

                    Assert.AreEqual(prediction, cachedPrediction);
                    Assert.AreEqual(example.Label.Label, Math.Round(prediction));
                }
            }
        }
        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));
                                }
                        }
                    }
        }
        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));
                    }
                }
            }
        }
        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>(new VowpalWabbitSettings("-k -c --passes 10")
            {
                EnableExampleCaching = false
            }))
            {
                foreach (var example in examples)
                {
                    vw.Learn(example, example.Label);
                }

                vw.Native.RunMultiPass();
                vw.Native.SaveModel("models/model1");
            }

            using (var vwModel = new VowpalWabbitModel(new VowpalWabbitSettings("-t")
            {
                ModelStream = File.OpenRead("models/model1")
            }))
                using (var vwCached = new VowpalWabbit <CachedData>(new VowpalWabbitSettings {
                    Model = vwModel, EnableExampleCaching = true, MaxExampleCacheSize = 5
                }))
                    using (var vw = new VowpalWabbit <CachedData>(new VowpalWabbitSettings {
                        Model = vwModel, EnableExampleCaching = false
                    }))
                    {
                        foreach (var example in examples)
                        {
                            var cachedPrediction = vwCached.Predict(example, VowpalWabbitPredictionType.Scalar);
                            var prediction       = vw.Predict(example, VowpalWabbitPredictionType.Scalar);

                            Assert.AreEqual(prediction, cachedPrediction);
                            Assert.AreEqual(example.Label.Label, Math.Round(prediction));
                        }
                    }
        }