analistica/ex-7/fisher.h

67 lines
1.6 KiB
C
Raw Permalink Normal View History

2020-03-06 11:54:28 +01:00
#include "common.h"
#include <gsl/gsl_matrix.h>
/* Builds the covariance matrix Σ
* from the standard parameters (σ, ρ)
* of a bivariate gaussian.
*/
gsl_matrix* normal_cov(struct par *p);
/* Builds the mean vector of
* a bivariate gaussian.
*/
gsl_vector* normal_mean(struct par *p);
/* `fisher_proj(c1, c2)` computes the optimal
* projection map, which maximises the separation
* between the two classes.
* The projection vector w is given by
*
* w = Sw¹ (μ - μ)
*
* where Sw = Σ + Σ is the so-called within-class
* covariance matrix.
*/
gsl_vector* fisher_proj(sample_t *c1, sample_t *c2);
/* `fisher_cut(ratio, w, c1, c2)` computes
* the threshold (cut), on the line given by
* `w`, to discriminates the classes `c1`, `c2`;
* with `ratio` being the ratio of their prior
* probabilities.
*
* The cut is fixed by the condition of
* conditional probability being the
* same for each class:
*
* P(c|x) p(x|c)p(c)
* ------- = --------------- = 1;
* P(c|x) p(x|c)p(c)
*
* where p(x|c) is the probability for point x
* along the fisher projection line. If the classes
* are bivariate gaussian then p(x|c) is simply
* given by a normal distribution:
*
* Φ(μ=(w,μ), σ=(w,Σw))
*
* The solution is then
*
* t = (b/a) + ((b/a)² - c/a);
*
* where
*
* 1. a = S² - S²
* 2. b = MS² - MS²
* 3. c = M²S² - M²S² - 2S²S² log(α)
* 4. α = p(c)/p(c)
*
*/
double fisher_cut(
double ratio,
gsl_vector *w,
sample_t *c1, sample_t *c2);