2016-08-21 13 views
11

Przeszedłem przez całą dokumentację i nie znalazłem sposobu ustawienia sieci RBF. Znalazłem przykład RBF w ConsoleExmpales/Examples/Radial, ale wygląda na to, że już nie działa, ponieważ niektóre metody zostały zmienione w Encog.Encog C# sieć RBF, jak zacząć?

tej pory jestem zatrzymany na to:

public static double[][] XORInput = { 
     new[] {0.0, 0.0}, 
     new[] {1.0, 0.0}, 
     new[] {0.0, 1.0}, 
     new[] {1.0, 1.0} 
    }; 

    public static double[][] XORIdeal = { 
     new[] {0.0}, 
     new[] {1.0}, 
     new[] {1.0}, 
     new[] {0.0} 
    }; 

     int dimension = 8; 
     int numNeuronsPerDimension = 64; 
     double volumeNeuronWidth = 2.0/numNeuronsPerDimension; 
     bool includeEdgeRBFs = true; 

     RBFNetwork n = new RBFNetwork(dimension, numNeuronsPerDimension, 1, RBFEnum.Gaussian); 
     n.SetRBFCentersAndWidthsEqualSpacing(0, 1, RBFEnum.Gaussian, volumeNeuronWidth, includeEdgeRBFs); 
     //n.RandomizeRBFCentersAndWidths(0, 1, RBFEnum.Gaussian); 

     INeuralDataSet trainingSet = new BasicNeuralDataSet(XORInput, XORIdeal); 
     SVDTraining train = new SVDTraining(n, trainingSet); 

     int epoch = 1; 
     do 
     { 
      train.Iteration(); 
      Console.WriteLine("Epoch #" + epoch + " Error:" + train.Error); 
      epoch++; 
     } while ((epoch < 1) && (train.Error > 0.001)); 

Kiedy uruchamiam to, otrzymuję błąd „Całkowita liczba neuronów RBF musi być jakaś całkowita do potęgi«wymiarach».” na SetRBFCentersAndWidthsEqualSpacing. Działa, jeśli zmienię tę metodę na RandomizeRBFCentersAndWidths do train.iteration() zostanie osiągnięty, gdzie otrzymam "Index był poza granicami tablicy".

Rozumiem, jak działa sieć RBF, ale jestem zdezorientowany ze wszystkich parametrów w metodzie SetRBFCentersAndWidthsEqualSpacing, czy ktoś może wyjaśnić to bardziej szczegółowo ?.

Odpowiedz

2

Bardzo dobre pytanie.

  1. SetRBFCentersAndWidthsEqualSpacingand here jest stosunkowo nową metodą sieci neuronowych szkolenia i Jeff Heaton postanowiliśmy je wdrożyć.
  2. Wygląda na to, że istnieje różnica między Java version i C# version na liniach 230-240, a błąd IMHO znajduje się w wersji Java.

  3. Mam zmodyfikowany kod, aby mogła ona być wykonalne z dodatkowymi uwagami:

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Threading.Tasks; 
    using Encog.MathUtil.RBF; 
    using Encog.Neural.Data.Basic; 
    using Encog.Neural.NeuralData; 
    using Encog.Neural.Rbf.Training; 
    using Encog.Neural.RBF; 
    
    namespace TestRBF 
    { 
        class Program 
        { 
         public static double[][] XORInput = { 
         new[] {0.0, 0.0}, 
         new[] {1.0, 0.0}, 
         new[] {0.0, 1.0}, 
         new[] {1.0, 1.0} 
        }; 
    
         public static double[][] XORIdeal = { 
         new[] {0.0}, 
         new[] {1.0}, 
         new[] {1.0}, 
         new[] {0.0} 
        }; 
    
         static void Main(string[] args) 
         { 
          int dimension = 2; // XORInput provides two-dimensional inputs. Not 8. 
          /* 
          If XORInput is 8 dimensional it should be like this: 
    
          public static double[][] XORInput = { 
          new[] {0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0, 0.0}, 
          . 
          . 
          .*/ 
          int numNeuronsPerDimension = 4; // could be also 16, 64, 256. I suppose it should accept 8, 32 but it needs additional investigation 
          double volumeNeuronWidth = 2.0/numNeuronsPerDimension; 
          bool includeEdgeRBFs = true; 
    
          RBFNetwork n = new RBFNetwork(dimension, numNeuronsPerDimension, 1, RBFEnum.Gaussian); 
          n.SetRBFCentersAndWidthsEqualSpacing(0, 1, RBFEnum.Gaussian, volumeNeuronWidth, includeEdgeRBFs); 
          //n.RandomizeRBFCentersAndWidths(0, 1, RBFEnum.Gaussian); 
    
          INeuralDataSet trainingSet = new BasicNeuralDataSet(XORInput, XORIdeal); 
          SVDTraining train = new SVDTraining(n, trainingSet); 
    
          int epoch = 1; 
          do 
          { 
           train.Iteration(); 
           Console.WriteLine("Epoch #" + epoch + " Error:" + train.Error); 
           epoch++; 
          } while ((epoch < 1) && (train.Error > 0.001)); 
    
         } 
        } 
    } 
    
+1

zapomniałem zmienić wymiar, 2 ma rację. Dziękuję za punkt numNeuronsPerDimension, teraz działa! Próbowałem 8, 32 i to nie działa, więc tylko 16, 64, 256. – EdWood

+1

Moc WRT wymiaru jest wymogiem centrów RBF i algorytmem odstępów o równej szerokości –

+0

Myślę, że jest błąd w wersji .NET na linii 232: var expectedSideLength = (int) Math.Pow (totalNumHiddenNeurons, 1.0d/dimensions); podwójne cmp = Math.Pow (totalNumHiddenNeurons, 1.0d/wymiary); jeśli (expectedSideLength! = cmp) te dwie zmienne nie mogą być równe, ponieważ "(int)" zaokrągla liczbę. To zbieg okoliczności, że działa na przykładzie XOR, z innym dimensonem jak 19, to nie zadziała. – EdWood