public void TrainDistributedMachines() { // set parameters for (int i = 0; i < _agents.Count; i++) { _agents[i].GetMachine()._lamda = 0.8; } for (int i = 0; i < _agentNum; i++) { for (int j = 0; j < _agentNum; j++) { if (_adjacency[i, j] == 1) { _agents[i].AddNeighbor(_agents[j]); } } } for (int t = 0; t < _iterationTime; t++) { for (int i = 0; i < _agentNum; i++) { _agents[i].SetValue(_dataGnr.Calc(_agents[i].GetPos())); } for (int i = 0; i < _agentNum; i++) { _agents[i].Train(); } } }
public OneDimDataTester(KernelRegression machine = null) { _dataGnr = new OneDimDataGenerator(); _rnd = new Random(); _trainDataX = new double[_trainDataSize][]; _trainDataY = new double[_trainDataSize]; for (int i = 0; i < _trainDataSize; i++) { _trainDataX[i] = new double[1]; _trainDataX[i][0] = 2 * _rnd.NextDouble() - 1.0; } _trainDataY = _dataGnr.Calc(_trainDataX); if (machine == null) { _regressionMachine = new KernelRegression(); } else { _regressionMachine = machine; } }
public DistributedOneDimDataTrainer() { _agentNum = _trainDataSize; _adjacency = new int[_agentNum, _agentNum]; _dataGnr = new OneDimDataGenerator(); _rnd = new Random(); _trainDataX = new double[_trainDataSize][]; _trainDataY = new double[_trainDataSize]; _agents = new List <KernelAgent>(); _centerMachine = new KernelRegression(); for (int i = 0; i < _agentNum; i++) { _trainDataX[i] = new double[1]; _trainDataX[i][0] = 2 * _rnd.NextDouble() - 1.0; _agents.Add(new KernelAgent(_trainDataX[i])); } _trainDataY = _dataGnr.Calc(_trainDataX); Init(); }
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); }