Beispiel #1
0
        public void Test()
        {
            double[][] testDataX    = new double[_testDataSize][];
            double[]   testDataY    = new double[_testDataSize];
            double[]   testDataRefY = new double[_testDataSize];

            for (int i = 0; i < _testDataSize; i++)
            {
                testDataX[i]    = new double[1];
                testDataX[i][0] = -1.0 + (double)((2 * i)) / (double)(_testDataSize);
            }

            testDataY    = _dataGnr.Calc(testDataX);
            testDataRefY = _regressionMachine.Predict(testDataX);

            DataAnalyzer analyzer = new DataAnalyzer();

            double[] err = analyzer.GetDifference(testDataY, testDataRefY);

            double mean     = analyzer.Mean(err);
            double variance = analyzer.Variance(err);

            Console.WriteLine("testDataX:");
            for (int i = 0; i < testDataX.Length; i++)
            {
                Console.Write(testDataX[i][0] + ",");
            }
            Console.Write("\n");
            Console.Write("\n");

            Console.WriteLine("testDataY:");
            for (int i = 0; i < testDataY.Length; i++)
            {
                Console.Write(testDataY[i] + ",");
            }
            Console.Write("\n");
            Console.Write("\n");

            Console.WriteLine("testDataRefY:");
            for (int i = 0; i < testDataRefY.Length; i++)
            {
                Console.Write(testDataRefY[i] + ",");
            }
            Console.Write("\n");
            Console.Write("\n");

            Console.WriteLine("testDataError:");
            for (int i = 0; i < err.Length; i++)
            {
                Console.Write(err[i] + ",");
            }
            Console.Write("\n");
            Console.Write("\n");

            Console.WriteLine("Mean: " + mean);
            Console.WriteLine("Variance: " + variance);
        }
Beispiel #2
0
        public void TestDistributedMachines()
        {
            Console.Write("\n");
            Console.Write("\n");
            Console.WriteLine("TestDistributedMachines");

            double[][] testDataX    = new double[_testDataSize][];
            double[]   testDataY    = new double[_testDataSize];
            double[]   testDataRefY = new double[_testDataSize];

            for (int i = 0; i < _testDataSize; i++)
            {
                testDataX[i]    = new double[1];
                testDataX[i][0] = -1.0 + (double)((2 * i)) / (double)(_testDataSize);
            }

            testDataY = _dataGnr.Calc(testDataX);

            int totalConnectivity = 0;

            for (int j = 0; j < _agentNum; j++)
            {
                totalConnectivity += _agents[j].connectivity;
            }

            for (int j = 0; j < _agentNum; j++)
            {
                testDataRefY = _agents[j].GetMachine().Predict(testDataX);
                DataAnalyzer analyzer2 = new DataAnalyzer();
                double[]     err2      = analyzer2.GetDifference(testDataY, testDataRefY);

                double mean2     = analyzer2.Mean(err2);
                double variance2 = analyzer2.Variance(err2);

                Console.WriteLine("Agent: " + j);
                Console.WriteLine("Mean: " + mean2);
                Console.WriteLine("Variance: " + variance2);
            }

            return;

            for (int i = 0; i < _testDataSize; i++)
            {
                for (int j = 0; j < _agentNum; j++)
                {
                    testDataRefY[i] += _agents[j].GetMachine().Predict(testDataX[i])
                                       * _agents[j].connectivity;
                }

                testDataRefY[i] = testDataRefY[i] / totalConnectivity;
            }

            DataAnalyzer analyzer = new DataAnalyzer();

            double[] err = analyzer.GetDifference(testDataY, testDataRefY);

            double mean     = analyzer.Mean(err);
            double variance = analyzer.Variance(err);

            Console.WriteLine("testDataRefY:");
            for (int i = 0; i < testDataRefY.Length; i++)
            {
                Console.Write(testDataRefY[i] + ",");
            }
            Console.Write("\n");
            Console.Write("\n");

            Console.WriteLine("Mean: " + mean);
            Console.WriteLine("Variance: " + variance);
        }