def getTree(): dich1 = statements.get_negation(statements.get_moreThan(statements.get_statement(statements.op_takeValue,['MinIntensity']),0.7)) dich11 = statements.get_negation(statements.get_moreThan(statements.get_statement(statements.op_takeValue,['MinIntensity']),0.35)) tree = treeNode.treeNode([],[]) tree.dichotomy = dich1 tree.isTerminal = False tree.childNegative = treeNode.treeNode([],[]) tree.childNegative.result = [False,False] tree.childPositive = treeNode.treeNode([],[]) tree.childPositive.dichotomy = dich11 tree.childPositive.isTerminal = False tree.childPositive.childNegative = treeNode.treeNode([],[]) tree.childPositive.childNegative.result = [True,False] tree.childPositive.childPositive = treeNode.treeNode([],[]) tree.childPositive.childPositive.result = [True,True] return tree
def getTree(boolStatements,numStatements,keyStatements,samples,nodesCount,optimisation=False,deadline = 0.005,isMajorant = False): '''dijkstra-inspired classifier''' #expand in order of replacement potential descension if not (keyStatements is list): keyStatements = list(keyStatements) if not (samples is set): samples = set(samples) treeRoot = treeNode(samples, keyStatements,isMajorant) treeRoot.update() openList = [treeRoot] budget = nodesCount while budget > 0 : budget -=2 if openList ==[]: break current = openList.pop(0) #must be sorted divisor = factor_connection.getBestLink(keyStatements,current.samples,boolStatements,numStatements,False,True) if divisor == False: continue;##this was absent in the original build. expand(current,boolStatements, numStatements,keyStatements,divisor) newNodes = [] if current.getInformationGain() < deadline: continue if current.childPositive.entropy >= deadline: newNodes.append(current.childPositive) if current.childNegative.entropy >= deadline: newNodes.append(current.childNegative) for node in newNodes: repPotential = node.getReplacementPotential() for cmpInd in range(len(openList)): if repPotential > openList[cmpInd].getReplacementPotential(): openList.insert(cmpInd,node) break else: openList.append(node) if optimisation: treeRoot.optimize() return treeRoot