상속: ThermalNetwork
예제 #1
0
        public void CalculateWeights(BoltzmannMachine network)
        {
            int n1, n2, n3, n4;
            int i, j;
            int predN3, succN3;
            double weight;

            for (n1 = 0; n1 < NUM_CITIES; n1++)
            {
                for (n2 = 0; n2 < NUM_CITIES; n2++)
                {
                    i = n1*NUM_CITIES + n2;
                    for (n3 = 0; n3 < NUM_CITIES; n3++)
                    {
                        for (n4 = 0; n4 < NUM_CITIES; n4++)
                        {
                            j = n3*NUM_CITIES + n4;
                            weight = 0;
                            if (i != j)
                            {
                                predN3 = (n3 == 0 ? NUM_CITIES - 1 : n3 - 1);
                                succN3 = (n3 == NUM_CITIES - 1 ? 0 : n3 + 1);
                                if ((n1 == n3) || (n2 == n4))
                                    weight = -gamma;
                                else if ((n1 == predN3) || (n1 == succN3))
                                    weight = -distance[n2][n4];
                            }
                            network.SetWeight(i, j, weight);
                        }
                    }
                    network.Threshold[i] = (-gamma/2);
                }
            }
        }
예제 #2
0
 private void ValidateHopfield(BoltzmannMachine network)
 {
     network.Run();// at least see if it can run without an exception
     Assert.AreEqual(4, network.NeuronCount);
     Assert.AreEqual(4, network.CurrentState.Count);
     Assert.AreEqual(16, network.Weights.Length);
     Assert.AreEqual(1.0, network.GetWeight(1, 1));
     Assert.AreEqual(2.0, network.Threshold[2]);
 }
예제 #3
0
        public void TestPersistSerial()
        {
            BoltzmannMachine network = new BoltzmannMachine(4);
            network.SetWeight(1, 1, 1);
            network.Threshold[2] = 2;

            SerializeObject.Save(SERIAL_FILENAME.ToString(), network);
            BoltzmannMachine network2 = (BoltzmannMachine)SerializeObject.Load(SERIAL_FILENAME.ToString());

            ValidateHopfield(network2);
        }
예제 #4
0
        public void TestPersistEG()
        {
            BoltzmannMachine network = new BoltzmannMachine(4);
            network.SetWeight(1, 1, 1);
            network.Threshold[2] = 2;

            EncogDirectoryPersistence.SaveObject(EG_FILENAME, network);
            BoltzmannMachine network2 = (BoltzmannMachine)EncogDirectoryPersistence.LoadObject(EG_FILENAME);

            ValidateHopfield(network2);
        }
예제 #5
0
        /// <inheritdoc/>
        public Object Read(Stream mask0)
        {
            var result = new BoltzmannMachine();
            var ins0 = new EncogReadHelper(mask0);
            EncogFileSection section;

            while ((section = ins0.ReadNextSection()) != null)
            {
                if (section.SectionName.Equals("BOLTZMANN")
                    && section.SubSectionName.Equals("PARAMS"))
                {
                    IDictionary<String, String> paras = section.ParseParams();
                    EngineArray.PutAll(paras, result.Properties);
                }
                if (section.SectionName.Equals("BOLTZMANN")
                    && section.SubSectionName.Equals("NETWORK"))
                {
                    IDictionary<String, String> p = section.ParseParams();
                    result.Weights = NumberList.FromList(CSVFormat.EgFormat,
                                                         (p[PersistConst.Weights]));
                    result.SetCurrentState(NumberList.FromList(CSVFormat.EgFormat,
                                                               (p[PersistConst.Output])));
                    result.NeuronCount = EncogFileSection.ParseInt(p,
                                                                   PersistConst.NeuronCount);

                    result.Threshold = NumberList.FromList(CSVFormat.EgFormat,
                                                           (p[PersistConst.Thresholds]));
                    result.AnnealCycles = EncogFileSection.ParseInt(p,
                                                                    BoltzmannMachine.ParamAnnealCycles);
                    result.RunCycles = EncogFileSection.ParseInt(p,
                                                                 BoltzmannMachine.ParamRunCycles);
                    result.Temperature = EncogFileSection.ParseDouble(p,
                                                                      PersistConst.Temperature);
                }
            }

            return result;
        }
