public NeuralNetwork(int inputUnits, int hiddenUnits, int outpuUnits, string folderName)
 {
     //学習値のデータがあるならそこから読み込む
     if (System.IO.File.Exists(@"Assets/Resources/AIData/" + folderName + "/LearningDataCSVw1.csv"))
     {
         w1 = NeuralReadCSV.readCSVData("AIData/" + folderName + "/LearningDataCSVw1");
         b1 = NeuralReadCSV.readCSVData("AIData/" + folderName + "/LearningDataCSVb1");
         w2 = NeuralReadCSV.readCSVData("AIData/" + folderName + "/LearningDataCSVw2");
         b2 = NeuralReadCSV.readCSVData("AIData/" + folderName + "/LearningDataCSVb2");
     }
     else
     {
         w1 = NumY.RandomArray(inputUnits, hiddenUnits, 1.0f, -1.0f);
         b1 = NumY.RandomArray(1, hiddenUnits, 1.0f, -1.0f);
         w2 = NumY.RandomArray(hiddenUnits, outpuUnits, 1.0f, -1.0f);
         b2 = NumY.RandomArray(1, outpuUnits, 1.0f, -1.0f);
     }
 }
Exemple #2
0
    // Use this for initialization
    void Start()
    {
        NumYArray xData = new NumYArray(NeuralReadCSV.readCSVData(inputDataName));
        NumYArray yData = new NumYArray(NeuralReadCSV.readCSVData(outputDataName));

        int   epochs       = 2000;
        float learningRate = 0.1f;

        //ニューラルネットワークの生成
        NeuralNetwork nn = new NeuralNetwork(xData.Size[1], 8, yData.Size[1], "Aoi");

        //時間計測
        float startTime = Time.realtimeSinceStartup;

        bool a = false;

        nn.InputData(xData, yData);
        a = nn.Train(epochs, learningRate, a);
        //データを基にトレーニング
        while (a)
        {
            a = nn.Train(epochs, learningRate, a);
        }

        float endTime = Time.realtimeSinceStartup;

        //トレーニング時間の表示
        Debug.Log(endTime - startTime);

        //仮データによる結果の予測
        float[][] testList = { new float[] { 0.1f, 0.5f, 0.5f, 0.5f, 0.0f } };
        NumYArray testData = new NumYArray(testList);
        NumYArray result   = new NumYArray(nn.Predict(testData));

        //予測結果の表示
        DisplayPredict(result);

        //学習した重みの保存
        nn.SaveLearningData("Aoi/");
    }
Exemple #3
0
    /// <summary>
    /// 初期化
    /// </summary>
    void Start()
    {
        charName = gameObject.name.Replace("IntentionObj", "");
        string filePath = @"Assets/Resources/AIData/" + charName + "/LearningDataCSVw1.csv";

        //csvファイルからデータの読み込み
        NumYArray xData = new NumYArray(NeuralReadCSV.readCSVData("AIData/" + inputDataName));
        NumYArray yData = new NumYArray(NeuralReadCSV.readCSVData("AIData/" + outputDataName));

        //ニューラルネットワークの生成
        nn = new NeuralNetwork(xData.Size[1], 8, yData.Size[1], charName);

        //学習値のデータがないなら初期学習をする
        if (!System.IO.File.Exists(filePath) && !isTrain)
        {
            nn.InputData(xData, yData);
            //データを基にトレーニング
            nn.Train(this.epochs, this.learningRate, false);

            nn.SaveLearningData(charName + "/");
        }
    }