lmpy.randomize.swap

Module containing Gotelli swap method for randomizing a PAM.

Module Contents

Functions

swap_randomize(matrix, num_swaps, max_tries=MAX_TRIES_WITHOUT_SWAP)

Randomize a PAM matrix using the Gotelli swap method.

trial_swap(matrix, num_trials=None)

Randomize a PAM matrix using the trial swap method.

lmpy.randomize.swap.swap_randomize(matrix, num_swaps, max_tries=MAX_TRIES_WITHOUT_SWAP)[source]

Randomize a PAM matrix using the Gotelli swap method.

Parameters
  • matrix (Matrix) – A Lifemapper matrix object with binary elements

  • num_swaps (int) – The number of swaps to perform

  • max_tries (int) – The maximum number of attempts to swap before failing.

Returns

A randomized matrix.

Return type

Matrix

Raises

Exception – Raised when the maximum number of tries is reached without swapping.

lmpy.randomize.swap.trial_swap(matrix, num_trials=None)[source]

Randomize a PAM matrix using the trial swap method.

Parameters
  • matrix (Matrix) – A Lifemapper matrix object with binary elements.

  • num_trials (int) – The number of trials to perform.

Returns

A randomized matrix.

Return type

Matrix