forked from aljarrahcs/EvoloPy-FS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
88 lines (63 loc) · 2.74 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
Created on Tue Dec 27 12:46:20 2019
@author: Ibrahim Aljarah, and Ruba Abu Khurma
"""
import csv
import numpy
import time
import selector as slctr
from sklearn.model_selection import train_test_split
import pandas as pd
import fitnessFUNs
# Select optimizers
PSO= True
MVO= True
GWO = True
MFO= True
WOA= True
FFA=True
BAT=True
optimizer=[PSO, MVO, GWO, MFO, WOA,FFA,BAT]
datasets=["ionosphere","BreastCancer","iris"]
#benchmarkfunc=[Fs1,Fs2,Fs3,Fs4,Fs5,Fs6,Fs7,Fs8,Fs9,Fs10]
# Select number of repetitions for each experiment.
# To obtain meaningful statistical results, usually 30 independent runs
# are executed for each algorithm.
NumOfRuns=1
# Select general parameters for all optimizers (population size, number of iterations)
PopulationSize = 20
Iterations= 20
#Export results ?
Export=True
#ExportToFile="YourResultsAreHere.csv"
#Automaticly generated file name by date and time
ExportToFile="experiment"+time.strftime("%Y-%m-%d-%H-%M-%S")+".csv"
# Check if it works at least once
Flag=False
# CSV Header for for the cinvergence
CnvgHeader1=[]
CnvgHeader2=[]
for l in range(0,Iterations):
CnvgHeader1.append("Iter"+str(l+1))
for l in range(0,Iterations):
CnvgHeader2.append("Iter"+str(l+1))
for j in range (0, len(datasets)): # specfiy the number of the datasets
for i in range (0, len(optimizer)):
if((optimizer[i]==True)): # start experiment if an optimizer and an objective function is selected
for k in range (0,NumOfRuns):
#func_details=["costNN",-1,1]
func_details=fitnessFUNs.getFunctionDetails(0)
completeData=datasets[j]+".csv"
x=slctr.selector(i,func_details,PopulationSize,Iterations,completeData)
if(Export==True):
with open(ExportToFile, 'a',newline='\n') as out:
writer = csv.writer(out,delimiter=',')
if (Flag==False): # just one time to write the header of the CSV file
header= numpy.concatenate([["Optimizer","Dataset","objfname","Experiment","startTime","EndTime","ExecutionTime","trainAcc","testAcc"],CnvgHeader1,CnvgHeader1])
writer.writerow(header)
a=numpy.concatenate([[x.optimizer,datasets[j],x.objfname,k+1,x.startTime,x.endTime,x.executionTime,x.trainAcc,x.testAcc],x.convergence1,x.convergence2])
writer.writerow(a)
out.close()
Flag=True # at least one experiment
if (Flag==False): # Faild to run at least one experiment
print("No Optomizer or Cost function is selected. Check lists of available optimizers and cost functions")