From 9d8d9c6649212548953f65395a86af0789831f70 Mon Sep 17 00:00:00 2001 From: beqakd Date: Sat, 13 Jun 2020 00:15:56 +0400 Subject: [PATCH 1/5] implementation of entropy algorithm. --- maths/entropy.py | 119 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 maths/entropy.py diff --git a/maths/entropy.py b/maths/entropy.py new file mode 100644 index 000000000000..970db39a8fee --- /dev/null +++ b/maths/entropy.py @@ -0,0 +1,119 @@ +""" + Implementation of entropy of information + https://en.wikipedia.org/wiki/Entropy_(information_theory) +""" + +import sys +import math +r = range + + +def create_alpha_array(): + """ + This method creates array of our alphabet to print probabilities later on. + :return: + """ + my_alphas = [" "] + for x in r(ord("a"), ord("z") + 1): + my_alphas += chr(x) + return my_alphas + + +def calculate_prob(my_dic_fir, my_dic_sec, path_dest): + """ + This method takes path and two dict as argument + and than calculates entropy of them. + :param my_dic_fir: + :param my_dic_sec: + :param path_dest: + :return: + """ + f = open(path_dest, mode="w+", encoding="utf-8") + + my_alphas = create_alpha_array() # create our alpha + # what is our total sum of probabilities. + values = my_dic_fir.values() + all_sum = sum(values) + + # one length string + my_fir_sum = 0 + # for each alpha we go in our dict and if it is in it we calculate entropy + for _ in my_alphas: + if _ in my_dic_fir: + my_str = my_dic_fir[_] + prob = my_str / all_sum + my_fir_sum += prob * math.log2(prob) # entropy formula. + + # write entropy to file + f.write("{0:.7f}".format(-1 * my_fir_sum)) + f.write("\n") + + # two len string + values = my_dic_sec.values() + all_sum = sum(values) # time for two len probabilities sum + my_sec_sum = 0 + # for each alpha (two in size) calculate entropy. + for _ in my_alphas: + for __ in my_alphas: + sequence = _ + __ + if sequence in my_dic_sec: + my_str = my_dic_sec[sequence] + prob = int(my_str) / all_sum + my_sec_sum += prob * math.log2(prob) + # write second entropy to the file + f.write("{0:.7f}".format(-1 * my_sec_sum)) + f.write("\n") + + # write the difference between them to the file + f.write("{0:.7f}".format((-1 * my_sec_sum) - (-1 * my_fir_sum))) + # f.write('\n') + + +# 0x +def open_file(path_src, path_dest): + """ + This method take path and also two clear dict as argument + And later on it open the file at this path and puts frequency on each dictionary + in first dictionary it puts one len strings. + in second dictionary it puts two len strings. + :param path_src: + :param path_dest: + :return: + """ + my_dic_fir = {} + my_dic_sec = {} + f = open(path_src, mode="r", encoding="utf-8") + text = f.read() + my_dic_fir[text[len(text) - 1]] = 1 + + # first case when we have space at start. + my_dic_sec[" " + text[0]] = 1 + for _ in r(0, len(text) - 1): + sequence_fir = text[_] + sequence_sec = text[_ : _ + 2] + # continue + if sequence_fir not in my_dic_fir: + my_dic_fir[sequence_fir] = 1 + else: + my_dic_fir[sequence_fir] += 1 + + if sequence_sec not in my_dic_sec: + my_dic_sec[sequence_sec] = 1 + else: + my_dic_sec[sequence_sec] += 1 + + return my_dic_fir, my_dic_sec + + +def main(): + path_src = sys.argv[1] + path_dest = sys.argv[2] + print("-" * 20) + print(path_src, path_dest) + + my_dic_fir, my_dic_sec = open_file(path_src, path_dest) + calculate_prob(my_dic_fir, my_dic_sec, path_dest) + + +if __name__ == "__main__": + main() From 6ce92220144cb3814244d16f90abf4326ea8d955 Mon Sep 17 00:00:00 2001 From: beqakd Date: Sun, 14 Jun 2020 17:55:12 +0400 Subject: [PATCH 2/5] add tests, fix requested changes --- maths/entropy.py | 111 ++++++++++++++++++++++++++++++----------------- 1 file changed, 71 insertions(+), 40 deletions(-) diff --git a/maths/entropy.py b/maths/entropy.py index 970db39a8fee..a14fbcd018cd 100644 --- a/maths/entropy.py +++ b/maths/entropy.py @@ -3,9 +3,8 @@ https://en.wikipedia.org/wiki/Entropy_(information_theory) """ -import sys import math -r = range +from collections import Counter def create_alpha_array(): @@ -14,90 +13,114 @@ def create_alpha_array(): :return: """ my_alphas = [" "] - for x in r(ord("a"), ord("z") + 1): + for x in range(ord("a"), ord("z") + 1): my_alphas += chr(x) return my_alphas -def calculate_prob(my_dic_fir, my_dic_sec, path_dest): +def calculate_prob(text): """ This method takes path and two dict as argument and than calculates entropy of them. - :param my_dic_fir: - :param my_dic_sec: - :param path_dest: - :return: + :param dict: + :param dict: + :return: Prints + 1) Entropy of information based on 1 alphabet + 2) Entropy of information based on couples of 2 alphabet + 3) print Entropy of H(X n∣Xn−1) + + Text from random books. Also, random quotes. + >>> text = ("Behind Winston’s back the voice" + ... "from the telescreen was still" + ... "babbling and the overfulfilment") + >>> calculate_prob(text) + 4.0 + 6.0 + 2.0 + + >>> text = ("The Ministry of Truth—Minitrue, in Newspeak [Newspeak was the official" + ... "face in elegant lettering, the three") + >>> calculate_prob(text) + 4.0 + 5.0 + 1.0 + >>> text = ("Had repulsive dashwoods suspicion sincerity but advantage now him. Remark easily garret nor nay." + ... "Civil those mrs enjoy shy fat merry. You greatest jointure saw horrible. He private he on be " + ... "imagine suppose. Fertile beloved evident through no service elderly is. Blind there if every " + ... "no so at. Own neglected you preferred way sincerity delivered his attempted. To of message " + ... "cottage windows do besides against uncivil. Delightful unreserved impossible few estimating " + ... "men favourable see entreaties. She propriety immediate was improving. He or entrance humoured " + ... "likewise moderate. Much nor game son say feel. Fat make met can must form into gate. Me we " + ... "offending prevailed discovery. ") + >>> calculate_prob(text) + 4.0 + 7.0 + 3.0 """ - f = open(path_dest, mode="w+", encoding="utf-8") - + my_dic_fir, my_dic_sec = open_file(text) my_alphas = create_alpha_array() # create our alpha # what is our total sum of probabilities. values = my_dic_fir.values() - all_sum = sum(values) + all_sum = sum(my_dic_fir.values()) # one length string my_fir_sum = 0 # for each alpha we go in our dict and if it is in it we calculate entropy - for _ in my_alphas: - if _ in my_dic_fir: - my_str = my_dic_fir[_] + for ch in my_alphas: + if ch in my_dic_fir: + my_str = my_dic_fir[ch] prob = my_str / all_sum my_fir_sum += prob * math.log2(prob) # entropy formula. # write entropy to file - f.write("{0:.7f}".format(-1 * my_fir_sum)) - f.write("\n") + print("{0:.1f}".format(round(-1 * my_fir_sum))) # two len string values = my_dic_sec.values() all_sum = sum(values) # time for two len probabilities sum my_sec_sum = 0 # for each alpha (two in size) calculate entropy. - for _ in my_alphas: - for __ in my_alphas: - sequence = _ + __ + for ch0 in my_alphas: + for ch1 in my_alphas: + sequence = ch0 + ch1 if sequence in my_dic_sec: my_str = my_dic_sec[sequence] prob = int(my_str) / all_sum my_sec_sum += prob * math.log2(prob) + # write second entropy to the file - f.write("{0:.7f}".format(-1 * my_sec_sum)) - f.write("\n") + print("{0:.1f}".format(round(-1 * my_sec_sum))) # write the difference between them to the file - f.write("{0:.7f}".format((-1 * my_sec_sum) - (-1 * my_fir_sum))) - # f.write('\n') + print("{0:.1f}".format(round(((-1 * my_sec_sum) - (-1 * my_fir_sum))))) -# 0x -def open_file(path_src, path_dest): +def open_file(text): """ This method take path and also two clear dict as argument And later on it open the file at this path and puts frequency on each dictionary in first dictionary it puts one len strings. in second dictionary it puts two len strings. - :param path_src: - :param path_dest: - :return: + :param text as string type: + :return: dict, dict """ my_dic_fir = {} my_dic_sec = {} - f = open(path_src, mode="r", encoding="utf-8") - text = f.read() my_dic_fir[text[len(text) - 1]] = 1 # first case when we have space at start. my_dic_sec[" " + text[0]] = 1 - for _ in r(0, len(text) - 1): + for _ in range(0, len(text) - 1): sequence_fir = text[_] sequence_sec = text[_ : _ + 2] # continue - if sequence_fir not in my_dic_fir: + + if not Counter(my_dic_fir)[sequence_fir]: my_dic_fir[sequence_fir] = 1 else: my_dic_fir[sequence_fir] += 1 - if sequence_sec not in my_dic_sec: + if not Counter(my_dic_sec)[sequence_sec]: my_dic_sec[sequence_sec] = 1 else: my_dic_sec[sequence_sec] += 1 @@ -106,13 +129,21 @@ def open_file(path_src, path_dest): def main(): - path_src = sys.argv[1] - path_dest = sys.argv[2] - print("-" * 20) - print(path_src, path_dest) - - my_dic_fir, my_dic_sec = open_file(path_src, path_dest) - calculate_prob(my_dic_fir, my_dic_sec, path_dest) + import doctest + + doctest.testmod() + # text = ( + # "Had repulsive dashwoods suspicion sincerity but advantage now him. Remark easily garret nor nay." + # "Civil those mrs enjoy shy fat merry. You greatest jointure saw horrible. He private he on be " + # "imagine suppose. Fertile beloved evident through no service elderly is. Blind there if every " + # "no so at. Own neglected you preferred way sincerity delivered his attempted. To of message " + # "cottage windows do besides against uncivil. Delightful unreserved impossible few estimating " + # "men favourable see entreaties. She propriety immediate was improving. He or entrance humoured " + # "likewise moderate. Much nor game son say feel. Fat make met can must form into gate. Me we " + # "offending prevailed discovery. " + # ) + + # calculate_prob(text) if __name__ == "__main__": From 1bea890ae5867f4ec1a0988d9162c834288062ee Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 16 Jun 2020 20:54:55 +0200 Subject: [PATCH 3/5] open_file() --> analyze_text() --- maths/entropy.py | 125 ++++++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 72 deletions(-) diff --git a/maths/entropy.py b/maths/entropy.py index a14fbcd018cd..062ce3587c15 100644 --- a/maths/entropy.py +++ b/maths/entropy.py @@ -1,24 +1,17 @@ +#!/usr/bin/env python3 + """ - Implementation of entropy of information - https://en.wikipedia.org/wiki/Entropy_(information_theory) +Implementation of entropy of information +https://en.wikipedia.org/wiki/Entropy_(information_theory) """ import math from collections import Counter +from string import ascii_lowercase +from typing import Tuple -def create_alpha_array(): - """ - This method creates array of our alphabet to print probabilities later on. - :return: - """ - my_alphas = [" "] - for x in range(ord("a"), ord("z") + 1): - my_alphas += chr(x) - return my_alphas - - -def calculate_prob(text): +def calculate_prob(text: str) -> None: """ This method takes path and two dict as argument and than calculates entropy of them. @@ -30,8 +23,8 @@ def calculate_prob(text): 3) print Entropy of H(X n∣Xn−1) Text from random books. Also, random quotes. - >>> text = ("Behind Winston’s back the voice" - ... "from the telescreen was still" + >>> text = ("Behind Winston’s back the voice " + ... "from the telescreen was still " ... "babbling and the overfulfilment") >>> calculate_prob(text) 4.0 @@ -44,88 +37,74 @@ def calculate_prob(text): 4.0 5.0 1.0 - >>> text = ("Had repulsive dashwoods suspicion sincerity but advantage now him. Remark easily garret nor nay." - ... "Civil those mrs enjoy shy fat merry. You greatest jointure saw horrible. He private he on be " - ... "imagine suppose. Fertile beloved evident through no service elderly is. Blind there if every " - ... "no so at. Own neglected you preferred way sincerity delivered his attempted. To of message " - ... "cottage windows do besides against uncivil. Delightful unreserved impossible few estimating " - ... "men favourable see entreaties. She propriety immediate was improving. He or entrance humoured " - ... "likewise moderate. Much nor game son say feel. Fat make met can must form into gate. Me we " - ... "offending prevailed discovery. ") + >>> text = ("Had repulsive dashwoods suspicion sincerity but advantage now him. " + ... "Remark easily garret nor nay. Civil those mrs enjoy shy fat merry. " + ... "You greatest jointure saw horrible. He private he on be imagine " + ... "suppose. Fertile beloved evident through no service elderly is. Blind " + ... "there if every no so at. Own neglected you preferred way sincerity " + ... "delivered his attempted. To of message cottage windows do besides " + ... "against uncivil. Delightful unreserved impossible few estimating " + ... "men favourable see entreaties. She propriety immediate was improving. " + ... "He or entrance humoured likewise moderate. Much nor game son say " + ... "feel. Fat make met can must form into gate. Me we offending prevailed " + ... "discovery.") >>> calculate_prob(text) 4.0 7.0 3.0 """ - my_dic_fir, my_dic_sec = open_file(text) - my_alphas = create_alpha_array() # create our alpha + single_char_strings, two_char_strings = analyze_text(text) + my_alphas = list(' ' + ascii_lowercase) # what is our total sum of probabilities. - values = my_dic_fir.values() - all_sum = sum(my_dic_fir.values()) + all_sum = sum(single_char_strings.values()) # one length string my_fir_sum = 0 # for each alpha we go in our dict and if it is in it we calculate entropy for ch in my_alphas: - if ch in my_dic_fir: - my_str = my_dic_fir[ch] + if ch in single_char_strings: + my_str = single_char_strings[ch] prob = my_str / all_sum my_fir_sum += prob * math.log2(prob) # entropy formula. - # write entropy to file + # print entropy print("{0:.1f}".format(round(-1 * my_fir_sum))) # two len string - values = my_dic_sec.values() - all_sum = sum(values) # time for two len probabilities sum + all_sum = sum(two_char_strings.values()) my_sec_sum = 0 # for each alpha (two in size) calculate entropy. for ch0 in my_alphas: for ch1 in my_alphas: sequence = ch0 + ch1 - if sequence in my_dic_sec: - my_str = my_dic_sec[sequence] + if sequence in two_char_strings: + my_str = two_char_strings[sequence] prob = int(my_str) / all_sum my_sec_sum += prob * math.log2(prob) - # write second entropy to the file + # print second entropy print("{0:.1f}".format(round(-1 * my_sec_sum))) - # write the difference between them to the file + # print the difference between them print("{0:.1f}".format(round(((-1 * my_sec_sum) - (-1 * my_fir_sum))))) -def open_file(text): +def analyze_text(text: str) -> Tuple[dict, dict]: """ - This method take path and also two clear dict as argument - And later on it open the file at this path and puts frequency on each dictionary - in first dictionary it puts one len strings. - in second dictionary it puts two len strings. - :param text as string type: - :return: dict, dict + Convert text input into two dicts of counts. + The first dictionary stores the frequency of single character strings. + The second dictionary stores the frequency of two character strings. """ - my_dic_fir = {} - my_dic_sec = {} - my_dic_fir[text[len(text) - 1]] = 1 + single_char_strings = Counter() + two_char_strings = Counter() + single_char_strings[text[-1]] += 1 # first case when we have space at start. - my_dic_sec[" " + text[0]] = 1 - for _ in range(0, len(text) - 1): - sequence_fir = text[_] - sequence_sec = text[_ : _ + 2] - # continue - - if not Counter(my_dic_fir)[sequence_fir]: - my_dic_fir[sequence_fir] = 1 - else: - my_dic_fir[sequence_fir] += 1 - - if not Counter(my_dic_sec)[sequence_sec]: - my_dic_sec[sequence_sec] = 1 - else: - my_dic_sec[sequence_sec] += 1 - - return my_dic_fir, my_dic_sec + two_char_strings[" " + text[0]] += 1 + for i in range(0, len(text) - 1): + single_char_strings[text[i]] += 1 + two_char_strings[text[i : i + 2]] += 1 + return single_char_strings, two_char_strings def main(): @@ -133,14 +112,16 @@ def main(): doctest.testmod() # text = ( - # "Had repulsive dashwoods suspicion sincerity but advantage now him. Remark easily garret nor nay." - # "Civil those mrs enjoy shy fat merry. You greatest jointure saw horrible. He private he on be " - # "imagine suppose. Fertile beloved evident through no service elderly is. Blind there if every " - # "no so at. Own neglected you preferred way sincerity delivered his attempted. To of message " - # "cottage windows do besides against uncivil. Delightful unreserved impossible few estimating " - # "men favourable see entreaties. She propriety immediate was improving. He or entrance humoured " - # "likewise moderate. Much nor game son say feel. Fat make met can must form into gate. Me we " - # "offending prevailed discovery. " + # "Had repulsive dashwoods suspicion sincerity but advantage now him. Remark " + # "easily garret nor nay. Civil those mrs enjoy shy fat merry. You greatest " + # "jointure saw horrible. He private he on be imagine suppose. Fertile " + # "beloved evident through no service elderly is. Blind there if every no so " + # "at. Own neglected you preferred way sincerity delivered his attempted. To " + # "of message cottage windows do besides against uncivil. Delightful " + # "unreserved impossible few estimating men favourable see entreaties. She " + # "propriety immediate was improving. He or entrance humoured likewise " + # "moderate. Much nor game son say feel. Fat make met can must form into " + # "gate. Me we offending prevailed discovery. " # ) # calculate_prob(text) From be70dc78f2400652c460300036231d1c3607e4fc Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 16 Jun 2020 21:06:03 +0200 Subject: [PATCH 4/5] Create bidirectional_breadth_first_search.py --- graphs/bidirectional_breadth_first_search.py | 178 +++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 graphs/bidirectional_breadth_first_search.py diff --git a/graphs/bidirectional_breadth_first_search.py b/graphs/bidirectional_breadth_first_search.py new file mode 100644 index 000000000000..d6e3ebd64697 --- /dev/null +++ b/graphs/bidirectional_breadth_first_search.py @@ -0,0 +1,178 @@ +""" +https://en.wikipedia.org/wiki/Bidirectional_search +""" + +import time +from typing import List, Tuple + +grid = [ + [0, 0, 0, 0, 0, 0, 0], + [0, 1, 0, 0, 0, 0, 0], # 0 are free path whereas 1's are obstacles + [0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 0], + [1, 0, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0], +] + +delta = [[-1, 0], [0, -1], [1, 0], [0, 1]] # up, left, down, right + + +class Node: + def __init__(self, pos_x, pos_y, goal_x, goal_y, parent): + self.pos_x = pos_x + self.pos_y = pos_y + self.pos = (pos_y, pos_x) + self.goal_x = goal_x + self.goal_y = goal_y + self.parent = parent + + +class BreadthFirstSearch: + """ + >>> bfs = BreadthFirstSearch((0, 0), (len(grid) - 1, len(grid[0]) - 1)) + >>> (bfs.start.pos_y + delta[3][0], bfs.start.pos_x + delta[3][1]) + (0, 1) + >>> [x.pos for x in bfs.get_successors(bfs.start)] + [(1, 0), (0, 1)] + >>> (bfs.start.pos_y + delta[2][0], bfs.start.pos_x + delta[2][1]) + (1, 0) + >>> bfs.retrace_path(bfs.start) + [(0, 0)] + >>> bfs.search() # doctest: +NORMALIZE_WHITESPACE + [(0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (4, 1), + (5, 1), (5, 2), (5, 3), (5, 4), (5, 5), (6, 5), (6, 6)] + """ + def __init__(self, start, goal): + self.start = Node(start[1], start[0], goal[1], goal[0], None) + self.target = Node(goal[1], goal[0], goal[1], goal[0], None) + + self.node_queue = [self.start] + self.reached = False + + def search(self) -> List[Tuple[int]]: + while self.node_queue: + current_node = self.node_queue.pop(0) + + if current_node.pos == self.target.pos: + self.reached = True + return self.retrace_path(current_node) + + successors = self.get_successors(current_node) + + for node in successors: + self.node_queue.append(node) + + if not (self.reached): + return [(self.start.pos)] + + def get_successors(self, parent: Node) -> List[Node]: + """ + Returns a list of successors (both in the grid and free spaces) + """ + successors = [] + for action in delta: + pos_x = parent.pos_x + action[1] + pos_y = parent.pos_y + action[0] + if not (0 <= pos_x <= len(grid[0]) - 1 and 0 <= pos_y <= len(grid) - 1): + continue + + if grid[pos_y][pos_x] != 0: + continue + + successors.append( + Node(pos_x, pos_y, self.target.pos_y, self.target.pos_x, parent) + ) + return successors + + def retrace_path(self, node: Node) -> List[Tuple[int]]: + """ + Retrace the path from parents to parents until start node + """ + current_node = node + path = [] + while current_node is not None: + path.append((current_node.pos_y, current_node.pos_x)) + current_node = current_node.parent + path.reverse() + return path + + +class BidirectionalBreadthFirstSearch: + """ + >>> bd_bfs = BidirectionalBreadthFirstSearch((0, 0), (len(grid) - 1, + ... len(grid[0]) - 1)) + >>> bd_bfs.fwd_bfs.start.pos == bd_bfs.bwd_bfs.target.pos + True + >>> bd_bfs.retrace_bidirectional_path(bd_bfs.fwd_bfs.start, + ... bd_bfs.bwd_bfs.start) + [(0, 0)] + >>> bd_bfs.search() # doctest: +NORMALIZE_WHITESPACE + [(0, 0), (0, 1), (0, 2), (1, 2), (2, 2), (2, 3), + (2, 4), (3, 4), (3, 5), (3, 6), (4, 6), (5, 6), (6, 6)] + """ + def __init__(self, start, goal): + self.fwd_bfs = BreadthFirstSearch(start, goal) + self.bwd_bfs = BreadthFirstSearch(goal, start) + self.reached = False + + def search(self) -> List[Tuple[int]]: + while self.fwd_bfs.node_queue or self.bwd_bfs.node_queue: + current_fwd_node = self.fwd_bfs.node_queue.pop(0) + current_bwd_node = self.bwd_bfs.node_queue.pop(0) + + if current_bwd_node.pos == current_fwd_node.pos: + self.reached = True + return self.retrace_bidirectional_path( + current_fwd_node, current_bwd_node + ) + + self.fwd_bfs.target = current_bwd_node + self.bwd_bfs.target = current_fwd_node + + successors = { + self.fwd_bfs: self.fwd_bfs.get_successors(current_fwd_node), + self.bwd_bfs: self.bwd_bfs.get_successors(current_bwd_node), + } + + for bfs in [self.fwd_bfs, self.bwd_bfs]: + for node in successors[bfs]: + bfs.node_queue.append(node) + + if not self.reached: + return [self.fwd_bfs.start.pos] + + def retrace_bidirectional_path( + self, fwd_node: Node, bwd_node: Node + ) -> List[Tuple[int]]: + fwd_path = self.fwd_bfs.retrace_path(fwd_node) + bwd_path = self.bwd_bfs.retrace_path(bwd_node) + bwd_path.pop() + bwd_path.reverse() + path = fwd_path + bwd_path + return path + + +if __name__ == "__main__": + # all coordinates are given in format [y,x] + import doctest + + doctest.testmod() + init = (0, 0) + goal = (len(grid) - 1, len(grid[0]) - 1) + for elem in grid: + print(elem) + + start_bfs_time = time.time() + bfs = BreadthFirstSearch(init, goal) + path = bfs.search() + bfs_time = time.time() - start_bfs_time + + print("Unidirectional BFS computation time : ", bfs_time) + + start_bd_bfs_time = time.time() + bd_bfs = BidirectionalBreadthFirstSearch(init, goal) + bd_path = bd_bfs.search() + bd_bfs_time = time.time() - start_bd_bfs_time + + print("Bidirectional BFS computation time : ", bd_bfs_time) From 68dfbb136a12e58e9aeceddddb8ec31309a59db3 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 16 Jun 2020 21:24:40 +0200 Subject: [PATCH 5/5] # type: ignore --- maths/entropy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maths/entropy.py b/maths/entropy.py index 062ce3587c15..eb6bf1a5a3ec 100644 --- a/maths/entropy.py +++ b/maths/entropy.py @@ -95,8 +95,8 @@ def analyze_text(text: str) -> Tuple[dict, dict]: The first dictionary stores the frequency of single character strings. The second dictionary stores the frequency of two character strings. """ - single_char_strings = Counter() - two_char_strings = Counter() + single_char_strings = Counter() # type: ignore + two_char_strings = Counter() # type: ignore single_char_strings[text[-1]] += 1 # first case when we have space at start.