jiaruifeng / genetic-algorithm-with-python Goto Github PK
View Code? Open in Web Editor NEWusing python to realize GA
using python to realize GA
计算适应度
def fitness(population,aimFunction):
value=[]
for i in range(len(population)):
value.append(aimFunction(decode(population[i])))
#weed out negative value
if value[i]<8:
value[i]=0
else:
value[i]-=8 # 因为最大值是13,所以把适应度都减个8(5也行),这样优秀种群更突出一些,更容易被随机到
return value
还有最后画图时:
plt.figure()
plt.plot(x,y)
# np.argmax
max_y=max(y)
max_x=x[y.index(max(y))]
print((max_x,max_y))
plt.scatter(max_x,max_y,color='r')
plt.figure()
plt.plot(t)
plt.axhline(max(y), linewidth=1, color='r')
plt.axhline(max(t), linewidth=1, color='g') # 红线和绿线重叠表明达到了最优解
plt.show()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.