def calculating_features(self, lineofFile, element, qtyofResults, preparedParameter, qtyFeatures , minValueCalculated, maxValueCalculated , dados_saida ): self.printProgressofEvents(element, qtyofResults, "Calculating features for nodes not liked: ") item = VariableSelection.getItemFromLine(lineofFile) resultLinestring = "" min = minValueCalculated max = maxValueCalculated for neighbor_node in item[1]: self.qtyDataCalculated = self.qtyDataCalculated + 1 item_result = [] #executing the calculation for each features chosen at parameter for index_features in range(qtyFeatures): preparedParameter.featuresChoice[index_features][0].parameter = preparedParameter valueCalculated = preparedParameter.featuresChoice[index_features][0].execute(item[0],neighbor_node) * preparedParameter.featuresChoice[index_features][1] if valueCalculated < min[index_features]: min[index_features] = valueCalculated if valueCalculated > max[index_features]: max[index_features] = valueCalculated item_result.append(valueCalculated) #generating a vetor with the name of the feature and the result of the calculate for indice in range(qtyFeatures): resultLinestring = resultLinestring + str({str(preparedParameter.featuresChoice[indice]):item_result[indice]}) + '\t' resultLinestring = resultLinestring + str(item[0]) + '\t' + str(neighbor_node) + '\n' finalresult = repr(min) + '|' + repr(max) + '|' + str(self.qtyDataCalculated) + '|' + resultLinestring dados_saida.put(finalresult)
def __init__(self, preparedParameter, fileAllNodes): print "Starting Generating Weights for all Nodes", datetime.today() self.preparedParameter = preparedParameter self.filepathAllNodes = Formating.get_abs_file_path(fileAllNodes) self.preparedParameter.open_connection() self.preparedParameter.clean_database() fcontentAllNodes = open(self.filepathAllNodes, 'r') self.minValueCalculated = list( 99999 for x in self.preparedParameter.WeightsChoiced) self.maxValueCalculated = list( 0 for x in self.preparedParameter.WeightsChoiced) qtyFeatures = len(self.preparedParameter.WeightsChoiced) qtyNodesCalculated = 0 for lineofFile in fcontentAllNodes: item = VariableSelection.getItemFromLine(lineofFile) item_result = [] #executing the calculation for each features chosen at parameter for index_features in range(qtyFeatures): self.preparedParameter.WeightsChoiced[index_features][ 0].parameter = preparedParameter valueCalculated = self.preparedParameter.WeightsChoiced[ index_features][0].execute( item[0], item[1]) * self.preparedParameter.WeightsChoiced[ index_features][1] if valueCalculated < self.minValueCalculated[index_features]: self.minValueCalculated[index_features] = valueCalculated if valueCalculated > self.maxValueCalculated[index_features]: self.maxValueCalculated[index_features] = valueCalculated item_result.append(valueCalculated) self.preparedParameter.add_weight(item[0], item[1], item_result) self.preparedParameter.add_weight(-1, -1, qtyNodesCalculated) self.preparedParameter.add_weight(-2, -2, repr(self.minValueCalculated)) self.preparedParameter.add_weight(-3, -3, repr(self.maxValueCalculated)) self.preparedParameter.close_connection() print "Finishinig Generating Weights for all Nodes", datetime.today()
def __init__(self, preparedParameter, fileAllNodes): print "Starting Generating Weights for all Nodes", datetime.today() self.preparedParameter = preparedParameter self.filepathAllNodes = Formating.get_abs_file_path(fileAllNodes) self.preparedParameter.open_connection() self.preparedParameter.clean_database() fcontentAllNodes = open(self.filepathAllNodes, 'r') self.minValueCalculated = list(99999 for x in self.preparedParameter.WeightsChoiced) self.maxValueCalculated = list(0 for x in self.preparedParameter.WeightsChoiced) qtyFeatures = len(self.preparedParameter.WeightsChoiced) qtyNodesCalculated = 0 for lineofFile in fcontentAllNodes: item = VariableSelection.getItemFromLine(lineofFile) item_result = [] #executing the calculation for each features chosen at parameter for index_features in range(qtyFeatures): self.preparedParameter.WeightsChoiced[index_features][0].parameter = preparedParameter valueCalculated = self.preparedParameter.WeightsChoiced[index_features][0].execute(item[0],item[1]) * self.preparedParameter.WeightsChoiced[index_features][1] if valueCalculated < self.minValueCalculated[index_features]: self.minValueCalculated[index_features] = valueCalculated if valueCalculated > self.maxValueCalculated[index_features]: self.maxValueCalculated[index_features] = valueCalculated item_result.append(valueCalculated) self.preparedParameter.add_weight(item[0], item[1], item_result) self.preparedParameter.add_weight(-1,-1, qtyNodesCalculated) self.preparedParameter.add_weight(-2,-2, repr(self.minValueCalculated)) self.preparedParameter.add_weight(-3,-3, repr(self.maxValueCalculated)) self.preparedParameter.close_connection() print "Finishinig Generating Weights for all Nodes", datetime.today()
def calculating_features(self, lineofFile, element, qtyofResults, preparedParameter, qtyFeatures, minValueCalculated, maxValueCalculated, dados_saida): self.printProgressofEvents( element, qtyofResults, "Calculating features for nodes not liked: ") item = VariableSelection.getItemFromLine(lineofFile) resultLinestring = "" min = minValueCalculated max = maxValueCalculated for neighbor_node in item[1]: self.qtyDataCalculated = self.qtyDataCalculated + 1 item_result = [] #executing the calculation for each features chosen at parameter for index_features in range(qtyFeatures): preparedParameter.featuresChoice[index_features][ 0].parameter = preparedParameter valueCalculated = preparedParameter.featuresChoice[ index_features][0].execute( item[0], neighbor_node ) * preparedParameter.featuresChoice[index_features][1] if valueCalculated < min[index_features]: min[index_features] = valueCalculated if valueCalculated > max[index_features]: max[index_features] = valueCalculated item_result.append(valueCalculated) #generating a vetor with the name of the feature and the result of the calculate for indice in range(qtyFeatures): resultLinestring = resultLinestring + str({ str(preparedParameter.featuresChoice[indice]): item_result[indice] }) + '\t' resultLinestring = resultLinestring + str( item[0]) + '\t' + str(neighbor_node) + '\n' finalresult = repr(min) + '|' + repr(max) + '|' + str( self.qtyDataCalculated) + '|' + resultLinestring dados_saida.put(finalresult)
def __init__(self, preparedParameter, filepathNodesNotLinked, filepathResult, filePathOrdered, filepathMaxMinCalculated): print "Starting Calculating Nodes not linked", datetime.today() self.preparedParameter = preparedParameter self.filePathOrdered = Formating.get_abs_file_path(filePathOrdered) self.filepathMaxMinCalculated = Formating.get_abs_file_path( filepathMaxMinCalculated) self.filepathResult = Formating.get_abs_file_path(filepathResult) self.filepathNodesNotLinked = Formating.get_abs_file_path( filepathNodesNotLinked) #for each links that is not linked all the calculates is done. element = 0 qtyofResults = FormatingDataSets.getTotalLineNumbers( self.filepathNodesNotLinked) fcontentNodesNotLinked = open(self.filepathNodesNotLinked, 'r') if os.path.exists(self.filepathResult): print "Calculate already done for this file, please delete if you want a new one.", datetime.today( ) self.reading_Max_min_file() return fcontentCalcResult = open(self.filepathResult, 'w') self.minValueCalculated = list( 99999 for x in self.preparedParameter.featuresChoice) self.maxValueCalculated = list( 0 for x in self.preparedParameter.featuresChoice) qtyFeatures = len(self.preparedParameter.featuresChoice) qtyNodesCalculated = 0 partialResults = [] for lineofFile in fcontentNodesNotLinked: element = element + 1 item = VariableSelection.getItemFromLine(lineofFile) qtyothernodenotlinked = len(item[1]) newelement = 0 for neighbor_node in item[1]: newelement = newelement + 1 qtyNodesCalculated = qtyNodesCalculated + 1 self.printProgressofEvents( element, qtyofResults, "Calculating features for nodes not liked: ") self.printProgressofEventsWihoutPercent( newelement, qtyothernodenotlinked, "Calculating nodes: " + str(item[0]) + ":" + str(neighbor_node)) item_result = [] #executing the calculation for each features chosen at parameter for index_features in range(qtyFeatures): self.preparedParameter.featuresChoice[index_features][ 0].parameter = preparedParameter valueCalculated = self.preparedParameter.featuresChoice[ index_features][0].execute( item[0], neighbor_node ) * self.preparedParameter.featuresChoice[ index_features][1] if valueCalculated < self.minValueCalculated[ index_features]: self.minValueCalculated[ index_features] = valueCalculated if valueCalculated > self.maxValueCalculated[ index_features]: self.maxValueCalculated[ index_features] = valueCalculated item_result.append(valueCalculated) lineContent = [] #generating a vetor with the name of the feature and the result of the calculate for indice in range(qtyFeatures): lineContent.append( str({ str(self.preparedParameter.featuresChoice[indice]): item_result[indice] })) partialResults.append([lineContent, item[0], neighbor_node]) if element % 10 == 0: for item in partialResults: for calc in item[0]: fcontentCalcResult.write(calc + '\t') fcontentCalcResult.write( str(item[1]) + '\t' + str(item[2]) + '\n') partialResults = [] for item in partialResults: for calc in item[0]: fcontentCalcResult.write(calc + '\t') fcontentCalcResult.write(str(item[1]) + '\t' + str(item[2]) + '\n') fcontentCalcResult.flush() fcontentCalcResult.close() fcontentNodesNotLinked.close() fcontentMaxMin = open(self.filepathMaxMinCalculated, 'w') fcontentMaxMin.write( str(qtyNodesCalculated) + '\t' + repr(self.minValueCalculated) + '\t' + repr(self.maxValueCalculated)) fcontentMaxMin.close() print "Calculating Nodes not linked finished", datetime.today()
def __init__(self, preparedParameter, filepathNodesNotLinked, filepathResult, filePathOrdered, filepathMaxMinCalculated): print "Starting Calculating Nodes not linked", datetime.today() self.preparedParameter = preparedParameter self.filePathOrdered = Formating.get_abs_file_path(filePathOrdered) self.filepathMaxMinCalculated = Formating.get_abs_file_path(filepathMaxMinCalculated) self.filepathResult = Formating.get_abs_file_path(filepathResult) self.filepathNodesNotLinked = Formating.get_abs_file_path(filepathNodesNotLinked) #for each links that is not linked all the calculates is done. element = 0 qtyofResults = FormatingDataSets.getTotalLineNumbers(self.filepathNodesNotLinked) fcontentNodesNotLinked = open(self.filepathNodesNotLinked, 'r') if os.path.exists(self.filepathResult): print "Calculate already done for this file, please delete if you want a new one.", datetime.today() self.reading_Max_min_file() return fcontentCalcResult = open(self.filepathResult, 'w') self.minValueCalculated = list(99999 for x in self.preparedParameter.featuresChoice) self.maxValueCalculated = list(0 for x in self.preparedParameter.featuresChoice) qtyFeatures = len(self.preparedParameter.featuresChoice) qtyNodesCalculated = 0 partialResults = [] for lineofFile in fcontentNodesNotLinked: element = element+1 item = VariableSelection.getItemFromLine(lineofFile) qtyothernodenotlinked = len(item[1]) newelement = 0 for neighbor_node in item[1]: newelement = newelement +1 qtyNodesCalculated = qtyNodesCalculated + 1 self.printProgressofEvents(element, qtyofResults, "Calculating features for nodes not liked: ") self.printProgressofEventsWihoutPercent(newelement, qtyothernodenotlinked, "Calculating nodes: " + str(item[0]) + ":" + str(neighbor_node) ) item_result = [] #executing the calculation for each features chosen at parameter for index_features in range(qtyFeatures): self.preparedParameter.featuresChoice[index_features][0].parameter = preparedParameter valueCalculated = self.preparedParameter.featuresChoice[index_features][0].execute(item[0],neighbor_node) * self.preparedParameter.featuresChoice[index_features][1] if valueCalculated < self.minValueCalculated[index_features]: self.minValueCalculated[index_features] = valueCalculated if valueCalculated > self.maxValueCalculated[index_features]: self.maxValueCalculated[index_features] = valueCalculated item_result.append(valueCalculated) lineContent = [] #generating a vetor with the name of the feature and the result of the calculate for indice in range(qtyFeatures): lineContent.append(str({str(self.preparedParameter.featuresChoice[indice]):item_result[indice]}) ) partialResults.append([lineContent, item[0], neighbor_node]) if element % 10 == 0: for item in partialResults: for calc in item[0]: fcontentCalcResult.write(calc + '\t') fcontentCalcResult.write(str(item[1]) + '\t' + str(item[2]) + '\n' ) partialResults = [] for item in partialResults: for calc in item[0]: fcontentCalcResult.write(calc + '\t') fcontentCalcResult.write(str(item[1]) + '\t' + str(item[2]) + '\n' ) fcontentCalcResult.flush() fcontentCalcResult.close() fcontentNodesNotLinked.close() fcontentMaxMin = open(self.filepathMaxMinCalculated, 'w') fcontentMaxMin.write(str(qtyNodesCalculated) + '\t' + repr(self.minValueCalculated) + '\t' + repr(self.maxValueCalculated) ) fcontentMaxMin.close() print "Calculating Nodes not linked finished", datetime.today()
for linha in calculatedFile: x.append(Calculate.reading_calculateLine(linha)) calculatedFile.close() myparams = Parameterization(util.keyword_decay, util.lengthVertex, util.t0, util.t0_, util.t1, util.t1_, util.FeaturesChoiced, util.graph_file, util.trainnig_graph_file, util.test_graph_file, util.decay) myparams.generating_Training_Graph() Nodes_notLinked = VariableSelection(myparams.trainnigGraph, util.nodes_notlinked_file,util.min_edges) nodes_notlinkedFile = open(FormatingDataSets.get_abs_file_path(util.nodes_notlinked_file), 'r') qtyLine = 0 qtyCalculated = 0 f = open(FormatingDataSets.get_abs_file_path(util.calculated_file )+ '.weight.txt', 'w') minValueCalculated = list(99999 for x in myparams.featuresChoice) maxValueCalculated = list(0 for x in myparams.featuresChoice) qtyFeatures = len(myparams.featuresChoice) for line in nodes_notlinkedFile: qtyLine = qtyLine + 1 item = VariableSelection.getItemFromLine(line) qtyofnodesnotLinked = len(item[1]) print 'Qtde of not linked itens', qtyofnodesnotLinked, ' in line ', qtyLine for neighbor_node in item[1]: qtyCalculated = qtyCalculated + 1 node1 = item[0] node2 = neighbor_node cn = util.FeaturesChoiced[0][0].get_common_neighbors(node1,node2) total = 0 for c in cn: total = total + ( Calculate.reading_calculateLine(getPairNodes(node1, c, calculatedFile))[0][0] + Calculate.reading_calculateLine(getPairNodes(node2, c, calculatedFile))[0][0]) for index_features in range(qtyFeatures): if total < minValueCalculated[index_features]: minValueCalculated[index_features] = total
Nodes_notLinked = VariableSelection(myparams.trainnigGraph, util.nodes_notlinked_file, util.min_edges) nodes_notlinkedFile = open( FormatingDataSets.get_abs_file_path(util.nodes_notlinked_file), 'r') qtyLine = 0 qtyCalculated = 0 f = open( FormatingDataSets.get_abs_file_path(util.calculated_file) + '.weight.txt', 'w') minValueCalculated = list(99999 for x in myparams.featuresChoice) maxValueCalculated = list(0 for x in myparams.featuresChoice) qtyFeatures = len(myparams.featuresChoice) for line in nodes_notlinkedFile: qtyLine = qtyLine + 1 item = VariableSelection.getItemFromLine(line) qtyofnodesnotLinked = len(item[1]) print 'Qtde of not linked itens', qtyofnodesnotLinked, ' in line ', qtyLine for neighbor_node in item[1]: qtyCalculated = qtyCalculated + 1 node1 = item[0] node2 = neighbor_node cn = util.FeaturesChoiced[0][0].get_common_neighbors(node1, node2) total = 0 for c in cn: total = total + ( Calculate.reading_calculateLine( getPairNodes(node1, c, calculatedFile))[0][0] + Calculate.reading_calculateLine( getPairNodes(node2, c, calculatedFile))[0][0])