Bsoft 2.1.4
Bernard's software package
matrix_util.cpp File Reference

Utility functions for matrices. More...

#include "matrix_util.h"
#include "Matrix.h"
#include "matrix_linear.h"
#include "math_util.h"
#include "utilities.h"

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 matrix, int window)
 Finds a linear sequence of elements based on a pairwise matrix. More...
 
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. More...
 
double matrix_calc_dist_fit (Matrix matrix, int *order)
 Calculates an R-factor for a specific order of elements in a pairwise matrix. More...
 

Variables

int verbose
 

Detailed Description

Utility functions for matrices.

Author
Bernard Heymann
Date
Created: 20010723
Modified: 20150124

Function Documentation

◆ 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
matrixpairwise square matrix.
*ordern-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.

◆ 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
mpairwise square matrix.
nnumber 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.

◆ 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
matrixpairwise square matrix.
windowrange of elements to permute.
Returns
int* the best order, NULL on error.

◆ matrix_log_1_R()

int matrix_log_1_R ( Matrix  matrix)

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

Parameters
matrixpairwise square matrix.
Returns
int 0.

◆ matrix_normalize()

int matrix_normalize ( Matrix m)

Normalizes a matrix.

Parameters
&mmatrix.
Returns
int 0.
The rows and columns are alternatively iteratively normalized until
the error is small enough.

◆ 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
istart of window within the order array.
jend of window within the order array.
matrixpairwise square matrix.
*ordern-value array holding the current order.
*best_RR-factor for the best order.
*best_ordern-value array holding the best order.
Returns
int 0.
A recursive function to pass through all possible permutations
within a given window.

Variable Documentation

◆ verbose

int verbose
extern