def nodeReplace(path): terminals = scrape.getTerminal() string_terminals = filter(lambda t: type(t) == type('str'), terminals) path_string_terminals = filter(lambda t: t in path, string_terminals) apple_data = filter(lambda t: t[0] == 'a', path_string_terminals) nasdaq_data = filter(lambda t: t[0] == 'n', path_string_terminals) sp500_data = filter(lambda t: t[0] == 's', path_string_terminals) map(lambda t: replaceWrapper(path, t, 'a'), apple_data) map(lambda t: replaceWrapper(path, t, 'n'), nasdaq_data) map(lambda t: replaceWrapper(path, t, 's'), sp500_data)
def fillGeneticTree(root): #Load terminal list with terminal nodes terminal = scrape.getTerminal() #Load functional list with functional nodes functional = scrape.getFunctional() #Keeps track of functional and terminal list positions terminal_index = 0 functional_index = 0 stack = [] stack.append(root) temp_terminal = sample(terminal, len(terminal)) #shuffle terminal temp_functional = sample(functional, len(functional)) #shuffle functional #While loop ensures that initial population has #one of each type of functional node #and one of each type of terminal node while (len(stack) > 0): current = stack.pop() if (current.left == None and current.right == None): #Node is a leaf, insert terminal node current.value = temp_terminal[terminal_index] terminal_index += 1 else: #Node is not a leaf, insert a functional node current.value = temp_functional[functional_index] functional_index += 1 #Resets indices if out of bounds if terminal_index == len(temp_terminal): terminal_index = 0 if functional_index == len(temp_functional): functional_index = 0 temp_node = current.right if temp_node != None: stack.append(temp_node) #stack.push temp_node = current.left if temp_node != None: stack.append(temp_node) #stack.push
def fillGeneticTree(root): #Load terminal list with terminal nodes terminal = scrape.getTerminal() #Load functional list with functional nodes functional = scrape.getFunctional() #Keeps track of functional and terminal list positions terminal_index = 0 functional_index = 0 stack = [] stack.append(root) temp_terminal = sample(terminal, len(terminal)) #shuffle terminal temp_functional = sample(functional,len(functional)) #shuffle functional #While loop ensures that initial population has #one of each type of functional node #and one of each type of terminal node while(len(stack) > 0): current = stack.pop() if(current.left == None and current.right == None): #Node is a leaf, insert terminal node current.value = temp_terminal[terminal_index] terminal_index += 1 else: #Node is not a leaf, insert a functional node current.value = temp_functional[functional_index] functional_index += 1 #Resets indices if out of bounds if terminal_index == len(temp_terminal): terminal_index = 0 if functional_index == len(temp_functional): functional_index = 0 temp_node = current.right if temp_node != None: stack.append(temp_node) #stack.push temp_node = current.left if temp_node != None: stack.append(temp_node) #stack.push