예제 #1
0
def drop_cond(PS):
	drop_PS = []
	for hipotesis in PS:
		# probabilidad 0.6
		if(random.randint(1,100) <= 60):
			# escoger un atributo aleatorio para droppear
			mask = mask_atributos[random.randint(0, len(mask_atributos)-1)]
			dropped_hip = bin(int(hipotesis,2) | int(mask, 2))
			hipotesis = codificar.complete_bin(rule_size, dropped_hip[2:])
		drop_PS.append(hipotesis)
	return drop_PS
예제 #2
0
def add_altern(PS):
	altern_PS = []
	for hipotesis in PS:
		# probabilidad 0.01
		if(random.randint(1, 100) == 1):
			# ver donde hay ceros en los atributos y elegir uno aleatorio para alterar
			cero_pos = []
			for i in range(len(hipotesis)-1):
				if hipotesis[i] == '0':
					cero_pos.append(i)
			if (len(cero_pos)>0):
				mask = make_mask(cero_pos[random.randint(0, len(cero_pos)-1)], len(hipotesis))
				altern_bin =  bin(int(hipotesis,2) | int(mask, 2))
				hipotesis = codificar.complete_bin(rule_size, altern_bin[2:])
		altern_PS.append(hipotesis)
	return altern_PS
예제 #3
0
def poblacion(string_len, p):
	P = []
	for i in range(p):
		rand = random.randint(0,2**string_len-1)
		P.append(codificar.complete_bin(string_len, bin(rand)[2:]))
	return P