示例#1
0
 public void InitializeNetwork()
 {
     classes = DataClass.CreateDataClasses(bow);
     classes = TestFunctions.CreateFullSet(classes, bow);
     myVector x = new myVector();
     {
         x = bow.GetVectorsList()[0];
         WithoutHiddenLayerNetwork = NeuralConstruction.CreateDefaultNetwork(x.GetVector().Count, classes);
         NeuralConstruction.SampleWeight(WithoutHiddenLayerNetwork, bow.GetVectorsList(), classes);
         NeuralNetwork = NeuralConstruction.CreateNewDefaultNetwork(x.GetVector().Count, classes, 5);
     }
 }
示例#2
0
        private void _Start_Copy_Click(object sender, RoutedEventArgs e)
        {
            myVector        x              = bow.GetVectorsList()[0];
            TestClass       T              = TestFunctions.CreateTest2(classes);
            List <myVector> vectors        = test.GetTestVectors();
            List <int>      kNNResultsIds  = new List <int>();
            List <int>      NNResultsIds   = new List <int>();
            List <int>      WHNNResultsIds = new List <int>();

            // Liczymy
            foreach (myVector V in vectors)
            {
                int id = 0;
                id = kNN.CalculateKNN(V, classes, 3);
                kNNResultsIds.Add(id);
                id = NeuralConstruction.OldSampleInput(V, WithoutHiddenLayerNetwork);
                WHNNResultsIds.Add(id);
                id = NeuralConstruction.SampleInput(V, NeuralNetwork);
                NNResultsIds.Add(id);
            }

            // Dodajemy wyniki dla KNN
            for (int i = 0; i < kNNResultsIds.Count; i++)
            {
                TestResult testresult = new TestResult("kNNAlgorithm");
                testresult.filltestData(T.GetTrainingClasses(), kNNResultsIds[i], vectors[i]);
                kNNResults.Add(testresult);
            }
            // Dodajemy wyniki dla sieci neuronowej
            for (int i = 0; i < NNResultsIds.Count; i++)
            {
                TestResult testresult = new TestResult("NNAlgorithm");
                testresult.filltestData(classes, NNResultsIds[i], vectors[i]);
                NNResults.Add(testresult);
            }
            // Dodajemy wyniki dla sieci neuronowej bez warstwy ukrytej
            for (int i = 0; i < WHNNResultsIds.Count; i++)
            {
                TestResult testresult = new TestResult("WHNNAlgorithm");
                testresult.filltestData(classes, WHNNResultsIds[i], vectors[i]);
                WHNNResults.Add(testresult);
            }
            ListView1.ItemsSource = kNNResults;
            ListView2.ItemsSource = NNResults;
            ListView3.ItemsSource = WHNNResults;

            kNNResults  = new List <TestResult>();
            NNResults   = new List <TestResult>();
            WHNNResults = new List <TestResult>();
            test        = new TestClass();
            test        = TestFunctions.CreateVectorTest(bow);
        }
示例#3
0
        private void UczenieSieci_Click(object sender, RoutedEventArgs e)
        {
            myVector x = bow.GetVectorsList()[0];

            BackPropagation.UczenieSieci(200, test.GetTrainingtVectors(), NeuralNetwork, classes);
            Console.Beep();

            foreach (myVector testvector in test.GetTestVectors())
            {
                int id     = NeuralConstruction.SampleInput(testvector, NeuralNetwork);
                var output = NeuralNetwork.getNetwork().Where(o => o.type == 2).ToList();
            }
            UczenieSieci.IsEnabled = false;
        }
示例#4
0
        public static void UczenieSieci(int k, List <myVector> V, Network N, List <DataClass> classes)
        {
            float        Eta      = 0.1f;
            List <float> ErrorLst = new List <float>();
            float        ErrorTotal;
            float        delta;
            float        target;
            float        coef   = 0.0f;
            var          middle = N.getNetwork().Where(o => o.type == 1).ToList();
            var          output = N.getNetwork().Where(o => o.type == 2).ToList();
            int          count  = k;

            while (k > 0)
            {
                foreach (var vector in V)
                {
                    NeuralConstruction.SampleInput(vector, N);
                    int id = classes.Where(o => o.GetVectors().Contains(vector)).First().GetID();

                    // Teaching the Output Part basing on the Hidden Part
                    var HiddenLayer = N.getNetwork().Where(o => o.type == 1);
                    foreach (var neuron in HiddenLayer)
                    {
                        var connections = neuron.GetConnections();
                        for (int i = 0; i < connections.Count; i++)
                        {
                            target = (id == i) ? 1 : 0;
                            delta  = (connections[i].To.Input - target) * (connections[i].To.Input * (1 - connections[i].To.Input)) * neuron.Input;
                            connections[i].NewWeight = connections[i].Weight - (Eta * delta);
                        }
                    }
                    // Teaching the Hidden Part basing on the Input Part

                    // Calculating the coeficient - I made it compute in here because it is constatnt for all outputs
                    // And the second part of the computations
                    var InputLayer = N.getNetwork().Where(o => o.type == 0);

                    foreach (var neuron in InputLayer)
                    {
                        var connections = neuron.GetConnections();

                        for (int i = 0; i < connections.Count; i++)
                        {
                            var ConTo = connections[i].To.GetConnections();
                            coef = 0;
                            for (int j = 0; j < ConTo.Count; j++)
                            {
                                target = (id == j) ? 1 : 0;
                                coef  += ConTo[j].Weight * (ConTo[j].To.Input * (1 - ConTo[j].To.Input)) * (ConTo[j].To.Input - target);
                            }

                            delta = coef * (connections[i].To.Input * (1 - connections[i].To.Input)) * neuron.Input;

                            connections[i].NewWeight = connections[i].Weight - (Eta * delta);
                        }
                    }

                    // Finalisation
                    AssingNewWeights(N);
                }
                k--;
            }
        }