LALInferenceGenerateROQ.h 5.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/*
 *  LALInferenceROQ.h: Reduced order quadrature basis and interpolant generation
 *
 *  Copyright (C) 2014 Matthew Pitkin, Rory Smith
 *
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with with program; see the file COPYING. If not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 */
#ifndef LALINFERENCEROQ_H
#define LALINFERENCEROQ_H

#include <lal/LALStdlib.h>
#include <lal/LALConstants.h>
#include <lal/LALDatatypes.h>
#include <lal/LALInference.h>
#include <lal/XLALError.h>

#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_cblas.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_complex.h>

#ifdef __cplusplus
extern "C" {
#endif

42

43 44
/** A structure to hold a real (double precision) interpolant matrix and interpolation node indices */
typedef struct tagLALInferenceREALROQInterpolant{
45
  REAL8Array *B;  /**< The interpolant matrix */
46 47 48 49 50
  UINT4 *nodes;   /**< The nodes (indices) for the interpolation */
}LALInferenceREALROQInterpolant;

/** A structure to hold a complex (double precision) interpolant matrix and interpolation node indices */
typedef struct tagLALInferenceCOMPLEXROQInterpolant{
51
  COMPLEX16Array *B;      /**< The interpolant matrix */
52 53 54
  UINT4 *nodes;           /**< The nodes (indices) for the interpolation */
}LALInferenceCOMPLEXROQInterpolant;

55 56
/* function to create or enrich a real orthonormal basis set from a training set of models */
REAL8 LALInferenceGenerateREAL8OrthonormalBasis(REAL8Array **RB,
57
                                                const REAL8Vector *delta,
58
                                                REAL8 tolerance,
59 60
                                                REAL8Array **TS,
                                                UINT4Vector **greedypoints);
61 62

REAL8 LALInferenceGenerateCOMPLEX16OrthonormalBasis(COMPLEX16Array **RB,
63
                                                    const REAL8Vector *delta,
64
                                                    REAL8 tolerance,
65 66
                                                    COMPLEX16Array **TS,
                                                    UINT4Vector **greedypoints);
67 68

/* functions to test the basis */
69 70 71 72 73 74 75 76 77 78 79
void LALInferenceValidateREAL8OrthonormalBasis(REAL8Vector **projerr,
                                               const REAL8Vector *delta,
                                               const REAL8Array *RB,
                                               REAL8Array **testmodels);

void LALInferenceValidateCOMPLEX16OrthonormalBasis(REAL8Vector **projerr,
                                                   const REAL8Vector *delta,
                                                   const COMPLEX16Array *RB,
                                                   COMPLEX16Array **testmodels);

INT4 LALInferenceTestREAL8OrthonormalBasis(const REAL8Vector *delta,
80
                                           REAL8 tolerance,
81 82
                                           const REAL8Array *RB,
                                           REAL8Array **testmodels);
83

84
INT4 LALInferenceTestCOMPLEX16OrthonormalBasis(const REAL8Vector *delta,
85
                                               REAL8 tolerance,
86 87
                                               const COMPLEX16Array *RB,
                                               COMPLEX16Array **testmodels);
88

89
/* functions to enrich the training model set and basis set */
90 91
REAL8 LALInferenceEnrichREAL8Basis(const REAL8Vector *delta,
                                   const REAL8 tolerance,
92
                                   REAL8Array **RB,
93 94 95
                                   UINT4Vector **greedypoints,
                                   const REAL8Array *testmodels,
                                   REAL8Array **testmodelsnew);
96

97 98
REAL8 LALInferenceEnrichCOMPLEX16Basis(const REAL8Vector *delta,
                                       const REAL8 tolerance,
99
                                       COMPLEX16Array **RB,
100 101 102
                                       UINT4Vector **greedypoints,
                                       const COMPLEX16Array *testmodels,
                                       COMPLEX16Array **testmodelsnew);
103

104
/* function to create the empirical interpolant */
105
LALInferenceREALROQInterpolant *LALInferenceGenerateREALROQInterpolant(REAL8Array *RB);
106

107
LALInferenceCOMPLEXROQInterpolant *LALInferenceGenerateCOMPLEXROQInterpolant(COMPLEX16Array *RB);
108

109 110
/* create ROQ weights for interpolant to calculate the linear <d|h> terms */
REAL8Vector *LALInferenceGenerateREAL8LinearWeights(REAL8Array *B, REAL8Vector *data, REAL8Vector *vars);
111

112 113
/* create ROQ weights for interpolant to calculate the quadratic model terms real(<h|h>) */
REAL8Vector *LALInferenceGenerateQuadraticWeights(REAL8Array *B, REAL8Vector *vars);
114 115

/* create ROQ weights for interpolant to calculate the data dot model terms */
116
COMPLEX16Vector *LALInferenceGenerateCOMPLEX16LinearWeights(COMPLEX16Array *B, COMPLEX16Vector *data, REAL8Vector *vars);
117

118 119 120
/* calculate ROQ version of the dot product (where the model vector is the model just computed at the interpolant points) */
REAL8 LALInferenceROQREAL8DotProduct(REAL8Vector *weights, REAL8Vector *model);
COMPLEX16 LALInferenceROQCOMPLEX16DotProduct(COMPLEX16Vector *weights, COMPLEX16Vector *model);
121 122 123 124 125 126 127 128 129 130

/* memory destruction */
void LALInferenceRemoveREALROQInterpolant( LALInferenceREALROQInterpolant *a );
void LALInferenceRemoveCOMPLEXROQInterpolant( LALInferenceCOMPLEXROQInterpolant *a );

#ifdef __cplusplus
}
#endif

#endif