Utility Functions

functions.utils.init_P_matrix(*shape)[source]

Generates a normalized probability matrix

Parameters:

shape: int or tuple of ints

Dimension of the probability matrix

Returns:

A normalized probability matrix that is normalized along the last axis

functions.utils.df_to_rst_table(df, title=None)[source]

Converts a pandas DataFrame to a RST table format.

Parameters:

df: pandas.DataFrame

The DataFrame to convert to a table.

title: str, default: None

The title of the table.

Returns:

A string with the RST table format.

functions.utils.add_codes(layer, col_name)[source]

Adds to the df property a column with an id of the value of the col_name column

Parameters:
  • layer (node_layer, BiNet) – Objects with a df attribute

  • col_name (str) – Name of the column in the df attribute that an integer id will be assigned to every different value of the column. This id is an integer that goes from 0 to N-1, where N is the number of different values in the col_name column.

Returns:

dict_codes – Dictionary where each key is a different value of the col_name column and the value is the id integer that was assigned.

Return type:

dict

functions.utils.finished(A, A_old, tol)[source]

Returns True if A and A_old are simmilar by looking if the mean absolute difference between A and A_old is lower than a tolerance tol

functions.utils.save_MMSBM_parameters(BiNet, dir='.', matrix_format='npy', BiNet_json=False)[source]

It saves the parameters into matrices in the dir directory

Parameters:

BiNet: BiNet object

Bipartite network with the MMSBM initialized

dir: str, default: “.”

Directory where the files with the MMSBM parameters will be saved

matrix_format: str, default: npy

Format that the matrices parameters will be saved. It can be, npy or npz.

BiNet_json: boolean, default: False

If it is True, the information of the BiNet class will be saved into a json.

functions.utils.save_nodes_layer_dict(layer, dir='.')[source]

It saves the some information, including the dict_codes from each layer, into a json called layer_data.json

Parameters:

layer: node_layer

Bipartite network object

dir: str

Directory where the files with the MMSBM parameters will be saved

functions.utils.save_BiNet_dict(BiNet, dir='.')[source]

It saves the some information, including the dict_codes from each layer, into a json called BiNet_data.json

Parameters:

BiNet: BiNet object

Bipartite network object

dir: str

Directory where the files with the MMSBM parameters will be saved

functions.utils.load_EM_parameters(BiNet, directory='.')[source]

It loads the parameters from matrices in the directory

Parameters:

BiNet: BiNet object

Bipartite network with the MMSBM initialized

directory: str, default: “.”

Directory where the files with the MMSBM parameters will be loaded