basic_rearrange

rearrangement_algorithm.basic_rearrange(x_mat, optim_func, lookback=0, tol=0.0, tol_type='absolute', max_ra=0, cost_func=<function sum>, is_sorted=False, *args, **kwargs)

Implementation of the matrix rearrangement algorithm.

Basic implementation of the rearrangement algorithm to get a permutation of a matrix \(X\) such that each column \(j\) is oppositely ordered to the vector derived by applying a function \(\psi\) to the (sub-)matrix without column \(j\).

The implementation is based on the R library qrmtools 1. A detailed description can be found in 2.

Parameters
  • x_mat (2D-array or matrix) – Matrix of shape (num_samples, num_var) that will get rearranged.

  • optim_func (func) – Internal optimization function. It needs to take a vector-argument and return a scalar. This usually is either min() or max().

  • lookback (int, optional) – Number of rearrangement steps to look back to determine convergence.

  • tol (float, optional) – Tolerance to determine convergence.

  • tol_type (str, optional) – Tolerance function used. Possible options are “absolute” and “relative”.

  • max_ra (int, optional) – Number of maximum column rearrangements. If 0, there will be no limit.

  • cost_func (func, optional) – Cost function \(\psi\) that is applied to each row. It takes a 2D numpy.array as input and outputs a vector that results by applying the function to each row. It needs to take the keyword argument axis in the numpy style. An example for the sum is numpy.sum().

  • is_sorted (bool, optional) – Indicates wheter the columns of the matrix x_mat are sorted in increasing order.

Returns

x_rearranged – Rearranged matrix of shape (num_samples, num_var).

Return type

numpy.array

References

1

M. Hofert, K. Hornik, and A. J. McNeil, “qrmtools: Tools for Quantitative Risk Management.” Version 0.0-13 (https://cran.r-project.org/web/packages/qrmtools/index.html)

2

M. Hofert, “Implementing the Rearrangement Algorithm: An Example from Computational Risk Management,” Risks, vol. 8, no. 2, May 2020.