idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
59,200 | def find_biconnected_components ( graph ) : list_of_components = [ ] components = get_connected_components_as_subgraphs ( graph ) for component in components : edge_list = _internal_get_biconnected_components_edge_lists ( component ) list_of_components . extend ( edge_list ) return list_of_components | Finds all the biconnected components in a graph . Returns a list of lists each containing the edges that form a biconnected component . Returns an empty list for an empty graph . |
59,201 | def find_biconnected_components_as_subgraphs ( graph ) : list_of_graphs = [ ] list_of_components = find_biconnected_components ( graph ) for edge_list in list_of_components : subgraph = get_subgraph_from_edge_list ( graph , edge_list ) list_of_graphs . append ( subgraph ) return list_of_graphs | Finds the biconnected components and returns them as subgraphs . |
59,202 | def find_articulation_vertices ( graph ) : articulation_vertices = [ ] all_nodes = graph . get_all_node_ids ( ) if len ( all_nodes ) == 0 : return articulation_vertices components = get_connected_components_as_subgraphs ( graph ) for component in components : vertex_list = _internal_get_cut_vertex_list ( component ) ar... | Finds all of the articulation vertices within a graph . Returns a list of all articulation vertices within the graph . Returns an empty list for an empty graph . |
59,203 | def output_component ( graph , edge_stack , u , v ) : edge_list = [ ] while len ( edge_stack ) > 0 : edge_id = edge_stack . popleft ( ) edge_list . append ( edge_id ) edge = graph . get_edge ( edge_id ) tpl_a = ( u , v ) tpl_b = ( v , u ) if tpl_a == edge [ 'vertices' ] or tpl_b == edge [ 'vertices' ] : break return ed... | Helper function to pop edges off the stack and produce a list of them . |
59,204 | def depth_first_search_with_parent_data ( graph , root_node = None , adjacency_lists = None ) : ordering = [ ] parent_lookup = { } children_lookup = defaultdict ( lambda : [ ] ) all_nodes = graph . get_all_node_ids ( ) if not all_nodes : return ordering , parent_lookup , children_lookup stack = deque ( ) discovered = d... | Performs a depth - first search with visiting order of nodes determined by provided adjacency lists and also returns a parent lookup dict and a children lookup dict . |
59,205 | def graph_to_dot ( graph , node_renderer = None , edge_renderer = None ) : node_pairs = list ( graph . nodes . items ( ) ) edge_pairs = list ( graph . edges . items ( ) ) if node_renderer is None : node_renderer_wrapper = lambda nid : '' else : node_renderer_wrapper = lambda nid : ' [%s]' % ',' . join ( [ '%s=%s' % tpl... | Produces a DOT specification string from the provided graph . |
59,206 | def get_connected_components ( graph ) : list_of_components = [ ] component = [ ] unreached = set ( graph . get_all_node_ids ( ) ) to_explore = deque ( ) while len ( unreached ) > 0 : if len ( to_explore ) == 0 : n = unreached . pop ( ) unreached . add ( n ) to_explore . append ( n ) component = [ ] list_of_components ... | Finds all connected components of the graph . Returns a list of lists each containing the nodes that form a connected component . Returns an empty list for an empty graph . |
59,207 | def get_connected_components_as_subgraphs ( graph ) : components = get_connected_components ( graph ) list_of_graphs = [ ] for c in components : edge_ids = set ( ) nodes = [ graph . get_node ( node ) for node in c ] for n in nodes : for e in n [ 'edges' ] : edge = graph . get_edge ( e ) a , b = edge [ 'vertices' ] if a... | Finds all connected components of the graph . Returns a list of graph objects each representing a connected component . Returns an empty list for an empty graph . |
59,208 | def new_edge ( self , node_a , node_b , cost = 1 ) : edge_id = super ( UndirectedGraph , self ) . new_edge ( node_a , node_b , cost ) self . nodes [ node_b ] [ 'edges' ] . append ( edge_id ) return edge_id | Adds a new undirected edge between node_a and node_b with a cost . Returns the edge id of the new edge . |
59,209 | def delete_edge_by_id ( self , edge_id ) : edge = self . get_edge ( edge_id ) from_node_id = edge [ 'vertices' ] [ 0 ] from_node = self . get_node ( from_node_id ) from_node [ 'edges' ] . remove ( edge_id ) to_node_id = edge [ 'vertices' ] [ 1 ] to_node = self . get_node ( to_node_id ) to_node [ 'edges' ] . remove ( ed... | Removes the edge identified by edge_id from the graph . |
59,210 | def find_minimum_spanning_tree ( graph ) : mst = [ ] if graph . num_nodes ( ) == 0 : return mst if graph . num_edges ( ) == 0 : return mst connected_components = get_connected_components ( graph ) if len ( connected_components ) > 1 : raise DisconnectedGraphError edge_list = kruskal_mst ( graph ) return edge_list | Calculates a minimum spanning tree for a graph . Returns a list of edges that define the tree . Returns an empty list for an empty graph . |
59,211 | def find_minimum_spanning_tree_as_subgraph ( graph ) : edge_list = find_minimum_spanning_tree ( graph ) subgraph = get_subgraph_from_edge_list ( graph , edge_list ) return subgraph | Calculates a minimum spanning tree and returns a graph representation . |
59,212 | def find_minimum_spanning_forest ( graph ) : msf = [ ] if graph . num_nodes ( ) == 0 : return msf if graph . num_edges ( ) == 0 : return msf connected_components = get_connected_components_as_subgraphs ( graph ) for subgraph in connected_components : edge_list = kruskal_mst ( subgraph ) msf . append ( edge_list ) retur... | Calculates the minimum spanning forest of a disconnected graph . Returns a list of lists each containing the edges that define that tree . Returns an empty list for an empty graph . |
59,213 | def find_minimum_spanning_forest_as_subgraphs ( graph ) : forest = find_minimum_spanning_forest ( graph ) list_of_subgraphs = [ get_subgraph_from_edge_list ( graph , edge_list ) for edge_list in forest ] return list_of_subgraphs | Calculates the minimum spanning forest and returns a list of trees as subgraphs . |
59,214 | def kruskal_mst ( graph ) : edges_accepted = 0 ds = DisjointSet ( ) pq = PriorityQueue ( ) accepted_edges = [ ] label_lookup = { } nodes = graph . get_all_node_ids ( ) num_vertices = len ( nodes ) for n in nodes : label = ds . add_set ( ) label_lookup [ n ] = label edges = graph . get_all_edge_objects ( ) for e in edge... | Implements Kruskal s Algorithm for finding minimum spanning trees . Assumes a non - empty connected graph . |
59,215 | def __get_cycle ( graph , ordering , parent_lookup ) : root_node = ordering [ 0 ] for i in range ( 2 , len ( ordering ) ) : current_node = ordering [ i ] if graph . adjacent ( current_node , root_node ) : path = [ ] while current_node != root_node : path . append ( current_node ) current_node = parent_lookup [ current_... | Gets the main cycle of the dfs tree . |
59,216 | def __get_segments_from_node ( node , graph ) : list_of_segments = [ ] node_object = graph . get_node ( node ) for e in node_object [ 'edges' ] : list_of_segments . append ( e ) return list_of_segments | Calculates the segments that can emanate from a particular node on the main cycle . |
59,217 | def __get_segments_from_cycle ( graph , cycle_path ) : list_of_segments = [ ] for n in cycle_path [ : : - 1 ] : segments = __get_segments_from_node ( n , graph ) if segments : list_of_segments . append ( segments ) return list_of_segments | Calculates the segments that emanate from the main cycle . |
59,218 | def make_subgraph ( graph , vertices , edges ) : local_graph = copy . deepcopy ( graph ) edges_to_delete = [ x for x in local_graph . get_all_edge_ids ( ) if x not in edges ] for e in edges_to_delete : local_graph . delete_edge_by_id ( e ) nodes_to_delete = [ x for x in local_graph . get_all_node_ids ( ) if x not in ve... | Converts a subgraph given by a list of vertices and edges into a graph object . |
59,219 | def convert_graph_directed_to_undirected ( dg ) : udg = UndirectedGraph ( ) udg . nodes = copy . deepcopy ( dg . nodes ) udg . edges = copy . deepcopy ( dg . edges ) udg . next_node_id = dg . next_node_id udg . next_edge_id = dg . next_edge_id for edge_id in udg . get_all_edge_ids ( ) : edge = udg . get_edge ( edge_id ... | Converts a directed graph into an undirected graph . Directed edges are made undirected . |
59,220 | def remove_duplicate_edges_directed ( dg ) : lookup = { } edges = sorted ( dg . get_all_edge_ids ( ) ) for edge_id in edges : e = dg . get_edge ( edge_id ) tpl = e [ 'vertices' ] if tpl in lookup : dg . delete_edge_by_id ( edge_id ) else : lookup [ tpl ] = edge_id | Removes duplicate edges from a directed graph . |
59,221 | def remove_duplicate_edges_undirected ( udg ) : lookup = { } edges = sorted ( udg . get_all_edge_ids ( ) ) for edge_id in edges : e = udg . get_edge ( edge_id ) tpl_a = e [ 'vertices' ] tpl_b = ( tpl_a [ 1 ] , tpl_a [ 0 ] ) if tpl_a in lookup or tpl_b in lookup : udg . delete_edge_by_id ( edge_id ) else : lookup [ tpl_... | Removes duplicate edges from an undirected graph . |
59,222 | def get_vertices_from_edge_list ( graph , edge_list ) : node_set = set ( ) for edge_id in edge_list : edge = graph . get_edge ( edge_id ) a , b = edge [ 'vertices' ] node_set . add ( a ) node_set . add ( b ) return list ( node_set ) | Transforms a list of edges into a list of the nodes those edges connect . Returns a list of nodes or an empty list if given an empty list . |
59,223 | def get_subgraph_from_edge_list ( graph , edge_list ) : node_list = get_vertices_from_edge_list ( graph , edge_list ) subgraph = make_subgraph ( graph , node_list , edge_list ) return subgraph | Transforms a list of edges into a subgraph . |
59,224 | def merge_graphs ( main_graph , addition_graph ) : node_mapping = { } edge_mapping = { } for node in addition_graph . get_all_node_objects ( ) : node_id = node [ 'id' ] new_id = main_graph . new_node ( ) node_mapping [ node_id ] = new_id for edge in addition_graph . get_all_edge_objects ( ) : edge_id = edge [ 'id' ] ol... | Merges an addition_graph into the main_graph . Returns a tuple of dictionaries mapping old node ids and edge ids to new ids . |
59,225 | def create_graph_from_adjacency_matrix ( adjacency_matrix ) : if is_adjacency_matrix_symmetric ( adjacency_matrix ) : graph = UndirectedGraph ( ) else : graph = DirectedGraph ( ) node_column_mapping = [ ] num_columns = len ( adjacency_matrix ) for _ in range ( num_columns ) : node_id = graph . new_node ( ) node_column_... | Generates a graph from an adjacency matrix specification . Returns a tuple containing the graph and a list - mapping of node ids to matrix column indices . |
59,226 | def add_set ( self ) : self . __label_counter += 1 new_label = self . __label_counter self . __forest [ new_label ] = - 1 self . __set_counter += 1 return new_label | Adds a new set to the forest . Returns a label by which the new set can be referenced |
59,227 | def find ( self , node_label ) : queue = [ ] current_node = node_label while self . __forest [ current_node ] >= 0 : queue . append ( current_node ) current_node = self . __forest [ current_node ] root_node = current_node for n in queue : self . __forest [ n ] = root_node return root_node | Finds the set containing the node_label . Returns the set label . |
59,228 | def union ( self , label_a , label_b ) : if label_a == label_b : return root_a = self . find ( label_a ) root_b = self . find ( label_b ) if root_a == root_b : return self . __internal_union ( root_a , root_b ) self . __set_counter -= 1 | Joins two sets into a single new set . label_a label_b can be any nodes within the sets |
59,229 | def __internal_union ( self , root_a , root_b ) : update_rank = False rank_a = self . __forest [ root_a ] rank_b = self . __forest [ root_b ] if rank_a < rank_b : larger = root_b smaller = root_a else : larger = root_a smaller = root_b if rank_a == rank_b : update_rank = True self . __forest [ smaller ] = larger if upd... | Internal function to join two set trees specified by root_a and root_b . Assumes root_a and root_b are distinct . |
59,230 | def is_planar ( graph ) : connected_components = get_connected_components_as_subgraphs ( graph ) for component in connected_components : biconnected_components = find_biconnected_components_as_subgraphs ( component ) for bi_component in biconnected_components : planarity = __is_subgraph_planar ( bi_component ) if not p... | Determines whether a graph is planar or not . |
59,231 | def __is_subgraph_planar ( graph ) : num_nodes = graph . num_nodes ( ) num_edges = graph . num_edges ( ) if num_nodes < 5 : return True if num_edges > 3 * ( num_nodes - 2 ) : return False return kocay_planarity_test ( graph ) | Internal function to determine if a subgraph is planar . |
59,232 | def __setup_dfs_data ( graph , adj ) : dfs_data = __get_dfs_data ( graph , adj ) dfs_data [ 'graph' ] = graph dfs_data [ 'adj' ] = adj L1 , L2 = __low_point_dfs ( dfs_data ) dfs_data [ 'lowpoint_1_lookup' ] = L1 dfs_data [ 'lowpoint_2_lookup' ] = L2 edge_weights = __calculate_edge_weights ( dfs_data ) dfs_data [ 'edge_... | Sets up the dfs_data object for consistency . |
59,233 | def __calculate_edge_weights ( dfs_data ) : graph = dfs_data [ 'graph' ] weights = { } for edge_id in graph . get_all_edge_ids ( ) : edge_weight = __edge_weight ( edge_id , dfs_data ) weights [ edge_id ] = edge_weight return weights | Calculates the weight of each edge for embedding - order sorting . |
59,234 | def __sort_adjacency_lists ( dfs_data ) : new_adjacency_lists = { } adjacency_lists = dfs_data [ 'adj' ] edge_weights = dfs_data [ 'edge_weights' ] edge_lookup = dfs_data [ 'edge_lookup' ] for node_id , adj_list in list ( adjacency_lists . items ( ) ) : node_weight_lookup = { } frond_lookup = { } for node_b in adj_list... | Sorts the adjacency list representation by the edge weights . |
59,235 | def __branch_point_dfs_recursive ( u , large_n , b , stem , dfs_data ) : first_vertex = dfs_data [ 'adj' ] [ u ] [ 0 ] large_w = wt ( u , first_vertex , dfs_data ) if large_w % 2 == 0 : large_w += 1 v_I = 0 v_II = 0 for v in [ v for v in dfs_data [ 'adj' ] [ u ] if wt ( u , v , dfs_data ) <= large_w ] : stem [ u ] = v ... | A recursive implementation of the BranchPtDFS function as defined on page 14 of the paper . |
59,236 | def __embed_branch ( dfs_data ) : u = dfs_data [ 'ordering' ] [ 0 ] dfs_data [ 'LF' ] = [ ] dfs_data [ 'RF' ] = [ ] dfs_data [ 'FG' ] = { } n = dfs_data [ 'graph' ] . num_nodes ( ) f0 = ( 0 , n ) g0 = ( 0 , n ) L0 = { 'u' : 0 , 'v' : n } R0 = { 'x' : 0 , 'y' : n } dfs_data [ 'LF' ] . append ( f0 ) dfs_data [ 'RF' ] . a... | Builds the combinatorial embedding of the graph . Returns whether the graph is planar . |
59,237 | def __embed_branch_recursive ( u , dfs_data ) : for v in dfs_data [ 'adj' ] [ u ] : nonplanar = True if a ( v , dfs_data ) == u : if b ( v , dfs_data ) == u : successful = __insert_branch ( u , v , dfs_data ) if not successful : nonplanar = True return nonplanar nonplanar = __embed_branch_recursive ( v , dfs_data ) if ... | A recursive implementation of the EmbedBranch function as defined on pages 8 and 22 of the paper . |
59,238 | def __embed_frond ( node_u , node_w , dfs_data , as_branch_marker = False ) : d_u = D ( node_u , dfs_data ) d_w = D ( node_w , dfs_data ) comp_d_w = abs ( d_w ) if as_branch_marker : d_w *= - 1 if dfs_data [ 'last_inserted_side' ] == 'LF' : __insert_frond_RF ( d_w , d_u , dfs_data ) else : __insert_frond_LF ( d_w , d_u... | Embeds a frond uw into either LF or RF . Returns whether the embedding was successful . |
59,239 | def __insert_frond_RF ( d_w , d_u , dfs_data ) : dfs_data [ 'RF' ] . append ( ( d_w , d_u ) ) dfs_data [ 'FG' ] [ 'r' ] += 1 dfs_data [ 'last_inserted_side' ] = 'RF' | Encapsulates the process of inserting a frond uw into the right side frond group . |
59,240 | def __insert_frond_LF ( d_w , d_u , dfs_data ) : dfs_data [ 'LF' ] . append ( ( d_w , d_u ) ) dfs_data [ 'FG' ] [ 'l' ] += 1 dfs_data [ 'last_inserted_side' ] = 'LF' | Encapsulates the process of inserting a frond uw into the left side frond group . |
59,241 | def merge_Fm ( dfs_data ) : FG = dfs_data [ 'FG' ] m = FG [ 'm' ] FGm = FG [ m ] FGm1 = FG [ m - 1 ] if FGm [ 0 ] [ 'u' ] < FGm1 [ 0 ] [ 'u' ] : FGm1 [ 0 ] [ 'u' ] = FGm [ 0 ] [ 'u' ] if FGm [ 0 ] [ 'v' ] > FGm1 [ 0 ] [ 'v' ] : FGm1 [ 0 ] [ 'v' ] = FGm [ 0 ] [ 'v' ] if FGm [ 1 ] [ 'x' ] < FGm1 [ 1 ] [ 'x' ] : FGm1 [ 1 ... | Merges Fm - 1 and Fm as defined on page 19 of the paper . |
59,242 | def __check_left_side_conflict ( x , y , dfs_data ) : l = dfs_data [ 'FG' ] [ 'l' ] w , z = dfs_data [ 'LF' ] [ l ] return __check_conflict_fronds ( x , y , w , z , dfs_data ) | Checks to see if the frond xy will conflict with a frond on the left side of the embedding . |
59,243 | def __check_right_side_conflict ( x , y , dfs_data ) : r = dfs_data [ 'FG' ] [ 'r' ] w , z = dfs_data [ 'RF' ] [ r ] return __check_conflict_fronds ( x , y , w , z , dfs_data ) | Checks to see if the frond xy will conflict with a frond on the right side of the embedding . |
59,244 | def __check_conflict_fronds ( x , y , w , z , dfs_data ) : if x < 0 and w < 0 and ( x == y or w == z ) : if x == w : return True return False if b ( x , dfs_data ) == b ( w , dfs_data ) and x > w and w > y and y > z : return False if x < 0 or w < 0 : if x < 0 : u = abs ( x ) t = y x = w y = z else : u = abs ( w ) t = z... | Checks a pair of fronds to see if they conflict . Returns True if a conflict was found False otherwise . |
59,245 | def __calculate_adjacency_lists ( graph ) : adj = { } for node in graph . get_all_node_ids ( ) : neighbors = graph . neighbors ( node ) adj [ node ] = neighbors return adj | Builds an adjacency list representation for the graph since we can t guarantee that the internal representation of the graph is stored that way . |
59,246 | def __get_all_lowpoints ( dfs_data ) : lowpoint_1_lookup = { } lowpoint_2_lookup = { } ordering = dfs_data [ 'ordering' ] for node in ordering : low_1 , low_2 = __get_lowpoints ( node , dfs_data ) lowpoint_1_lookup [ node ] = low_1 lowpoint_2_lookup [ node ] = low_2 return lowpoint_1_lookup , lowpoint_2_lookup | Calculates the lowpoints for each node in a graph . |
59,247 | def __get_lowpoints ( node , dfs_data ) : ordering_lookup = dfs_data [ 'ordering_lookup' ] t_u = T ( node , dfs_data ) sorted_t_u = sorted ( t_u , key = lambda a : ordering_lookup [ a ] ) lowpoint_1 = sorted_t_u [ 0 ] lowpoint_2 = sorted_t_u [ 1 ] return lowpoint_1 , lowpoint_2 | Calculates the lowpoints for a single node in a graph . |
59,248 | def __edge_weight ( edge_id , dfs_data ) : graph = dfs_data [ 'graph' ] edge_lookup = dfs_data [ 'edge_lookup' ] edge = graph . get_edge ( edge_id ) u , v = edge [ 'vertices' ] d_u = D ( u , dfs_data ) d_v = D ( v , dfs_data ) lp_1 = L1 ( v , dfs_data ) d_lp_1 = D ( lp_1 , dfs_data ) if edge_lookup [ edge_id ] == 'back... | Calculates the edge weight used to sort edges . |
59,249 | def is_type_I_branch ( u , v , dfs_data ) : if u != a ( v , dfs_data ) : return False if u == L2 ( v , dfs_data ) : return True return False | Determines whether a branch uv is a type I branch . |
59,250 | def is_type_II_branch ( u , v , dfs_data ) : if u != a ( v , dfs_data ) : return False if u < L2 ( v , dfs_data ) : return True return False | Determines whether a branch uv is a type II branch . |
59,251 | def __get_descendants ( node , dfs_data ) : list_of_descendants = [ ] stack = deque ( ) children_lookup = dfs_data [ 'children_lookup' ] current_node = node children = children_lookup [ current_node ] dfs_current_node = D ( current_node , dfs_data ) for n in children : dfs_child = D ( n , dfs_data ) if dfs_child > dfs_... | Gets the descendants of a node . |
59,252 | def S_star ( u , dfs_data ) : s_u = S ( u , dfs_data ) if u not in s_u : s_u . append ( u ) return s_u | The set of all descendants of u with u added . |
59,253 | def classify_segmented_recording ( recording , result_format = None ) : global single_symbol_classifier if single_symbol_classifier is None : single_symbol_classifier = SingleClassificer ( ) return single_symbol_classifier . predict ( recording , result_format ) | Use this function if you are sure you have a single symbol . |
59,254 | def predict ( self , recording , result_format = None ) : evaluate = utils . evaluate_model_single_recording_preloaded results = evaluate ( self . preprocessing_queue , self . feature_list , self . model , self . output_semantics , recording ) if result_format == 'LaTeX' : for i in range ( len ( results ) ) : results [... | Predict the class of the given recording . |
59,255 | def get_symbol_ids ( symbol_yml_file , metadata ) : with open ( symbol_yml_file , 'r' ) as stream : symbol_cfg = yaml . load ( stream ) symbol_ids = [ ] symbol_ids_set = set ( ) for symbol in symbol_cfg : if 'latex' not in symbol : logging . error ( "Key 'latex' not found for a symbol in %s (%s)" , symbol_yml_file , sy... | Get a list of ids which describe which class they get mapped to . |
59,256 | def read_csv ( filepath ) : symbols = [ ] with open ( filepath , 'rb' ) as csvfile : spamreader = csv . DictReader ( csvfile , delimiter = ',' , quotechar = '"' ) for row in spamreader : symbols . append ( row ) return symbols | Read a CSV into a list of dictionarys . The first line of the CSV determines the keys of the dictionary . |
59,257 | def load_raw ( raw_pickle_file ) : with open ( raw_pickle_file , 'rb' ) as f : raw = pickle . load ( f ) logging . info ( "Loaded %i recordings." , len ( raw [ 'handwriting_datasets' ] ) ) return raw | Load a pickle file of raw recordings . |
59,258 | def get_metrics ( metrics_description ) : return utils . get_objectlist ( metrics_description , config_key = 'data_analyzation_plugins' , module = sys . modules [ __name__ ] ) | Get metrics from a list of dictionaries . |
59,259 | def prepare_file ( filename ) : directory = os . path . join ( utils . get_project_root ( ) , "analyzation/" ) if not os . path . exists ( directory ) : os . makedirs ( directory ) workfilename = os . path . join ( directory , filename ) open ( workfilename , 'w' ) . close ( ) return workfilename | Truncate the file and return the filename . |
59,260 | def sort_by_formula_id ( raw_datasets ) : by_formula_id = defaultdict ( list ) for el in raw_datasets : by_formula_id [ el [ 'handwriting' ] . formula_id ] . append ( el [ 'handwriting' ] ) return by_formula_id | Sort a list of formulas by id where id represents the accepted formula id . |
59,261 | def _write_data ( self , symbols , err_recs , nr_recordings , total_error_count , percentages , time_max_list ) : write_file = open ( self . filename , "a" ) s = "" for symbol , count in sorted ( symbols . items ( ) , key = lambda n : n [ 0 ] ) : if symbol in [ 'a' , '0' , 'A' ] : s += "\n%s (%i), " % ( symbol , count ... | Write all obtained data to a file . |
59,262 | def print_featurelist ( feature_list ) : input_features = sum ( map ( lambda n : n . get_dimension ( ) , feature_list ) ) print ( "## Features (%i)" % input_features ) print ( "```" ) for algorithm in feature_list : print ( "* %s" % str ( algorithm ) ) print ( "```" ) | Print the feature_list in a human - readable form . |
59,263 | def _stroke_simplification ( self , pointlist ) : dmax = 0 index = 0 for i in range ( 1 , len ( pointlist ) ) : d = geometry . perpendicular_distance ( pointlist [ i ] , pointlist [ 0 ] , pointlist [ - 1 ] ) if d > dmax : index = i dmax = d if dmax >= self . epsilon : rec_results1 = self . _stroke_simplification ( poin... | The Douglas - Peucker line simplification takes a list of points as an argument . It tries to simplifiy this list by removing as many points as possible while still maintaining the overall shape of the stroke . It does so by taking the first and the last point connecting them by a straight line and searchin for the poi... |
59,264 | def get_preprocessing_queue ( preprocessing_list ) : return utils . get_objectlist ( preprocessing_list , config_key = 'preprocessing' , module = sys . modules [ __name__ ] ) | Get preprocessing queue from a list of dictionaries |
59,265 | def print_preprocessing_list ( preprocessing_queue ) : print ( "## Preprocessing" ) print ( "```" ) for algorithm in preprocessing_queue : print ( "* " + str ( algorithm ) ) print ( "```" ) | Print the preproc_list in a human - readable form . |
59,266 | def _get_parameters ( self , hwr_obj ) : a = hwr_obj . get_bounding_box ( ) width = a [ 'maxx' ] - a [ 'minx' ] + self . width_add height = a [ 'maxy' ] - a [ 'miny' ] + self . height_add factor_x , factor_y = 1 , 1 if width != 0 : factor_x = self . max_width / width if height != 0 : factor_y = self . max_height / heig... | Take a list of points and calculate the factors for scaling and moving it so that it s in the unit square . Keept the aspect ratio . Optionally center the points inside of the unit square . |
59,267 | def _calculate_pen_down_strokes ( self , pointlist , times = None ) : if times is None : times = [ ] for stroke in pointlist : stroke_info = { "start" : stroke [ 0 ] [ 'time' ] , "end" : stroke [ - 1 ] [ 'time' ] , "pen_down" : True } x , y , t = [ ] , [ ] , [ ] for point in stroke : if point [ 'time' ] not in t : x . ... | Calculate the intervall borders times that contain the information when a stroke started when it ended and how it should be interpolated . |
59,268 | def _calculate_pen_up_strokes ( self , pointlist , times = None ) : if times is None : times = [ ] for i in range ( len ( pointlist ) - 1 ) : stroke_info = { "start" : pointlist [ i ] [ - 1 ] [ 'time' ] , "end" : pointlist [ i + 1 ] [ 0 ] [ 'time' ] , "pen_down" : False } x , y , t = [ ] , [ ] , [ ] for point in [ poin... | Pen - up strokes are virtual strokes that were not drawn . It models the time when the user moved from one stroke to the next . |
59,269 | def _space ( self , hwr_obj , stroke , kind ) : new_stroke = [ ] stroke = sorted ( stroke , key = lambda p : p [ 'time' ] ) x , y , t = [ ] , [ ] , [ ] for point in stroke : x . append ( point [ 'x' ] ) y . append ( point [ 'y' ] ) t . append ( point [ 'time' ] ) x , y = numpy . array ( x ) , numpy . array ( y ) failed... | Do the interpolation of kind for stroke |
59,270 | def _calculate_average ( self , points ) : assert len ( self . theta ) == len ( points ) , "points has length %i, but should have length %i" % ( len ( points ) , len ( self . theta ) ) new_point = { 'x' : 0 , 'y' : 0 , 'time' : 0 } for key in new_point : new_point [ key ] = self . theta [ 0 ] * points [ 0 ] [ key ] + s... | Calculate the arithmetic mean of the points x and y coordinates seperately . |
59,271 | def create_model ( model_folder , model_type , topology , override ) : latest_model = utils . get_latest_in_folder ( model_folder , ".json" ) if ( latest_model == "" ) or override : logging . info ( "Create a base model..." ) model_src = os . path . join ( model_folder , "model-0.json" ) command = "%s make %s %s > %s" ... | Create a model if it doesn t exist already . |
59,272 | def main ( model_folder , override = False ) : model_description_file = os . path . join ( model_folder , "info.yml" ) with open ( model_description_file , 'r' ) as ymlfile : model_description = yaml . load ( ymlfile ) project_root = utils . get_project_root ( ) feature_folder = os . path . join ( project_root , model_... | Parse the info . yml from model_folder and create the model file . |
59,273 | def interactive ( ) : global n if request . method == 'GET' and request . args . get ( 'heartbeat' , '' ) != "" : return request . args . get ( 'heartbeat' , '' ) if request . method == 'POST' : logging . warning ( 'POST to /interactive is deprecated. ' 'Use /worker instead' ) else : return render_template ( 'canvas.ht... | Interactive classifier . |
59,274 | def _get_part ( pointlist , strokes ) : result = [ ] strokes = sorted ( strokes ) for stroke_index in strokes : result . append ( pointlist [ stroke_index ] ) return result | Get some strokes of pointlist |
59,275 | def _get_translate ( ) : translate = { } model_path = pkg_resources . resource_filename ( 'hwrt' , 'misc/' ) translation_csv = os . path . join ( model_path , 'latex2writemathindex.csv' ) arguments = { 'newline' : '' , 'encoding' : 'utf8' } with open ( translation_csv , 'rt' , ** arguments ) as csvfile : contents = csv... | Get a dictionary which translates from a neural network output to semantics . |
59,276 | def main ( port = 8000 , n_output = 10 , use_segmenter = False ) : global n global use_segmenter_flag n = n_output use_segmenter_flag = use_segmenter logging . info ( "Start webserver..." ) app . run ( port = port ) | Main function starting the webserver . |
59,277 | def generate_training_command ( model_folder ) : update_if_outdated ( model_folder ) model_description_file = os . path . join ( model_folder , "info.yml" ) with open ( model_description_file , 'r' ) as ymlfile : model_description = yaml . load ( ymlfile ) project_root = utils . get_project_root ( ) data = { } data [ '... | Generate a string that contains a command with all necessary parameters to train the model . |
59,278 | def train_model ( model_folder ) : os . chdir ( model_folder ) training = generate_training_command ( model_folder ) if training is None : return - 1 logging . info ( training ) os . chdir ( model_folder ) os . system ( training ) | Train the model in model_folder . |
59,279 | def main ( model_folder ) : model_description_file = os . path . join ( model_folder , "info.yml" ) with open ( model_description_file , 'r' ) as ymlfile : model_description = yaml . load ( ymlfile ) logging . info ( model_description [ 'model' ] ) data = { } data [ 'training' ] = os . path . join ( model_folder , "tra... | Main part of the training script . |
59,280 | def get_bounding_box ( points ) : assert len ( points ) > 0 , "At least one point has to be given." min_x , max_x = points [ 0 ] [ 'x' ] , points [ 0 ] [ 'x' ] min_y , max_y = points [ 0 ] [ 'y' ] , points [ 0 ] [ 'y' ] for point in points : min_x , max_x = min ( min_x , point [ 'x' ] ) , max ( max_x , point [ 'x' ] ) ... | Get the bounding box of a list of points . |
59,281 | def do_bb_intersect ( a , b ) : return a . p1 . x <= b . p2 . x and a . p2 . x >= b . p1 . x and a . p1 . y <= b . p2 . y and a . p2 . y >= b . p1 . y | Check if BoundingBox a intersects with BoundingBox b . |
59,282 | def segments_distance ( segment1 , segment2 ) : assert isinstance ( segment1 , LineSegment ) , "segment1 is not a LineSegment, but a %s" % type ( segment1 ) assert isinstance ( segment2 , LineSegment ) , "segment2 is not a LineSegment, but a %s" % type ( segment2 ) if len ( get_segments_intersections ( segment1 , segme... | Calculate the distance between two line segments in the plane . |
59,283 | def perpendicular_distance ( p3 , p1 , p2 ) : px = p2 [ 'x' ] - p1 [ 'x' ] py = p2 [ 'y' ] - p1 [ 'y' ] squared_distance = px * px + py * py if squared_distance == 0 : line_point = Point ( p1 [ 'x' ] , p1 [ 'y' ] ) point = Point ( p3 [ 'x' ] , p3 [ 'y' ] ) return line_point . dist_to ( point ) u = ( ( p3 [ 'x' ] - p1 [... | Calculate the distance from p3 to the stroke defined by p1 and p2 . The distance is the length of the perpendicular from p3 on p1 . |
59,284 | def dist_to ( self , p2 ) : return math . hypot ( self . x - p2 . x , self . y - p2 . y ) | Measure the distance to another point . |
59,285 | def get_slope ( self ) : return ( ( self . p1 . y - self . p2 . y ) / ( self . p1 . x - self . p2 . x ) ) | Return the slope m of this line segment . |
59,286 | def get_offset ( self ) : return self . p1 . y - self . get_slope ( ) * self . p1 . x | Get the offset t of this line segment . |
59,287 | def count_selfintersections ( self ) : counter = 0 for i , j in itertools . combinations ( range ( len ( self . lineSegments ) ) , 2 ) : inters = get_segments_intersections ( self . lineSegments [ i ] , self . lineSegments [ j ] ) if abs ( i - j ) > 1 and len ( inters ) > 0 : counter += 1 return counter | Get the number of self - intersections of this polygonal chain . |
59,288 | def count_intersections ( self , line_segments_b ) : line_segments_a = self . lineSegments intersection_points = [ ] for line1 , line2 in itertools . product ( line_segments_a , line_segments_b ) : intersection_points += get_segments_intersections ( line1 , line2 ) return len ( set ( intersection_points ) ) | Count the intersections of two strokes with each other . |
59,289 | def get_area ( self ) : return ( self . p2 . x - self . p1 . x ) * ( self . p2 . y - self . p1 . y ) | Calculate area of bounding box . |
59,290 | def get_center ( self ) : return Point ( ( self . p1 . x + self . p2 . x ) / 2.0 , ( self . p1 . y + self . p2 . y ) / 2.0 ) | Get the center point of this bounding box . |
59,291 | def _list_ids ( path_to_data ) : loaded = pickle . load ( open ( path_to_data , "rb" ) ) raw_datasets = loaded [ 'handwriting_datasets' ] raw_ids = { } for raw_dataset in raw_datasets : raw_data_id = raw_dataset [ 'handwriting' ] . raw_data_id if raw_dataset [ 'formula_id' ] not in raw_ids : raw_ids [ raw_dataset [ 'fo... | List raw data IDs grouped by symbol ID from a pickle file path_to_data . |
59,292 | def _get_system ( model_folder ) : model_description_file = os . path . join ( model_folder , "info.yml" ) if not os . path . isfile ( model_description_file ) : logging . error ( "You are probably not in the folder of a model, because " "%s is not a file. (-m argument)" , model_description_file ) sys . exit ( - 1 ) wi... | Return the preprocessing description the feature description and the model description . |
59,293 | def display_data ( raw_data_string , raw_data_id , model_folder , show_raw ) : print ( "## Raw Data (ID: %i)" % raw_data_id ) print ( "```" ) print ( raw_data_string ) print ( "```" ) preprocessing_desc , feature_desc , _ = _get_system ( model_folder ) print ( "## Model" ) print ( "%s\n" % model_folder ) tmp = preproce... | Print raw_data_id with the content raw_data_string after applying the preprocessing of model_folder to it . |
59,294 | def main ( list_ids , model , contact_server , raw_data_id , show_raw , mysql_cfg = 'mysql_online' ) : if list_ids : preprocessing_desc , _ , _ = _get_system ( model ) raw_datapath = os . path . join ( utils . get_project_root ( ) , preprocessing_desc [ 'data-source' ] ) _list_ids ( raw_datapath ) else : if contact_ser... | Main function of view . py . |
59,295 | def get_parameters ( folder ) : with open ( os . path . join ( folder , "info.yml" ) , 'r' ) as ymlfile : preprocessing_description = yaml . load ( ymlfile ) raw_datapath = os . path . join ( utils . get_project_root ( ) , preprocessing_description [ 'data-source' ] ) outputpath = os . path . join ( folder , "data.pick... | Get the parameters of the preprocessing done within folder . |
59,296 | def create_preprocessed_dataset ( path_to_data , outputpath , preprocessing_queue ) : logging . info ( "Data soure %s" , path_to_data ) logging . info ( "Output will be stored in %s" , outputpath ) tmp = "Preprocessing Queue:\n" for preprocessing_class in preprocessing_queue : tmp += str ( preprocessing_class ) + "\n" ... | Create a preprocessed dataset file by applying preprocessing_queue to path_to_data . The result will be stored in outputpath . |
59,297 | def main ( folder ) : raw_datapath , outputpath , p_queue = get_parameters ( folder ) create_preprocessed_dataset ( raw_datapath , outputpath , p_queue ) utils . create_run_logfile ( folder ) | Main part of preprocess_dataset that glues things togeter . |
59,298 | def _create_index_formula_lookup ( formula_id2index , feature_folder , index2latex ) : index2formula_id = sorted ( formula_id2index . items ( ) , key = lambda n : n [ 1 ] ) index2formula_file = os . path . join ( feature_folder , "index2formula_id.csv" ) with open ( index2formula_file , "w" ) as f : f . write ( "index,... | Create a lookup file where the index is mapped to the formula id and the LaTeX command . |
59,299 | def main ( feature_folder , create_learning_curve = False ) : with open ( os . path . join ( feature_folder , "info.yml" ) , 'r' ) as ymlfile : feature_description = yaml . load ( ymlfile ) path_to_data = os . path . join ( utils . get_project_root ( ) , feature_description [ 'data-source' ] ) if os . path . isdir ( pa... | main function of create_ffiles . py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.