Exemplo n.º 1
0
def de(kl, interval, pops, generation, num_inputx, num_hiddenx, num_outputx, data_learning):
    global num_hidden
    global num_input
    global num_output
    global inps
    format = data_learning[-4:-1] + data_learning[-1]

    if format == ".dat":
        inps = loader.loadDat(data_learning)
    elif format == ".csv":
        inps = loader.loadCsv(data_learning)
    inps = loader.stringifyVar(inps, loader.normalizeVar(loader.getVar(inps)))
    num_hidden = num_hiddenx
    num_input = num_inputx
    num_output = num_outputx
    pop = initPop(pops, kl, interval)
    n = 0
    best1 = fitnessRanking(pop, pops)[0]
    best2 = list(best1)
    while n <= generation:
        best1 = fitnessRanking(pop, pops)[0]
        mut = mutation(pop, best1[1], best2[1], pop[best1[0]])
        off = [crossOver((mut, pop[i]), best1[1], best2[1], kl) for i in xrange(pops)]
        for i in xrange(pops):
            if fitness(off[i]) > fitness(pop[i]):
                pop[i] = off[i]
        best2 = best1
        print n, (1 / best2[1]) - 0.0001
        n += 1
    ret = pop[fitnessRanking(pop, pops)[0][0]]
    return ret
Exemplo n.º 2
0
def de(kl,interval,pops,generation,num_hiddenx,data_learning):
	global num_hidden
	global inps
	inps = loader.loadCsv(data_learning)
	inps = loader.stringifyVar(inps,loader.normalizeVar(loader.getVar(inps)))
	num_hidden = num_hiddenx
	pop = initPop(pops,kl,interval)
	n = 0
	best1 = fitnessRanking(pop,pops)[0]
	best2 = list(best1)
	while(n<=generation):
		best1 = fitnessRanking(pop,pops)[0]
		mut = mutation(pop,best1[1],best2[1],pop[best1[0]])
		off = [crossOver((mut,pop[i]),best1[1],best2[1],kl) for i in xrange(pops)]
		for i in xrange(pops):
			if(fitness(off[i])>fitness(pop[i])):
				pop[i] = off[i]
		best2 = best1
		print n,1/best2[1]
		n += 1
	ret = pop[fitnessRanking(pop,pops)[0][0]]
	return ret
Exemplo n.º 3
0
import numpy as np
import math
import ann
import loader

inps = loader.load('paru.xlsx')
inps = loader.stringifyVar(inps,loader.normalizeVar(loader.getVar(inps)))
# inps = loader.loadDat('titanic.dat')

def fitness(kr):
	# return plus(kr)
	# print len(kr)
	return 1/(ann.epoch(inps,kr)+0.1)
	# return ann.epoch(inps,kr)

def plus(kr):
	return 1/((kr[0]+kr[1])+0.001)

def initKromosom(kl,interval):
	kr = np.array([(np.random.uniform()*(2*interval))-interval for i in xrange(kl)])
	# kr = []
	# for i in range(kl):
	# 	kr.append((np.random.uniform()*(2*interval))-interval)
	return kr

def initPop(pops,kl,interval):
	pop = np.array([initKromosom(kl,interval) for i in xrange(pops)])
	# pop = []
	# for i in range(pops):
	# 	pop.append(initKromosom(kl,interval))
	return pop