public RBF(int K, int numOfEpocks, double learningRate, double maxError, List<List<double>> trainingSamples, List<List<double>> trainingLabels, List<List<double>> testSamples, List<List<double>> testLabels)
        {
            this.numOfEpocks = numOfEpocks;
            this.trainingSamples = trainingSamples;
            this.trainingLabels = trainingLabels;
            this.testSamples = testSamples;
            this.testLabels = testLabels;
            this.maxError = maxError;
            this.learningRate = learningRate;
            Centroids = new List<List<double>>();  //[NumOfCluster][NumOfFeatures (means)]
            Random rnd = new Random(Guid.NewGuid().GetHashCode());
            int counter = K; // Num of Clusters
            while (counter-- > 0)
            {
                int index = rnd.Next(trainingSamples.Count);
                Centroids.Add(trainingSamples[index]);
            }

            KMean = new K_Means(ref Centroids, trainingSamples);
            Variance = KMean.GetVariance;
            ////

            ////
            List<int> numOfNeuronsPerLayer = new List<int>();
            backpropagation = new Backpropagation();

            numOfNeuronsPerLayer.Add(K);
            numOfNeuronsPerLayer.Add(3);

            this.neuralNetwork = new FeedforwardNeuralNetwrok(2);
            this.neuralNetwork.setNetwork(numOfNeuronsPerLayer);

            this.neuralNetwork.LMSsetLayer(1, new IdentityFunction());
        }
 /// <summary>
 /// Train the network given the training samples (features) and the labels (classes),
 /// then using the chosen learning algorithm to update the weights.
 /// </summary>
 /// <param name="trainingSamples"> Training Samples Features</param>
 /// <param name="trainingLabels"> Training Labels (classes)</param>
 /// <param name="learningRate">Training learning Rate</param>
 /// <param name="learningAlgorithm">The learning algorithm that will be used to train the network</param>
 public void train(List<List<double>> trainingSamples, List<List<double>> trainingLabels, double learningRate, LearningAlgorithm learningAlgorithm)
 {
     double sum = 0;
     for (int i = 0; i < trainingSamples.Count; ++i)
     {
         List<double> output = this.feedforward(trainingSamples[i]);
         this.network = learningAlgorithm.learn(learningRate, trainingSamples[i], trainingLabels[i], this.network);
         for (int j = 0; j < network[0].Count; j++)
         {
             sum += Math.Pow(network[0][j].SignalError, 2);
         }
     }
     ErrorSqr = sum / network[0].Count;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Train the network given the training samples (features) and the labels (classes),
        /// then using the chosen learning algorithm to update the weights.
        /// </summary>
        /// <param name="trainingSamples"> Training Samples Features</param>
        /// <param name="trainingLabels"> Training Labels (classes)</param>
        /// <param name="learningRate">Training learning Rate</param>
        /// <param name="learningAlgorithm">The learning algorithm that will be used to train the network</param>
        public void train(List <List <double> > trainingSamples, List <List <double> > trainingLabels, double learningRate, LearningAlgorithm learningAlgorithm)
        {
            double sum = 0;

            for (int i = 0; i < trainingSamples.Count; ++i)
            {
                List <double> output = this.feedforward(trainingSamples[i]);
                this.network = learningAlgorithm.learn(learningRate, trainingSamples[i], trainingLabels[i], this.network);
                for (int j = 0; j < network[0].Count; j++)
                {
                    sum += Math.Pow(network[0][j].SignalError, 2);
                }
            }
            ErrorSqr = sum / network[0].Count;
        }