コード例 #1
0
    void TrainEpoch(Request requestAnswer)
    {
        var beginTrainingRequest = TelegramFactory.CreateBeginTrainingRequest();

        externalCommunication.SendAsynch(beginTrainingRequest, TrainEpoch);
    }
コード例 #2
0
    void Start()
    {
        externalCommunication = ExternalCommunication.GetSingleton();
        trainGameObjects      = new List <GameObject>();
        predictGameObjects    = new List <GameObject>();
        if (Train)
        {
            System.Type mType = System.Type.GetType(TrainScriptName);
            gameObject.AddComponent(mType);

            for (int i = 0; i < TrainAmount; i++)
            {
                transform.position = transform.position + new Vector3(
                    Random.Range(-MaxStartDiff, MaxStartDiff),
                    Random.Range(-MaxStartDiff, MaxStartDiff),
                    Random.Range(-MaxStartDiff, MaxStartDiff));

                var newVelocity = new Vector3(
                    Random.Range(-MaxStartVelocity, MaxStartVelocity),
                    Random.Range(-MaxStartVelocity, MaxStartVelocity),
                    Random.Range(-MaxStartVelocity, MaxStartVelocity));

                var trainObject = (Instantiate(TrainPrefab, transform.position, Quaternion.identity));
                trainObject.GetComponent <WaterDropReset>().MaxStartDiff     = MaxStartDiff;
                trainObject.GetComponent <WaterDropReset>().MaxStartVelocity = MaxStartVelocity;
                var stateHistory = trainObject.GetComponent <StateHistory>();
                stateHistory.HistoryParameterTypes.Add(StateHistory.HistoryParameterType.Position);
                stateHistory.HistoryParameterTypes.Add(StateHistory.HistoryParameterType.Velocity);
                stateHistory.StepsToRemember = StepsToRemember;
                trainGameObjects.Add(trainObject);
            }

            new Thread(new ThreadStart(() =>
            {
                Thread.Sleep(CollectTraindataTime * 1000);
                UnityMainThreadDispatcher.Instance().Enqueue(() =>
                {
                    foreach (var trainGameObject in trainGameObjects)
                    {
                        Destroy(trainGameObject);
                    }
                    if (BeginLearningAfterDataGeneration)
                    {
                        var beginTrainingRequest = TelegramFactory.CreateBeginTrainingRequest();
                        externalCommunication.SendAsynch(beginTrainingRequest, TrainEpoch);
                    }
                });
            })).Start();
        }

        if (Predict)
        {
            System.Type mType = System.Type.GetType(PredictScriptName);
            gameObject.AddComponent(mType);

            for (int i = 0; i < PredictAmount; i++)
            {
                var predictObject = (Instantiate(PredictPrefab, transform.position, Quaternion.identity));
                predictGameObjects.Add(predictObject);
            }
        }
    }