def generate_graph(n, beta, mean_degree): """ Test Graph generation """ G = nx.empty_graph(n) degreeArray = utils.degreeDistribution(beta, n, mean_degree) utils.randPairings(G, degreeArray) # output of the RGG if not os.path.exists('generated'): os.mkdir('generated') txtName = "generated/adj-%s-%s-%s-.txt" % (str(n), str(beta), str(mean_degree)) nx.write_adjlist(G, txtName) # plotting utils.drawDegreeHistogram(G) if n < 1000: utils.drawGraph(G) pngname = "generated/graph-%s-%s-%s-.png" % (str(n), str(beta), str(mean_degree)) plt.savefig(pngname) if not os.path.exists('feed'): os.mkdir('feed') utils.generateFeed(n)
def testMultipleStartLocalSearch(testerRuns, algorithmRuns): data = utils.readTspFile("../data/kroA200.tsp") paths = [] times = [] for _ in range(testerRuns): start = time.time() paths.append(multipleStartLocalSearch(data, algorithmRuns)) end = time.time() times.append(end - start) minRun = min(paths, key=lambda t: t[0]) maxRun = max(paths, key=lambda t: t[0]) distances = [p[0] for p in paths] averageDistance = sum(distances) / len(distances) minTime = min(times) maxTime = max(times) averageTime = sum(times) / len(times) print("minimalny dystans: " + str(minRun[0]), "średni dystans: " + str(averageDistance), "maksymalny dystans: " + str(maxRun[0])) print("minimalny czas: " + str(minTime), "maksymalny czas: " + str(maxTime), "średni czas: " + str(averageTime)) utils.drawGraph(data, minRun[1])
def RGG(n, beta, mean_degree): G = nx.empty_graph(n) degreeArray = utils.degreeDistribution(beta, n, mean_degree) utils.randPairings(G, degreeArray) txtName = "generated/adj-%s-%s-%s-.txt" % (str(n), str(beta), str(mean_degree)) nx.write_adjlist(G, txtName) utils.drawDegreeHistogram(G) if n < 1000: utils.drawGraph(G) pngname = "generated/graph-%s-%s-%s-.png" % (str(n), str(beta), str(mean_degree)) plt.savefig(pngname)
def draw(self): x = self.base.keys() z = "" for i in x: if (i != "target"): z += str('target') + "->" + str(i) + ";" return ut.drawGraph(z)
def drawNaiveBayes(df, parent): s = ";" l = [] for attr in df.keys(): if (attr != parent): l.append('target->' + attr) return utils.drawGraph(s.join(l))
def drawNaiveBayes(df, parent): liste_attr = list(df) grph = "" for attr in liste_attr: if attr != parent: grph += parent + "->" + attr + ";" return utils.drawGraph(grph)
def drawNaiveBayes(df, attrs): attributes = list(df) attributes.remove(attrs) dessin = attrs for attr in attributes: dessin += "->" + attr + ";" + attrs return util.drawGraph(dessin)
def draw(self): arcs = "" for attr in self.listeA: arcs = arcs + "target" + "->" + attr + ";" return utils.drawGraph(arcs)
def draw(self): """ Construit un graphe orienté représentant naïve Bayes réduit. """ results = "" for child in self.dictionnaire_P2D_l: results = results + "target" + "->" + child + ";" return utils.drawGraph(results[:-1])
def drawNaiveBayes(df,nom_attribut_classe): chaine_draw = nom_attribut_classe list_attr = list(df) list_attr.remove(nom_attribut_classe) for attribut in list_attr: chaine_draw += "->" + attribut + ";" chaine_draw += nom_attribut_classe return ut.drawGraph(chaine_draw)
def draw(self): """ Construit un graphe orienté représentant naïve Bayes réduit. """ res = "" for enfant in self.dico_P2D_l: res = res + "target" + "->" + enfant + ";" return utils.drawGraph(res[:-1])
def drawNaiveBayes(df, attr): res = "" for a in {e for e in df} - {attr}: res += attr + "->" + a + ";" res = res[:len(res) - 1] return utils.drawGraph(res)
def testIteratedLocalSearch(testerRuns, algorithmStopTime): data = utils.readTspFile("../data/kroB200.tsp") paths = [] for _ in range(testerRuns): paths.append(iteratedLocalSearch(data, algorithmStopTime)) minRun = min(paths, key=lambda t: t[0]) maxRun = max(paths, key=lambda t: t[0]) distances = [p[0] for p in paths] averageDistance = sum(distances) / len(distances) print("minimalny dystans: " + str(minRun[0]), "średni dystans: " + str(averageDistance), "maksymalny dystans: " + str(maxRun[0])) utils.drawGraph(data, minRun[1])
def draw(self): """ Construit un graphe orienté représentant le modèle TAN. """ res = "" for enfant in self.dico_P2D_l: res = res + "target" + "->" + enfant + ";" for enfant in self.dico_P3D_l: res = res + self.dico_P3D_l[enfant].pere + "->" + enfant + ";" res = res + "target" + "->" + enfant + ";" return utils.drawGraph(res[:-1])
def draw(self): """ Dessine le Naïve Bayes """ res = 'target' for att in self.l_att: res += "->" + att + ";" res += 'target' return ut.drawGraph(res)
def test_evolutionary(testerRuns, algorithmStopTime): data = utils.readTspFile("../data/kroA200.tsp") distanceMatrix = utils.makeDistanceMatrix(data) paths = [] for _ in range(testerRuns): paths.append( evolutionaryTravelingSalesman(distanceMatrix, algorithmStopTime)) minRun = min(paths, key=lambda t: t[0]) maxRun = max(paths, key=lambda t: t[0]) distances = [p[0] for p in paths] averageDistance = sum(distances) / len(distances) print("minimalny dystans: " + str(minRun[0]), "średni dystans: " + str(averageDistance), "maksymalny dystans: " + str(maxRun[0])) utils.drawGraph(data, minRun[1])
def drawNaiveBayes(df, nom_col): """ A partir d'un dataframe et du nom de la colonne qui est la classe, dessine le graphe. """ l_att = list(df) l_att.remove(nom_col) res = nom_col for att in l_att: res += "->" + att + ";" res += nom_col return ut.drawGraph(res)
def draw(self): """ Construit un graphe orienté représentant le modèle TAN. """ results = "" for child in self.dictionnaire_P2D_l: results = results + "target" + "->" + child + ";" for child in self.dictionnaire_P3D_l: results = results + self.dictionnaire_P3D_l[ child].father + "->" + child + ";" results = results + "target" + "->" + child + ";" return utils.drawGraph(results[:-1])
def drawNaiveBayes(df, col): """ Construit un graphe orienté représentant naïve Bayes. :param df: Dataframe contenant les données. :param col: le nom de la colonne du Dataframe utilisée comme racine. """ tab_col = list(df.columns.values) tab_col.remove(col) res = "" for enfant in tab_col: res = res + col + "->" + enfant + ";" return utils.drawGraph(res[:-1])
def drawNaiveBayes(df, col): """ Construit un graphe orienté représentant naïve Bayes. *les parametres: df: Dataframe contenant les données. col: le nom de la colonne du Dataframe utilisée comme racine. *le return: Le graphe. """ tab_col = list(df.columns.values) tab_col.remove(col) resultant = "" for child in tab_col: resultant = resultant + col + "->" + child + ";" return utils.drawGraph(resultant[:-1])
def drawNaiveBayes(df, colClass): """Dessine un graphique à partir à partir d'un dataframe et d'une colonne de class Parameters ---------- df : dataFrame col :str DESCRIPTION: c'est la classe "target" Returns ------- Image graphe """ listeA = list(df.columns) #print(listeA) arcs = "" for attr in listeA: if attr != colClass: arcs = arcs + colClass + "->" + attr + ";" return utils.drawGraph(arcs)
def drawNaiveBayes(df, a): string = "" for i in df.columns: if i != a: string += a + "->" + i + ";" return utils.drawGraph(string)
def draw(self): graph = "" for att in self.attrs: if att != "target": graph += "target->" + att + ";" return utils.drawGraph(graph)
def draw(self): chaine_draw = 'target' for attribut in self.list_attr: chaine_draw += "->" + attribut + ";" chaine_draw += 'target' return ut.drawGraph(chaine_draw)
def drawNaiveBayes(df,target): attr = df.columns graph ="" for i in attr : graph = graph+target+"->"+i+";" return utils.drawGraph(graph)
def drawNaiveBayes(data, att='target'): x = list(data.columns) x.remove(att) return ut.drawGraph("target->" + ";target->".join(x))
index=df.index, columns=df.index) matrix = matrix.round(0) whole_matrix = matrix unvisited = set(cities) start_1 = random.choice(tuple(cities)) tour_1 = [start_1] unvisited = unvisited - {start_1} matrix = matrix.drop(index=start_1) tour_1_length = 0 added_cities = 1 while added_cities < number_of_cities: last_element_1 = tour_1[-1] id_min_value_1 = matrix[last_element_1].idxmin() tour_1_length += matrix[last_element_1][id_min_value_1] tour_1.append(id_min_value_1) unvisited.remove(id_min_value_1) matrix = matrix.drop(index=id_min_value_1) added_cities += 1 tour_1_length += whole_matrix[tour_1[0]][tour_1[-1]] tour_1.append(tour_1[0]) return tour_1 if __name__ == "__main__": kroA100Data = utils.readTspFile("../data/kroA100.tsp") kroA100 = greedy_nearest_neighbor() kroA100 = [int(i) - 1 for i in kroA100] print(kroA100) utils.drawGraph(kroA100Data, kroA100)
def drawNaiveBayes(df, attr): result = "" for i in utils.getNthDict(df, 0).keys(): if (i != attr): result += attr + "->" + i + ";" return utils.drawGraph(result)
def draw(self): result = "" for i in self.proba.keys(): if (i != 'target'): result += "target" + "->" + i + ";" return utils.drawGraph(result)