##A simple example of 3D-FOA by Python
# Find the min value of QF by FOA
"""
author: Wei-Yuan Lin
Soochow University, Taipei
Taiwan
Ver.2
"""
import numpy as np
import matplotlib.pyplot as plt
Population = 100
Gen = 100
def initParams(bestX,bestY,bestZ,Population):
location = []
fitness = []
for num in range(Population):
x,y,z= bestX+2*np.random.rand()-1,bestY+2*np.random.rand()-1,bestZ+2*np.random.rand()-1
S = 1/np.sqrt(x**2+y**2+z**2)
smell = -7+S**2
location.append((x,y,z))
fitness.append(smell)
bestIndex = np.argmin(fitness)
bestX,bestY,bestZ = location[bestIndex]
bestSmell = fitness[bestIndex]
return bestX,bestY,bestZ,bestSmell
bestX,bestY,bestZ,bestSmell = initParams(10*np.random.rand(),10*np.random.rand(),10*np.random.rand(),Population)
xlist,ylist,zlist,value = [],[],[],[]
for time in range(Gen):
tmpX,tmpY,tmpZ,tmpSmell = initParams(bestX,bestY,bestZ,Population)
if tmpSmell < bestSmell:
bestX = tmpX
bestY = tmpY
bestZ = tmpZ
bestSmell = tmpSmell
xlist.append(bestX)
ylist.append(bestY)
zlist.append(bestZ)
value.append(bestSmell)
# fig,ax
fig,ax = plt.subplots(1,2,figsize=(12,4))
plt.subplot(1, 3, 1)
plt.plot(range(1,Gen+1),value,'*',color='blue')
plt.xlabel('Gen')
plt.title('Min f(S)=-7+S**2',fontsize=16)
plt.ylabel('Best Value',fontsize=10)
plt.grid(linestyle='--')
plt.subplot(1, 3, 2)
plt.plot(xlist,ylist,'*',color='black')
plt.title('2D-Route of Best Fly',fontsize=16)
plt.xlabel('X Axis',fontsize=12)
plt.ylabel('Y Axis',fontsize=12)
plt.grid(linestyle='--')
# plt.subplot(1, 3, 3)
# add 3-D Graph
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot(xlist,ylist,zlist,'*')
ax.set_title("3D-Route of Best Fly",fontsize=16)
# plt.title('3D-Route of Best Fly',fontsize=16)
ax.set_xlabel("X Axis")
ax.set_ylabel("Y Axis")
ax.set_zlabel("Z Axis")
# ax.xlabel('X',fontsize=12)
# plt.ylabel('Y',fontsize=12)
# plt.zlabel('Z',fontsize=12)
plt.show()
fig.savefig("3dFOA.png")
CI Algorithms - Fruit Fly Optimization Algorithm (FFOA)
Thursday, October 18, 2018
A simple example of 3D-FOA by Python
Posted on 6:46 PM by linwayne8888@gmail.com
| 19 comments
Subscribe to:
Post Comments (Atom)
Great Article
ReplyDeleteB.Tech Final Year Projects for CSE in Python
FInal Year Project Centers in Chennai
Python Training in Chennai
Python Training in Chennai
There is lots of Post about Python But your way of Writing is so Good & Knowledgeable. Thanks for Sharing a Nice & Informative Information
ReplyDeletePython Training in Delhi
Python Training in Noida
Python Training in Gurgaon
Live instructional courses from bunches of universities propose this as significant theme because of its dynamic upmachine learning certificationdates in the web and industry.
ReplyDelete# Previous example
ReplyDelete"""
Typo corrected
@author: Wei-Yuan Lin
"""
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
Population = 10
Gen = 100
def initParams(bestX,bestY,bestZ,Population):
location = []
fitness = []
for num in range(Population):
x,y,z= bestX+2*np.random.rand()-1,bestY+2*np.random.rand()-1,bestZ+2*np.random.rand()-1
S = 1/np.sqrt(x**2+y**2+z**2)
smell = -7+S**2
location.append((x,y,z))
fitness.append(smell)
bestIndex = np.argmin(fitness)
bestX,bestY,bestZ = location[bestIndex]
bestSmell = fitness[bestIndex]
return bestX,bestY,bestZ,bestSmell
bestX,bestY,bestZ,bestSmell = initParams(10*np.random.rand(),10*np.random.rand(),10*np.random.rand(),Population)
xlist,ylist,zlist,value = [],[],[],[]
for time in range(Gen):
tmpX,tmpY,tmpZ,tmpSmell = initParams(bestX,bestY,bestZ,Population)
if tmpSmell < bestSmell:
bestX = tmpX
bestY = tmpY
bestZ = tmpZ
bestSmell = tmpSmell
xlist.append(bestX)
ylist.append(bestY)
zlist.append(bestZ)
value.append(bestSmell)
# fig,ax
fig,ax = plt.subplots(1,2,figsize=(12,4))
plt.subplot(1, 3, 1)
plt.plot(range(1,Gen+1),value,'*',color='green')
plt.title('FOA_Min f(S)=-7+S**2 ',fontsize=14)
plt.xlabel('Gen',fontsize=12)
plt.ylabel('Optimal Value',fontsize=12)
plt.grid(linestyle='--')
plt.subplot(1, 3, 2)
plt.plot(xlist,ylist,'*',color='blue')
plt.title('2D-Route of Best FOA Fly',fontsize=14)
plt.xlabel('X ',fontsize=12)
plt.ylabel('Y ',fontsize=12)
plt.grid(linestyle='--')
#plt.subplot(1, 3, 3)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot(xlist,ylist,zlist,'*')
ax.set_title("3D-Route of Best FOA Fly",fontsize=14)
# plt.title('3D-Route of Best Fly',fontsize=16)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
plt.show()
fig.savefig("3dFOA.png")
t mpY -> tmpY
ReplyDeleteit need to be done with another import
"from mpl_toolkits.mplot3d import Axes3D;"
Malatya
ReplyDeleteKırıkkale
Aksaray
Bitlis
Manisa
4PZRN8
Batman
ReplyDeleteArdahan
Adıyaman
Antalya
Giresun
GC440
Antalya
ReplyDeleteAntep
Burdur
Sakarya
istanbul
WME0KS
van
ReplyDeletekastamonu
elazığ
tokat
sakarya
31L6
bitlis
ReplyDeletekastamonu
çorum
van
sakarya
T7RA
ankara parça eşya taşıma
ReplyDeletetakipçi satın al
antalya rent a car
antalya rent a car
ankara parça eşya taşıma
KU45Z
86C8A
ReplyDeleteVan Evden Eve Nakliyat
Bitlis Evden Eve Nakliyat
Silivri Boya Ustası
Çerkezköy Evden Eve Nakliyat
Adıyaman Evden Eve Nakliyat
Kilis Evden Eve Nakliyat
sustanon for sale
Referans Kimliği Nedir
Çanakkale Evden Eve Nakliyat
F53A5
ReplyDeletebinance kod
FFF08
ReplyDeleteçanakkale rastgele sohbet uygulaması
yalova ücretsiz sohbet
afyon telefonda canlı sohbet
Ankara Sohbet Muhabbet
maraş bedava sohbet uygulamaları
Aydın Sesli Sohbet Siteleri
trabzon bedava sohbet siteleri
bedava sohbet uygulamaları
aksaray mobil sohbet bedava
78CB6
ReplyDeleteBinance Borsası Güvenilir mi
Coin Nasıl Oynanır
Parasız Görüntülü Sohbet
Telegram Abone Hilesi
Telcoin Coin Hangi Borsada
Okex Borsası Güvenilir mi
Tiktok Beğeni Satın Al
Onlyfans Beğeni Satın Al
Bitcoin Madenciliği Nedir
00A0C
ReplyDelete4g mobil proxy
kucoin
en iyi kripto para uygulaması
bybit
bkex
mercatox
güvenilir kripto para siteleri
kripto para haram mı
binance
9E81C
ReplyDeletekripto para kanalları telegram
mobil proxy 4g
btcturk
kraken
papaya
kripto para nasıl alınır
canlı sohbet ucretsiz
poloniex
bitcoin hangi bankalarda var
8AC70
ReplyDeleteTwitter Beğeni
jeneratör fiyatları
SEO Danışmanı
Logo Tasarım
Backlink Paketleri
Mobil Proxy
vds satın al
seo nedir
Web Site Kurma
7ED45
ReplyDeleteEtsy SEO
Telegram Grup Satın Al
Sanal Sunucu Kiralama
Tarayıcı Oyunları
Web Hosting
güneş paneli fiyatları
İçerik Editörü
Telegram Kanal Satın Al
fuar standı