Inheritance: Encog.ML.BasicML, IMLClassification, IMLResettable, IMLError
Example #1
0
        /**
	 * {@inheritDoc}
	 */

        public Object Read(Stream istream)
        {
            var result = new SOMNetwork();
            var reader = new EncogReadHelper(istream);
            EncogFileSection section;

            while ((section = reader.ReadNextSection()) != null)
            {
                if (section.SectionName.Equals("SOM")
                    && section.SubSectionName.Equals("PARAMS"))
                {
                    IDictionary<String, String> p = section.ParseParams();
                    EngineArray.PutAll(p, result.Properties);
                }
                if (section.SectionName.Equals("SOM")
                    && section.SubSectionName.Equals("NETWORK"))
                {
                    IDictionary<String, String> p = section.ParseParams();
                    result.Weights = EncogFileSection.ParseMatrix(p,
                                                                  PersistConst.Weights)
                        ;
                }
            }

            return result;
        }
        public void TestSOM()
        {
            // create the training set
            IMLDataSet training = new BasicMLDataSet(
                SOMInput, null);

            // Create the neural network.
            var network = new SOMNetwork(4, 2) {Weights = new Matrix(MatrixArray)};

            var train = new BasicTrainSOM(network, 0.4,
                                          training, new NeighborhoodSingle()) {ForceWinner = true};

            int iteration = 0;

            for (iteration = 0; iteration <= 100; iteration++)
            {
                train.Iteration();
            }

            IMLData data1 = new BasicMLData(
                SOMInput[0]);
            IMLData data2 = new BasicMLData(
                SOMInput[1]);

            int result1 = network.Classify(data1);
            int result2 = network.Classify(data2);

            Console.WriteLine(result1 + " result 2 :"+result2);
            Assert.IsTrue(result1 != result2);
        }
Example #3
0
        /**
         * {@inheritDoc}
         */

        public Object Read(Stream istream)
        {
            var result = new SOMNetwork();
            var reader = new EncogReadHelper(istream);
            EncogFileSection section;

            while ((section = reader.ReadNextSection()) != null)
            {
                if (section.SectionName.Equals("SOM") &&
                    section.SubSectionName.Equals("PARAMS"))
                {
                    IDictionary <String, String> p = section.ParseParams();
                    EngineArray.PutAll(p, result.Properties);
                }
                if (section.SectionName.Equals("SOM") &&
                    section.SubSectionName.Equals("NETWORK"))
                {
                    IDictionary <String, String> p = section.ParseParams();
                    result.Weights = EncogFileSection.ParseMatrix(p,
                                                                  PersistConst.Weights)
                    ;
                }
            }

            return(result);
        }
 /// <summary>
 /// Construct the object.
 /// </summary>
 ///
 /// <param name="network">The network to train.</param>
 /// <param name="training">The training data.</param>
 public SOMClusterCopyTraining(SOMNetwork network, IMLDataSet training)
     : base(TrainingImplementationType.OnePass)
 {
     _network = network;
     Training = training;
     if (_network.OutputCount < training.Count)
     {
         throw new NeuralNetworkError(
                 "To use cluster copy training you must have at least as many output neurons as training elements.");
     }
 }
        public SOMColors()
        {
            InitializeComponent();

            network = CreateNetwork();
            gaussian = new NeighborhoodRBF(RBFEnum.Gaussian, WIDTH, HEIGHT);
            train = new BasicTrainSOM(network, 0.01, null, gaussian);

            train.ForceWinner = false;

            samples = new List<IMLData>();
            for (int i = 0; i < 15; i++)
            {
                IMLData data = new BasicMLData(3);
                data.Data[0] = RangeRandomizer.Randomize(-1, 1);
                data.Data[1] = RangeRandomizer.Randomize(-1, 1);
                data.Data[2] = RangeRandomizer.Randomize(-1, 1);
                samples.Add(data);
            }

            train.SetAutoDecay(100, 0.8, 0.003, 30, 5);
        }
