Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ProbabilityDensity.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 Reinhard Prix
3 *
4 * This program is 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 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program 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 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19
20/*********************************************************************************/
21/**
22 * \author R. Prix
23 * \file
24 * \brief
25 * Header file containing the exported API for the ProbabilityDensity Module.
26 *
27 */
28
29#ifndef _PROBABILITY_DENSITY_H
30#define _PROBABILITY_DENSITY_H
31
32/* C++ protection. */
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/* ---------- System includes ---------- */
38#include <math.h>
39
40/* gsl-includes */
41#include <gsl/gsl_rng.h>
42#include <gsl/gsl_randist.h>
43
44/* LAL-includes */
45#include <lal/LALDatatypes.h>
46
47/* ---------- exported API defines ---------- */
48
49/* ---------- exported API types ---------- */
50
51/**
52 * Encode a pdf(x) as a discretized function probDens[i] = pdf( x[i] ) with user-specified bins xBin[i].
53 * We store the actual probability *density values, such that prob(x in xBin[i]) = probDens[i] * xBin[i].
54 *
55 * NOTE: Allows for some special encodings for simplicity and efficiency:
56 * - one x0 known with certainty: pdf(x) = delta(x-x0): ==> xTics = {x0}, probDens=NULL
57 * - uniform pdf over [xMin,xMax]: pdf(x) = const. ==> xTics = {xMin, xMax}, probDens=NULL
58 *
59 * NOTE2: the optional field 'sampling' is used to buffer gsl-precomputed internals to allow using
60 * gsl_ran_discrete() to efficiently draw samples from that distribution (cost ~ O(1)).
61 * This field is only for internal use, and will be created automatically by XLALDrawFromPDF1D()
62 * if it's not initialized yet.
63 *
64 */
65struct tagpdf1D_t {
66 REAL8Vector *xTics; /**< N+1-dim vector of ordered x 'tics', i.e. bin-boundaries {x[0], x[1], x[2], ... x[N]} */
67 REAL8Vector *probDens; /**< N-dim vector of binned probability densities probDens[i] = prob( x in [ x[i],x[i+i] )/xBin[i] */
68 BOOLEAN isNormalized; /**< true if the prob is normalized, ie 1 = int P(x) dx ~ sum_i probDens[i] xBin[i] */
69 gsl_ran_discrete_t *sampling; /**< internal: buffer preprocessed sampling distribution for drawing samples using gsl_ran_discrete() */
70};
71
72
73/**
74 * Probability-density function object type.
75 * This could be made into an *opaque* type, such that only methods defined in ProbabilityDensity.c
76 * can operate on the internals of such objects. Everyone would only be able to pass them around.
77 * This requires lots more methods though to be useful, so for now this move is postponed.
78 */
79typedef struct tagpdf1D_t pdf1D_t;
80
81
82/* empty struct initializers */
83
84
85/* ---------- exported API prototypes ---------- */
86pdf1D_t *XLALCreateSingularPDF1D( REAL8 x0 );
87pdf1D_t *XLALCreateUniformPDF1D( REAL8 xMin, REAL8 xMax );
88pdf1D_t *XLALCreateDiscretePDF1D( REAL8 xMin, REAL8 xMax, UINT4 numBins );
89
90REAL8 XLALDrawFromPDF1D( pdf1D_t *pdf, const gsl_rng *rng );
91int XLALCheckValidPDF1D( const pdf1D_t *pdf );
92int XLALNormalizePDF1D( pdf1D_t *pdf );
93
94REAL8 XLALFindModeOfPDF1D( const pdf1D_t *pdf );
95
96int XLALOutputPDF1D_to_fp( FILE *fp, const pdf1D_t *pdf, const char *name );
97
98
99void XLALDestroyPDF1D( pdf1D_t *pdf );
100
101
102#ifdef __cplusplus
103}
104#endif
105/* C++ protection. */
106
107#endif /* Double-include protection. */
int XLALOutputPDF1D_to_fp(FILE *fp, const pdf1D_t *pdf, const char *name)
Function to write a pdf1D to given filepointer fp.
pdf1D_t * XLALCreateSingularPDF1D(REAL8 x0)
Creator function for a 'singular' 1D pdf, containing a single value with certainty,...
pdf1D_t * XLALCreateDiscretePDF1D(REAL8 xMin, REAL8 xMax, UINT4 numBins)
Creator function for a generic discrete 1D pdf over [xMin, xMax], discretized into numBins bins.
int XLALNormalizePDF1D(pdf1D_t *pdf)
Method to normalize the given pdf1D.
REAL8 XLALFindModeOfPDF1D(const pdf1D_t *pdf)
Find the 'mode' of the probabilty distribution, ie.
pdf1D_t * XLALCreateUniformPDF1D(REAL8 xMin, REAL8 xMax)
Creator function for a uniform 1D pdf over [xMin, xMax].
void XLALDestroyPDF1D(pdf1D_t *pdf)
Destructor function for 1-D pdf.
REAL8 XLALDrawFromPDF1D(pdf1D_t *pdf, const gsl_rng *rng)
Function to generate random samples drawn from the given pdf(x) NOTE: if the 'sampling' field is NULL...
int XLALCheckValidPDF1D(const pdf1D_t *pdf)
Checks internal consistency of pdf1D object.
const char * name
Definition: SearchTiming.c:93
unsigned char BOOLEAN
double REAL8
uint32_t UINT4
Encode a pdf(x) as a discretized function probDens[i] = pdf( x[i] ) with user-specified bins xBin[i].
gsl_ran_discrete_t * sampling
internal: buffer preprocessed sampling distribution for drawing samples using gsl_ran_discrete()
BOOLEAN isNormalized
true if the prob is normalized, ie 1 = int P(x) dx ~ sum_i probDens[i] xBin[i]
REAL8Vector * probDens
N-dim vector of binned probability densities probDens[i] = prob( x in [ x[i],x[i+i] )/xBin[i]
REAL8Vector * xTics
N+1-dim vector of ordered x 'tics', i.e.