Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
        public void SingleAdditionNeuronInLayer(decimal val1, decimal val2)
        {
            // Arrange
            var receiver = new ValueStoringNeuron<decimal>();
            var sut = new OnNextSplittingObserverDecorator<decimal>(new CompositeObserver<decimal>(new IObserver<decimal>[]
            {
                new DelayedActivationNeuron<decimal, decimal>(new DecimalSumFunction(), receiver)
            }));

            // Act
            sut.OnNext(new decimal[] { val1, val2 });

            // Assert
            var result = receiver.LastValue;
            result.Should().Be(val1 + val2);
        }
        public void SimpleAdditionNeuron(decimal val1, decimal val2)
        {
            // Arrange
            var receiver = new ValueStoringNeuron<decimal>();
            var sut = new CompositeObserver<decimal>(new IObserver<decimal>[]
            {
                new DelayedActivationNeuron<decimal, decimal>(new DecimalSumFunction(), receiver)
            });

            // Act
            sut.OnNext(val1);
            sut.OnNext(val2);
            sut.OnCompleted();

            // Assert
            var result = receiver.LastValue;
            result.Should().Be(val1 + val2);
        }