Esempio n. 1
0
        public void CalculateWeights(BoltzmannMachine logic)
        {
            for (var sourceTour = 0; sourceTour < NUM_CITIES; sourceTour++)
            {
                for (var sourceCity = 0; sourceCity < NUM_CITIES; sourceCity++)
                {
                    var sourceIndex = sourceTour * NUM_CITIES + sourceCity;
                    for (var targetTour = 0; targetTour < NUM_CITIES; targetTour++)
                    {
                        for (var targetCity = 0; targetCity < NUM_CITIES; targetCity++)
                        {
                            var    targetIndex = targetTour * NUM_CITIES + targetCity;
                            double weight      = 0;

                            if (sourceIndex != targetIndex)
                            {
                                var predTargetTour = targetTour == 0 ? NUM_CITIES - 1 : targetTour - 1;
                                var succTargetTour = targetTour == NUM_CITIES - 1 ? 0 : targetTour + 1;
                                if ((sourceTour == targetTour) || (sourceCity == targetCity))
                                {
                                    weight = -gamma;
                                }
                                else if ((sourceTour == predTargetTour) || (sourceTour == succTargetTour))
                                {
                                    weight = -distance[sourceCity][targetCity];
                                }
                            }
                            logic.SetWeight(sourceIndex, targetIndex, weight);
                        }
                    }
                    logic.Threshold[sourceIndex] = -gamma / 2;
                }
            }
        }
        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);
        }
        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);
        }
Esempio n. 4
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);
                }
            }
        }