public void And(bool val1, bool val2) { // Arrange var boolTransformer = new BoolDecimalTransformer(); var receiver = new ValueStoringNeuron<bool>(); var perceptron = new OneToManyBufferingDecorator<decimal>( new ManyInputNeuron<decimal, decimal>( new DecimalSumFunction(), new ActivationNeuron<decimal, decimal>( new DecimalThresholdFunction { Threshold = 2M }, new ActivationNeuron<decimal, bool>( boolTransformer, receiver))) , 2); var leftNeuron = new ActivationNeuron<bool, decimal>( boolTransformer, perceptron); var rightNeuron = new ActivationNeuron<bool, decimal>( boolTransformer, perceptron); // Act leftNeuron.OnNext(val1); rightNeuron.OnNext(val2); // Assert var result = receiver.LastValue; var expected = val1 && val2; result.Should().Be(expected); }
public void Xor(bool val1, bool val2) { // Arrange var boolTransformer = new BoolDecimalTransformer(); var receiver = new ValueStoringNeuron<bool>(); var wrappedReceiver = new OneToManyBufferingDecorator<decimal>( new ManyInputNeuron<decimal, decimal>( new DecimalSumFunction(), new ActivationNeuron<decimal, decimal>( new DecimalThresholdFunction { Threshold = 0.5M }, new ActivationNeuron<decimal, bool>( boolTransformer, receiver))) , 3); var pivotNeuron = new OneToManyBufferingDecorator<decimal>( new ManyInputNeuron<decimal, decimal>( new DecimalSumFunction(), new ActivationNeuron<decimal, decimal>( new DecimalThresholdFunction { Threshold = 1.5M }, new DecimalWeight(wrappedReceiver, -2M))) , 2); var leftNeuron = new ActivationNeuron<bool, decimal>( boolTransformer, new CompositeObserver<decimal>( new DecimalWeight(wrappedReceiver, 1), new DecimalWeight(pivotNeuron, 1))); var rightNeuron = new ActivationNeuron<bool, decimal>( boolTransformer, new CompositeObserver<decimal>( new DecimalWeight(wrappedReceiver, 1), new DecimalWeight(pivotNeuron, 1))); // Act leftNeuron.OnNext(val1); rightNeuron.OnNext(val2); // Assert var result = receiver.LastValue; var expected = val1 ^ val2; result.Should().Be(expected); }