Example #6
0
 public BasicTrainSOM(SOMNetwork network, double learningRate, IMLDataSet training, INeighborhoodFunction neighborhood)
     : base(TrainingImplementationType.Iterative)
 {
     this._x3d0ce91dbd8e0b1b = neighborhood;
     while (true)
     {
         this.Training = training;
         while (0 == 0)
         {
             this._x9b481c22b6706459 = learningRate;
             this._x87a7fc6a72741c2e = network;
             this._x57202a8751db8895 = network.InputCount;
             this._x0c37ff3adde9bc44 = network.OutputCount;
             this._xf7c1f63ae5cd87f7 = false;
             this.Error = 0.0;
             this._x42cc0dadfb982948 = new Matrix(this._x57202a8751db8895, this._x0c37ff3adde9bc44);
             this._x703660d5c67ed8fb = new BestMatchingUnit(network);
             if (0 == 0)
             {
                 return;
             }
         }
     }
 }
Example #7
0
 public BestMatchingUnit(SOMNetwork som)
 {
     this._x7af5fe5ee7d4a6c7 = som;
 }
Example #8
0
 /// <summary>
 /// Generate the RSOM network.
 /// </summary>
 public IMLMethod Generate()
 {
     var som = new SOMNetwork(_inputNeurons, _outputNeurons);
     som.Reset();
     return som;
 }
        public void TestSOM2()
        {
            // create the training set
            IMLDataSet training = new BasicMLDataSet(
                SOMInput2, null);

            // Create the neural network.
            var network = new SOMNetwork(4,4);

            var train = new BasicTrainSOM(network, 0.01,
                                       training, new NeighborhoodSingle()) { ForceWinner = true };

            int iteration = 0;

            for (iteration = 0; iteration <= 1000; iteration++)
            {
                train.Iteration();
            }

            IMLData data1 = new BasicMLData(
                SOMInput2[2]);
            IMLData data2 = new BasicMLData(
                SOMInput2[0]);

            IMLData data3 = new BasicMLData(
               SOMInput2[1]);
            IMLData data4 = new BasicMLData(
                SOMInput2[3]);

            int result1 = network.Classify(data1);
            int result2 = network.Classify(data2);
            int result3 = network.Classify(data3);
            int result4 = network.Classify(data4);

            Console.WriteLine("Winner in someinput 2 "+network.Winner(new BasicMLData(SOMInput2[0])));

            Console.WriteLine("First  :" +result1);
            Console.WriteLine("Second "+result2);
            Console.WriteLine("Third  :" + result3);
            Console.WriteLine("Fourth " + result4);

            Assert.IsTrue(result1 != result2);

            train.TrainPattern(new BasicMLData(SOMInput2[2]));
            Console.WriteLine("After training pattern: " + network.Winner(new BasicMLData(SOMInput2[1])));

            var result = new SupportVectorMachine(4, SVMType.SupportVectorClassification, KernelType.Sigmoid);
            training = new BasicMLDataSet(
                SOMInput2, SOMInput2);
            SVMTrain trainsvm = new SVMTrain(result, training);

            trainsvm.Iteration(50);

            result1 = result.Classify(data1);

            result2 = result.Classify(data2);
            result3 = result.Classify(data3);
            result4 = result.Classify(data4);

            Console.WriteLine("SVM classification : EURUSD 1 :"+result1 + "  GBPUSD:"+result2 + " EURCHF :"+result3+  " EURJPY:"+result4 );
        }
 private void Validate(SOMNetwork network)
 {
     Assert.AreEqual(4, network.InputCount);
     Assert.AreEqual(2, network.OutputCount);
     Assert.AreEqual(8, network.Weights.ToPackedArray().Length);
 }
 private SOMNetwork Create()
 {
     SOMNetwork network = new SOMNetwork(4, 2);
     return network;
 }
 private SOMNetwork CreateNetwork()
 {
     var result = new SOMNetwork(3, WIDTH*HEIGHT);
     result.Reset();
     return result;
 }
