Пример #1
0
        private MovingDataset[] LoadMovingDatasets()
        {
            List <MovingDataset> datasetList = new List <MovingDataset>();

            string[] movingVecFilenames = Directory.GetFiles(MovingVectorDirectoryName, "*.vec");
            foreach (string movingVecFilename in movingVecFilenames)
            {
                byte[] data = File.ReadAllBytes(movingVecFilename);

                MovingDataset dataset = new MovingDataset();
                dataset.AddBytesData(data);

                datasetList.Add(dataset);
            }

            return(datasetList.ToArray());
        }
Пример #2
0
        public unsafe Vector2 PredictMoving(ChampIndicator indicator)
        {
            float[] outputDataF;
            try {
                float[] inputDataF = MovingDataset.GetInputData(indicator.positionHistoryList
                                                                .Skip(indicator.positionHistoryList.Count - MovingDataset.InputVectorCount - 1)
                                                                .Take(MovingDataset.InputVectorCount + 1).ToArray());
                for (int i = 0; i < inputDataF.Length; ++i)
                {
                    inputDatas[0, i] = inputDataF[i];
                }

                var outputData = model.PredictOnBatch(inputDatas);
                outputDataF = outputData.GetData <float>();
            } catch {
                outputDataF = new float[2];
            }

            return(new Vector2(outputDataF[0], outputDataF[1]));
        }
Пример #3
0
        public async void TrainMovingData()
        {
            try {
                // Compile
                var optimizer = new Adam(lr: 0.001f);
                model.Compile(optimizer: optimizer, loss: "mse", metrics: new string[] { "accuracy" });

                // Train
                MovingDataset[] movingTrainDatasets = LoadMovingDatasets();
                int             dataCount           = 0;

                List <float[, ]> inputList  = new List <float[, ]>();
                List <float[, ]> outputList = new List <float[, ]>();
                for (int i = 0; i < movingTrainDatasets.Length; ++i)
                {
                    MovingDataset datasetPart = movingTrainDatasets[i];

                    TrainData trainData = datasetPart.GetTrainData();

                    inputList.Add(trainData.inputs);
                    outputList.Add(trainData.outputs);
                    dataCount += trainData.inputs.GetLength(0);
                }
                float[,] inputs  = new float[dataCount, MovingDataset.InputFloatCount];
                float[,] outputs = new float[dataCount, MovingDataset.OutputFloatCount];

                int inputIndex = 0;
                foreach (float[,] input in inputList)
                {
                    for (int i = 0; i < input.GetLength(0); ++i)
                    {
                        for (int f = 0; f < MovingDataset.InputFloatCount; ++f)
                        {
                            inputs[inputIndex, f] = input[i, f];
                        }

                        ++inputIndex;
                    }
                }

                int outputIndex = 0;
                foreach (float[,] output in outputList)
                {
                    for (int i = 0; i < output.GetLength(0); ++i)
                    {
                        for (int f = 0; f < MovingDataset.OutputFloatCount; ++f)
                        {
                            outputs[outputIndex, f] = output[i, f];
                        }

                        ++outputIndex;
                    }
                }

                for (; ;)
                {
                    model.Fit(inputs, outputs, batch_size: 100, epochs: 100, verbose: 1);

                    SaveModel();

                    await Task.Delay(10);
                }



                //float[] predicts = model.Predict(x).GetData<float>();

                //Stopwatch watch = new Stopwatch();
                //watch.Start();
                //for (int i = 0; i < 1; ++i) {
                //	predicts = model.Predict(x, verbose: 0).GetData<float>();

                //	//Debug.WriteLine($"Result: ({string.Join(",", predicts)})");
                //}
                //watch.Stop();

                //MainWindow.Instance.Dispatcher.BeginInvoke(new Action(() => {
                //	MainWindow.Instance.DebugTextBox.Text = watch.GetElapsedMilliseconds().ToString();
                //}));
            } catch (Exception ex) {
                MainWindow.Instance.Dispatcher.BeginInvoke(new Action(() => {
                    MainWindow.Instance.DebugTextBox.Text = ex.ToString();
                }));
            }
        }