public Data(StreamReader r1, StreamReader r2, int epochs, double learning_rate, Random r, bool DymanicLearningRate, double margin, bool Average, bool Aggressive) { double[] w_average = new double[68]; double b_average; WeightBias wb_average = null; if (Average) { for (int i = 0; i < 68; i++) { double randomNumber = (r.NextDouble() * (0.01 + 0.01) - 0.01); w_average[i] = randomNumber; } b_average = (r.NextDouble() * (0.01 + 0.01) - 0.01); wb_average = new WeightBias(w_average, b_average, 0); } Training_Data = new List <Entry>(); Test_Data = new List <Entry>(); AccuracyWeightB = new Dictionary <int, AccuracyWB>(); SetData(r1, r2); perceptron = new Perceptron(Training_Data, Test_Data, learning_rate, DymanicLearningRate, margin, wb_average, Aggressive); double[] w = new double[68]; double b = (r.NextDouble() * (0.01 + 0.01) - 0.01); for (int i = 0; i < 68; i++) { double randomNumber = (r.NextDouble() * (0.01 + 0.01) - 0.01); w[i] = randomNumber; } WeightBias wb = new WeightBias(w, b, 0); for (int i = 0; i < epochs; i++) { wb = perceptron.CalculateWB(wb); if (Average) { perceptron.WeightBias_Average.Updates = wb.Updates; AccuracyWeightB.Add(i + 1, new AccuracyWB(perceptron.GetAccuracy(Test_Data, perceptron.WeightBias_Average), perceptron.WeightBias_Average)); } else { AccuracyWeightB.Add(i + 1, new AccuracyWB(perceptron.GetAccuracy(Test_Data, wb), wb)); } perceptron.ShuffleTraining_Data(r); } //foreach (var item in AccuracyWeightB) //{ // Console.WriteLine(item.Value.Accuracy); //} AccuracyWB bestAccuracy = AccuracyWeightB.OrderByDescending(x => x.Value.Accuracy).ThenByDescending(y => y.Key).Select(z => z.Value).First(); Accuracy = bestAccuracy.Accuracy; BestWeightBias = bestAccuracy.Weight_Bias; Learning_Rate = learning_rate; //Console.WriteLine("\n" + Accuracy); }
public Data(StreamReader r1, StreamReader r2, Random r, int epochs, double learning_rate, double margin, double c, bool logistic_regression, double tradeoff) { C = c; Tradeoff = tradeoff; Training_Data = new List <Entry>(); Test_Data = new List <Entry>(); AccuracyWeightB = new Dictionary <int, AccuracyWB>(); SetData(r1, r2); perceptron = new Perceptron(Training_Data, Test_Data, learning_rate, margin, C, logistic_regression, Tradeoff, r); Dictionary <int, double> w = new Dictionary <int, double>(); double b = (r.NextDouble() * (0.01 + 0.01) - 0.01); //for (int i = 1; i < 67693; i++) //{ // double randomNumber = (r.NextDouble() * (0.01 + 0.01) - 0.01); // if (randomNumber != 0) // { // w.Add(i, randomNumber); // } //} WeightBias wb = new WeightBias(w, b, 0); for (int i = 0; i < epochs; i++) { wb = perceptron.CalculateWB(wb); AccuracyWeightB.Add(i + 1, new AccuracyWB(perceptron.GetAccuracy(Test_Data, wb), wb)); perceptron.ShuffleTraining_Data(r); } AccuracyWB bestAccuracy = AccuracyWeightB.OrderByDescending(x => x.Value.Accuracy).ThenByDescending(y => y.Key).Select(z => z.Value).First(); Training_Accuracy = perceptron.GetAccuracy(Training_Data, bestAccuracy.Weight_Bias); //Train Accuracy Accuracy = bestAccuracy.Accuracy; //Test Accuracy BestWeightBias = bestAccuracy.Weight_Bias; Learning_Rate = learning_rate; }