Example #1
0
        public void CanStoreABit(bool expected)
        {
            var sut = new MemoryGate(new NAnd(new Not(), new And()));

            var result = sut.Apply(expected, true);

            Assert.AreEqual(expected, result);
        }
Example #2
0
        public void CanKeepTheValueOfABit()
        {
            var sut = new MemoryGate(new NAnd(new Not(), new And()));

            // set the initial state of the memory to on
            var result = sut.Apply(true, true);

            // assert that the bit is set
            Assert.AreEqual(true, result);

            // turn off set mode and try and set the input bit to off
            result = sut.Apply(false, false);
            Assert.AreEqual(true, result);
        }
Example #3
0
        /// <summary>
        ///   Evaluates the state.
        /// </summary>
        /// <returns></returns>
        public override double Evaluate()
        {
            // guarantee updates to Input
            base.Evaluate();

            if (In.Count > 0)
            {
                // is hidden unit - apply memory states
                // Input is equal to combined input weights with bias values

                R = ResetGate.Compute(Rx * Input + Rh * H + Rb);
                Z = MemoryGate.Compute(Zx * Input + Zh * H + Zb);

                var htP = ActivationFunction.Compute(Input + R * H);

                H = (1.0 - Z) * H + Z * htP;

                Output = OutputFunction?.Compute(H) ?? H;
            }

            return(Output);
        }