benson skal til at cooke

This commit is contained in:
2024-04-19 14:10:31 +02:00
parent 851558c6db
commit 8f16297e05
5 changed files with 2093 additions and 1596 deletions

View File

@@ -1 +1 @@
{"count":1,"self":37.447126399999995,"total":38.1944854,"children":{"InitializeActuators":{"count":1,"self":0.0025220999999999998,"total":0.0025220999999999998,"children":null},"InitializeSensors":{"count":1,"self":0.0015034,"total":0.0015034,"children":null},"AgentSendState":{"count":1670,"self":0.10014859999999999,"total":0.668503,"children":{"CollectObservations":{"count":1670,"self":0.54390779999999994,"total":0.54390779999999994,"children":null},"WriteActionMask":{"count":1670,"self":0.0030217,"total":0.0030217,"children":null},"RequestDecision":{"count":1670,"self":0.012055399999999999,"total":0.0214249,"children":{"RayPerceptionSensor.Perceive":{"count":3340,"self":0.0093695,"total":0.0093695,"children":null}}}}},"DecideAction":{"count":1670,"self":0.0163969,"total":0.0163969,"children":null},"AgentAct":{"count":1670,"self":0.056928099999999995,"total":0.056928099999999995,"children":{"RayPerceptionSensor.Perceive":{"count":4,"self":0,"total":0,"children":null}}}},"gauges":{"BensonV4.CumulativeReward":{"count":2,"max":24.2291832,"min":23.1571674,"runningAverage":23.6931763,"value":24.2291832,"weightedAverage":23.42517}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713519122","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\noahk\\Documents\\Unity projects\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-noahk -hubSessionId 4068a663-bd5e-4526-907d-88111baad304 -accessToken lEnHrjqkaCSQA7MdFiPPC8yoqdYZh4_FAtRTqZKLQPI005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"AI training","end_time_seconds":"1713519160"}}
{"count":1,"self":10.153191999999999,"total":27.592682399999998,"children":{"InitializeActuators":{"count":10,"self":0.0015107999999999999,"total":0.0015107999999999999,"children":null},"InitializeSensors":{"count":10,"self":0.0023767,"total":0.0023767,"children":null},"AgentSendState":{"count":5201,"self":0.2085676,"total":0.39965059999999997,"children":{"CollectObservations":{"count":10410,"self":0.0506109,"total":0.0506109,"children":null},"WriteActionMask":{"count":10410,"self":0.0049118999999999994,"total":0.0049118999999999994,"children":null},"RequestDecision":{"count":10410,"self":0.0353548,"total":0.1355602,"children":{"AgentInfo.ToProto":{"count":10410,"self":0.0238086,"total":0.1002054,"children":{"GenerateSensorData":{"count":10410,"self":0.066654999999999992,"total":0.0763968,"children":{"RayPerceptionSensor.Perceive":{"count":20820,"self":0.0097418,"total":0.0097418,"children":null}}}}}}}}},"DecideAction":{"count":5201,"self":16.709854399999998,"total":16.7098548,"children":null},"AgentAct":{"count":5201,"self":0.3219187,"total":0.32504869999999997,"children":{"AgentInfo.ToProto":{"count":260,"self":0,"total":0.00313,"children":{"GenerateSensorData":{"count":260,"self":0.0021091,"total":0.00313,"children":{"RayPerceptionSensor.Perceive":{"count":520,"self":0.0010209,"total":0.0010209,"children":null}}}}}}}},"gauges":{"BensonV4.CumulativeReward":{"count":260,"max":0.137023434,"min":0.09874481,"runningAverage":0.120815031,"value":0.120933376,"weightedAverage":0.120719552}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713525165","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\noahk\\Documents\\Unity projects\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-noahk -hubSessionId 4068a663-bd5e-4526-907d-88111baad304 -accessToken 2br8Tr5WDuAnqRzlr3wnNZ_EORRyV0BMpmUN7FvToCw005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"AI training","end_time_seconds":"1713525193"}}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a3462884d5dfc9e49a4a1c1abb5c98e7
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -14,8 +14,6 @@ using System;
public class AgentControllerV4 : Agent
{
public float motorForce = 300;
public float brakeForce = 500;
public float maxSpeed = 400;
public float steeringRange = 9;
Rigidbody rigidBody;
public List<GameObject> checkpoints;
@@ -24,14 +22,12 @@ public class AgentControllerV4 : Agent
int currentStep = 0;
int stepsSinceCheckpoint = 0;
public int maxStepsPerCheckpoint = 300;
public int distanceBetweenCheckpoints;
public int distanceBetweenCheckpoints = 5;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent<Rigidbody>();
// Find all child GameObjects that have the WheelControl script attached
startPosition = transform.localPosition;
startRotation = transform.localRotation;
}
@@ -67,8 +63,8 @@ public class AgentControllerV4 : Agent
}
}
print(transform.rotation.y);
sensor.AddObservation(transform.rotation.y);
// Agent rotation
sensor.AddObservation(transform.localRotation.y);
Vector3 position = transform.localPosition;
Vector3 checkpointPosition = currentCheckpoint.localPosition;
@@ -78,21 +74,15 @@ public class AgentControllerV4 : Agent
checkpointPosition.z - position.z
);
// Normalized vector in direction of checkpoint and distancce to checkpoint.
sensor.AddObservation(toCheckpoint.normalized);
sensor.AddObservation(toCheckpoint.magnitude);
sensor.AddObservation(distanceToCheckpoint(currentCheckpoint));
var FullVelocityMagnitude = rigidBody.velocity.magnitude; // Velocity including angular velocity
var angularMagnitude = rigidBody.angularVelocity.magnitude;
var forwardMagnitude = Mathf.Sqrt( Mathf.Pow(FullVelocityMagnitude, 2) - Mathf.Pow(angularMagnitude, 2)); // Agent velocity in forward direction
if (forwardMagnitude >= 0.001)
sensor.AddObservation(forwardMagnitude);
else
sensor.AddObservation(FullVelocityMagnitude);
sensor.AddObservation(angularMagnitude);
Vector2 velocity = new Vector2(rigidBody.velocity.x, rigidBody.velocity.z);
// Velocity
sensor.AddObservation(velocity);
}
public override void OnActionReceived(ActionBuffers actions)
@@ -111,13 +101,6 @@ public class AgentControllerV4 : Agent
if (actions.DiscreteActions[1] == 1)
hInput = 1f;
// reward for going forward
// if (vInput == 1f)
// {
// AddReward(0.02f);
// }
// give benson mental pain for existing (punishment for maximizing first checkpoint by standing still)
AddReward(-0.002f);
@@ -155,12 +138,13 @@ public class AgentControllerV4 : Agent
currentCheckpoint.GetComponent<Checkpoint>().isCollected = true;
stepsSinceCheckpoint = 0;
// If last checkpoint
if (currentCheckpoint == checkpoints[checkpoints.Count - 1].transform)
{
AddReward(10f);
EndEpisode();
}
AddReward(1.0f);
AddReward(1f);
}
currentStep += 1;
@@ -208,19 +192,19 @@ public class AgentControllerV4 : Agent
return angle;
}
// punishment for hitting a wall
private void OnCollisionEnter(Collision other) {
if (other.gameObject.tag == "Wall")
{
AddReward(-0.05f);
}
}
// // punishment for hitting a wall
// private void OnCollisionEnter(Collision other) {
// if (other.gameObject.tag == "Wall")
// {
// AddReward(-0.05f);
// }
// }
// punishment for staying at a wall
private void OnCollisionStay(Collision other) {
if (other.gameObject.tag == "Wall")
{
AddReward(-0.05f);
}
}
// // punishment for staying at a wall
// private void OnCollisionStay(Collision other) {
// if (other.gameObject.tag == "Wall")
// {
// AddReward(-0.005f);
// }
// }
}