https://github.com/esa/dcgp.js
JavaScript bindings for the differential Cartesian Genetic Programming library
https://github.com/esa/dcgp.js
cpp dcgp javascript webassembly
Last synced: 8 months ago
JSON representation
JavaScript bindings for the differential Cartesian Genetic Programming library
- Host: GitHub
- URL: https://github.com/esa/dcgp.js
- Owner: esa
- Created: 2019-03-03T15:27:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T21:40:17.000Z (about 3 years ago)
- Last Synced: 2025-04-17T23:54:10.836Z (9 months ago)
- Topics: cpp, dcgp, javascript, webassembly
- Language: JavaScript
- Homepage: https://esa.github.io/dcgp.js/
- Size: 1.88 MB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dcgp.js
JavaScript bindings for the [differential Cartesian Genetic Programming library](https://github.com/darioizzo/dcgp). The goal of this project is to provide a library that can run dcgp both on node.js and the web.
## Installation
Install dcgp.js with npm:
```bash
npm install dcgp
```
### Usage
```js
import { initialise, KernelSet, Expression, algorithms } from 'dcgp'
await initialise(/* specify custom path to dcgp.wasm */);
const myKernelSet = new KernelSet('sum', 'diff', 'mul', 'div');
const myExpression = new Expression(2, 1, 2, 6, 5, 2, myKernelSet, 5);
// some simple dataset: y = 2x + 2
const inputs = [[0, 1, 2, 3, 4]];
const outputs = [[2, 4, 6, 8, 10]];
const { loss } = algorithms.muPlusLambda(myExpression, 2, 5, 50, inputs, outputs, [1]);
// Free memory
myKernelSet.destroy()
myExpression.destroy()
```
# Development
Anyone is welcome to help progress and improve this library. Tasks and issues can be found in the [issues tab](https://github.com/esa/dcgp.js/issues). If your problem/task is not in the tasks, feel free to create a new issue explaining your problem/task.
## Prerequisite
- docker
## Installation
**Note:** the instructions shown below assume Linux or macOS. Comments are provided with instructions for Windows.
```bash
git clone https://github.com/mikeheddes/dcgp.js.git
cd dcgp.js
# Start the 32bit ubuntu image with all dcgp.js' dependencies installed
# Note: make sure the docker daemon is running
docker run -it -v "$(pwd):/root/repo" -w /root/repo mikeheddes/dcgp.js-dependencies bash
# Command for windows
# docker run -it -v "%CD%:/root/repo" -w /root/repo mikeheddes/dcgp.js-dependencies bash
# A bash environment will open
npm install
npm run build
# To test the generated bundle in the browser run the following command
npx http-server lib
# To leave the bash environment run
exit
```
## VSCode IntelliSense support
To have IntelliSense support for the C++ files the include folder from the container needs to be copied to the local file system. For this you can use the following commands ones the docker images `mikeheddes/dcgp.js-dependencies` is running.
```bash
# Copy the container ID
docker ps
docker cp REPLACE_WITH_THE_ID:/usr/local/include ./
docker cp REPLACE_WITH_THE_ID:/root/emsdk/emscripten/tag-1.38.30/system/include/ ./
docker cp REPLACE_WITH_THE_ID:/usr/include/eigen3 ./include/
```