File tree 4 files changed +31
-2
lines changed
4 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -70,8 +70,10 @@ and this project adheres to
70
70
- Academy.InferenceSeed property was added. This is used to initialize the
71
71
random number generator in ModelRunner, and is incremented for each ModelRunner. (#3823 )
72
72
- Updated Barracuda to 0.6.3-preview.
73
- - Model updates can now happen asynchronously with environment steps for better performance. (#3690 )
74
- - ` num_updates ` and ` train_interval ` for SAC were replaced with ` steps_per_update ` . (#3690 )
73
+ - Added `Agent.GetObservations(), which returns a read-only view of the observations
74
+ added in ` CollectObservations() ` . (#3825 )
75
+ - Model updates can now happen asynchronously with environment steps for better performance. (#3690 )
76
+ - ` num_updates ` and ` train_interval ` for SAC were replaced with ` steps_per_update ` . (#3690 )
75
77
76
78
### Bug Fixes
77
79
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Collections . ObjectModel ;
3
4
using UnityEngine ;
4
5
using Barracuda ;
5
6
using MLAgents . Sensors ;
@@ -691,6 +692,17 @@ public virtual void CollectObservations(VectorSensor sensor)
691
692
{
692
693
}
693
694
695
+ /// <summary>
696
+ /// Returns a read-only view of the observations that were generated in
697
+ /// <see cref="CollectObservations(VectorSensor)"/>. This is mainly useful inside of a
698
+ /// <see cref="Heuristic(float[])"/> method to avoid recomputing the observations.
699
+ /// </summary>
700
+ /// <returns>A read-only view of the observations list.</returns>
701
+ public ReadOnlyCollection < float > GetObservations ( )
702
+ {
703
+ return collectObservationsSensor . GetObservations ( ) ;
704
+ }
705
+
694
706
/// <summary>
695
707
/// Collects the masks for discrete actions.
696
708
/// When using discrete actions, the agent will not perform the masked action.
Original file line number Diff line number Diff line change 1
1
using System . Collections . Generic ;
2
+ using System . Collections . ObjectModel ;
2
3
using UnityEngine ;
3
4
4
5
namespace MLAgents . Sensors
@@ -60,6 +61,15 @@ public int Write(WriteAdapter adapter)
60
61
return expectedObservations ;
61
62
}
62
63
64
+ /// <summary>
65
+ /// Returns a read-only view of the observations that added.
66
+ /// </summary>
67
+ /// <returns>A read-only view of the observations list.</returns>
68
+ internal ReadOnlyCollection < float > GetObservations ( )
69
+ {
70
+ return m_Observations . AsReadOnly ( ) ;
71
+ }
72
+
63
73
/// <inheritdoc/>
64
74
public void Update ( )
65
75
{
Original file line number Diff line number Diff line change @@ -96,6 +96,8 @@ public override void OnEpisodeBegin()
96
96
97
97
public override void Heuristic ( float [ ] actionsOut )
98
98
{
99
+ var obs = GetObservations ( ) ;
100
+ actionsOut [ 0 ] = obs [ 0 ] ;
99
101
heuristicCalls ++ ;
100
102
}
101
103
}
@@ -667,6 +669,9 @@ public void TestHeuristicPolicyStepsSensors()
667
669
Assert . AreEqual ( numSteps , agent1 . heuristicCalls ) ;
668
670
Assert . AreEqual ( numSteps , agent1 . sensor1 . numWriteCalls ) ;
669
671
Assert . AreEqual ( numSteps , agent1 . sensor2 . numCompressedCalls ) ;
672
+
673
+ // Make sure the Heuristic method read the observation and set the action
674
+ Assert . AreEqual ( agent1 . collectObservationsCallsForEpisode , agent1 . GetAction ( ) [ 0 ] ) ;
670
675
}
671
676
}
672
677
You can’t perform that action at this time.
0 commit comments