Пример #1
0
    //================================================================
    //テキストファイルの重み、バイアスを読み込む
    private IEnumerator ReadWeightAndBias()
    {
        string s_id = weightAndBias.GetData(weightAndBias.GetDataSize() - 5, 0);

        Debug.Log(weightAndBias.GetDataSize() - 5 + "/" + s_id);
        if (s_id != "none")
        {
            int id = int.Parse(s_id);
            parameterManager.NeuralNetworkID = id;

            for (int i = 0; i < hiddenLayer.Length; i++)
            {
                for (int j = 0; j < inputLayer.Length; j++)
                {
                    weightI_H[j, i] = double.Parse(weightAndBias.GetData(1 + id * 5, 10 + j + i * inputLayer.Length));
                }

                biasHiddenLayer[i] = double.Parse(weightAndBias.GetData(3 + id * 5, 10 + i));
            }

            for (int i = 0; i < outputLayer.Length; i++)
            {
                for (int j = 0; j < hiddenLayer.Length; j++)
                {
                    weightH_O[j, i] = double.Parse(weightAndBias.GetData(2 + id * 5, 10 + j + i * inputLayer.Length));
                }

                biasOutputLayer[i] = double.Parse(weightAndBias.GetData(4 + id * 5, 10 + i));
            }
        }
        else
        {
            parameterManager.NeuralNetworkID = 0;

            for (int i = 0; i < hiddenLayer.Length; i++)
            {
                for (int j = 0; j < inputLayer.Length; j++)
                {
                    weightI_H[j, i] = UnityEngine.Random.Range(0f, 1f);
                    //Debug.Log("w:" + weightI_H[j,i]);
                }

                biasHiddenLayer[i] = UnityEngine.Random.Range(0f, 1f);
                //Debug.Log("b:" + biasHiddenLayer[i]);
            }

            for (int i = 0; i < outputLayer.Length; i++)
            {
                for (int j = 0; j < hiddenLayer.Length; j++)
                {
                    weightH_O[j, i] = UnityEngine.Random.Range(0f, 1f);
                    //Debug.Log("w:" + weightH_O[j,i]);
                }

                biasOutputLayer[i] = UnityEngine.Random.Range(0f, 1f);
                //Debug.Log("b:" + biasOutputLayer[i]);
            }

            yield return(WriteWeightAndBias());
        }

        yield break;
    }