Skip to content

Commit 6377c96

Browse files
Merge branch 'main' into pump_spec_tests
2 parents a559cb6 + 753b481 commit 6377c96

25 files changed

Lines changed: 178 additions & 162 deletions

File tree

src/main/scala/symsim/Agent.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ trait Agent[State, ObservableState, Action, Reward, Scheduler[_]]:
3535
* convenient to maintain discretizations with the agent, as this makes the
3636
* examples compact.
3737
*/
38-
def discretize (s: State): ObservableState
38+
def observe (s: State): ObservableState
3939

4040
/** Return the reward assigned to state s when action a is given (the
4141
* reward estimation function)

src/main/scala/symsim/ExactRL.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ trait ExactRL[State, ObservableState, Action, Reward, Scheduler[_]]
4949
def learningEpisode (f: VF, s_t: State): Scheduler[VF] =
5050
def p (f: VF, s: State, a: Action): Boolean = agent.isFinal (s)
5151
for
52-
a <- chooseAction (f) (agent.discretize (s_t))
52+
a <- chooseAction (f) (agent.observe (s_t))
5353
fin <- Monad[Scheduler].iterateUntilM (f, s_t, a) (learningEpoch) (p)
5454
yield fin._1
5555

src/main/scala/symsim/QLearning.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ trait QLearning[State, ObservableState, Action, Reward, Scheduler[_]]
2424
sa_tt <- agent.step (s_t) (a_t)
2525
(s_tt, r_tt) = sa_tt
2626

27-
ds_t = agent.discretize (s_t)
28-
ds_tt = agent.discretize (s_tt)
27+
ds_t = agent.observe (s_t)
28+
ds_tt = agent.observe (s_tt)
2929

3030
// Q-learning is off-policy (p.844 in Russel & Norvig)
3131
a_tt = bestAction (q) (ds_tt)

src/main/scala/symsim/Sarsa.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ trait Sarsa[State, ObservableState, Action, Reward, Scheduler[_]]
2424
sa_tt <- agent.step (s_t) (a_t)
2525
(s_tt, r_tt) = sa_tt
2626
// SARSA: on-policy (p.844 in Russel & Norvig)
27-
a_tt <- chooseAction (q) (agent.discretize (s_tt))
27+
a_tt <- chooseAction (q) (agent.observe (s_tt))
2828

29-
ds_t = agent.discretize (s_t)
30-
ds_tt = agent.discretize (s_tt)
29+
ds_t = agent.observe (s_t)
30+
ds_tt = agent.observe (s_tt)
3131
old_entry = q (ds_t) (a_t)
3232
correction = r_tt + gamma * q (ds_tt) (a_tt) - old_entry
3333
qval = old_entry + alpha * correction

src/main/scala/symsim/examples/concrete/breaking/Car.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object Car
4343
s.v == 0.0 || s.p >= 10 || Math.abs (s.p) >= 1000.0
4444

4545

46-
def discretize (s: CarState): CarObservableState =
46+
def observe (s: CarState): CarObservableState =
4747
require (s.v >= 0, s"s.v = ${s.v} is not non-negative")
4848
require (s.p >= 0, s"s.p = ${s.p} is not non-negative")
4949

src/main/scala/symsim/examples/concrete/golf/Golf.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object Golf
4545
s == 9
4646

4747
// Golf is discrete
48-
def discretize (s: GolfState): GolfObservableState = s
48+
def observe (s: GolfState): GolfObservableState = s
4949

5050
private def golfReward (s: GolfState) (a: GolfAction): GolfReward = (s, a) match
5151
case (6, (Club.P, _)) => -100.0

src/main/scala/symsim/examples/concrete/mountaincar/MountainCar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ object MountainCar
4242
s.p >= 0.5
4343

4444

45-
def discretize (s: CarState): CarObservableState =
45+
def observe (s: CarState): CarObservableState =
4646
require (s.p >= -1.2, s"s.p = ${s.p} is not within the boundaries")
4747
require (s.p <= 0.5, s"s.p = ${s.p} is not within the boundaries")
4848
require (s.v >= -1.5, s"s.v = ${s.v} is not within the boundaries")

src/main/scala/symsim/examples/concrete/pumping/Pump.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ end PumpState
4242

4343
/** Discretize cut points for flow, head, and tank variables./
4444
*
45-
* We discretize to the first point on the list that is lower than the actual
45+
* We observe to the first point on the list that is lower than the actual
4646
* value of the variable. So we 'round down'. Values below the last element
4747
* in the cut-point list are rounded up (to the last value).
4848
*
@@ -106,7 +106,7 @@ object Pump extends
106106
s.t >= 4000 || s.h < HEAD_MIN || s.tl > TANK_MAX || s.tl < TANK_MIN
107107

108108

109-
def discretize (s: PumpState): ObservablePumpState =
109+
def observe (s: PumpState): ObservablePumpState =
110110
require (s.tl >= TANK_MIN, s"s.tl = ${s.tl} >= $TANK_MIN")
111111

112112
val df = closest (s.f) (flowCutPoints)

src/main/scala/symsim/examples/concrete/simplebandit/Bandit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Bandit (banditReward: List [Randomized[BanditReward]])
3939
override def isFinal (s: BanditState): Boolean = s
4040

4141
// Bandit is discrete
42-
override def discretize (s: BanditState): BanditState = s
42+
override def observe (s: BanditState): BanditState = s
4343

4444
override def step (s: BanditState) (a: BanditAction): Randomized[(BanditState, BanditReward)] =
4545
for r <- banditReward (a) yield (true, r)

src/main/scala/symsim/examples/concrete/simplemaze/Maze.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object Maze
5656
s == (4, 3) || s == (4, 2)
5757

5858
// Maze is discrete
59-
def discretize (s: MazeState): MazeObservableState = s
59+
def observe (s: MazeState): MazeObservableState = s
6060

6161
private def mazeReward (s: MazeState): MazeReward = s match
6262
case (4, 3) => 1.0 // Good final state

0 commit comments

Comments
 (0)