orderings

Methods for orderings for signals.

Methods return flattened indices. Hopefully these orderings make the signals more sparse in some domain.

mr_utils.utils.orderings.brute_force1d(x, T)[source]

Given transform matrix, T, sort 1d signal exhaustively.

Parameters:
  • x (array_like) – 1D signal to find ordering of.
  • T (array_like) – Transform matrix.
Returns:

  • array_like – Flattened indices giving sorted order.
  • .. warning:: – This IS NOT A GOOD IDEA.

mr_utils.utils.orderings.bulk_up(x, T, Ti, k)[source]

Given existing nonzero coefficients, try to make large ones larger.

Parameters:
  • x (array_like) – Array to find ordering of.
  • T (callable) – Transform function.
  • Ti (callable) – Inverse transform function.
  • k (float) – Percent of coefficients to shoot for.
Returns:

idx – Flattened indices giving sorted order.

Return type:

array_like

Notes

Uses random_match(), should probably use min linear assignment.

mr_utils.utils.orderings.col_stacked_order(x)[source]

Find ordering of monotonically varying flattened array, x.

Parameters:x (array_like) – Array to find ordering of.
Returns:idx – Flattened indices giving sorted order.
Return type:array_like

Notes

Note that you might want to provide abs(x) if x is a complex array.

mr_utils.utils.orderings.colwise(x)[source]

Find ordering of monotonically varying columns.

Parameters:x (array_like) – Array to find ordering of.
Returns:idx – Flattened indices giving sorted order.
Return type:array_like
mr_utils.utils.orderings.gen_sort1d(x, T)[source]

Given 1D transform T, sort 1d signal, x.

Parameters:
  • x (array_like) – 1D signal to find ordering of.
  • T (array_like) – Transform matrix.
Returns:

Flattened indices giving sorted order.

Return type:

array_like

mr_utils.utils.orderings.get_gini_sort(vals)[source]

Sort groups so that we get largest possible coefficients.

mr_utils.utils.orderings.get_gini_sort2(vals)[source]

Sort groups to get highest possible single coefficient.

Notes

Get the largest coefficient we can and then minimize the others.

mr_utils.utils.orderings.inverse_permutation(ordering)[source]

Given some permutation, find the inverse permutation.

Parameters:ordering (array_like) – Flattened indicies, such as output of np.argsort.
Returns:Inverse permutation.
Return type:inverse_ordering
mr_utils.utils.orderings.random_match(x, T, return_sorted=False)[source]

Match x to T as closely as possible pixel by pixel.

Parameters:
  • x (array_like) – Array to find ordering of.
  • T (array_like) – Target matrix.
  • return_sorted (bool, optional) – Whether or not to return the sorted matrix.
Returns:

  • idx (array_like) – Flattened indices giving sorted order.
  • array_like, optional – Sorted array.

mr_utils.utils.orderings.random_match_by_col(x, T, return_sorted=False)[source]

Given matrix T, choose reordering of x that matches it col by col.

Parameters:
  • x (array_like) – Array to find ordering of.
  • T (array_like) – Target matrix.
  • return_sorted (bool, optional) – Whether or not to return the sorted matrix.
Returns:

  • idx (array_like) – Flattened indices giving sorted order.
  • array_like, optional – Sorted array.

Given transform T, find the best of k permutations.

Parameters:
  • x (array_like) – Array to find the ordering of.
  • T (array_like or callable) – Transform matrix/function that we want x to be sparse under.
  • k (int) – Number of permutations to try (randomly selected).
  • compare ({'nonzero', 'l1'} or callable, optional) – How to compare two permutations.
  • compare_opts (dict, optional) – Arguments to pass to compare function.
  • disp (bool, optional) – Verbose mode.
Returns:

Flattened indices giving sorted order.

Return type:

array_like

Raises:

NotImplementedError – If compare is not valid option or callable.

mr_utils.utils.orderings.rowwise(x)[source]

Find ordering of monotonically varying rows.

Parameters:x (array_like) – Array to find ordering of.
Returns:idx – Flattened indices giving sorted order.
Return type:array_like
mr_utils.utils.orderings.whittle_down(x, T, Ti, k)[source]

Given existing nonzero coefficients, try to remove lower ones.

Parameters:
  • x (array_like) – Array to find ordering of.
  • T (callable) – Transform function.
  • Ti (callable) – Inverse transform function.
  • k (float) – Percent of coefficients to shoot for.
Returns:

idx – Flattened indices giving sorted order.

Return type:

array_like

Notes

Uses random_match(), should probably use min linear assignment.