| 1 |
/* |
| 2 |
* Copyright (C) 1996-2011 Daniel Waggoner |
| 3 |
* |
| 4 |
* This free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation, either version 3 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* It is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* If you did not received a copy of the GNU General Public License |
| 15 |
* with this software, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#ifndef __ELLIPTICAL_DISTRIBUTIONS__ |
| 19 |
#define __ELLIPTICAL_DISTRIBUTIONS__ |
| 20 |
|
| 21 |
#include "dw_matrix.h" |
| 22 |
#include <stdio.h> |
| 23 |
|
| 24 |
typedef struct TElliptical_tag |
| 25 |
{ |
| 26 |
PRECISION logabsdet; // = -ln(abs(det(scale)))) |
| 27 |
int dim; // = dimension of elliptical random vector |
| 28 |
PRECISION variance_scale; // variance = variance_scale * (scale * scale') |
| 29 |
TVector center; // mean = center |
| 30 |
TMatrix scale; |
| 31 |
TMatrix quadratic_form; // Inverse(scale * scale') |
| 32 |
TVector draw; |
| 33 |
char *type; |
| 34 |
|
| 35 |
void *data; |
| 36 |
|
| 37 |
PRECISION (*logdensity_radius)(PRECISION, struct TElliptical_tag *); |
| 38 |
PRECISION (*logdensity_draw)(PRECISION*, struct TElliptical_tag *); |
| 39 |
PRECISION (*cummulative_radius)(PRECISION, struct TElliptical_tag *); |
| 40 |
PRECISION (*draw_vector)(PRECISION*, struct TElliptical_tag *); |
| 41 |
void (*print_info)(FILE *, struct TElliptical_tag *); |
| 42 |
void (*free)(void*); |
| 43 |
|
| 44 |
} TElliptical; |
| 45 |
|
| 46 |
typedef struct |
| 47 |
{ |
| 48 |
TMatrix variance; |
| 49 |
PRECISION logconstant; |
| 50 |
PRECISION lower_bound; |
| 51 |
PRECISION upper_bound; |
| 52 |
PRECISION cumulative_lower_bound; |
| 53 |
PRECISION cumulative_upper_bound; |
| 54 |
PRECISION probability; |
| 55 |
} TElliptical_gaussian; |
| 56 |
|
| 57 |
typedef struct |
| 58 |
{ |
| 59 |
PRECISION lower_bound; |
| 60 |
PRECISION upper_bound; |
| 61 |
PRECISION power; |
| 62 |
PRECISION shift; |
| 63 |
PRECISION multiplier; |
| 64 |
PRECISION logconstant; |
| 65 |
} TElliptical_power; |
| 66 |
|
| 67 |
typedef struct |
| 68 |
{ |
| 69 |
PRECISION *t; |
| 70 |
int m; |
| 71 |
PRECISION logconstant; |
| 72 |
} TElliptical_step; |
| 73 |
|
| 74 |
void FreeElliptical(TElliptical *elliptical); |
| 75 |
PRECISION RadiusElliptical(PRECISION *draw, TElliptical *elliptical); |
| 76 |
#define DrawElliptical(draw,elliptical) ((elliptical)->draw_vector(draw,elliptical)) |
| 77 |
#define LogDensityElliptical_Radius(radius,elliptical) ((elliptical)->logdensity_radius(radius,elliptical)) |
| 78 |
#define LogDensityElliptical_Draw(draw,elliptical) ((elliptical)->logdensity_draw(draw,elliptical)) |
| 79 |
#define CummulativeDensityElliptical_Radius(radius,elliptical) ((elliptical)->cummulative_radius(radius,elliptical)) |
| 80 |
#define PrintEllipticalInfo(f_out,elliptical) ((elliptical)->print_info(f_out,elliptical)) |
| 81 |
#define EllipticalType(elliptical) ((elliptical)->type) |
| 82 |
void PrintEllipticalInfo_full(FILE *f_out, TElliptical *elliptical); |
| 83 |
|
| 84 |
PRECISION VarianceScale_TruncatedPower(int dim, PRECISION lower_bound, PRECISION upper_bound, PRECISION power); |
| 85 |
PRECISION VarianceScale_TruncatedGaussian(int dim, PRECISION lower_bound, PRECISION upper_bound); |
| 86 |
PRECISION VarianceScale_Step(int dim, PRECISION *t, int m); |
| 87 |
|
| 88 |
TElliptical* CreateElliptical_TruncatedGaussian(int dim, TVector mean, TMatrix variance, PRECISION lower_bound, PRECISION upper_bound); |
| 89 |
TElliptical* CreateElliptical_Gaussian(int dim, TVector mean, TMatrix variance); |
| 90 |
TElliptical* CreateElliptical_Uniform(int dim, TVector center, TMatrix scale, PRECISION lower_bound, PRECISION upper_bound); |
| 91 |
TElliptical* CreateElliptical_Power(int dim, TVector center, TMatrix scale, PRECISION bound, PRECISION power); |
| 92 |
TElliptical* CreateElliptical_TruncatedPower(int dim, TVector center, TMatrix scale, |
| 93 |
PRECISION lower_bound, PRECISION upper_bound, PRECISION power); |
| 94 |
TElliptical* CreateElliptical_Step(int dim, TVector center, TMatrix scale, PRECISION *table, int m); |
| 95 |
|
| 96 |
#endif |
| 97 |
|
| 98 |
/******************************************************************************** |
| 99 |
|
| 100 |
The random vector x is spherical and centered at zero if and only if the density |
| 101 |
of x depends only on the norm of x. |
| 102 |
|
| 103 |
The random vector z is elliptical if and only if z = S*x + c for some spherical |
| 104 |
random vector x centered at zero. We call the square invertiable matrix S the |
| 105 |
scale and the vector c the center. If h(x) is the density of the random vector |
| 106 |
x, then the density of the random vector z is |
| 107 |
|
| 108 |
h(Inverse(S)*(z - c))/abs(det(S)). |
| 109 |
|
| 110 |
Elliptical distributions can be characterized by their scale, center, and a one |
| 111 |
dimensional distribution with non-negative support. If r is a one-dimensional |
| 112 |
random variable with positive support, y is the random vector that has the |
| 113 |
uniform distribution on the n-1 dimensional unit sphere, and r and y are |
| 114 |
independent, then z = r*S*y + c is elliptical with scale S and center c. If the |
| 115 |
density of r is given by f(r), then the density of x = r*y is given by |
| 116 |
|
| 117 |
h(x) = f(r)/S(r,n-1) |
| 118 |
|
| 119 |
where S(r,n-1) is the surface area of the n-1 dimensional sphere of radius r. |
| 120 |
S(r,n-1) is given by |
| 121 |
|
| 122 |
S(r,n-1) = [2*pi^(n/2))/gamma(n/2)]*(r^(n-1)) |
| 123 |
|
| 124 |
where gamma() is the gamma function. (Note that n*gamma(n/2)=2*gamma(n/2+1)). |
| 125 |
This gives that the log of the density of z is given by |
| 126 |
|
| 127 |
-ln(abs(det(S)))-ln(2)-0.5*n*ln(pi)+ln(gamma(n/2))-(n-1)*ln(r)+ln(f(r)) |
| 128 |
|
| 129 |
where r=(z-c)'*Inverse(S*S')*(z-c). |
| 130 |
|
| 131 |
--------------------------------------------------------------------------------- |
| 132 |
Note that |
| 133 |
|
| 134 |
E[z] = c |
| 135 |
|
| 136 |
and |
| 137 |
|
| 138 |
E[(z-E[z])*(z-E[z])'] = S*E[x*x']*S' = E[r^2]*S*E[y*y']*S' |
| 139 |
= sigma^2*E[r^2]*(S*S') |
| 140 |
|
| 141 |
where E[y*y'] = (sigma^2)*I(n) and I(n) is the n-dimensional identity matrix. By |
| 142 |
considering the n-dimensional standard normal distribution, which is spherical, |
| 143 |
one sees that: |
| 144 |
|
| 145 |
sigma^2 = 1/n |
| 146 |
|
| 147 |
--------------------------------------------------------------------------------- |
| 148 |
The mapping to the data structure is: |
| 149 |
|
| 150 |
variance_scale = sigma^2*E[r^2] |
| 151 |
center = c |
| 152 |
scale = S |
| 153 |
quadratic_form = Inverse(S*S') |
| 154 |
logabsdet = -ln(abs(det(S))) |
| 155 |
dim = n |
| 156 |
|
| 157 |
********************************************************************************/ |