Пример #1
0
        public Data(List <Entry> r1, List <Entry> r2, Random r, int epochs, double learning_rate, double margin, double c, bool logistic_regression, double tradeoff)
        {
            C               = c;
            Tradeoff        = tradeoff;
            Training_Data   = r1;
            Test_Data       = r2;
            AccuracyWeightB = new Dictionary <int, AccuracyWB>();
            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);

            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();

            Train_Accuracy = perceptron.GetAccuracy(Training_Data, bestAccuracy.Weight_Bias); //Train Accuracy
            Test_Accuracy  = bestAccuracy.Accuracy;                                           //Test Accuracy
            BestWeightBias = bestAccuracy.Weight_Bias;
            Learning_Rate  = learning_rate;
        }
Пример #2
0
        public Data(List <Entry> train, List <Entry> test, int epochs, double learning_rate, Random r, bool DymanicLearningRate, double margin, bool Average, bool Aggressive,
                    double c, bool svm, double tradeoff, bool logistic_regression, int forestSize)
        {
            C                   = c;
            SVM                 = svm;
            Tradeoff            = tradeoff;
            Logistic_Regression = logistic_regression;
            ForestSize          = forestSize;

            double[]   w_average = new double[ForestSize];
            double     b_average;
            WeightBias wb_average = null;

            if (Average)
            {
                for (int i = 0; i < ForestSize; 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);
            }

            data_1          = train;
            data_2          = test;
            AccuracyWeightB = new Dictionary <int, AccuracyWB>();
            perceptron      = new Perceptron(data_1, data_2, learning_rate, DymanicLearningRate, margin, wb_average, Aggressive, C, SVM, Tradeoff, Logistic_Regression, ForestSize);
            double[] w = new double[ForestSize];
            double   b = (r.NextDouble() * (0.01 + 0.01) - 0.01);

            for (int i = 0; i < ForestSize; 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(data_2, perceptron.WeightBias_Average), perceptron.WeightBias_Average));
                }
                else
                {
                    AccuracyWeightB.Add(i + 1, new AccuracyWB(perceptron.GetAccuracy(data_2, 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();


            Test_Accuracy  = bestAccuracy.Accuracy;
            BestWeightBias = bestAccuracy.Weight_Bias;
            Learning_Rate  = learning_rate;
            //Console.WriteLine("\n" + Accuracy);
        }