Skip to content

Commit

Permalink
improved log, added minimalRun.wppl
Browse files Browse the repository at this point in the history
  • Loading branch information
mensch72 committed Mar 1, 2024
1 parent fb01e79 commit 19c36e3
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 133 deletions.
14 changes: 14 additions & 0 deletions examples/minimalRun.wppl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// run via webppl --require webppl-dp --require . examples/minimalRun.wppl

var env = getEnv(),
mdp = VerySimpleGW("GW6"),
agent = makeMDPAgentSatisfia(mdp.params, mdp.world);

var simulationResults = simulateMDPAgentSatisfia(mdp, agent, mdp.startState, mdp.aleph0);

if (env.inBrowser) {
viz.gridworld(mdp.orig_world, { trajectory: simulationResults.states });
} else {
console.log("simulationResults", simulationResults);
}

38 changes: 15 additions & 23 deletions examples/runVerySimpleGW.wppl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ var _SU = webpplAgents.satisfia;
var _PP = webpplAgents.pretty;

var env = getEnv(),
argv = env.argv,
params = extend({
// some env-specific parameter settings
}, argv),
options = extend({
// debug: true
// some env-specific option settings
}, argv),
argv = extend({}, env.argv),
params = extend({}, argv),
mdp = VerySimpleGW(argv.gw || "GW2", argv.gwparms, argv.time, argv.timeOutDelta),
world = mdp.world,
transition = world.transition,
Expand All @@ -22,34 +16,32 @@ var env = getEnv(),
startState = mdp.startState,
aleph0 = argv.aleph0 || mdp.aleph0,
agent = makeMDPAgentSatisfia(extend(params, {
expectedDelta, uninformedPolicy, referencePolicy, aleph0, options
expectedDelta, uninformedPolicy, referencePolicy, aleph0, argv
}), world),
localPolicy = agent.localPolicy,
propagateAspiration = agent.propagateAspiration,
getAspiration4state = agent.getAspiration4state,
V = agent.V,
V2 = agent.V2,
entropy = agent.behaviorEntropy_state,
KLdiv = agent.behaviorKLdiv_state,
messingPotential = agent.messingPotential_state,
cupLoss = agent.cupLoss_state;

console.log("aleph0", asInterval(aleph0));
behaviorEntropy_state = agent.behaviorEntropy_state,
behaviorKLdiv_state = agent.behaviorKLdiv_state,
messingPotential_state = agent.messingPotential_state,
cupLoss_state = agent.cupLoss_state;

var t0 = _SU.time();
// verify meeting of expectations:
console.log("V", V(startState, aleph0));
console.log("TIME:", _SU.time() - t0, "ms");
console.log("cupLoss", cupLoss(mdp.startState, aleph0));
console.log("entropy", entropy(mdp.startState, aleph0));
console.log("KLdiv", KLdiv(mdp.startState, aleph0));
console.log("messPot", messingPotential(mdp.startState, aleph0));
console.log("\nV", V(startState, aleph0),"\n");
console.log("\nTIME:", _SU.time() - t0, "ms\n");
console.log("\ncupLoss", cupLoss_state(mdp.startState, aleph0),"\n");
console.log("\nentropy", behaviorEntropy_state(mdp.startState, aleph0),"\n");
console.log("\nKLdiv", behaviorKLdiv_state(mdp.startState, aleph0),"\n");
console.log("\nmessingPotential", messingPotential_state(mdp.startState, aleph0),"\n");

var gd = agent.getData, agentData = gd();

// estimate distribution of trajectories:

var sym = simulateMDPAgentSatisfia(mdp, agent, mdp.startState, aleph0, options); // simulate(mdp.startState, aleph0);
var sym = simulateMDPAgentSatisfia(mdp, agent, mdp.startState, aleph0, argv); // simulate(mdp.startState, aleph0);

var trajDist = Infer({ model() {
return sym.trajectory;
Expand Down Expand Up @@ -85,7 +77,7 @@ console.log("\naction frequencies:");
console.log(_PP.locActionData2ASCII(locActionData.actionFrequency));


var tr=sym.tr4viz;
var tr=sym.states;
console.log(tr);
console.log(tr[0].loc);
console.log(tr[1].loc);
Expand Down
6 changes: 3 additions & 3 deletions restaurant_choice.wppl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var agent = makeMDPAgentSatisfia(extend(params, {
var getLocalPolicy = agent.getLocalPolicy, propagateAspiration = agent.propagateAspiration,
getAspiration4state = agent.getAspiration4state,
V = agent.V, V2 = agent.V2,
entropy = agent.entropy, KLdiv = agent.KLdiv;
behaviorEntropy_state = agent.entropy, behaviorKLdiv = agent.KLdiv;

// Generate and draw a trajectory:
var simulate = function(state, aleph) {
Expand Down Expand Up @@ -156,8 +156,8 @@ stddev = Math.sqrt(expectedSquaredIndicator - Math.pow(expectedIndicator,2));
console.log("indicator has a std.dev. of", stddev,
"which should equal", Math.sqrt(V2(mdp.startState, aleph0) - Math.pow(V(mdp.startState, aleph0),2)));

console.log("Entropy of policy is", entropy(mdp.startState, aleph0));
console.log("KL divergence from reference policy is", KLdiv(mdp.startState, aleph0));
console.log("Entropy of policy is", behaviorEntropy_state(mdp.startState, aleph0));
console.log("KL divergence from reference policy is", behaviorKLdiv(mdp.startState, aleph0));

if (inBrowser) {
// simulate and show a single trajectory:
Expand Down
Loading

0 comments on commit 19c36e3

Please sign in to comment.