An Emergent Computing Playground for DQN CAs
This simulation takes the progeny.js library and makes it simulate a predator and prey scenario in a continuous 2D space. Predators must learn how to hunt efficiently while prey must learn how to eveade predators. This is a simple context for using the library in a setting where Deep Q Agents must be driven to gain a sense of self preservation. Use the keyboard arrow keys to change agents or click on the agent in the menu on the bottom left.
This simulation is the exact same one as the 2D simulation except I used Three.js to add two more dimensions to the cell data: (Z and Z-Velocity). The simulation is set to follow the selected agent by default (vomit warning?) and you can make the camera stop/start following the selected agent by pressing spacebar
.
...
<canvas id="world"></canvas>
var conf = {
numCells: 30,
dataWidth: 4,
initDimRange: [100, 100, 1, 1],
actions: [
function(cell, neighbor){
// Do something
// cell = the actual cell, neighbor = neibhor's data vector
},
function(cell, neighbor){
// Add as many functions as you want
// as long as they are in this format...
},
...
],
cellStep: function(cell){
// this function does something at the end of each step
},
cellReward: function(cell, neighbor){
// Most important function of all, controls what behaviors emerge
// good to start out with some metric like k-dimensional distance
// note: this function is only in the scope of a cell and one neighbor
},
draw: function(world){
// Go through all cells in the world...
world.cells.forEach(function(cell, index){
// Show each cell on a canvas or however you want to visualize the cell.data space.
});
}
};
// Create world from configuration
var world = new World(conf);
// Create the cells in the world
world.generate();
// Start the world, to stop use world.stop()
world.start();
actions
- An array of action functions that each cell can performdataWidth
- The number of dimensions in thedata
vector of each cellnumCells
- Total number of cells to add to theWorld
dimTitles
- The titles for each dimension given bydataWidth
initDimRange
- The range within which to choose randomly for init valuesinitValues
- OverridesinitDimRange
to make value fixed. index matchesdimTitles
andinitDimRange
stats
- An object that counts happenings in the cellmaxLinks
- Maximum number of links a cell can have (default 4)initEnergy
- Used to distribute among random values across each dimneighborDistance
- Maximum distance to search for nearest neighborsinterval
- The interval between world frames inms
draw
- Callback function for drawing the world on a canvascellReward
- The reward function for each cell (controls how they learn)cellStep
- Callback function happening at the end of each step for cellbrainConfig
- This is a configuration object for the rl.js DQNAgent class. See demos for more settings.