Я создал среду для самостоятельного вождения автомобиля, чтобы тренироваться для достижения цели в холмистой местности. Как выглядит среда в Unity
Теперь скрипт CarAgent для обучения автомобиля определяется с наградой как:
- -. 05f за каждый шаг
- 1f при достижении цели
- -. 6f при падении с платформы
Чтобы проверить окружение, я использовал обертку для тренажерного зала и инициализировал ее. Теперь я напечатал значение вознаграждения за каждое случайное действие, которое он выполнял, но значение, которое он показал, было 0.50000006 для каждого случайного действия. Каким-то образом конечная награда на каждом этапе умножается на 10 для любой награды, которую мы определяем. Есть ли внутренний прирост, который я пропустил или есть ошибка на моей стороне. Вот код для генерации награды:
public override void AgentAction(float[] vectorAction)
{
float h = vectorAction[0]; //Horizontal keys, representing 'acceleration' and 'backward-force'
float v = vectorAction[1]; //Vertical movement keys, representing 'left-turn' or 'right-turn'
/*
* We add a small negative reward in order to compel the agent to take a step and not remain
* idle. Refer the Agent Documentation.
*/
rew = .05f;
AddReward(rew);
m_Car.Move(h, v, v, 0f);
/*
* All values are passed to the concerned function in the CrossPlatformInput class of the
* Unity Standard Assets package. (Check namespaces used)
*/
/*
* Allocate rewards to an Agent by calling the AddReward() method in the AgentAction() function.
* The reward assigned between each decision should be in the range [-1,1].
* Values outside this range can lead to unstable training.
* The reward value is reset to zero when the agent receives a new decision.
* If there are multiple calls to AddReward() for a single agent decision,
* the rewards will be summed together to evaluate how good the previous decision was.
* There is a method called SetReward() that will override all previous rewards given to an
* agent since the previous decision.
*/
//Getting distance from Destination
float distanceToTarget = Vector3.Distance(this.transform.position, Target.position);
//Defining Reward and resetting the agent when it reaches destination.
if (distanceToTarget < 30.0f)
{
AddReward(1.0f);
Done();
}
//Defining Reward and resetting the agent if it falls off the terrain.
if (this.transform.position.y < 0)
{
AddReward(-.6f); // Randomly setting the reward value. **Needs clarification
Done();
}
//base.AgentReset();
}
Код задокументирован для уточнения. Я прошу прощения. Вот код, который я написал для проверки вознаграждения, возвращаемого после каждого шага, где вознаграждение было предварительно определено для -0,005f для каждого шага.
import matplotlib.pyplot as plt
import numpy as np
import sys
from gym_unity.envs import UnityEnv
%matplotlib inline
env = UnityEnv("NewSETAgentFinal\ModifiedFinalSEt", use_visual = True, uint8_visual = True)
print(str(env))
#Taking random actions in the environment
for episode in range(10):
initial_observation = env.reset()
done = False
episode_rewards = 0
step = 0
while not done:
observation, reward, done, info = env.step(env.action_space.sample())
print(step," ",reward)
step += 1
episode_rewards += reward
print("Total reward this episode: {}".format(episode_rewards))
Вот снимок экрана с наградами, полученными на каждом шаге: Награды за каждый шаг