Esempio n. 1
0
        public void ShouldRecogniseInversedSymbolWithNoises()
        {
            // given
            var hopfieldNetwork = new HopfieldNetwork();
            var symbolsToLearn  = new List <BipolarSymbol>
            {
                SymbolFactory.CreateBipolarFromDigit(0),
                SymbolFactory.CreateBipolarFromDigit(1),
                SymbolFactory.CreateBipolarFromDigit(2)
            };

            hopfieldNetwork.Learn(symbolsToLearn);

            // when
            bool symbolIsRecognised = hopfieldNetwork.TryRecognise(IversedNumberOneWithNoises());

            // then
            Assert.Equal(1, hopfieldNetwork.IterationsCountOfRecognising);
            Assert.True(symbolIsRecognised);

            BipolarSymbol expectedRecognisedSymbol = SymbolFactory.CreateBipolarFromDigit(1);

            expectedRecognisedSymbol.Inverse();
            Assert.Equal(expectedRecognisedSymbol.ConvertToOneDimensionalArray(), hopfieldNetwork.SymbolsOut);
        }
Esempio n. 2
0
        public void ShouldRaiseErrorWhenLearningWithoutSymbols(List <BipolarSymbol> emptySymbols)
        {
            // given
            var hopfieldNetwork = new HopfieldNetwork();

            // when
            Action networkLearning = () => hopfieldNetwork.Learn(emptySymbols);

            // then
            Assert.Throws <NoSymbollsPassedException>(networkLearning);
        }
Esempio n. 3
0
        public void ShouldCorrectlyLearnDigits(List <int> digits)
        {
            // given
            int[,] expectedWeights = HopfieldNetworkWeightsFactory.WeightsForHebbianLearningOfDigits(digits);
            var hopfieldNetwork = new HopfieldNetwork();
            IList <BipolarSymbol> symbolsToLearn = digits.Select(SymbolFactory.CreateBipolarFromDigit).ToList();

            // when
            hopfieldNetwork.Learn(symbolsToLearn);

            // then
            Assert.Equal(expectedWeights, hopfieldNetwork.Weights);
        }
Esempio n. 4
0
        public void ShouldRecogniseLearnedSymbol()
        {
            // given
            var hopfieldNetwork = new HopfieldNetwork();
            var symbolsToLearn  = new List <BipolarSymbol> {
                SymbolFactory.CreateBipolarFromDigit(1), SymbolFactory.CreateBipolarFromDigit(3)
            };

            hopfieldNetwork.Learn(symbolsToLearn);

            // when
            bool symbolIsRecognised = hopfieldNetwork.TryRecognise(SymbolFactory.CreateBipolarFromDigit(1));

            // then
            Assert.True(symbolIsRecognised);
            Assert.Equal(0, hopfieldNetwork.IterationsCountOfRecognising);
        }
Esempio n. 5
0
        public void ShouldRecogniseTheClosestLearnedSymbol()
        {
            // given
            var hopfieldNetwork = new HopfieldNetwork();
            var symbolsToLearn  = new List <BipolarSymbol> {
                SymbolFactory.CreateBipolarFromDigit(1), SymbolFactory.CreateBipolarFromDigit(3)
            };

            hopfieldNetwork.Learn(symbolsToLearn);

            // when
            bool symbolIsRecognised = hopfieldNetwork.TryRecognise(SymbolFactory.CreateBipolarFromDigit(2));

            // then
            Assert.True(symbolIsRecognised);
            Assert.Equal(1, hopfieldNetwork.IterationsCountOfRecognising);
            Assert.Equal(SymbolFactory.CreateBipolarFromDigit(3).ConvertToOneDimensionalArray(), hopfieldNetwork.SymbolsOut);
        }
Esempio n. 6
0
        public void ShouldNotRecogniseIncorrectSymbol()
        {
            // given
            var hopfieldNetwork = new HopfieldNetwork();
            var symbolsToLearn  = new List <BipolarSymbol>
            {
                SymbolFactory.CreateBipolarFromDigit(1),
                SymbolFactory.CreateBipolarFromDigit(2),
                SymbolFactory.CreateBipolarFromDigit(4)
            };

            hopfieldNetwork.Learn(symbolsToLearn);

            // when
            bool symbolIsRecognised = hopfieldNetwork.TryRecognise(SymbolFactory.CreateBipolarFromDigit(9));

            // then
            Assert.Equal(1, hopfieldNetwork.IterationsCountOfRecognising);
            Assert.Equal(OutputForUnrecognisedDigitNine(), hopfieldNetwork.SymbolsOut);
            Assert.False(symbolIsRecognised);
        }