Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Heuristic

Discussion in 'ML-Agents' started by pranavasm, Apr 5, 2020.

  1. pranavasm

    pranavasm

    Joined:
    Jan 12, 2020
    Posts:
    2
    Hi,

    i'm a beginner at mlagents, i played around with the example environments for a while, and took on to make my own flappy bird ai (i thought it'll be easier considering almost everyone has done this, and i'll be able to find a lot of resources in case i get stuck)

    So i'm stuck here at configuring the actions,

    can't control the agent properly, the button press is not registered everytime,

    and since i can't get the heuristic right, i suppose i won't be able to train the AI properly.

    Heuristic Function

    Code (CSharp):
    1.     public override float[] Heuristic()
    2.     {
    3.         var action = new float[1];      
    4.         if (Input.GetKeyDown(KeyCode.Space))
    5.         {
    6.             Debug.Log("Pressed");
    7.             action[0] = 1 ;
    8.         }
    9.         else
    10.         {
    11.             action[0] = 0;
    12.         }
    13.         return action;
    14.     }


    OnActionReceived Function

    Code (CSharp):
    1.     public override void OnActionReceived(float[] vectorAction)
    2.     {
    3.         {
    4.             AddReward(0.01f);
    5.             int action = Mathf.FloorToInt(vectorAction[0]);
    6.             if(action == 0)
    7.             {
    8.             }
    9.             if(action == 1)
    10.             {
    11.                 m_AgentRb.velocity = Vector3;
    12. m_AgentRb.AddForce(Vector2.up * tapForce, ForceMode2D.Force);
    13.             }
    14.         }
    15.     }
    can't figure out what's wrong with this code

    Please Help
     
  2. awjuliani

    awjuliani

    Unity Technologies

    Joined:
    Mar 1, 2017
    Posts:
    69
    Hi,

    What is triggering the call to RequestDecision on the agent? The Heuristic function will only be called when a decision request is made.
     
  3. hooman_zkh

    hooman_zkh

    Joined:
    Aug 12, 2020
    Posts:
    2
    try this Out :

    Code (CSharp):
    1. public override void Heuristic(float[] actionsOut)
    2.     {
    3.         actionsOut[0] = Input.GetKeyDown(KeyCode.Space) ? 1 : 0 ;
    4.     }
    5.  
    and make sure your behavior type in behavior parameters is set to default for training Section and Heuristic for debugging Section
     
    Last edited: Aug 12, 2020