Exemplo n.º 1
0
    public int Predict(List <float> input)
    {
        input.Add(1.0f);
        float[] inputs = input.ToArray();
        float[] values =
        {
            _n1.Activate(inputs),
            _n2.Activate(inputs),
            _n3.Activate(inputs)
        };

        float sum = 0;

        foreach (var value in values)
        {
            sum += Mathf.Exp(value);
        }

        for (var i = 0; i < values.Length; i++)
        {
            values[i] = Mathf.Exp(values[i]) / sum;
        }

        var max = values.Max();

        return(values.ToList().IndexOf(max));
    }
Exemplo n.º 2
0
        public void Should_propogate_acitivation_energy()
        {
            var NeuronA = new Neuron();
            var NeuronB = new Neuron();

            NeuronA.Connect(NeuronB, 2.0);

            NeuronA.Activate(2);

            Assert.AreEqual(NeuronB.ActivatedValue, 4.0);
        }
Exemplo n.º 3
0
 private double Activate(Pattern pattern)
 {
     for (int i = 0; i < pattern.Inputs.Length; i++)
     {
         _inputs[i].Output = pattern.Inputs[i];
     }
     foreach (Neuron neuron in _hidden)
     {
         neuron.Activate();
     }
     _output.Activate();
     return(_output.Output);
 }
Exemplo n.º 4
0
        public void Scaffold_Test_Neuron()
        {
            activator = new ReLU();
            for (int i = 0; i < testInputs.Length; i++)
            {
                testInputs[i] = new Neuron();
            }
            neuronToTest = new Neuron(testInputs, activator, 2); // Defines each weight in the inputs as 1 for testing purposes

            foreach (Neuron inputNeuron in testInputs)
            {
                inputNeuron.Input = 1;
                inputNeuron.Activate(); // playing the role of the neuron layer
            }

            // Act for every test, test case
            neuronToTest.Input = givenInput;
            neuronToTest.Activate();
            neuronToTest.SetError(expected);
        }
Exemplo n.º 5
0
 public void InheritActivation()
 {
     neuronToTest.Input = null;
     neuronToTest.Activate();
     Assert.AreEqual(11, neuronToTest.Activation); // should give us the weighted sum!
 }
Exemplo n.º 6
0
 public void Is_high_if_both_high()
 {
     _nA.Activate(1);
     _nB.Activate(1);
     Assert.AreEqual(_nOutput.ActivatedValue, 1);
 }