예제 #6
0
        /// <inheritdoc/>
        public Object Read(Stream mask0)
        {
            var result = new BoltzmannMachine();
            var ins0   = new EncogReadHelper(mask0);
            EncogFileSection section;

            while ((section = ins0.ReadNextSection()) != null)
            {
                if (section.SectionName.Equals("BOLTZMANN") &&
                    section.SubSectionName.Equals("PARAMS"))
                {
                    IDictionary <String, String> paras = section.ParseParams();
                    EngineArray.PutAll(paras, result.Properties);
                }
                if (section.SectionName.Equals("BOLTZMANN") &&
                    section.SubSectionName.Equals("NETWORK"))
                {
                    IDictionary <String, String> p = section.ParseParams();
                    result.Weights = NumberList.FromList(CSVFormat.EgFormat,
                                                         (p[PersistConst.Weights]));
                    result.SetCurrentState(NumberList.FromList(CSVFormat.EgFormat,
                                                               (p[PersistConst.Output])));
                    result.NeuronCount = EncogFileSection.ParseInt(p,
                                                                   PersistConst.NeuronCount);

                    result.Threshold = NumberList.FromList(CSVFormat.EgFormat,
                                                           (p[PersistConst.Thresholds]));
                    result.AnnealCycles = EncogFileSection.ParseInt(p,
                                                                    BoltzmannMachine.ParamAnnealCycles);
                    result.RunCycles = EncogFileSection.ParseInt(p,
                                                                 BoltzmannMachine.ParamRunCycles);
                    result.Temperature = EncogFileSection.ParseDouble(p,
                                                                      PersistConst.Temperature);
                }
            }

            return(result);
        }
예제 #7
0
 /// <summary>
 /// Generate the network.
 /// </summary>
 public IMLMethod Generate()
 {
     var boltz = new BoltzmannMachine(_neuronCount);
     boltz.Temperature = _temperature;
     boltz.RunCycles = _runCycles;
     boltz.AnnealCycles = _annealCycles;
     return boltz;
 }
예제 #8
0
 public object Read(Stream mask0)
 {
     EncogFileSection section;
     IDictionary<string, string> dictionary2;
     BoltzmannMachine machine = new BoltzmannMachine();
     EncogReadHelper helper = new EncogReadHelper(mask0);
     Label_0034:
     if ((section = helper.ReadNextSection()) != null)
     {
         goto Label_012B;
     }
     return machine;
     Label_00A3:
     machine.Threshold = NumberList.FromList(CSVFormat.EgFormat, dictionary2["thresholds"]);
     machine.AnnealCycles = EncogFileSection.ParseInt(dictionary2, "annealCycles");
     machine.RunCycles = EncogFileSection.ParseInt(dictionary2, "runCycles");
     if (0 == 0)
     {
         machine.Temperature = EncogFileSection.ParseDouble(dictionary2, "temperature");
         goto Label_0034;
     }
     goto Label_0142;
     Label_00C4:
     if (section.SectionName.Equals("BOLTZMANN") && section.SubSectionName.Equals("NETWORK"))
     {
         dictionary2 = section.ParseParams();
         machine.Weights = NumberList.FromList(CSVFormat.EgFormat, dictionary2["weights"]);
     }
     else
     {
         goto Label_0034;
     }
     machine.SetCurrentState(NumberList.FromList(CSVFormat.EgFormat, dictionary2["output"]));
     machine.NeuronCount = EncogFileSection.ParseInt(dictionary2, "neurons");
     goto Label_00A3;
     Label_012B:
     if (!section.SectionName.Equals("BOLTZMANN"))
     {
         goto Label_00C4;
     }
     Label_0142:
     if (section.SubSectionName.Equals("PARAMS"))
     {
         EngineArray.PutAll<string, string>(section.ParseParams(), machine.Properties);
         if (0 == 0)
         {
             goto Label_00C4;
         }
         goto Label_012B;
     }
     if (0 != 0)
     {
         goto Label_0142;
     }
     if (2 == 0)
     {
         if (-1 == 0)
         {
             goto Label_00A3;
         }
         if (8 != 0)
         {
             goto Label_012B;
         }
         goto Label_0142;
     }
     goto Label_00C4;
 }