pf_pdf.h
00001 /* 00002 * Player - One Hell of a Robot Server 00003 * Copyright (C) 2003 00004 * Andrew Howard 00005 * Brian Gerkey 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 */ 00022 00023 00024 /************************************************************************** 00025 * Desc: Useful pdf functions 00026 * Author: Andrew Howard 00027 * Date: 10 Dec 2002 00028 * CVS: $Id: pf_pdf.h 8108 2009-07-23 23:03:37Z thjc $ 00029 *************************************************************************/ 00030 00031 #ifndef PF_PDF_H 00032 #define PF_PDF_H 00033 00034 #include "pf_vector.h" 00035 00036 //#include <gsl/gsl_rng.h> 00037 //#include <gsl/gsl_randist.h> 00038 00039 #ifdef __cplusplus 00040 extern "C" { 00041 #endif 00042 00043 /************************************************************************** 00044 * Gaussian 00045 *************************************************************************/ 00046 00047 // Gaussian PDF info 00048 typedef struct 00049 { 00050 // Mean, covariance and inverse covariance 00051 pf_vector_t x; 00052 pf_matrix_t cx; 00053 //pf_matrix_t cxi; 00054 double cxdet; 00055 00056 // Decomposed covariance matrix (rotation * diagonal) 00057 pf_matrix_t cr; 00058 pf_vector_t cd; 00059 00060 // A random number generator 00061 //gsl_rng *rng; 00062 00063 } pf_pdf_gaussian_t; 00064 00065 00066 // Create a gaussian pdf 00067 pf_pdf_gaussian_t *pf_pdf_gaussian_alloc(pf_vector_t x, pf_matrix_t cx); 00068 00069 // Destroy the pdf 00070 void pf_pdf_gaussian_free(pf_pdf_gaussian_t *pdf); 00071 00072 // Compute the value of the pdf at some point [z]. 00073 //double pf_pdf_gaussian_value(pf_pdf_gaussian_t *pdf, pf_vector_t z); 00074 00075 // Draw randomly from a zero-mean Gaussian distribution, with standard 00076 // deviation sigma. 00077 // We use the polar form of the Box-Muller transformation, explained here: 00078 // http://www.taygeta.com/random/gaussian.html 00079 double pf_ran_gaussian(double sigma); 00080 00081 // Generate a sample from the the pdf. 00082 pf_vector_t pf_pdf_gaussian_sample(pf_pdf_gaussian_t *pdf); 00083 00084 00085 #if 0 00086 00087 /************************************************************************** 00088 * Discrete 00089 *************************************************************************/ 00090 00091 // Discrete PDF info 00092 typedef struct 00093 { 00094 // The list of discrete probs 00095 int prob_count; 00096 double *probs; 00097 00098 // A random number generator 00099 gsl_rng *rng; 00100 00101 // The discrete prob generator 00102 gsl_ran_discrete_t *ran; 00103 00104 } pf_pdf_discrete_t; 00105 00106 00107 // Create a discrete pdf 00108 pf_pdf_discrete_t *pf_pdf_discrete_alloc(int count, double *probs); 00109 00110 // Destroy the pdf 00111 void pf_pdf_discrete_free(pf_pdf_discrete_t *pdf); 00112 00113 // Compute the value of the probability of some element [i] 00114 double pf_pdf_discrete_value(pf_pdf_discrete_t *pdf, int i); 00115 00116 // Generate a sample from the the pdf. 00117 int pf_pdf_discrete_sample(pf_pdf_discrete_t *pdf); 00118 #endif 00119 00120 #ifdef __cplusplus 00121 } 00122 #endif 00123 00124 #endif