Exemple #1
0
def __calc_dm(graph: gc.Graph, removed_nodes: [int],
              save_info: sl.MemoryAccess, i: int) -> (int, pd.DataFrame):
    if save_info.has_distance_matrix(removed_nodes=removed_nodes, iteration=i):
        # print("Distance matrix for removed nodes", removed_nodes, "and iteration", i, "is already trained")
        return i, save_info.load_distance_matrix(removed_nodes=removed_nodes,
                                                 iteration=i)
    else:
        # print(f'Calculate distance matrix for removed nodes {removed_nodes} iteration {i}')
        # model = embedding_function(graph=graph, save_info=save_info, removed_nodes=removed_nodes, iteration=i)
        # thows error if embedding does not exist

        model = save_info.load_embedding(removed_nodes=removed_nodes,
                                         iteration=i)
        dm = cd.calc_distances(model=model,
                               graph=graph,
                               save_info=save_info,
                               removed_nodes=removed_nodes,
                               iteration=i,
                               save=False)

        save_info.save_distance_matrix(removed_nodes=removed_nodes,
                                       iteration=i,
                                       dm=dm)

        return i, dm
Exemple #2
0
def calc_distances(model,
                   save_info: sl.MemoryAccess,
                   removed_nodes: [int],
                   iteration: int,
                   graph: gc.Graph = None,
                   save: bool = True,
                   check_for_existing: bool = True):
    if check_for_existing and save_info.has_distance_matrix(
            removed_nodes, iteration):
        return save_info.load_distance_matrix(removed_nodes, iteration)

    dm = calc_distances_based_on_gensim_fast(model=model)
    """
    if type(model) == pd.DataFrame:
        dm = __calc_distances_based_on_df(embedding=model)
    else:
        dm = calc_distances_based_on_gensim_fast(model=model)
        # dm = __calc_distances_based_on_gensim(model=model, node_names=node_names)
    """

    if save:
        save_info.save_distance_matrix(removed_nodes, iteration, dm)

    return dm