Code Monkey home page Code Monkey logo

morvanzhou / evolutionary-algorithm Goto Github PK

View Code? Open in Web Editor NEW
1.2K 65.0 632.0 2.26 MB

Evolutionary Algorithm using Python, 莫烦Python 中文AI教学

Home Page: https://mofanpy.com/tutorials/machine-learning/evolutionary-algorithm/

License: MIT License

Python 100.00%
evolutionary-algorithm genetic-algorithm neuroevolution microbial-genetic-algorithm travel-sale-problem evolution-strategy es reinforcement-learning neural-network microbial-ga

evolutionary-algorithm's People

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  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

evolutionary-algorithm's Issues

gym WARN

Hi.
Gym is updated and now have warning:
WARN: gym.spaces.Box autodetected dtype as <class 'numpy.float32'>. Please provide explicit dtype.

发现一些(可能的) BUG

第一个(可能的) BUG:
https://github.com/MorvanZhou/Evolutionary-Algorithm/blob/master/tutorial-contents/Genetic%20Algorithm/Genetic%20Algorithm%20Basic.py#L49

使用 repeat 导致初始种群所有个体都有相同的 DNA; 正确做法是 pop = np.random.randint(2, size=(POP_SIZE, DNA_SIZE)) 使种群每个个体拥有随机的基因;

第二个(可能的) BUG:
https://github.com/MorvanZhou/Evolutionary-Algorithm/blob/master/tutorial-contents/Genetic%20Algorithm/Genetic%20Algorithm%20Basic.py#L34

crossover 在求函数最大最小值一般采用单点交叉, 类似生物体染色体交叉, 而非对每一个基因座做交叉, 单点交叉示意如下

A: 10110111|00  crossover  A': 10110111|11
B: 00011100|11  -------->  B': 00011100|00

并且在做交叉时, 需要对个体进行两两配对, 而非从整体中随机选择, 这会导致群体内的部分已经过 select 个体繁殖几率不同. 从原理上来说, 经过 select 的个体必须拥有相同的繁殖几率.

Unable to figure out ideal library for my project

Hey!

I am working on some code with open cv to track the percentage of frames in which my face is detected in terms of "attention span". I intend to optimize this attention span with an evolutionary solver that iterates a combination of diffused and direct light levels in my environment with an arduino board. Owing to the long range of time over which a generation of light levels need to be iterated I am unsure as to the best Evolutionary algorithm library or approach i can use to do this. I am currently not connected to an arduino and am just trying to do this with dummy numbers (1-4,1-4) for diffused and direct respectively. The idea is that every 15 mins or so ( lets say 50,000 frames) the light levels assume a new and improved combination and wait for another 15.

I am new to python and coding in general so I am finding it harder to figure out which library and it's ideal implementation for this purpose I'd be grateful if you have any advice.

DNA_SIZE > 1 error.

when DNA_SIZE > 1, index out of boundary at
good_idx = idx[fitness.argsort()][-POP_SIZE:]

so, suggestion is :
def kill_bad(pop, kids):
# put pop and kids together
for key in ['DNA', 'mut_strength']:
pop[key] = np.vstack((pop[key], kids[key]))

fitness = get_fitness(F(pop['DNA']))            # calculate global fitness
w,h = pop['DNA'].shape
idx = np.arange(w*h)    
good_idx = idx[fitness.argsort()][-POP_SIZE*DNA_SIZE:]   # selected by fitness ranking (not value)
for key in ['DNA', 'mut_strength']:
    pop[key] = pop[key].flatten()
    pop[key] = pop[key][good_idx]
    pop[key] = pop[key].reshape((POP_SIZE,DNA_SIZE))
return pop

Travel Salesman Problem - Add constraints

Hi Morvan, amazing work!

It is really helping me understand GAs. I am curious how could I add the constraint of having to come back to the original position, so the travel is a round trip.

In which part should the constraint be added?

Thanks in advance!

Regards,
Pablo

关于变异强度的自适应

在代码的进化中,我认为变异强度并不是自适应地往低值走,它主要还是决定于最初达到峰值的学习点对应的'mut_strength‘,在basic和(1+1)中都可以体现(我是进行了输出。结果只是趋向于某一个值而已),我的想法是DNA与函数峰值的差去决定变异强度(当然这只能用于这两个代码)。如果我的想法有错误,也请你告诉我,谢谢!

Same questions.

Hi, your tutorials are awesome! I just start learning python & machine learning and not without your help.

Regarding "Evolutionary-Algorithm / tutorial-contents / Using Neural Nets / Evolution Strategy with Neural Nets.py":

  • is it possible to run your 'maze_env.py' on it? And how to do it? I try to do it for a week, but without result((
  • how to save trained net for different games and load it, without new training?

Thanks a lots.

关于basic_EA

为什么要用正态分布去改变DNA
如何保证在DNA逐渐优化的过程中,变异强度会逐渐减弱。也是依靠计算机随机的选择么?

A problem with code in Genetic Algorithm Basic.py

你好!感谢你的视频分享,很通俗易懂!但是我有一点小疑问,如下:

for parent in pop:
        child = crossover(parent, pop_copy)
        child = mutate(child)
        parent[:] = child       # parent is replaced its child

我对这一段代码的最后一句有一点疑惑,就是为什么要重新更改parent的值呢?它在for循环里作为迭代变量,更改它的值是不是没有意义啊?为什么不是把child的值更新到pop里面?
谢谢你!

关于ES算法individuals的数量的问题

您好,莫烦老师,非常感谢你的视频分享。
我对ES neuroevolution的算法有个疑问想请教下,你的算法中只用了20个individuals就可以起到比较好的效果了,我看openai的算法,为什么他们需要1000个才行?而且我将openai算法中的individuals的数量减少了,似乎他们的算法就无法收敛了。

model saving

Hello,

how does one save an evolved model and then load one for later use?

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.