Example #13
0
 private SOMNetwork CreateNetwork()
 {
     SOMNetwork result = new SOMNetwork(3, SOMColors.WIDTH * SOMColors.HEIGHT);            
     result.Reset();
     return result;
 }
Example #14
0
 public IMLMethod Generate()
 {
     SOMNetwork network = new SOMNetwork(this._xcfe830a7176c14e5, this._x8f581d694fca0474);
     network.Reset();
     return network;
 }
 /// <summary>
 /// Construct the object.
 /// </summary>
 ///
 /// <param name="network">The network to train.</param>
 /// <param name="training">The training data.</param>
 public SOMClusterCopyTraining(SOMNetwork network, IMLDataSet training)
     : base(TrainingImplementationType.OnePass)
 {
     _network = network;
     Training = training;
 }
Example #16
0
        private void btnBeginTraining_Click(object sender, EventArgs e)
        {
            if (!this.training)
            {
                int inputCount = OCRForm.DOWNSAMPLE_HEIGHT * OCRForm.DOWNSAMPLE_WIDTH;

                this.trainingSet = new BasicMLDataSet();

                foreach (char ch in this.letterData.Keys)
                {
                    BasicMLData item = new BasicMLData(inputCount);

                    bool[] data = this.letterData[ch];
                    for (int i = 0; i < inputCount; i++)
                    {
                        item[i] = data[i] ? 0.5 : -0.5;
                    }
                    this.trainingSet.Add(item);
                }

                this.network = new SOMNetwork(this.downsampled.Length, this.letterData.Count);
                this.network.Reset();
                this.training = true;

                Thread thread = new Thread(TrainNetwork);
                thread.Start();
            }
            else
            {
                this.training = false;
            }
        }
Example #17
0
 public SOMClusterCopyTraining(SOMNetwork network, IMLDataSet training)
     : base(TrainingImplementationType.OnePass)
 {
     this._x87a7fc6a72741c2e = network;
     this.Training = training;
 }
Example #18
0
 public object Read(Stream mask0)
 {
     EncogReadHelper helper;
     EncogFileSection section;
     SOMNetwork network = new SOMNetwork();
     goto Label_00FC;
     Label_000B:
     if (section.SubSectionName.Equals("NETWORK"))
     {
         IDictionary<string, string> paras = section.ParseParams();
         network.Weights = EncogFileSection.ParseMatrix(paras, "weights");
         network.OutputCount = EncogFileSection.ParseInt(paras, "outputCount");
         network.InputCount = EncogFileSection.ParseInt(paras, "inputCount");
         if (0 != 0)
         {
             if (0 == 0)
             {
                 goto Label_0055;
             }
             goto Label_0039;
         }
     }
     Label_001D:
     if ((section = helper.ReadNextSection()) != null)
     {
         if (!section.SectionName.Equals("SOM"))
         {
             goto Label_003E;
         }
         goto Label_00A0;
     }
     if (15 != 0)
     {
         return network;
     }
     goto Label_00FC;
     Label_0039:
     if (0 == 0)
     {
         goto Label_001D;
     }
     goto Label_000B;
     Label_003E:
     if (!section.SectionName.Equals("SOM"))
     {
         goto Label_0039;
     }
     if (1 != 0)
     {
         goto Label_000B;
     }
     return network;
     Label_0055:
     if (0 != 0)
     {
         if (0 != 0)
         {
             goto Label_001D;
         }
     }
     else
     {
         goto Label_003E;
     }
     Label_00A0:
     if (section.SubSectionName.Equals("PARAMS"))
     {
         EngineArray.PutAll<string, string>(section.ParseParams(), network.Properties);
     }
     goto Label_003E;
     Label_00FC:
     if (4 == 0)
     {
         goto Label_0055;
     }
     helper = new EncogReadHelper(mask0);
     goto Label_001D;
 }