// STATS protected virtual void AddTensorboardStats() { m_TBStats.Add(m_BehaviorName + "/Avg. Height", m_Body.AvgHeight); m_TBStats.Add(m_BehaviorName + "/Inclination", m_Body.Inclination); m_TBStats.Add(m_BehaviorName + "/Speed Error", GetSpeedError()); m_TBStats.Add(m_BehaviorName + "/Look Error", GetNormLookDirectionError()); m_TBStats.Add(m_BehaviorName + "/Walk Error", GetNormWalkDirectionError()); }
public override void OnActionReceived(float[] vectorAction) { // Debug.Log("Action"); // Get the action index for movement float dx = Mathf.Clamp(vectorAction[0], -1f, 1f); float dy = Mathf.Clamp(vectorAction[1], -1f, 1f); float visionIncrease = Mathf.Clamp(vectorAction[2], -1f, 1f); foreach (Fence fence in Paca.World.Fences) { if (fence.Collider.IsTouching(Paca.TouchCollider)) { AddReward(-1f); EndEpisode(); _statsRecorder.Add("FoodFound", 0); _statsRecorder.Add("FenceTouched", 1); _statsRecorder.Add("Starved", 0); return; } } Target touchedFood = null; foreach (Collider2D collider in Paca.CurrentlyTouching) { if (collider.GetComponent <Target>() != null) { touchedFood = collider.GetComponent <Target>(); break; } } if (touchedFood != null) { AddReward(1f - Mathf.Lerp(0.5f, 0f, Paca.Hunger / Paca.HungerFull)); _statsRecorder.Add("Hunger", Paca.Hunger); _statsRecorder.Add("FoodFound", 1); _statsRecorder.Add("FenceTouched", 0); _statsRecorder.Add("Starved", 0); EndEpisode(); return; } if (Paca.Hunger <= 0f) { AddReward(-1f); _statsRecorder.Add("FoodFound", 0); _statsRecorder.Add("FenceTouched", 0); _statsRecorder.Add("Starved", 1); EndEpisode(); return; } Paca.Step(dx, dy, visionIncrease); Paca.Text.text = "Reward: " + GetCumulativeReward().ToString("F2") + "\nHunger: " + Paca.Hunger.ToString("F2"); }
public override void Kill() { _stats.Add("Healed", GameManager.HealedCounter); _stats.Add("RelativeDriveTime", _driveCount / _timer); _stats.Add("RelativeWalkTime", _walkCount / _timer); AddReward(-_timer / 180); EndEpisode(); Destroy(_ambulance.gameObject); Destroy(gameObject); }
public override void OnActionReceived(ActionBuffers actionBuffers) { base.OnActionReceived(actionBuffers); if (StepCount % m_StatsInterval == 0) { m_Stats.Add("Searcher/Energy", m_Energy); m_Stats.Add("Searcher/Distance", m_DistanceSqrRatio); } }
public void AddScore(int score) { scoreText.text = $"Score: {score}"; statsRecorder.Add("Score", score, StatAggregationMethod.MostRecent); if (score > highScore) { highScore = score; highscoreText.text = $"Highscore: {highScore}"; statsRecorder.Add("High Score", highScore, StatAggregationMethod.MostRecent); } }
public void Update() { scoreText.text = $"Score: {totalScore}\nGhosts: {ghostScore}"; // Send stats via SideChannel so that they'll appear in TensorBoard. // These values get averaged every summary_frequency steps, so we don't // need to send every Update() call. if ((Time.frameCount % 100) == 0) { m_Recorder.Add("TotalScore", totalScore); m_Recorder.Add("GhostScore", ghostScore); } }
public void Update() { scoreText1.text = $"Agent1 : {score1}"; scoreText2.text = $"Agent2 : {score2}"; scoreText3.text = $"Agent3 : {score3}"; scoreText4.text = $"Agent4 : {score4}"; if ((Time.frameCount % 100) == 0) { m_Recorder.Add("Agent1 score", score1); m_Recorder.Add("Agent2 score", score2); m_Recorder.Add("Agent3 score", score3); m_Recorder.Add("Agent4 score", score4); } }
/// <summary> /// We collect the normalized rotations, angularal velocities, and velocities of both /// limbs of the reacher as well as the relative position of the target and hand. /// </summary> public override void CollectObservations(VectorSensor sensor) { sensor.AddObservation(pendulumA.transform.localPosition); sensor.AddObservation(pendulumA.transform.rotation); sensor.AddObservation(m_RbA.angularVelocity); sensor.AddObservation(m_RbA.velocity); sensor.AddObservation(pendulumB.transform.localPosition); sensor.AddObservation(pendulumB.transform.rotation); sensor.AddObservation(m_RbB.angularVelocity); sensor.AddObservation(m_RbB.velocity); sensor.AddObservation(goal.transform.localPosition); sensor.AddObservation(hand.transform.localPosition); sensor.AddObservation(nextTarget == 0 ? 1.0f : 0.0f); sensor.AddObservation(nextTarget == 1 ? 1.0f : 0.0f); sensor.AddObservation(nextTarget == 2 ? 1.0f : 0.0f); sensor.AddObservation(nextTarget == 3 ? 1.0f : 0.0f); // we will use this to determine if target touched if (justTouchedTarget) { sensor.AddObservation(1.0f); } else { sensor.AddObservation(0.0f); } //moveSpeed = m_RbA.velocity.magnitude + m_RbB.velocity.magnitude; moveSpeed = Vector3.Distance(hand.transform.position, prevHandPos); prevHandPos = hand.transform.position; //Debug.Log("Dist " + Vector3.Distance(new Vector3(0f, 0f, 0f), (hand.transform.position - transform.position))); //Debug.Log("Dist " + (goal.transform.position - transform.position)); m_Recorder.Add("Distance to base", Vector3.Distance(new Vector3(0f, -8.0f, 0f), (hand.transform.position - transform.position))); m_Recorder.Add("Distance moved", moveSpeed); rewardToGet *= timeDecay; rewardToGet = Mathf.Max(minReward, rewardToGet); }
void UpdateIfRunning() { if (!gameReadyToStart || !startCalled) { return; } ; nextTurnReady = true; wolfWon = 0; sheepWon = 0; tie = 0; // Send stats via SideChannel so that they'll appear in TensorBoard. // These values get averaged every summary_frequency steps, so we don't // need to send every Update() call. if ((Time.frameCount % 100) == 0) { statsRecorder.Add("WolfGamesWon", wolfWon); statsRecorder.Add("SheepGamesWon", sheepWon); } foreach (var area in traingingAreas) { if (!area.turnDone) { nextTurnReady = false; return; } wolfWon += area.wolfWon; sheepWon += area.sheepWon; tie += area.tie; } if (nextTurnReady) { if (haveAI) { Academy.Instance.EnvironmentStep(); } AllowNextTurn(); wolfGamesWonText.SetText(wolfWon.ToString()); sheepGamesWonText.SetText(sheepWon.ToString()); tieText.SetText(tie.ToString()); } }
public override void OnActionReceived(ActionBuffers actionBuffers) { var actions = actionBuffers.DiscreteActions; float speed = m_Ship.ManagedUpdate(actions[0] - 1, actions[1] - 1, actions[2] - 1); CheckTargets(); if (StepCount % m_StatsInterval == 0) { float n = m_StatsInterval; m_Stats.Add("Pilot/Speed", speed); m_Stats.Add("Pilot/Collision Ratio", m_CollisionCount / n); m_Stats.Add("Pilot/Hit Score Ratio", m_HitScoreCount / n); m_CollisionCount = 0; m_HitScoreCount = 0; } }
public virtual void Kill() { float survivalLength = Count / Total; AddReward(2.5f * survivalLength * survivalLength); GameManager.RelativeSurvivalLength.Add(survivalLength); if (ReportStats) { StatsRecorder stats = Academy.Instance.StatsRecorder; float citizenCount = GameManager.NumberOfNormalCitizen + GameManager.NumberOfExtrovertedCitizen + GameManager.NumberOfIntrovertedCitizen; stats.Add("Collisions/Collisions", GameManager.CollisionsTotal / citizenCount); stats.Add("Collisions/Symptomatic", GameManager.CollisionsSymptomatic / citizenCount); stats.Add("Collisions/Not Symptomatic", (GameManager.CollisionsTotal - GameManager.CollisionsSymptomatic) / citizenCount); stats.Add("Citizen/Susceptible at end", GameManager.GetCount(HealthStatus.Susceptible)); stats.Add("Citizen/Recovered at end", GameManager.GetCount(HealthStatus.Recovered)); stats.Add("Citizen/Relative survival length", GameManager.RelativeSurvivalLength.Average()); foreach (HealthStatus healthStatus in Enum.GetValues(typeof(HealthStatus))) { stats.Add($"Collisions/{healthStatus}", GameManager.Collisions[healthStatus] / citizenCount); } } EndEpisode(); Destroy(gameObject); }
public void AddScore(int score) { if (score > highScore) // highScore is the highest score achieved before the last collision. { highScore = score; display.text = score.ToString(); statsRecorder.Add("High Score", highScore, StatAggregationMethod.MostRecent); } }
// Update is called once per frame void Update() { //If every agent is infected finish episode early. if (infectedCounts == pandemicArea.agents.Count) { pandemicArea.endAllAgentsEpisodes(); } scoreText.text = $"Score: {infectedCounts}"; // Send stats via SideChannel so that they'll appear in TensorBoard. // These values get averaged every summary_frequency steps, so we don't // need to send every Update() call. if ((Time.frameCount % 100) == 0) { m_Recorder.Add("TotalScore", totalScore); m_Recorder.Add("InfectedCounts", infectedCounts); m_Recorder.Add("CollisionCounts", collisionCounts / 2); } }
public void AddScore(int score) { if (score > highScore) { highScore = score; display.text = score.ToString(); statsRecorder.Add("High Score", highScore, StatAggregationMethod.MostRecent); } }
public void AddLaps(int lap) { if (lap > highestLap) { highestLap = lap; highestLapText.text = highestLap.ToString("000"); statsRecorder.Add("Highest Lap", highestLap, StatAggregationMethod.MostRecent); } }
public override void OnActionReceived(ActionBuffers actionBuffers) { var actions = actionBuffers.DiscreteActions; float speed = m_Car.ManagedUpdate(actions[0] - 1, actions[1] - 1); AddReward(speed * 0.01f); if (StepCount % m_StatsInterval == 0) { m_Stats.Add("Driver/Speed", speed); m_Stats.Add("Driver/Collision Ratio", m_CollisionCount / (float)m_StatsInterval); m_CollisionCount = 0; } if (StepCount % c_CheckStateInterval == 0) { CheckState(); } }
public override void OnActionReceived(ActionBuffers actionBuffers) { base.OnActionReceived(actionBuffers); ManagedUpdate(); float speed = Vector3.Dot(m_TargetDirXZ, m_AntPhysics.Body.Velocity); AddReward(speed * m_SpeedRewardFactor); float error = Mathf.Abs(NormalizedTargetAngle); AddReward(error * -m_TargetPenaltyFactor); if (StepCount % m_StatsInterval == 0) { m_Stats.Add("Walker/Speed", speed); m_Stats.Add("Walker/Error", error); } }
void OnCollisionEnter(Collision col) { if (col.gameObject.CompareTag("symbol_O_Goal") || col.gameObject.CompareTag("symbol_X_Goal")) { if ((m_Selection == 0 && col.gameObject.CompareTag("symbol_O_Goal")) || (m_Selection == 1 && col.gameObject.CompareTag("symbol_X_Goal"))) { SetReward(1f); StartCoroutine(GoalScoredSwapGroundMaterial(m_HallwaySettings.goalScoredMaterial, 0.5f)); m_statsRecorder.Add("Goal/Correct", 1, StatAggregationMethod.Sum); } else { SetReward(-0.1f); StartCoroutine(GoalScoredSwapGroundMaterial(m_HallwaySettings.failMaterial, 0.5f)); m_statsRecorder.Add("Goal/Wrong", 1, StatAggregationMethod.Sum); } EndEpisode(); } }
public override void OnActionReceived(ActionBuffers actionBuffers) { m_Physics.ApplyActions(actionBuffers.ContinuousActions.Array, Time.fixedDeltaTime); m_Physics.Stabilize(); if (m_Train) { Vector3 delta = transform.position - m_RoadPosition; float offRoad = delta.sqrMagnitude - 4; // TBD if (offRoad > 0) { m_OffRoadCount++; AddReward(-Mathf.Clamp01(offRoad * m_OffRoadPenaltyFactor)); if (Time.time - m_TimeStamp > m_OffRoadTimeout) { transform.position = m_RoadPosition; transform.rotation = Quaternion.LookRotation(m_RoadForward); m_Physics.ManagedReset(); } } else { float speed = Vector3.Dot(m_RoadForward, m_Physics.Velocity); AddReward(speed * m_SpeedRewardFactor); m_TimeStamp = Time.time; } if (StepCount % m_StatsInterval == 0) { float d = m_StatsInterval; float speed = Vector3.Dot(m_RoadForward, m_Physics.Velocity); m_Stats.Add("Driver/Speed", speed); m_Stats.Add("Driver/Off Road Ratio", m_OffRoadCount / d); m_Stats.Add("Driver/Collision Ratio", m_CollisionCount / d); m_CollisionCount = 0; m_OffRoadCount = 0; } } }
/// <inheritdoc/> public override void OnActionReceived(ActionBuffers actionBuffers) { var actions = actionBuffers.ContinuousActions; m_Car.Move(actions[0], actions[1], actions[1], actions[2]); float speed = m_Car.ForwardSpeed; AddReward(speed * 0.01f); if (StepCount % m_StatsInterval == 0) { m_Stats.Add("Driver/Speed", speed); m_Stats.Add("Driver/Collision Ratio", m_CollisionCount / (float)m_StatsInterval); m_CollisionCount = 0; } if (StepCount % c_CheckStateInterval == 0) { CheckState(); } }
private void Update() { if (isBallReady) { RequestDecision(); } if (triesLeft == 0) { cummlativeScore += highScore; stats.Add("Custom/Cumulative Score", cummlativeScore); highScore = 0.0f; EndEpisode(); } timeLeft -= Time.deltaTime; if (timeLeft <= 0) { stats.Add("Custom/Time Left", timeLeft); stats.Add("Custom/Reward", 0); Reset(); } }
public override void OnActionReceived(ActionBuffers actionBuffers) { var actions = actionBuffers.DiscreteActions; float speed = m_Ship.ManagedUpdate(actions[0] - 1, actions[1] - 1, actions[2] - 1); // Reward for forward speed. // Increasing this factor will cause the agent to // favour speed over following/targeting opponents. AddReward(speed * 0.001f); if (StepCount % m_StatsInterval == 0) { float n = m_StatsInterval; m_Stats.Add("Pilot/Speed", speed); m_Stats.Add("Pilot/Collision Ratio", m_CollisionCount / n); m_Stats.Add("Pilot/Hit Score Ratio", m_HitScoreCount / n); m_Stats.Add("Pilot/Target Ratio", m_TargetingCount / n); m_CollisionCount = 0; m_HitScoreCount = 0; m_TargetingCount = 0; } }
void FixedUpdate() { frames++; if (frames % (Mathf.Round(updateRate)) == 0) { //Debug.Log(frames); for (int i = 0; i < Agents.Count; i++) { m_Recorder.Add("Load Count", Agents[i].cargoCount, StatAggregationMethod.Average); Agents[i].cargoCount = 0; m_Recorder.Add("Unload Count", Agents[i].unloadCount, StatAggregationMethod.Average); Agents[i].unloadCount = 0; m_Recorder.Add("Finish Count", Agents[i].finishCount, StatAggregationMethod.Average); Agents[i].finishCount = 0; } for (int i = 0; i < sceneControllers.Count; i++) { m_Recorder.Add("Current Ratio", sceneControllers[i].currentRatio, StatAggregationMethod.Average); m_Recorder.Add("Agent Period", sceneControllers[i].agentPeriod, StatAggregationMethod.Average); } } }
public override void OnActionReceived(ActionBuffers actionBuffers) { base.OnActionReceived(actionBuffers); var speed = m_Walker.WorldVelocity.magnitude; AddReward(speed * m_CrntSpeedRewardFactor / (WalkerAgent.MaxSpeed * c_MaxSpeedRewardFactor)); if (m_IsPreDecisionStep) { m_CrntSpeedRewardFactor = Mathf.Max(1, m_CrntSpeedRewardFactor - 1); if (m_Requester.DecisionStepCount % m_TBStatsInterval == 0) { m_TBStats.Add(m_BehaviorName + "/Speed", speed); m_TBStats.Add(m_BehaviorName + "/Collisions Per Second", m_CollisionCount / (Time.time - m_Time)); m_TBStats.Add(m_BehaviorName + "/Weapon Shots Per Second", m_Weapon.ShotsPerSecond); m_TBStats.Add(m_BehaviorName + "/Weapon Hits Per Second", m_Weapon.HitsPerSecond); m_TBStats.Add(m_BehaviorName + "/Weapon Hit Ratio", m_Weapon.HitRatio); } } }
// Start is called before the first frame update public void UpdateStatsRecorder(string key, float val) { statsRecorder = Academy.Instance.StatsRecorder; statsRecorder.Add(key, val); }