lmpy.randomize.grady

Randomize PAMs using CJ’s algorithm.

This module contains functions used to randomize a PAM using CJ’s algorithm. This algorithm can run in a parallel fashion and uses a fill-based approach so as to prevent a bias caused by starting with an initial condition of a populated matrix.

Module Contents

Functions

all_ones_heuristic(orig_pam)

Creates a two-dimensional approximation composed of all ones.

all_zeros_heuristic(orig_pam)

Creates a two-dimensional approximation composed of all zeros.

fill_shuffle_reshape_heuristic(orig_pam)

Create an approximation with the correct number of 1s randomly placed.

grady_randomize(mtx, approximation_heuristic=total_fill_percentage_heuristic)

Main function for creating a random matrix.

max_col_or_row_heuristic(orig_pam)

Weighting method using max weight between row and column.

min_col_or_row_heuristic(orig_pam)

Weighting method using max weight between row and column.

total_fill_percentage_heuristic(orig_pam)

Create an approximation using the total fill percentage of the PAM.

lmpy.randomize.grady.all_ones_heuristic(orig_pam)[source]

Creates a two-dimensional approximation composed of all ones.

Parameters

orig_pam (Matrix) – The observed PAM to randomize.

Returns

An approximate randomization of the PAM that is uncorrected.

Return type

Matrix

lmpy.randomize.grady.all_zeros_heuristic(orig_pam)[source]

Creates a two-dimensional approximation composed of all zeros.

Parameters

orig_pam (Matrix) – The observed PAM to randomize.

Returns

An approximate randomization of the PAM that is uncorrected.

Return type

Matrix

lmpy.randomize.grady.fill_shuffle_reshape_heuristic(orig_pam)[source]

Create an approximation with the correct number of 1s randomly placed.

Creates an array with the total number of ones from the original PAM and shuffles it then it reshapes it to match the shape of the original PAM.

Parameters

orig_pam (Matrix) – The observed PAM to randomize.

Returns

An approximate randomization of the PAM that is uncorrected.

Return type

Matrix

lmpy.randomize.grady.grady_randomize(mtx, approximation_heuristic=total_fill_percentage_heuristic)[source]

Main function for creating a random matrix.

Parameters
  • mtx (Matrix) – A Matrix object representation of a PAM

  • approximation_heuristic (Method) – A function that generates an approximation of a final randomized matrix.

Returns

A matrix of random presence absence values with the same

marginal totals as the input matrix ‘mtx’.

Return type

Matrix

lmpy.randomize.grady.max_col_or_row_heuristic(orig_pam)[source]

Weighting method using max weight between row and column.

This method returns a matrix of weights where the weight of each cell is the maximum between the proportions of the row and col

Parameters

orig_pam (Matrix) – The observed PAM to randomize.

Returns

An approximate randomization of the PAM that is uncorrected.

Return type

Matrix

lmpy.randomize.grady.min_col_or_row_heuristic(orig_pam)[source]

Weighting method using max weight between row and column.

This method returns a matrix of weights where the weight of each cell is the maximum between the proportions of the row and col

Parameters

orig_pam (Matrix) – The observed PAM to randomize.

Returns

An approximate randomization of the PAM that is uncorrected.

Return type

Matrix

lmpy.randomize.grady.total_fill_percentage_heuristic(orig_pam)[source]

Create an approximation using the total fill percentage of the PAM.

Creates an approximation using the total matrix fill of the original PAM as a weight threshold to compare with randomly generated numbers.

Parameters

orig_pam (Matrix) – The observed PAM to randomize.

Returns

An approximate randomization of the PAM that is uncorrected.

Return type

Matrix