public static DataFrame TestScikitAPI_EngineSimpleTrainAndPredict(string engine, int th, int N, int ncall, bool cacheScikit)
        {
            var dico     = new Dictionary <Tuple <int, string, int, int>, double>();
            var scorer   = _TrainSentiment();
            var trscorer = _TrainSentiment2();

            foreach (var res in _MeasureTime(th, engine, scorer, trscorer, N, ncall, cacheScikit))
            {
                dico[new Tuple <int, string, int, int>(res.Item1, engine, th, res.Item3)] = res.Item2.TotalSeconds;
            }
            var df = DataFrameIO.Convert(dico, "N", "engine", "number of threads", "call", "time(s)");

            return(df);
        }
        public void TestScikitAPI_EngineSimpleTrainAndPredict()
        {
            var dico     = new Dictionary <Tuple <int, string, string, int, int>, double>();
            var scorer   = _TrainSentiment();
            var trscorer = _TrainSentiment2Transformer();

            foreach (var cache in new[] { false, true })
            {
                for (int th = 1; th <= 3; ++th)
                {
                    var memo = new Dictionary <string, float[]>();
                    foreach (var engine in new[] { "mlnet", "scikit" })
                    {
                        foreach (var kind in new[] { "array", "stream" })
                        {
                            var strat_ = new[] {
                                cache ? "extcache" : "viewcache",
                                 kind,
                            };
                            var strat = string.Join("+", strat_);
                            foreach (var res in _MeasureTime(th, strat, engine, scorer, trscorer, 2))
                            {
                                dico[new Tuple <int, string, string, int, int>(res.Item1, engine, strat, th, res.Item3)] = res.Item2.TotalSeconds;
                                if (res.Item3 == 1)
                                {
                                    memo[engine] = res.Item4;
                                }
                            }
                        }
                    }
                    var p1 = memo["mlnet"];
                    var p2 = memo["scikit"];
                    Assert.AreEqual(p1.Length, p2.Length);
                    var abs = 0.0;
                    for (int ii = 0; ii < p1.Length; ++ii)
                    {
                        abs += Math.Abs(p1[ii] - p2[ii]);
                    }
                    abs /= p1.Length;
                    // Assert.IsTrue(abs <= 2);
                }
            }
            var df         = DataFrameIO.Convert(dico, "N", "engine", "strategy", "number of threads", "call", "time(s)");
            var methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            var filename   = FileHelper.GetOutputFile("benchmark_ValueMapperPredictionEngineMultiThread.txt", methodName);

            df.ToCsv(filename);
            Assert.AreEqual(dico.Count, 48);
        }
        public void TestValueMapperPredictionEngineMultiThread()
        {
            var name = FileHelper.GetTestFile("bc-lr.zip");

            /*using (*/
            var env = EnvHelper.NewTestEnvironment();

            using (var engine0 = new ValueMapperPredictionEngineFloat(env, name, conc: 1))
            {
                var feat = new float[] { 5, 1, 1, 1, 2, 1, 3, 1, 1 };
                var exp  = new float[100];
                for (int i = 0; i < exp.Length; ++i)
                {
                    feat[0] = i;
                    exp[i]  = engine0.Predict(feat);
                    Assert.IsFalse(float.IsNaN(exp[i]));
                    Assert.IsFalse(float.IsInfinity(exp[i]));
                }

                var dico = new Dictionary <Tuple <int, bool, int>, double>();

                foreach (var each in new[] { false, true })
                {
                    foreach (int th in new int[] { 2, 0, 1, 3 })
                    {
                        var engine = new ValueMapperPredictionEngineFloat(env, name, conc: th);
                        var sw     = new Stopwatch();
                        sw.Start();
                        for (int i = 0; i < exp.Length; ++i)
                        {
                            feat[0] = i;
                            var res = engine.Predict(feat);
                            Assert.AreEqual(exp[i], res);
                        }
                        sw.Stop();
                        dico[new Tuple <int, bool, int>(exp.Length, each, th)] = sw.Elapsed.TotalSeconds;
                    }
                }
                Assert.AreEqual(dico.Count, 8);
                var df         = DataFrameIO.Convert(dico, "N", "number of threads", "time(s)");
                var methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                var filename   = FileHelper.GetOutputFile("benchmark_ValueMapperPredictionEngineMultiThread.txt", methodName);
                df.ToCsv(filename);
            }
        }