コード例 #1
0
    void TrainLoop()
    {
        int[] inputs = new int[_network.InputLength];
        int   output = _rand.Next() % _network.OutputLength;

        for (int i = 0; i < inputs.Length; i++)
        {
            inputs [i] = _rand.Next() % 100;
        }
        inputs[0] = _rand.Next() % 2;
        if (inputs [0] > 0.5)
        {
            output = 0;
        }
        _network.Train(inputs, output, null, 0.005f);
        _loopsCount++;
        CompositionRoot.Instance.ExecuteInMainThread(() => {
            _loopsCountLabel.text = _loopsCount.ToString();
        });
    }
コード例 #2
0
    public void OnToggleTrainPressed()
    {
        _isTraining = !_isTraining;
        if (!_isTraining)
        {
            return;
        }

        // Train thread.
        Thread thread = new Thread(new ThreadStart(() => {
            while (_isTraining)
            {
                TrainingDecisionModel currTraining = _trainingModels[_trainingsCount % _trainingModels.Count];
                float currSpeed = 0.0005f;                //*currTraining.RewardPercent*0.01f;
                _decider.Train(currTraining.Inputs, currTraining.Output, currTraining.Options, currSpeed);
                _trainingsCount++;
                CompositionRoot.Instance.ExecuteInMainThread(() => {
                    _performedTrainingsCount.text = _trainingsCount.ToString();
                });
            }
        }));

        thread.Start();

        // Calc success thread.
        Thread thread2 = new Thread(new ThreadStart(() => {
            while (_isTraining)
            {
                float error = GetError();
                System.Threading.Thread.Sleep(300);
                CompositionRoot.Instance.ExecuteInMainThread(() => {
                    _error.text = error.ToString("00.0000");
                    Debug.Log("success updated, success = " + error.ToString());
                });
            }
        }));

        thread2.Start();
    }