| Bsoft 2.0.5 Bernard's software package

Functions
matrix_util.h File Reference

Utility functions for matrices. More...

`#include "Matrix.h"`
`#include "rwimg.h"`

Go to the source code of this file.

## Functions
int | matrix_normalize (Matrix &m)
| Normalizes a matrix. More...
double | matrix_find_cutoff_for_number (Matrix m, int n)
| Calculates a cutoff to ensure that the given number of elements fall below it. More...
int | matrix_log_1_R (Matrix matrix)
| Calculates the logarithmic derivative of an R-factor in a matrix. More...
int * | matrix_find_linear_sequence (Matrix, int window)
| Finds a linear sequence of elements based on a pairwise matrix. More...
int | matrix_permute (int i, int j, Matrix, int *order, double *best_R, int *best_order)
| Permutes the order of a pairwise matrix and calculate a distance criterion. More...
double | matrix_calc_dist_fit (Matrix, int *order)
| Calculates an R-factor for a specific order of elements in a pairwise matrix. More...
Bimage * | img_from_matrix (Matrix &matrix, long scale)
| Converts a matrix to an image. More...

## Detailed Description

Utility functions for matrices.

Author
  Bernard Heymann

Date
  Created: 20010723
  Modified: 20190911

Definition in file matrix_util.h.

## Function Documentation

## ◆ img_from_matrix()

Bimage* img_from_matrix | ( | Matrix & | matrix,
|  | long | scale
| ) |  |

Converts a matrix to an image.

Parameters

  matrix | matrix.
  scale | integer scale for enlarging the image.

Returns
  Bimage* new image.

Definition at line 298 of file matrix_util.cpp.

## ◆ matrix_calc_dist_fit()

double matrix_calc_dist_fit | ( | Matrix | matrix,
|  | int * | order
| ) |  |

Calculates an R-factor for a specific order of elements in a pairwise matrix.

Parameters

  matrix | pairwise square matrix.
  *order | n-value array holding the order.

Returns
  double the R-factor.

      A new matrix is composed with the lower triangle taken from the input
      matrix in the given order, and the upper triangle calculated as the
      sum of the diagonal elements between the indices of the element.
      I.e, if i and j are the indices of an upper triangle element, then
      it is the sum of all the diagonal elements from i to j:
          up(i,j) = sum(mat(k,k+1)) for i<=k<j
      The difference between the lower and upper triangles is then calculated
      as:
                    1      up(i,j) - upmin   lo(j,i) - lomin
          R = sum(----- * (--------------- - ---------------) )
                  i - j     upmax - upmin     lomax - lomin
      where upmin, upmax, lomin, and lomax are the extremes in each triangle.

Definition at line 232 of file matrix_util.cpp.

## ◆ matrix_find_cutoff_for_number()

double matrix_find_cutoff_for_number | ( | Matrix | m,
|  | int | n
| ) |  |

Calculates a cutoff to ensure that the given number of elements fall below it.

Parameters

  m | pairwise square matrix.
  n | number of elements below cutoff.

Returns
  double cutoff.

      Each column is scanned and the cutoff adjusted so that at least the
      given number of elements will fall below it.

Definition at line 78 of file matrix_util.cpp.

## ◆ matrix_find_linear_sequence()

int* matrix_find_linear_sequence | ( | Matrix | matrix,
|  | int | window
| ) |  |

Finds a linear sequence of elements based on a pairwise matrix.

Parameters

  matrix | pairwise square matrix.
  window | range of elements to permute.

Returns
  int* the best order, NULL on error.

Definition at line 129 of file matrix_util.cpp.

## ◆ matrix_log_1_R()

int matrix_log_1_R | ( | Matrix | matrix | ) |

Calculates the logarithmic derivative of an R-factor in a matrix.

Parameters

  matrix | pairwise square matrix.

Returns
  int 0.

Definition at line 107 of file matrix_util.cpp.

## ◆ matrix_normalize()

int matrix_normalize | ( | Matrix & | m | ) |

Normalizes a matrix.

Parameters

  &m | matrix.

Returns
  int 0.

      The rows and columns are alternatively iteratively normalized until
      the error is small enough.

Definition at line 27 of file matrix_util.cpp.

## ◆ matrix_permute()

int matrix_permute | ( | int | i,
|  | int | j,
|  | Matrix | matrix,
|  | int * | order,
|  | double * | best_R,
|  | int * | best_order
| ) |  |

Permutes the order of a pairwise matrix and calculate a distance criterion.

Parameters

  i | start of window within the order array.
  j | end of window within the order array.
  matrix | pairwise square matrix.
  *order | n-value array holding the current order.
  *best_R | R-factor for the best order.
  *best_order | n-value array holding the best order.

Returns
  int 0.

      A recursive function to pass through all possible permutations
      within a given window.

Definition at line 182 of file matrix_util.cpp.