philsupertramp/game-math
Loading...
Searching...
No Matches
Classes | Enumerations | Functions
Probability.h File Reference
#include "../Matrix.h"
#include "../matrix_utils.h"

Go to the source code of this file.

Classes

struct  LinearModel
 

Enumerations

enum  P_NORM { Inf , One , Eukl }
 

Functions

double getExponent (double x)
 
double round (double x, int precision)
 
double abs (double x)
 
double pow (double x, int exponent)
 
double norm (const Matrix< double > &vec, P_NORM pNorm)
 
double cov (const Matrix< double > &x, const Matrix< double > &y)
 
double var (const Matrix< double > &x)
 
Matrix< double > sd (const Matrix< double > &x, int axis=0)
 
LinearModel lm (const Matrix< double > &x, const Matrix< double > &y)
 
double coefficientOfDetermination (const Matrix< double > &y, const Matrix< double > &yHat)
 
double likelihood (const Matrix< double > &)
 
Matrix< double > Regression (const Matrix< double > &A)
 
Matrix< double > corr (const Matrix< double > &A, const Matrix< double > &B)
 
Matrix< double > expected_value (const Matrix< double > &A)
 

Detailed Description

Contains methods of the field of probability calculation.

Enumeration Type Documentation

◆ P_NORM

enum P_NORM

enum to chose a norm to compute

Enumerator
Inf 

$$||x||_\infty$$

One 

$$||x||_1$$

Eukl 

$$||x||_2$$

Function Documentation

◆ abs()

double abs ( double  x)

Absolute value $$|x|$$

Parameters
xa value
Returns
$$|x|$$

◆ coefficientOfDetermination()

double coefficientOfDetermination ( const Matrix< double > &  y,
const Matrix< double > &  yHat 
)

The coefficient of determination ($R^2$) is the proportion of the variation in the dependent variable that is predictable from independent variables.

$$R^2 = \frac{\text{var}(y)}{\text{var}(\hat{y})}$$

Parameters
y$$y$$
yHat$$\hat{y}$$
Returns
proportion of the variation

◆ corr()

Matrix< double > corr ( const Matrix< double > &  A,
const Matrix< double > &  B 
)

Computes correlation matrix of two matrices

$$ \text{corr}(X, Y) = \frac{\text{cov}(X, Y)}{\sigma_X\sigma_Y} $$ with $\sigma$ the standard deviations of $X$ and $Y$.

The correlation matrix contains correlation coefficients $\text{corr}_{x_i, y_i} \in [-1, 1]$.

  • negative correlation coefficients: The values negatively influence each other
  • positive correlation coefficients: The values positively influence each other
  • neutral correlation coefficients: The values don't influence each other
    Parameters
    Athe first matrix of values
    Bsecond matrix of values in same shape as A
    Returns
    The correlation matrix of A and B
Examples
statistics/TestProbability.cpp.

◆ cov()

double cov ( const Matrix< double > &  x,
const Matrix< double > &  y 
)

Computes covariance of two given vectors $$\text{cov}(x, y) = E[(x - E[x])(y - E[y])]$$

The covariance is a measure of joint variability of two random variables.

  • Positive covariance -> variables have same tendencies, i.e. high and low values in both variables at the same time
  • Negative covariance -> variables have different tendencies, i.e. high values in variable $x$ correspond to low values in variable $y$ and vice versa
Parameters
xa vector
yanother vector
Returns
resulting covariance

◆ expected_value()

Matrix< double > expected_value ( const Matrix< double > &  A)

Computes the expected value of a given vector.

$$ E[X] = \sum x_i P(x_i) $$

The expected value is a generalization of the weighted average. Given a set of random values, the expected value is the value that is most likely to occur within given distribution of values.

Parameters
Athe matrix to caclulate the expected value(s) of, each row will receive a corresponding expected value
Returns
The expected value(s) of A

◆ getExponent()

double getExponent ( double  x)

regular helpers Method to calculate exponent of given value

Parameters
xvalue to calculate exponent of
Returns
exponent

◆ likelihood()

double likelihood ( const Matrix< double > &  )

Computes likelihood

Returns

◆ lm()

LinearModel lm ( const Matrix< double > &  x,
const Matrix< double > &  y 
)

Computes linear (regression) model for given random sample $$ (Y_i; X_i) $$ $$ Y_i = \beta_0 + \beta_1\phi_1(x_i) + \epsilon_i $$

Parameters
x$$X_i$$
y$$Y_i$$
Returns
constructed linear model
Examples
statistics/TestProbability.cpp.

◆ norm()

double norm ( const Matrix< double > &  vec,
P_NORM  pNorm 
)

Calculates the Norm of a given vector

Parameters
vecvector to calculate the norm of
pNormdesired norm to compute
Returns
computed norm value

◆ pow()

double pow ( double  x,
int  exponent 
)

calculates $$x^{exponent}$$

Parameters
xa value
exponentdesired exponent
Returns
$$x^{exponent}$$
Examples
statistics/TestProbability.cpp, and symb/TestSymbolic.cpp.

◆ Regression()

Matrix< double > Regression ( const Matrix< double > &  A)

Computes orthogonal-linear regression for given values A, mapped onto points $$P(i, a_i)$$.

$$Y_i = \beta_0 + \beta_1 * a_i$$

Parameters
Avector of y-values
Returns
A vector of x-value approximations
Examples
statistics/TestProbability.cpp.

◆ round()

double round ( double  x,
int  precision 
)

Rounds double value to given precision, cuts off other elements

Parameters
xvalue to round
precisionprecision in resulting value
Returns
rounded value
Examples
statistics/TestProbability.cpp.

◆ sd()

Matrix< double > sd ( const Matrix< double > &  x,
int  axis = 0 
)

Computes standard deviation of given vector $$ \text{sd}(x) = \sigma(x) = \sqrt{E[(X-\mu)^2]} = \sqrt{E[X^2] - (E[X])^2} $$

The standard deviation is a measure of variance or dispersion of a set of values.

Parameters
xset of values to compute standard deviation from @returnss standard deviation of given x
Examples
statistics/TestProbability.cpp.

◆ var()

double var ( const Matrix< double > &  x)

Computes variance of given vector $$\text{var}(x)=E[(X - \mu)^2] = \text{cov}(X,X)$$

The variance is the expectation of the square deviation of a random variable from its population mean or sample mean.

Parameters
xa vector
Returns
$$\text{var}(x)$$