public NeuralNetworkSaveData Load(bool isSupervised)
    {
        if (isSupervised)
        {
            if (File.Exists(Application.persistentDataPath + "/FlappyBirdsSupervised.txt"))
            {
                BinaryFormatter bf   = new BinaryFormatter();
                FileStream      file = File.Open(Application.persistentDataPath + "/FlappyBirdsSupervised.txt", FileMode.Open);

                NeuralNetworkSaveData data2 = (NeuralNetworkSaveData)bf.Deserialize(file);
                file.Close();

                return(data2);
            }
        }
        else
        {
            if (File.Exists(Application.persistentDataPath + "/FlappyBirdsReinforced.txt"))
            {
                BinaryFormatter bf   = new BinaryFormatter();
                FileStream      file = File.Open(Application.persistentDataPath + "/FlappyBirdsReinforced.txt", FileMode.Open);

                NeuralNetworkSaveData data2 = (NeuralNetworkSaveData)bf.Deserialize(file);
                file.Close();

                return(data2);
            }
        }

        return(null);
    }
    void Start()
    {
        player         = GameObject.FindGameObjectWithTag("Player");
        gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController> ();
        bottomBorder   = GameObject.FindGameObjectWithTag("BottomBorder");

        if (playMode == PlayMode.SupervisedTesting || playMode == PlayMode.SupervisedTraining)
        {
            data = Load(true);
            if (data == null)
            {
                nnSupervised = new NeuralNetwork(3, 3, 1);
            }
            else
            {
                nnSupervised = new NeuralNetwork(data);
            }
        }         /*else if (playMode == PlayMode.ReinforcementTraining || playMode == PlayMode.ReinforcementTesting) {
                   *    data = Load (false);
                   *    if (data == null) {
                   *            nnReinforced = new NeuralNetwork (3, 3, 1);
                   *    } else {
                   *            nnReinforced = new NeuralNetwork (data);
                   *    }
                   * }*/
    }
    public void Save(bool isSupervised)
    {
        if (isSupervised)
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Create(Application.persistentDataPath + "/FlappyBirdsSupervised.txt");

            NeuralNetworkSaveData data2;

            if (nnSupervised != null)
            {
                data2 = new NeuralNetworkSaveData(nnSupervised);
                bf.Serialize(file, data2);
            }

            file.Close();
        }
        else
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Create(Application.persistentDataPath + "/FlappyBirdsReinforced.txt");

            NeuralNetworkSaveData data2;

            if (nnReinforced != null)
            {
                data2 = new NeuralNetworkSaveData(nnReinforced);
                bf.Serialize(file, data2);
            }

            file.Close();
        }
    }
Exemplo n.º 4
0
 void Start()
 {
     myRigidbody    = GetComponent <Rigidbody> ();
     nn             = new NeuralNetwork(3, 3, 2);
     bottomBorder   = GameObject.FindGameObjectWithTag("BottomBorder");
     gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController> ();
     data           = new NeuralNetworkSaveData(nn);
     destroyPlayer += DestroySelf;
 }
    public NeuralNetwork(NeuralNetworkSaveData data)
    {
        inputNodes  = data.inputNodes;
        hiddenNodes = data.hiddenNodes;
        outputNodes = data.outputNodes;

        weightsInputHidden  = Matrix.FromArrayToMatrix(data.weightsInputHidden, hiddenNodes, inputNodes);
        weightsHiddenOutput = Matrix.FromArrayToMatrix(data.weightsHiddenOutput, outputNodes, hiddenNodes);

        hiddenBiases = Matrix.FromArrayToMatrix(data.hiddenBiases);
        outputBiases = Matrix.FromArrayToMatrix(data.outputBiases);
    }