Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInference 4.1.9.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
_bayespputils.c
Go to the documentation of this file.
1/*
2 * ============================================================================
3 *
4 * C extensions for Bayesian post-processing codes
5 *
6 * ============================================================================
7 */
8
9
10#include <Python.h>
11
12#include <numpy/arrayobject.h>
13
14#include <stdlib.h>
15
16#define MAX_IN_FILES 128
17
18double findMaxLogL(FILE * input, double maxLogL);
19
20typedef struct tagBurnInInput{
21 char** files;
22 int nfiles;
23 int spin;
24 float deltaLogL;
25 int thin;
28
29typedef struct tagBurnInOutput{
30 double** pos;
34
36
37static PyObject* _burnin(PyObject *self, PyObject *args) {
38
39 /***DECLARATION***/
40
41 //INPUT
42
43 PyObject* py_inputfile_list=NULL ;// List of files containing posterior chains."
44 Py_ssize_t nfiles;
45 PyObject* py_spin=NULL;
46
47 //RETURN
48 PyObject* py_pos_array=NULL;
49 PyObject* py_pos_obj=NULL;
50 PyObject* py_bayes=NULL;
51
52 //BurnIn input
53 BurnInInput* input=(BurnInInput*)malloc(sizeof(BurnInInput));
54
55 int ndims;
56
57 /***PARSE/PROCESS INPUT***/
58
59 if (!PyArg_ParseTuple(args,"O!O!ds",&PyList_Type,&py_inputfile_list,&PyBool_Type,&py_spin,&input->deltaLogL,&input->output_file_name)) return NULL;
60
61 input->nfiles=PyList_Size(py_inputfile_list);
62
63 input->files = (char**)calloc(MAX_IN_FILES, sizeof(char*));
64
65 Py_ssize_t i;
66 for(i=0;i<input->nfiles;i++){
67 char* ptemp=NULL;
68 if((ptemp=PyUnicode_AsUTF8(PyList_GetItem(py_inputfile_list,i)))!=0){
69 input->files[i]=ptemp;
70 }
71 else {
72 nfiles--;
73 }
74 }
75
76 Py_INCREF(Py_True);
77 if(py_spin==Py_True) {
78 input->spin=1;
79 ndims = 9;
80 } else {
81 input->spin=0;
82 ndims=15;
83 }
84
85 Py_DECREF(Py_True);
86
87 /* Create output struct*/
89
90 /** BEGIN ROUTINE**/
91 int burnin_exit;
92 burnin_exit=BurnIn(input,output);
93
94 py_bayes=PyFloat_FromDouble(output->bayesFactorFromHarmonicMean);
95
96 npy_intp pos_dims[2] = {output->nSamples,ndims};
97
98 py_pos_array=PyArray_SimpleNewFromData(2,pos_dims,NPY_DOUBLE,(void*)output->pos);
99 py_pos_obj=PyArray_Return((PyArrayObject*)py_pos_array);
100
101 Py_INCREF(py_pos_obj);
102
103 return Py_BuildValue("(OO)",py_pos_obj,py_bayes);
104}
105
106
107/*
108 * ============================================================================
109 *
110 * Module Registration
111 *
112 * ============================================================================
113 */
114
115
116static struct PyMethodDef methods[] = {
117 {"_burnin", _burnin, METH_VARARGS,
118 "This function 'burns in' MCMC chains."
119 },
120 {NULL,}
121};
122
123
124static PyModuleDef moduledef = {
125 PyModuleDef_HEAD_INIT,
126 "_bayespputils",
127 "This module provides C extensions for Bayesian analysis and post-processing codes.",
128 -1, methods, NULL, NULL, NULL, NULL
129};
130
131
132PyMODINIT_FUNC PyInit__bayespputils(void); /* Silence -Wmissing-prototypes */
133PyMODINIT_FUNC PyInit__bayespputils(void)
134{
135 import_array();
136 return PyModule_Create(&moduledef);
137}
#define MAX_IN_FILES
Definition: _bayespputils.c:16
int BurnIn(BurnInInput *, BurnInOutput *)
PyMODINIT_FUNC PyInit__bayespputils(void)
static PyModuleDef moduledef
double findMaxLogL(FILE *input, double maxLogL)
static PyObject * _burnin(PyObject *self, PyObject *args)
Definition: _bayespputils.c:37
static struct PyMethodDef methods[]
args
char * output_file_name
Definition: _bayespputils.c:26
float deltaLogL
Definition: _bayespputils.c:24
char ** files
Definition: _bayespputils.c:21
double bayesFactorFromHarmonicMean
Definition: _bayespputils.c:32
double ** pos
Definition: _bayespputils.c:30