def __init__(self,keyParams,boolParams, numParams, samples, samplesCount, nodesCount,attrsAvgPerTree, majorant = False, logWriter = None): '''the LICS itself''' '''reverse keyparams pls!''' self.boolParams = boolParams self.numParams = numParams self.keyParams = keyParams self.keyStatements = [ statements.get_statement(statements.op_takeValue,p) for p in keyParams] self.boolStatements = [ statements.get_statement(statements.op_takeValue,p) for p in boolParams] self.numStatements = [ statements.get_statement(statements.op_takeValue,p) for p in numParams] self.maxSamplesCount = samplesCount self.maxNodesCount = nodesCount self.maxAttrsCount = 0 self.maxAvgAttrsPerTree = attrsAvgPerTree self.currentNodesCount = 0 self.currentSamplesCount = 0 #not unique samples, but sample inclusions. self.currentAttrsCount = 0 #same self.isMajorant = majorant self.writeLog = False self.writeDump = False self.treesPool = set()#set chromo self.samplesPool = {sample:set() for sample in samples}#dict sample:trees with this sample. self.attrsPool = {attr:set() for attr in self.numStatements}
def getDifferences(numStatements): import statements numCombinations = [] for i in range(len(numStatements)): for j in range(i,len(numStatements)): numCombinations.append(statements.get_statement(statements.op_sum, [statements[i], statements.get_statement(statements.op_minus,[statements[j]])])) return numCombinations
def __init__(self,keyParams,boolParams, numParams, samples, samplesCount, nodesCount, majorant = False): '''the LICS itself''' '''reverse keyparams pls!''' self.boolParams = boolParams self.numParams = numParams self.keyParams = keyParams self.keyStatements = [ statements.get_statement(statements.op_takeValue,p) for p in keyParams] self.boolStatements = [ statements.get_statement(statements.op_takeValue,p) for p in boolParams] self.numStatements = [ statements.get_statement(statements.op_takeValue,p) for p in numParams] self.samples = set(samples) self.samplesCount = samplesCount self.nodesCount = nodesCount self.tree = treeNode.treeNode(self.samples,self.keyStatements,majorant) self.clusteriser = cluster.kmeans(self,numParams,boolParams + keyParams,samplesCount) self.isMajorant = majorant
def getPairedSums(numStatements): import statements numCombinations = [] for statement1 in numStatements: for statement2 in numStatements: if statement1 == statement2:continue numCombinations.append(statements.get_statement(statements.op_sum,[statement1,statement2])) return numCombinations
def getCombinations(numStatements): import statements combinations = [] for code in range(1,3**len(numStatements)): s = statements.statement() s.operation = statements.op_sum s.args = [] minusCount = 0 plusCount = 0 for i in range(len(numStatements)): form = (code % (3**(i+1)))/(3**i) if form ==0: continue elif form ==1: plusCount +=1 s.args.append(numStatements[i]) else: #form ==2 minusCount +=1 s.args.append(statements.get_statement(statements.op_minus,numStatements[i])) if plusCount >= minusCount: combinations.append(s) return combinations
outer=[] def check(classifier,keyStates,num): successes = 0 for i in range(num): smpl = createSample() for i in range(len(keyStates)): if round(classifier.classify(smpl)[i]) != keyStates[i].extractValue(smpl): #print smpl.__dict__ #print classifier.classify(smpl), [kstate.extractValue(smpl) for kstate in keyStates] break else:successes +=1 return successes state0 = statements.get_statement(statements.op_takeValue,'A') state1 = statements.get_statement(statements.op_takeValue,'B') state2 = statements.get_statement(statements.op_takeValue,'O') state3 = statements.get_statement(statements.op_takeValue,'C1') state4 = statements.get_statement(statements.op_takeValue,'C2') state5 = statements.get_statement(statements.op_takeValue,'G') state6 = statements.get_statement(statements.op_takeValue,'L1') state7 = statements.get_statement(statements.op_takeValue,'L2') state8 = statements.get_statement(statements.op_takeValue,'L3') state9 = statements.get_statement(statements.op_takeValue,'L4') boolStatements = [state2,state3,state4,state5] numStatements = [state0,state1,state6,state7,state8,state9] keyStates =[statements.get_statement(statements.op_takeValue,'R')]#,statements.get_statement(statements.op_takeValue,'isLandDry')] slist = [createSample_prejudiced() for i in range(100)] numparams= ['A','B','L1','L2','L3','L4']