コード例 #1
0
def mutate(index,bands,length,maxlength,mutation_rate = 0.05):


    if(random.random() < mutation_rate):

        if random.random() < 0.5:
            # print("BASIC")
            mutateBasic(index,bands,mutation_rate = 0.5)
        
        else:
            # print("EXPAND")
            if length < maxlength:
                bools = [True,False]
                index2 = SpectralIndex.SpectralIndex(bands)
                expandIndex(index,index2.index,random.choice(bools))
コード例 #2
0
	MUTATION_RATE = 0.5
	MAXLENGTH = 15
	STAGNATION = 20;

	bestEver = ""

	# INITIALIZE POPULATION

	print("Initializing Population...")
	population = []

	averageFitnessInitialPopulation = 0;

	for p in range(POPSIZE):
	    # print(p)
	    index = SpectralIndex.SpectralIndex(bands);
	    index.fitness,index.score,index.isLarger,index.isPointFive,index.isNotPointFive,index.lessThanTen,index.jmd = calculateFitness(index.index,bands,pointSet)
	    index.normalizedFitness = 0
	    averageFitnessInitialPopulation += index.fitness
	    population.append(index)
	    

	averageFitnessInitialPopulation /= POPSIZE;

	bestEver = population[0]

	for individual in population:
		print(individual.fitness)


	# print("SNAP")
コード例 #3
0
    return tree3, tree4


bands = ["B1", "B2", "B3", "B4", "B5", "B6", "B7"]

values = {}
values['B1'] = 1.0
values['B2'] = 2.0
values['B3'] = 3.0
values['B4'] = 4.0
values['B5'] = 5.0
values['B6'] = 6.0
values['B7'] = 7.0

index = SpectralIndex.SpectralIndex(bands)
# index.pretty(index.index,0)
indexAppend = SpectralIndex.SpectralIndex(bands)
# indexAppend.pretty(indexAppend.index,0)

expandIndex(index.index, indexAppend.index, True)

indexAppendAgain = SpectralIndex.SpectralIndex(bands)

expandIndex(index.index, indexAppendAgain.index, True)

index.pretty(index.index, 0)

print("---------------------------------")
index2 = SpectralIndex.SpectralIndex(bands)
# index2.pretty(index2.index,0)