コード例 #1
0
ファイル: ThrowerService.cs プロジェクト: rhoninn11/Basket_nn
    private void _ThrowingManagment()
    {
        if (_thrower.IsReady())
        {
            List <TrajectoryData> collectedData = _thrower.CollectTrajecoryData();

            if (collectedData.Count > 0)
            {
                float throwDistance;
                var   directionToLern = dataProcessor.findOptimalThrowDirection(collectedData, target, LastThrowDirection, out throwDistance);

                _deviationFactor = (float)Sigmoid.Output((double)throwDistance * 0.5 - 2) * 0.4f;

                var ppDirToLern = (directionToLern + Vector3.one) * 0.5f;

                if (!_first)
                {
                    neuralService.NetAdaptation(_lastThrowPosition, target.GetTargetCords(), ppDirToLern);
                }
            }
            var throwPosition       = _thrower.GetThrowPosition();
            var calcualtedDirection = neuralService.CalculateThrowDirection(throwPosition, target.GetTargetCords());
            var ppDir = calcualtedDirection * 2 - Vector3.one;

            _thrower.DataGatteringThrow(ppDir, _deviationFactor);

            LastThrowDirection = ppDir;
            _lastThrowPosition = throwPosition;
            _first             = false;
        }
    }
コード例 #2
0
 private void collectLearningdata()
 {
     using (var writer = File.AppendText(LearnignDataFileName))
     {
         var expectedOutput = Sigmoid.Output(DistanceToRightWall - DistanceToLeftWall);
         Debug.Log(expectedOutput);
         writer.WriteLine(string.Format("{0}{3}{1}{3}{2}", DistanceToLeftWall, DistanceToRightWall, expectedOutput, learningFileDelimiter));
         Debug.Log(DistanceToLeftWall + " " + DistanceToRightWall + " " + expectedOutput);
     }
 }
コード例 #3
0
    public void Compute()
    {
        float sum = 0;

        for (int i = 0; i < InputNeurons.Count; i++)
        {
            sum += InputNeurons[i].OutputValue * Weights[i];
        }

        OutputValue = Sigmoid.Output(sum + Weights[Weights.Count - 1]);
    }
コード例 #4
0
ファイル: Neuron.cs プロジェクト: Lkledu/NeuralNetwork
    public float CalculateValue()
    {
        /*for (int i = 0; i < InputSynapses.Count; i++)
         * {
         *  xSum += InputSynapses[i].Weight * InputSynapses[i].InputNeuron.Value;
         * }
         ****** é o mesmo que fazer o Sum do LINQ
         */

        float xSum = InputSynapses.Sum(x => x.Weight * x.InputNeuron.Value);
        float u    = xSum + Bias;

        Value = Sigmoid.Output(u);

        return(Value);
    }
コード例 #5
0
    public List <float> GetInputs()
    {
        List <float> inputs = new List <float>();
        float        angle  = GameObject.transform.rotation.eulerAngles.magnitude * Mathf.Deg2Rad;

        for (int i = 0; i < ConfigManager.config.neuralNet.nInputNeurons; i++)
        {
            float startingRot  = ConfigManager.config.simulation.individualRaycastStartingRotation;
            float rotationStep = ConfigManager.config.simulation.individualRaycastRotationStep;
            float realAngle    = angle + startingRot + rotationStep * i;

            RaycastHit2D hit = Physics2D.Raycast(GameObject.transform.position, new Vector2(Mathf.Cos(realAngle), Mathf.Sin(realAngle)), 2);
            //Debug.DrawRay(GameObject.transform.position, new Vector3(Mathf.Cos(realAngle), Mathf.Sin(realAngle), 0), Color.red, 8);
            inputs.Add(hit.collider ? Sigmoid.Output(hit.distance / ConfigManager.config.neuralNet.inputEase) : 0);
        }

        return(inputs);
    }
コード例 #6
0
 public virtual double CalculateValue()
 {
     return(Value = Sigmoid.Output(InputSynapses.Sum(a => a.Weight * a.InputNeuron.Value) + Bias));
 }
コード例 #7
0
 public float CalculateValue()
 {
     return(Value = Sigmoid.Output(InputSynapses.Sum(x => x.Weight * x.InputNeuron.Value) + Bias));
 }