Code Monkey home page Code Monkey logo

genetic_algorithm's Introduction

Genetic_Algorithm

Genetic Algorithm on OpenSiv3D

#include "GA.hpp"

で使えるようになります。自作ゲームのCPU作成などにどうぞ。

Genetic_Algorithm(int32 NumAgents_,int32 Actions_,int32 Samples_=2,double MutationRate_=0.01,int32 RandomSample_=1);

NumAgents_:個体数
Actions_:行動の種類数(特徴数)
Samples_:選別のときに選ぶ個体数
MutationRate_:突然変異を起こす確率
RandomSample_:各世代で、ランダムに生成する個体の個数

Genetic_Algorithm について

遺伝的アルゴリズムのためのクラスです。各個体は0~1までの乱数(浮動小数点数)からなる遺伝子を持ちます。
学習は、
最も適応できた個体をいくつか選別

それらを2つずつ交配させて新しい世代を作成
という流れです。

メンバ関数

Array<double> reply(Array<double>rewards);

rewards:各個体の適応度の格納したArray配列

戻り値:その世代の中で最も優秀だった個体の遺伝子を返します。

各遺伝子の総和が10に近づくようにするプログラムです

# include <Siv3D.hpp> // OpenSiv3D v0.4.3
# include"GA.hpp"
void Main(){
    int32 frame=0,Agents=1000,actions=10;
    Genetic_Algorithm GA(Agents, actions,5,0.05,10);
    
    while(System::Update()){
        Array<double>rewards;
        double max=0;
        
        for(auto i:step(Agents)){
            double sum=0;
            for(auto j:step(actions)) sum+=GA.Agents[i][j];
            rewards<<sum;
            max=Max(max,sum);
        }
        
        ClearPrint();
        Print<<frame;
        Print<<max;
        Print<<GA.reply(rewards);
        ++frame;
    }
}

わからないこと・問題点等あれば、Issuesに投げていただけば回答します

genetic_algorithm's People

Contributors

luke256 avatar

Stargazers

Plat avatar

Watchers

 avatar

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.