Skip to content

Commit 1ba9d5b

Browse files
stateless policy
1 parent a7618b1 commit 1ba9d5b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ let model = null
4646
class Policy{
4747
constructor(){
4848
this.step = 0
49+
this.state = null
4950
}
5051
evaluate_step(state) {
5152
state.observe()
@@ -92,18 +93,19 @@ class Policy{
9293
}
9394
}
9495
const observation_description = document.getElementById("observations").observation
95-
let input = math.matrix([[observation_description.split(".").map(x => get_obs(x)).flat()]])
96+
let input = math.matrix([observation_description.split(".").map(x => get_obs(x)).flat()])
9697
const input_offset = default_trajectory(this.step / 100)
9798
input_offset.forEach((x, i) => {
98-
input._data[0][0][i] = input._data[0][0][i] - x
99+
input._data[0][i] = input._data[0][i] - x
99100
})
100-
const output = model.evaluate_step(input)
101+
const [output, new_state] = model.evaluate_step(input, this.state)
102+
this.state = new_state
101103
this.step += 1
102-
return output.valueOf()[0][0]
104+
return output.valueOf()[0]
103105
}
104106
reset() {
105107
this.step = 0
106-
model.reset()
108+
this.state = null
107109
}
108110
}
109111

0 commit comments

Comments
 (0)