Public
Edited
Apr 15, 2019
Importers
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chooseAction = (env, observation, policyFn) => {
const actionProbabilities = policyFn(env, observation);
return env.actions[chooseRandomly(actionProbabilities)];
}
Insert cell
function* genEpisodeStep(env, policyFn, episodeNumber, limit) {
let { state: state, observation: observation } = reset(env);
let action = chooseAction(env, observation, policyFn);
let done = false,
i = 0;
while (!done && i < limit) {
const result = step(env, state, action);
const nextAction = !result.done && chooseAction(env, result.observation, policyFn);
yield {
current: {
observation: observation,
action: action,
_state: state
// Technically, the agent can not directly access the current state;
// it can only make observations that are possibly noisy measurements of
// the current state -- but it's convenient to keep it here for
// visualization purposes, so we slap the underscore in front here.
},
reward: result.reward,
next: {
observation: result.observation,
action: nextAction,
_state: result.state // technically, state is hidden... hence the underscore
},
done: result.done,
episodeNumber: episodeNumber,
stepNumber: i
};
done = result.done;
state = result.state;
observation = result.observation;
action = nextAction;
++i;
}
}

// episode = (policy, limit) => [...genEpisodeStep(env, policy, limit)]
Insert cell
function* genEpisode(env, policy, limit) {
let epi = [];
for (const aStep of genEpisodeStep(env, policy, epi.length, limit)) {
epi.push(aStep);
yield epi;
}
}
Insert cell
function* slowGenEpisode(env, policyFn, limit=100, interval=1000) {
yield* slowly(() => genEpisode(env, policyFn, limit), interval);
// for (const aStep of genEpisode(env, policyFn, limit))
// yield Promises.tick(interval, aStep);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more