Ejemplo n.º 1
0
        public NeuralOutput Think(SensoryInput input)
        {
            for (var layer = 0; layer < Network.Layers.Length; ++layer)
            {
                for (var neuron = 0; neuron < Network.Layers[layer].Neurons.Length; neuron++)
                {
                    if (layer == 0)
                    {
                        Network.Layers[layer].Neurons[neuron].Value = input.Values[neuron];
                    }
                    else
                    {
                        Network.Layers[layer].Neurons[neuron].Value = 0;
                        for (var dentrite = 0; dentrite < Network.Layers[layer - 1].Neurons.Length; ++dentrite)
                        {
                            Network.Layers[layer].Neurons[neuron].Value = Network.Layers[layer].Neurons[neuron].Value +
                                                                          Network.Layers[layer - 1].Neurons[dentrite]
                                                                          .Value *
                                                                          Network.Layers[layer].Neurons[neuron].Dendrite
                                                                          [dentrite].Weight;
                        }
                        Network.Layers[layer].Neurons[neuron].Value =
                            MathUtilityHelper.HyperbolicTangent(Network.Layers[layer].Neurons[neuron].Value);
                    }
                }
            }

            NeuralOutput output;

            output.Values = new double[Network.Layers[Network.Layers.Length - 1].Neurons.Length];
            for (var neuron = 0; neuron < output.Values.Length; ++neuron)
            {
                output.Values[neuron] = Network.Layers[Network.Layers.Length - 1].Neurons[neuron].Value;
//                    Mathf.Clamp((float) Network.Layers[Network.Layers.Length - 1].Neurons[neuron].Value, -1, 1);
            }

            return(output);
        }
        public void Start()
        {
            originalPosition = transform.position;
            originalRotation = transform.rotation;

            const float exclude = 0.3f;

            // translation
            xTrans = new Vector2(-0.6f, 0.6f);
            yTrans = new Vector2(-0.6f, 0.6f);
            zTrans = new Vector2(-0.6f, 0.6f);
            translation = new Vector3(
                MathUtilityHelper.Range(xTrans.x, xTrans.y, -exclude, exclude),
                MathUtilityHelper.Range(yTrans.x, yTrans.y, -exclude, exclude),
                MathUtilityHelper.Range(zTrans.x, zTrans.y, -exclude, exclude)
            );
            transSpeed = new Vector3(
                MathUtilityHelper.Range(minRotSpeed.x, minRotSpeed.y, -exclude, exclude),
                MathUtilityHelper.Range(minRotSpeed.x, minRotSpeed.y, -exclude, exclude),
                MathUtilityHelper.Range(minRotSpeed.x, minRotSpeed.y, -exclude, exclude)
            );

            // rotation
            xRot = new Vector2 (-5f,5f);
            yRot = new Vector2 (-5f,5f);
            zRot = new Vector2 (-5f,5f);
            minRotSpeed = new Vector2 (-0.8f,0.8f);
            minRotation = new Vector2 (-5,5);
            rotation.x = MathUtilityHelper.Range(xRot.x,xRot.y, minRotation.x, minRotation.y);	
            rotation.y = MathUtilityHelper.Range(yRot.x,yRot.y, minRotation.x, minRotation.y);
            rotation.z = MathUtilityHelper.Range(zRot.x,zRot.y, minRotation.x, minRotation.y);
            rotSpeed = new Vector3 (
                MathUtilityHelper.Range(minRotSpeed.x,minRotSpeed.y,-exclude,exclude),
                MathUtilityHelper.Range(minRotSpeed.x,minRotSpeed.y,-exclude,exclude),
                MathUtilityHelper.Range(minRotSpeed.x,minRotSpeed.y,-exclude,exclude)
            );
        }