void Calculate()
    {
        float stepSize = 1f / steps;

        Color[] colors = new Color[(steps + 1) * (steps + 1)];
        for (int x = 0; x <= steps; x++)
        {
            for (int y = 0; y <= steps; y++)
            {
                double res = perceptron.CalculateOutput(new double[] { x *stepSize, y *stepSize });
                colors [y * (steps + 1) + x] = new Color(1 - (float)res, (float)res, 0);
            }
        }

        foreach (var ti in perceptron.trainingData.itens)
        {
            var x = Mathf.FloorToInt((float)ti.input [0] * steps);
            var y = Mathf.FloorToInt((float)ti.input [1] * steps);

            float res = (float)perceptron.CalculateOutput(new double[] { x *stepSize, y *stepSize }) * 0.5f;

            colors [y * (steps + 1) + x] = new Color(0.5f - res, res, 0);
        }

        Texture2D t2d = new Texture2D(steps + 1, steps + 1);

        t2d.SetPixels(colors);
        t2d.Apply();
        GetComponent <RawImage> ().texture = t2d;
    }
示例#2
0
        public void PerceptronWeightsAreTakenIntoAccount()
        {
            LayerStructure structure  = new LayerStructure(9, new[] { 7 }, 5);
            Perceptron     perceptron = new Perceptron(GetInitParamsByLayerStructure(structure));

            perceptron.FillWeightsRandomly();
            float[] inputVector = new[] { 0.44f, 0.354f, 0.667f, 0, 0.454f, 0.48f, 0.456f, 0.44f, 0.456f };

            float[] outputVector = perceptron.CalculateOutput(inputVector);

            Assert.AreNotEqual(inputVector, outputVector, "Input and output vectors are same");
        }
示例#3
0
        public void PerceptronOutputIsFromZeroToOne()
        {
            LayerStructure structure  = new LayerStructure(9, new[] { 6, 6 }, 5);
            Perceptron     perceptron = new Perceptron(GetInitParamsByLayerStructure(structure));

            perceptron.FillWeightsRandomly();
            float[] inputVector = { 0.44f, 0.354f, 0.667f, 0, 0.454f, 0.48f, 0.456f, 0.44f, 0.456f };

            float[] outputVector = perceptron.CalculateOutput(inputVector);

            int correctValuesCount = outputVector.Count(value => value > 0 && value <= 1);

            Assert.AreEqual(outputVector.Count(), correctValuesCount);
        }
    void OnProjectileIsThrown(Projectitle0327 projectile)
    {
        double result = perceptron.CalculateOutput(projectile.color, projectile.shape);

        if (result == 0)
        {
            m_rigidBody.isKinematic = false;
            m_animator.SetTrigger("Crouch");
        }
        else
        {
            m_rigidBody.isKinematic = true;
        }

        perceptron.AcquireKnowledge(projectile.name, projectile.result, projectile.color, projectile.shape);
    }
示例#5
0
 public void TestPerceptron_PositiveInput_TrueResult(string filePath)
 {
     Assert.AreEqual(1, _neuron.CalculateOutput(filePath));
 }