Skip to content

Commit

Permalink
0.1.1 Fix reward on simple motion
Browse files Browse the repository at this point in the history
  • Loading branch information
thibo73800 committed Nov 27, 2018
1 parent e4ab9e4 commit a43024f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<b>Metacar</b> is a 2D reinforcement learning environment for autonomous vehicles running in the browser. The project aims to let reinforcement learning be more accessible to everyone through solving fun problems. Metacar comes with a set of a predefined levels, some harder to address than others. More levels and possibile scenarios will be added soon (pedestrian, bikes...). Furthermore, the library let you create your own levels and personalize the environment to create your desired scenario.

If you want to be part of the project, whether to implement features in the environment or demonstrate algorithms, feel free to join
the [slack channel](https://join.slack.com/t/metacar/shared_invite/enQtMzgyODI4NDMzMDc0LTY1MjIwNzk1MTAzOTBiZjJlOGUwM2YyYjA3MzBmNjQyNjUyMDZkOGNkYmU0MmUyYzUzNGRhNGJhZDE1M2EzNzM) to ask questions and talk about all your fantastic ideas!
the [slack channel](https://join.slack.com/t/metacar/shared_invite/enQtMzgyODI4NDMzMDc0LTY1MjIwNzk1MTAzOTBiZjJlOGUwM2YyYjA3MzBmNjQyNjUyMDZkOGNkYmU0MmUyYzUzNGRhNGJhZDE1M2EzNzM) to ask questions and talk about all your fantastic ideas!

To start developing with metacar check out the Documentation and the [API Reference](http://metacar-project.com/docs/modules/_index_.html)

Expand All @@ -27,7 +27,7 @@ You can also take a look at the <b>[online demo](https://www.metacar-project.com
Getting started
------------

### Installing Metacar
### Installing Metacar

You can use Metacar with a direct link in your HTML file or install it from NPM. However, metacar is based on [Pixi.js](http://www.pixijs.com/): 4.7.1, then you need to include pixi.js as a global dependency in your HTML.

Expand All @@ -43,7 +43,7 @@ You can use Metacar with a direct link in your HTML file or install it from NPM.
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.7.1/pixi.min.js"></script>
</head>
<body>
<script src="https://cdn.jsdelivr.net/combine/npm/metacar@0.0.1,npm/[email protected].0"></script>
<script src="https://cdn.jsdelivr.net/combine/npm/metacar@0.1.1,npm/[email protected].1"></script>
</body>
</html>
```
Expand Down Expand Up @@ -139,7 +139,7 @@ env.load().then(() => {
// Log the reward
console.log(reward);
});

});
```

Expand Down Expand Up @@ -174,12 +174,12 @@ The state of the environment is made of four fields:
{
a: number|undefined // Acceleration of the car (if any)
lidar: number[][] // Lidar points values
linear: number[] // The flatten lidar values + the current speed of the car
steering: number|undefined // Steering angle of the car (if any)
linear: number[] // The flatten lidar values + the current speed of the car
steering: number|undefined // Steering angle of the car (if any)
}
```

Here is an example of simple training loop.
Here is an example of simple training loop.

```javascript
env.load().then(() => {
Expand Down Expand Up @@ -214,7 +214,7 @@ env.load().then(() => {
env.addEvent("custom", () => {
env.reset();
});

});
```

Expand All @@ -227,11 +227,11 @@ env.load().then(() => {
env.addEvent("Shuffle only the agent", () => {
env.shuffle({cars: false});
});

env.addEvent("Shuffle all", () => {
env.shuffle();
});

});
```

Expand All @@ -240,12 +240,12 @@ env.load().then(() => {
Custom the environement
------------

<b>!WARNING:</b> The method presented in this section must be called <b>BEFORE</b> loading the environment.
<b>!WARNING:</b> The method presented in this section must be called <b>BEFORE</b> loading the environment.

<a id='change-motion'></a>
### Change the motion engine

There are two motion engine available: BasicMotion and ControlMotion.
There are two motion engine available: BasicMotion and ControlMotion.

#### BasicMotion

Expand Down Expand Up @@ -295,7 +295,7 @@ Other methods

### Load a file from your computer

This features can be useful to load the content of one file from your computer (the result of a trained model for
This features can be useful to load the content of one file from your computer (the result of a trained model for
instance).

```javascript
Expand Down Expand Up @@ -358,6 +358,3 @@ editor.load().then(() => {

});
```



2 changes: 1 addition & 1 deletion demo/dist/metacar.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/metacar.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "metacar",
"description": "A reinforcement learning environment for self-driving cars in the browser.",
"version": "0.1.0",
"version": "0.1.1",
"main": "dist/metacar.min.js",
"author": "Thibault Neveu",
"license": "MIT",
Expand Down
12 changes: 9 additions & 3 deletions src/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Level extends World {
}

/**
*
*
* options Options to change the lidar options of the agent.
* Changing the lidar change the state representation of the car in the
* environement.
Expand Down Expand Up @@ -106,11 +106,17 @@ export class Level extends World {
this.agent.reset();
for (var c = 0; c < this.cars.length; c++) {
this.cars[c].reset();
}
}
}

setReward(agent_col: any, on_road: any, action: any){
let reward = 0 + Math.max(0., this.agent.core.v) / this.agent.motion.maxSpeed;
let reward;
if (isNaN(action) || action == null){
reward = 0 + Math.max(0., this.agent.core.v) / this.agent.motion.maxSpeed;
}
else{
reward = action == 0 ? 1 : 0;
}
if (agent_col.length > 0){
reward = -1;
}
Expand Down

0 comments on commit a43024f

Please sign in to comment.