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); }
public void ShouldRaiseErrorWhenLearningWithoutSymbols(List <BipolarSymbol> emptySymbols) { // given var hopfieldNetwork = new HopfieldNetwork(); // when Action networkLearning = () => hopfieldNetwork.Learn(emptySymbols); // then Assert.Throws <NoSymbollsPassedException>(networkLearning); }
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); }
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); }
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); }
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); }