Skip to content

Commit

Permalink
update fitness
Browse files Browse the repository at this point in the history
  • Loading branch information
amirdeljouyi committed Jan 26, 2018
1 parent f37925c commit d2119d8
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 508 deletions.
Empty file added .gitignore
Empty file.
28 changes: 14 additions & 14 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import pandas as pd

from cluster import Cluster
from cluster import Clustering
from genetic import Genetic
from generation import Generation

Expand All @@ -23,7 +23,7 @@ def readVars(config_file):


# minmax normalization
def normalize(data):
def minmax(data):
normData = data
data = data.astype(float)
normData = normData.astype(float)
Expand All @@ -42,12 +42,11 @@ def normalize(data):
normData.to_csv('result/norm_data.csv', index=None, header=None)
return normData


if __name__ == '__main__':
config_file = "config.txt"
if(NORMALIZATION):
data = pd.read_csv('data/iris2.csv', header=None)
data = normalize(data) # normalize
data = pd.read_csv('data/iris.csv', header=None)
data = minmax(data) # normalize
else:
data = pd.read_csv('result/norm_data.csv', header=None)
# size of column
Expand All @@ -66,7 +65,8 @@ def normalize(data):
print("Pc", Pc)
print("---------------------------------------")

chromosome_length = kmax + kmax * dim
# dim or pattern id
chromosome_length = kmax * dim

#-------------------------------------------------------#
# main #
Expand All @@ -75,18 +75,18 @@ def normalize(data):
initial.randomGenerateChromosomes(
chromosome_length) # initial generate chromosome

cluster = Cluster(initial, data, kmax) # eval fit of chromo
clustering = Clustering(initial, data, kmax) # eval fit of chromosomes

# ------------------cal fitness------------------#
generation, countFitTime = cluster.calcChromosomesFit()
# ------------------calc fitness------------------#
generation = clustering.calcChromosomesFit()

# ------------------------GA----------------------#
while countFitTime <= budget:
while generationCount <= budget:
GA = Genetic(numOfInd, Ps, Pm, Pc, budget, data, generationCount, kmax)
generation, countFitTime, generationCount = GA.geneticProcess(
generation, countFitTime)
generation, generationCount = GA.geneticProcess(
generation)
iBest = generation.chromosomes[0]
cluster.printIBest(iBest, countFitTime)
clustering.printIBest(iBest)

# ------------------output result-------------------#
cluster.output_result(iBest, data)
clustering.output_result(iBest, data)
Binary file modified __pycache__/cluster.cpython-36.pyc
Binary file not shown.
Binary file modified __pycache__/generation.cpython-36.pyc
Binary file not shown.
Binary file modified __pycache__/genetic.cpython-36.pyc
Binary file not shown.
Loading

0 comments on commit d2119d8

Please sign in to comment.