Loading distances.py +13 −4 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ class Robustness: yield w0 for i in range(1, d): before = time.time() lowest_distance = self.distance(w0, self.l[i]) lowest_index = i for j in range(i+1, d): Loading @@ -53,9 +54,11 @@ class Robustness: lowest_distance = dist lowest_index = j self.swap(i, j) after = time.time() print("Found the %dth closest word in %d seconds" % (i, after-before)) yield self.l[i] def closest_among_m_permutation(self, m=10): def closest_word_among(self, m=10): """ generates a permutation where w_0 is randomly choosen and w_n+1 is the closest neighbor of w_n among m randomly choosen words. Loading @@ -70,6 +73,7 @@ class Robustness: # select all the remaining ones for i in range(1, d): # pick the closest one among m random ones before = time.time() i_n = random.randint(i, d-1) w_n = self.l[i_n] lowest_distance = self.distance(w0, w_n) Loading @@ -82,6 +86,8 @@ class Robustness: lowest_distance = dist lowest_index = i_n self.swap(i, lowest_index) after = time.time() print("Found the %dth closest word in " %i, after-before, "seconds") yield self.l[i] def cost_rate(self): Loading Loading @@ -133,8 +139,11 @@ class Robustness: print(w, after-before) if __name__ == '__main__': before = time.time() R = Robustness(sys.argv[1]) R.algo = R.closest_word # R.distance = jaro.jaro_winkler_metric # R.k = int(len(R.l)/10) after = time.time() print("File loaded in %d seconds" % (after-before)) R.algo = R.closest_word_among # R.k = int(len(R.l)/10**7) print(R.k) print(R.min_cost(n=10)) Loading
distances.py +13 −4 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ class Robustness: yield w0 for i in range(1, d): before = time.time() lowest_distance = self.distance(w0, self.l[i]) lowest_index = i for j in range(i+1, d): Loading @@ -53,9 +54,11 @@ class Robustness: lowest_distance = dist lowest_index = j self.swap(i, j) after = time.time() print("Found the %dth closest word in %d seconds" % (i, after-before)) yield self.l[i] def closest_among_m_permutation(self, m=10): def closest_word_among(self, m=10): """ generates a permutation where w_0 is randomly choosen and w_n+1 is the closest neighbor of w_n among m randomly choosen words. Loading @@ -70,6 +73,7 @@ class Robustness: # select all the remaining ones for i in range(1, d): # pick the closest one among m random ones before = time.time() i_n = random.randint(i, d-1) w_n = self.l[i_n] lowest_distance = self.distance(w0, w_n) Loading @@ -82,6 +86,8 @@ class Robustness: lowest_distance = dist lowest_index = i_n self.swap(i, lowest_index) after = time.time() print("Found the %dth closest word in " %i, after-before, "seconds") yield self.l[i] def cost_rate(self): Loading Loading @@ -133,8 +139,11 @@ class Robustness: print(w, after-before) if __name__ == '__main__': before = time.time() R = Robustness(sys.argv[1]) R.algo = R.closest_word # R.distance = jaro.jaro_winkler_metric # R.k = int(len(R.l)/10) after = time.time() print("File loaded in %d seconds" % (after-before)) R.algo = R.closest_word_among # R.k = int(len(R.l)/10**7) print(R.k) print(R.min_cost(n=10))