liberata_metrics.generators package

Submodules

Module contents

liberata_metrics.generators.build_capital_matrix(references: spmatrix, shares: spmatrix) coo_matrix[source]

computes capital matrix given shares and reference at current time

liberata_metrics.generators.generate_capital_time_series(references: spmatrix, shares: spmatrix, manuscript_index_map: Dict[str, int], upload_dates: Dict[str, date], start_date: date, end_date: date, time_step: timedelta) Dict[str, object][source]

generates time series data for capital matrices at different time snapshots

liberata_metrics.generators.generate_references_matrix(num_manuscripts: int, citation_density: float = 0.05, start_date: date = datetime.date(2020, 1, 1), end_date: date = datetime.date(2024, 1, 1), seed: int | None = None) Tuple[coo_matrix, List[str], Dict[str, int], Dict[str, date], DataFrame, coo_matrix, coo_matrix][source]

build toy references matrix

liberata_metrics.generators.generate_shares_matrix(manuscript_ids: Iterable[str], manuscript_index_map: Dict[str, int], num_contributors: int, avg_contributors_per_man: int, std_contributors_per_man: int, contributor_shares_dist: str = 'dirichlet', pareto_alpha: int = 2, seed: int | None = None) Tuple[coo_matrix, List[str], Dict[str, int]][source]

build toy shares matrix

liberata_metrics.generators.get_capital_earlier(references: spmatrix, shares: spmatrix, manuscript_index_map: Dict[str, int], upload_dates: Dict[str, date], time_cutoff: date) spmatrix[source]

builds the earlier capital matrix corresponding to given time cutoff

liberata_metrics.generators.update_retractions_graph(references: spmatrix, retractions: spmatrix | None, manuscript_index_map: Dict[str, int], newly_retracted_manuscript_ids: List[str], manuscripts_metadata: DataFrame | list) Tuple[csr_matrix, csr_matrix, DataFrame | list][source]

This function handles the movement of citation rows from the references graph to the retractions graph when manuscripts are newly retracted. It also updates previously retracted manuscripts to capture any new citations that occurred after retraction.

Parameters:
  • references (sparse.spmatrix) – Sparse matrix where columns represent manuscripts and rows represent cited works. Non-zero entries represent citation relationships.

  • retractions (Union[sparse.spmatrix, None]) – Sparse matrix of the same shape as references containing previously retracted manuscript citations. If None, an empty sparse matrix is initialized.

  • manuscript_index_map (Dict[str, int]) – Mapping from manuscript IDs to their corresponding row indices in the matrices.

  • newly_retracted_manuscript_ids (List[str]) – List of manuscript IDs that have been newly retracted in this update.

  • manuscripts_metadata (Union[pd.DataFrame, list]) – Metadata associated with manuscripts. If a DataFrame, the retraction_cutoff column is updated for newly retracted manuscripts.

Returns:

A tuple containing: - retractions (sparse.coo_matrix): Updated retractions graph with newly retracted

and previously retracted manuscript citations.

  • references (sparse.coo_matrix): Updated references graph with retracted manuscript rows zeroed out.

  • manuscripts_metadata (Union[pd.DataFrame, list]): Updated metadata with retraction information for newly retracted manuscripts.

Return type:

Tuple[sparse.csr_matrix, sparse.csr_matrix, Union[pd.DataFrame, list]]

Notes

  • Both newly retracted and previously retracted manuscript rows are removed from the references graph and consolidated in the retractions graph.

  • If manuscripts_metadata is not a DataFrame, a warning is issued and metadata is returned unchanged.

  • Output matrices are converted to COO format for sparse representation efficiency.