Exemple #1
0
        public void DeltaRuleLearning_Test_iterations_1000_learningrate_02()
        {
            loadRealDataSample();              // System coefficients initialization.

            var         desc = loadMetaData(); // Description of the system.
            LearningApi api  = new LearningApi(desc);

            //Real dataset must be defined as object type, because data can be numeric, binary and classification
            api.UseActionModule <double[, ], double[, ]>((input, ctx) =>
            {
                return(loadRealDataSample()); // return actual System coefficients data
            });

            // run input = UseActionModule output
            //run Delta Rule for 1000 iterations with learningRate=0.2
            api.UseDeltaRuleLearning(0.2, 1000);
            var result = api.Run() as double[];

            Debug.WriteLine("************ Output Predictions***********");
            for (int i = 0; i < result.Length; i++)
            {
                if (result[i] != 0)
                {
                    Debug.WriteLine(result[i]);
                }
            }
            using (var fs = File.OpenRead(@"H_Test.csv"))
                using (var reader = new StreamReader(fs))
                {
                    while (!reader.EndOfStream)
                    {
                        var line   = reader.ReadLine();
                        var values = line.Split(',');
                        ti = new double[values.Length];
                        to = new double[values.Length];
                        for (int i = 0; i < values.Length; i++)
                        {
                            var val = values[i].Split(' ');
                            double.TryParse(val[0], out x);
                            double.TryParse(val[1], out y);

                            ti[i] = x;
                            to[i] = y;
                        }
                    }
                }
            for (int i = 0; i < to.Length; i++)
            {
                //Testing of Test data with Predicted System model
                Assert.Equal(Math.Round(result[i], 4), Math.Round(to[i], 4));
            }
        }