2

I am trying to create a really simple example where i train the agent with "and" gate values, i.e

1,0 = 0
1,1 = 1
0,0 = 0
0,1 = 0

I know this a really strange test project but i need to check that i can use the ML for evaluating data without requiring game objects.

I've followed the "Basic" example included in this project but i can't get it to work. I have posted my code below. Any help would be much appreciated.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MLAgents;
using UnityEngine.UI;

public class TestAgent : Agent {

    public Text text;

    public List<float[]> inputs = new List<float[]>();
    public List<float[]> answers = new List<float[]>();

    float expectedAnswer;
    float[] inp;
    int rec;

    private void Start()
    {
        inputs.Add(new float[] { 0, 0 });
        answers.Add(new float[] { 0 });

        inputs.Add(new float[] { 1, 1 });
        answers.Add(new float[] { 1 });

        inputs.Add(new float[] { 1, 0 });
        answers.Add(new float[] { 0 });

        inputs.Add(new float[] { 0, 1 });
        answers.Add(new float[] { 0 });
    }

    public override void CollectObservations()
    {
        AddVectorObs(inp);
    }

    public override void AgentAction(float[] vectorAction, string textAction)
    {
        var movement = (int)vectorAction[0];

        text.text += ", Result = " + movement;

        // Time penalty
        AddReward(-0.05f);

        if ((int)movement == (int)expectedAnswer){
            AddReward(1f);
            Done();
        }
        else{
            AddReward(-1f);
            Done();
        }
    }

    public override void AgentOnDone()
    {
        base.AgentOnDone();
        Debug.Log("agent is done");
    }

    public override void AgentReset()
    {
        //this is where we submit the input data, i think
        rec = Random.Range(0, inputs.Count);
        inp = inputs[rec];
        expectedAnswer = answers[rec][0];
        text.text = "Inputs = [" + inp[0] + "," + inp[1] + "], Expecting = " + expectedAnswer;
    }

}

UPDATE Sorry i forgot to mention, i followed the setup guide on the unity ml GitHub page on my mac and have the python stuff installed so i just run "mlagents-learn config/trainer_config.yaml --run-id=firstrun --train" and then press the play button in unity to start the training process.

In the terminal window i get feedback on the training process, at first everything seems to be working ok'ish as i get a printout with a reward value but then on the next printout it says "no episode completed since last summary" but i have no idea what that means or what the issue is.

I have the brain and academy in the scene as required as i followed the "Basic" example in the unity ml project but for some reason it doesn't work but all the examples do so i'm guessing it's something in my code and not my config, but i cannot work out what.

user414025
  • 105
  • 1
  • 10
  • 2
    I don't see a reference to "episode" anywhere in the code. Also, please elaborate on "but i can't get it to work" – IanQ Oct 25 '18 at 17:17

0 Answers0