Skip to content

Commit

Permalink
noise to actions + remove height in reward proportions
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanjzhao committed Sep 4, 2024
1 parent b72de86 commit d53ecce
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions examples/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,17 +605,15 @@ export class MuJoCoDemo {
const originalPosProp = originalPosWeighted / totalReward;
const velocityProp = velocityWeighted / totalReward;
const orientationProp = orientationWeighted / totalReward;
const heightProp = heightWeighted / totalReward;

console.log(orientation)
// const heightProp = heightWeighted / totalReward;

// Log proportions (equivalent to jax.debug.print)
console.log(
`Reward proportions: total_reward: ${totalReward}, ` +
`ctrl_cost: ${ctrlCostProp}, ` +
`original_pos: ${originalPosProp}, ` +
`orientation: ${orientationProp}, ` +
`height: ${heightProp}`
`Reward proportions: total_reward: ${totalReward}, `
+ `ctrl_cost: ${ctrlCostProp}, `
+ `original_pos: ${originalPosProp}, `
+ `orientation: ${orientationProp}`
// + `height: ${heightProp}`
);

this.state = nextState;
Expand Down Expand Up @@ -686,7 +684,12 @@ export class MuJoCoDemo {
// Scale action to actuator range
let [min, max] = this.actuatorRanges[i];
let newValue = min + (clippedAction + 1) * (max - min) / 2;


// Add noise to the new value
if (this.params["ctrlnoisestd"] > 0.0) {
newValue += this.params["ctrlnoisestd"] * standardNormal(); // Add Gaussian noise
}

this.simulation.ctrl[i] = newValue;
this.params[this.actuatorNames[i]] = newValue;
} else {
Expand All @@ -711,7 +714,7 @@ export class MuJoCoDemo {

// updates states from dragging
// Jitter the control state with gaussian random noise
if (this.params["ctrlnoisestd"] > 0.0) {
if (this.params["ctrlnoisestd"] > 0.0 && !this.params["useModel"]) {
let rate = Math.exp(-timestep / Math.max(1e-10, this.params["ctrlnoiserate"]));
let scale = this.params["ctrlnoisestd"] * Math.sqrt(1 - rate * rate);
let currentCtrl = this.simulation.ctrl;
Expand Down

0 comments on commit d53ecce

Please sign in to comment.