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 step03(paramFile, num_people): #util = ParameterUtil(parameter_file = 'data/formatado/arxiv/nowell_example_1994_1999.txt') util = ParameterUtil(parameter_file=paramFile) 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() selection = VariableSelection(myparams.trainnigGraph, util.nodes_notlinked_file, util.min_edges, False, num_people) return
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()
from calculating.CalculateInMemory import CalculateInMemory if __name__ == '__main__': #plt.show() #util = ParameterUtil(parameter_file = 'data/formatado/arxiv/nowell_astroph_1994_1999/AllExecutionScores/config.txt') util = ParameterUtil(parameter_file = 'data/formatado/arxiv/exemplomenor/config/config.txt') myparams = Parameterization(t0 = util.t0, t0_ = util.t0_, t1 = util.t1, t1_ = util.t1_, linear_combination=util.linear_combination, filePathGraph = util.graph_file, filePathTrainingGraph = util.trainnig_graph_file, filePathTestGraph = util.test_graph_file, decay = util.decay, domain_decay = util.domain_decay, min_edges = util.min_edges, scoreChoiced = util.ScoresChoiced, weightsChoiced = util.WeightsChoiced, weightedScoresChoiced = util.WeightedScoresChoiced, FullGraph = None, result_random_file=util.result_random_file) myparams.generating_Training_Graph() #myparams.generating_Test_Graph() selection = VariableSelection(myparams.trainnigGraph, util.min_edges) nodesNotLinked = selection.get_pair_nodes_not_linked() selection.saveResults(util.nodes_notlinked_file, nodesNotLinked) #dado = selection.readingResultsFile(util.nodes_notlinked_file) #print dado[1] #calc = CalculateInMemory(myparams, nodesNotLinked) #resultsCalculate = calc.executingCalculate() #resultados = [] #orderDataMetrica0 = sorted(resultsCalculate, key=lambda value: value[0][0], reverse=True) #orderDataMetrica1 = sorted(resultsCalculate, key=lambda value: value[0][5], reverse=True) #for result in orderDataMetrica1: # metricas = result[0] # no1 = result[1]
t1=util.t1, t1_=util.t1_, filePathGraph=util.graph_file, filePathTrainingGraph=util.trainnig_graph_file, filePathTestGraph=util.test_graph_file, decay=util.decay, domain_decay=util.domain_decay, min_edges=util.min_edges, scoreChoiced=util.ScoresChoiced, weightsChoiced=util.WeightsChoiced, weightedScoresChoiced=util.WeightedScoresChoiced, FullGraph=None) myparams.generating_Training_Graph() myparams.generating_Test_Graph() selection = VariableSelection(myparams.trainnigGraph, util.nodes_notlinked_file, util.min_edges) calc = Calculate(myparams, util.nodes_notlinked_file, util.calculated_file, util.ordered_file, util.maxmincalculated_file) calc.Separating_calculateFile() analise = Analyse( myparams, FormatingDataSets.get_abs_file_path(util.calculated_file), FormatingDataSets.get_abs_file_path(util.analysed_file) + '.random.analised.txt', calc.qtyDataCalculated) topRank = Analyse.getTopRank(util.analysed_file + '.random.analised.txt') calc.Ordering_separating_File(topRank) for OrderingFilePath in calc.getfilePathOrdered_separeted(): analise = Analyse(myparams, OrderingFilePath, OrderingFilePath + '.analised.txt', topRank) print "Trainning Period:", myparams.t0, " - ", myparams.t0_ print "Test Period:", myparams.t1, " - ", myparams.t1_
t1=util.t1, t1_=util.t1_, linear_combination=util.linear_combination, filePathGraph=util.graph_file, filePathTrainingGraph=util.trainnig_graph_file, filePathTestGraph=util.test_graph_file, decay=util.decay, domain_decay=util.domain_decay, min_edges=util.min_edges, scoreChoiced=util.ScoresChoiced, weightsChoiced=util.WeightsChoiced, weightedScoresChoiced=util.WeightedScoresChoiced, FullGraph=None, result_random_file=util.result_random_file) myparams.generating_Training_Graph() selection = VariableSelection(myparams.trainnigGraph, util.min_edges) nodesNotLinked = selection.readingResultsFile(util.nodes_notlinked_file) calc = CalculateInMemory(myparams, nodesNotLinked) resultsofCalculation = calc.executingCalculate() #print resultsofCalculation calc.saving_calculateResult(util.calculated_file, resultsofCalculation) calc.saving_calculateResult_normalized( util.calculated_file + '_normalizated.csv', resultsofCalculation) result2 = calc.reading_calculateResult_normalized(util.calculated_file) calc.save_Max_min_file(util.maxmincalculated_file, calc.qtyDataCalculated, calc.minValueCalculated, calc.maxValueCalculated) print resultsofCalculation print result2
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
from parametering.ParameterUtil import ParameterUtil from parametering.Parameterization import Parameterization from calculating.CalculateInMemory import CalculateInMemory from calculating.VariableSelection import VariableSelection if __name__ == '__main__': util = ParameterUtil(parameter_file = 'data/formatado/arxiv/exemplomenor/config/config.txt') #util = ParameterUtil(parameter_file = 'data/formatado/arxiv/nowell_astroph_1994_1999/config/configuration_forAG.txt') myparams = Parameterization(t0 = util.t0, t0_ = util.t0_, t1 = util.t1, t1_ = util.t1_, linear_combination=util.linear_combination, filePathGraph = util.graph_file, filePathTrainingGraph = util.trainnig_graph_file, filePathTestGraph = util.test_graph_file, decay = util.decay, domain_decay = util.domain_decay, min_edges = util.min_edges, scoreChoiced = util.ScoresChoiced, weightsChoiced = util.WeightsChoiced, weightedScoresChoiced = util.WeightedScoresChoiced, FullGraph = None, result_random_file=util.result_random_file) myparams.generating_Training_Graph() selection = VariableSelection(myparams.trainnigGraph, util.min_edges) nodesNotLinked = selection.readingResultsFile(util.nodes_notlinked_file) calc = CalculateInMemory(myparams,nodesNotLinked) resultsofCalculation = calc.executingCalculate() #print resultsofCalculation calc.saving_calculateResult(util.calculated_file, resultsofCalculation) calc.saving_calculateResult_normalized(util.calculated_file + '_normalizated.csv', resultsofCalculation) result2 = calc.reading_calculateResult_normalized(util.calculated_file) calc.save_Max_min_file(util.maxmincalculated_file, calc.qtyDataCalculated, calc.minValueCalculated, calc.maxValueCalculated) print resultsofCalculation print result2
if __name__ == '__main__': util = ParameterUtil( parameter_file='data/formatado/arxiv/nowell_astroph_1994_1999.txt') calculatedFile = open( FormatingDataSets.get_abs_file_path(util.calculated_file), 'r') 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)
from analysing.Analyse import Analyse from calculating.VariableSelection import VariableSelection from formating.FormatingDataSets import FormatingDataSets import networkx import mysql.connector if __name__ == '__main__': util = ParameterUtil( parameter_file='data/formatado/arxiv/nowell_astroph_1994_1999.txt') 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() AllNodes = VariableSelection(myparams.trainnigGraph, util.nodes_file, util.min_edges, True) calc = Calculate(myparams, util.nodes_file, util.calculated_file, util.ordered_file, util.maxmincalculated_file) print 'armazenando resultados' cnx = mysql.connector.connect(user='******', password='******', host='127.0.0.1', database='calculos') add_result = ("INSERT INTO resultadopesos " "(no1, no2, resultados) " "VALUES (%s, %s, %s)") cursor = cnx.cursor() calculatedFile = open( FormatingDataSets.get_abs_file_path(util.calculated_file), 'r') for linha in calculatedFile: dado = Calculate.reading_calculateLine(linha)
''' from parametering.ParameterUtil import ParameterUtil from parametering.Parameterization import Parameterization from analysing.Analyse import Analyse from calculating.CalculateInMemory import CalculateInMemory from calculating.VariableSelection import VariableSelection if __name__ == '__main__': util = ParameterUtil(parameter_file = 'data/formatado/arxiv/exemplomenor/config/config.txt') myparams = Parameterization(t0 = util.t0, t0_ = util.t0_, t1 = util.t1, t1_ = util.t1_, linear_combination=util.linear_combination, filePathGraph = util.graph_file, filePathTrainingGraph = util.trainnig_graph_file, filePathTestGraph = util.test_graph_file, decay = util.decay, domain_decay = util.domain_decay, min_edges = util.min_edges, scoreChoiced = util.ScoresChoiced, weightsChoiced = util.WeightsChoiced, weightedScoresChoiced = util.WeightedScoresChoiced, FullGraph = None, result_random_file=util.result_random_file) myparams.generating_Training_Graph() myparams.generating_Test_Graph() selecao = VariableSelection(myparams.trainnigGraph) nodesNotLinked = selecao.readingResultsFile(util.nodes_notlinked_file) calc = CalculateInMemory(myparams, myparams.trainnigGraph) resultsNormalized = calc.reading_calculateResult_normalized(util.calculated_file) AnalyseNodesnotLinkedInFuture = Analyse.reading_analyseResult(util.result_random_file) topRank = Analyse.get_topRank(AnalyseNodesnotLinkedInFuture) orderResult = [] if myparams.linear_combination: resultCombination = calc.combinate_linear(resultsNormalized) orderResult = calc.ordering_combinate_linear(topRank, resultCombination) else: orderResult = calc.ordering(topRank, resultsNormalized) FinalResult = [] for featureOrderResult in orderResult: final = Analyse.AnalyseNodesInFuture(featureOrderResult, myparams.testGraph)
from parametering.Parameterization import Parameterization from analysing.Analyse import Analyse from calculating.VariableSelection import VariableSelection from formating.FormatingDataSets import FormatingDataSets import networkx from calculating.CalculateInMemory import CalculateInMemory if __name__ == '__main__': util = ParameterUtil(parameter_file = 'data/formatado/exemplomenor/config/config.txt') myparams = Parameterization(t0 = util.t0, t0_ = util.t0_, t1 = util.t1, t1_ = util.t1_, filePathGraph = util.graph_file, filePathTrainingGraph = util.trainnig_graph_file, filePathTestGraph = util.test_graph_file, decay = util.decay, domain_decay = util.domain_decay, min_edges = util.min_edges, scoreChoiced = util.ScoresChoiced, weightsChoiced = util.WeightsChoiced, weightedScoresChoiced = util.WeightedScoresChoiced, FullGraph = None) myparams.generating_Training_Graph() myparams.generating_Test_Graph() selection = VariableSelection(myparams.trainnigGraph, util.min_edges) nodesNotLinked = selection.get_pair_nodes_not_linked() calc = CalculateInMemory(myparams, nodesNotLinked) resultsCalculate = calc.executingCalculate() calc.Separating_calculateFile() analise = Analyse(myparams, FormatingDataSets.get_abs_file_path(util.calculated_file), FormatingDataSets.get_abs_file_path(util.analysed_file) + '.random.analised.txt', calc.qtyDataCalculated) topRank = Analyse.getTopRank(util.analysed_file + '.random.analised.txt') calc.Ordering_separating_File(topRank) for OrderingFilePath in calc.getfilePathOrdered_separeted(): analise = Analyse(myparams, OrderingFilePath, OrderingFilePath + '.analised.txt', topRank ) print "Trainning Period:", myparams.t0, " - ", myparams.t0_ print "Test Period:", myparams.t1, " - ", myparams.t1_
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()
filePathGraph=util.graph_file, filePathTrainingGraph=util.trainnig_graph_file, filePathTestGraph=util.test_graph_file, decay=util.decay, domain_decay=util.domain_decay, min_edges=util.min_edges, scoreChoiced=util.ScoresChoiced, weightsChoiced=util.WeightsChoiced, weightedScoresChoiced=util.WeightedScoresChoiced, FullGraph=None, result_random_file=util.result_random_file) myparams.generating_Training_Graph() #myparams.generating_Test_Graph() selection = VariableSelection(myparams.trainnigGraph, util.min_edges) nodesNotLinked = selection.get_pair_nodes_not_linked() selection.saveResults(util.nodes_notlinked_file, nodesNotLinked) #dado = selection.readingResultsFile(util.nodes_notlinked_file) #print dado[1] #calc = CalculateInMemory(myparams, nodesNotLinked) #resultsCalculate = calc.executingCalculate() #resultados = [] #orderDataMetrica0 = sorted(resultsCalculate, key=lambda value: value[0][0], reverse=True) #orderDataMetrica1 = sorted(resultsCalculate, key=lambda value: value[0][5], reverse=True) #for result in orderDataMetrica1: # metricas = result[0] # no1 = result[1]