/Users/bernard/b20/bsoft/include/math_util.h(3)

NAME
/Users/bernard/b20/bsoft/include/math_util.h - Header file for general utilities.

SYNOPSIS

#include <stdlib.h>
#include <cmath>
#include 'Bstring.h'
#include 'utilities.h'

  Functions
double bfloor (double value, int places)
Truncates a value to a specified number of decimal places.
double bround (double value, int places)
Rounds a value to a specified number of decimal places.
double factorial (int n)
Calculates the factorial of n.
double number_of_combinations (int n, int r)
Calculates the number of combinations of size r in set of size n.
int partition (vector< double > &a, int n, int k)
Determines the index k'th value in the array.
int partition (double *a, int n, int k)
long * prime_factors (long number, long &n)
Finds all the prime factor for the input number.
long smallest_prime (long number)
Finds the smallest prime number factor of the input number.
int next_permutation (Bstring &s)
Produces the next permutation in lexical order.
double fishers_z_transform (double value)
Calculates Fisher's z-transform.
double betacf (double a, double b, double x)
Evaluates the continued fraction for the incomplete beta function.
double betai (double a, double b, double x)
Calculates the incomplete beta function Ix(a,b).
double kmeans_threshold (long n, double *v)
Finds a threshold that partitions an array into foreground and background clusters.

Detailed Description

Header file for general utilities.

Author:
    Bernard Heymann

Date:
    Created: 19990722

    Modified: 20151203

Definition in file math_util.h.

Function Documentation

  double betacf (double a, double b, double x)

Evaluates the continued fraction for the incomplete beta function.

Parameters:
    a first parameter.
    b second parameter.
    x domain variable [0,1].

Returns:
    double

Lentz's method.

 Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 268 of file math_util.cpp.

  double betai (double a, double b, double x)

Calculates the incomplete beta function Ix(a,b).

Parameters:
    a first parameter.
    b second parameter.
    x domain variable [0,1].

Returns:
    double

Limiting values: I0(a,b) = 0, I1(a,b) = 1.
Symmetry relation: Ix(a,b) = 1 - I1-x(b,a).

 Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 320 of file math_util.cpp.

  double bfloor (double value, int places)

Truncates a value to a specified number of decimal places.

Parameters:
    value value to be truncated.
    places number of decimal places.

Returns:
    int 0.

Definition at line 21 of file math_util.cpp.

  double bround (double value, int places)

Rounds a value to a specified number of decimal places.

Parameters:
    value value to be rounded.
    places number of decimal places.

Returns:
    double rounded value.

Definition at line 39 of file math_util.cpp.

  double factorial (int n)

Calculates the factorial of n.

All values of n less than 1 returns 1.
An exact calculation is done for 1 < n <= 50.
The Lancos approximation is used for n > 50.
Factorials of integers larger than 170 exceeds the capacity of a
double and causes program termination.
The largest relative error is for 170: 1.22378e-13.

 Reference: Press W.H. et al (1992) Numerical Recipes in C.

Parameters:
    n integer.

Returns:
    double factorial of n, <0 on error.

Definition at line 66 of file math_util.cpp.

  double fishers_z_transform (double value)

Calculates Fisher's z-transform.

Parameters:
    value a value.

Returns:
    double z value.

    Fisher's z-transform is given by:
        z = 0.5*log((1+v)/(1-v))

     Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 249 of file math_util.cpp.

  double kmeans_threshold (long n, double * v)

Finds a threshold that partitions an array into foreground and background clusters.

Parameters:
    n number of array elements.
    v array.

Returns:
    double threshold.

Limiting values: I0(a,b) = 0, I1(a,b) = 1.
Symmetry relation: Ix(a,b) = 1 - I1-x(b,a).

 Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 345 of file math_util.cpp.

  int next_permutation (Bstring & s)

Produces the next permutation in lexical order.

Parameters:
    &s string of symbols to permute.

Returns:
    int 1 = success, 0 = no next permutation.

    To get all permutations, the first string needs
    to be ordered in ascending order.

     Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 220 of file math_util.cpp.

  double number_of_combinations (int n, int r)

Calculates the number of combinations of size r in set of size n.

Parameters:
    n number in set.
    r number in subset.

Returns:
    double number of combinations, <0 on error.

    All values of n less than 1 returns 1.
    An exact calculation is done for 1 < n <= 50.
    The Lancos approximation is used for n > 50.

     Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 97 of file math_util.cpp.

  int partition (vector< double > & a, int n, int k)

Determines the index k'th value in the array.

Parameters:
    *a array.
    n number of array elements.
    k rank index to look for.

Returns:
    0

    The array is partioned into 2 sides, with the left side lower or equal
    to and the right side higher or equal to the k'th element.
    This is useful to determine the median without full sorting.

     Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 123 of file math_util.cpp.

  int partition (double * a, int n, int k)

  long* prime_factors (long number, long & n)

Finds all the prime factor for the input number.

Parameters:
    number integer.
    &n number of prime factors.

Returns:
    long* array of prime factors (can be NULL).

    Calculates the prime factors from the smallest to the largest.

     Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 152 of file math_util.cpp.

  long smallest_prime (long number)

Finds the smallest prime number factor of the input number.

Parameters:
    number integer.

Returns:
    long smallest prime factor.

    Tries to divide the given positive integer number by
    primes from 2 to the square root of the integer.
    Returns the first prime divisor found, which may be the
    input number if it is prime.

     Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 191 of file math_util.cpp.

Author

Generated automatically by Doxygen for Bsoft from the source code.