Giter Site home page Giter Site logo

genetic's People

Contributors

dolphin278 avatar jimlynchcodes avatar samnajian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

genetic's Issues

Cannot read property 'score' of undefined

Someone got this problem before? I cannot run more than 100 generations.

/Users/michaelmalura/Development/bot/node_modules/genetic/lib/genetic/Task.js:210
            level += self.parents[position].score
                                           ^

TypeError: Cannot read property 'score' of undefined
    at /Users/michaelmalura/Development/bot/node_modules/genetic/lib/genetic/Task.js:210:44
    at Object.async.until (/Users/michaelmalura/Development/bot/node_modules/genetic/node_modules/async/lib/async.js:568:13)
    at /Users/michaelmalura/Development/bot/node_modules/genetic/lib/genetic/Task.js:198:13
    at /Users/michaelmalura/Development/bot/node_modules/genetic/node_modules/async/lib/async.js:486:21
    at /Users/michaelmalura/Development/bot/node_modules/genetic/node_modules/async/lib/async.js:185:13
    at iterate (/Users/michaelmalura/Development/bot/node_modules/genetic/node_modules/async/lib/async.js:108:13)
    at /Users/michaelmalura/Development/bot/node_modules/genetic/node_modules/async/lib/async.js:119:25
    at /Users/michaelmalura/Development/bot/node_modules/genetic/node_modules/async/lib/async.js:187:17
    at /Users/michaelmalura/Development/bot/node_modules/genetic/node_modules/async/lib/async.js:491:34
    at /Users/michaelmalura/Development/bot/node_modules/genetic/lib/genetic/Task.js:192:7
function random(start, end) {
    return Math.floor(Math.random() * end) + start;
};

function getRandomSolution(callback) {
    // let threshhold = 0.03;
    // let buyCut = 3;
    // let sellCut = 8;

    callback({
        threshhold: random(0.02, 0.3), // 2% - 30%
        buyCut: random(1, 100), // 1/1 - 1/100
        sellCut: random(1, 100) // 1/1 - 1/100
    })
}

function fitness(solution, callback) {
    const { profit, sells, buys } = simulate(stockData, Object.assign({}, solution));
    callback(profit)
}

function mutate(solution, callback) {
    let s = Object.assign({}, solution);
    if (Math.random() < 0.3) {
        s.threshhold = random(0.02, 0.3);
    }
    if (Math.random() < 0.3) {
        s.buyCut = random(1, 100);
    }
    if (Math.random() < 0.3) {
        s.sellCut = random(1, 100);
    }
    callback(s)
}

function crossover(father, mother, callback) {
    var child = {};

    assert(!!father, `No father`);
    assert(!!mother, `No mother`);

    if (Math.random() >= 0.5) {
        child.threshhold = father.threshhold;
    } else {
        child.threshhold = mother.threshhold;
    }

    if (Math.random() >= 0.5) {
        child.sellCut = father.sellCut;
    } else {
        child.sellCut = mother.sellCut;
    }

    if (Math.random() >= 0.5) {
        child.buyCut = father.buyCut;
    } else {
        child.buyCut = mother.buyCut;
    }
    callback(child);
}

function stopCriteria() {
    return (this.generation === 300)
}

const geneticOptions = {
    getRandomSolution: getRandomSolution,  // previously described to produce random solution
    popSize: 100,  // population size
    stopCriteria: stopCriteria,  // previously described to act as stopping criteria for entire process
    fitness: fitness,  // previously described to measure how good your solution is
    minimize: false,  // whether you want to minimize fitness function. default is `false`, so you can omit it
    mutateProbability: 0.1,  // mutation chance per single child generation
    mutate: mutate,  // previously described to implement mutation
    crossoverProbability: 0.3, // crossover chance per single child generation
    crossover: crossover // previously described to produce child solution by combining two parents
}

const runEvolution = function () {
    const taskInstance = new Task(geneticOptions);
    taskInstance.on('error', function (error) { console.log('ERROR - ', error) })
    taskInstance.run(function (stats) {
        console.log('results', stats);
    });
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.