22#include <lal/LALInferenceGenerateROQ.h>
23#include <lal/XLALGSL.h>
36 gsl_matrix *projections,
40 gsl_matrix_complex *RB,
41 gsl_matrix_complex *TS,
42 gsl_matrix_complex *projections,
51void normalise(
const gsl_vector *weight, gsl_vector *
a);
61 gsl_vector_complex *ortho_basis,
62 const gsl_matrix_complex *RB_space,
63 const gsl_vector *wQuad,
67 gsl_vector_complex *ortho_basis,
68 const gsl_matrix_complex *RB_space,
69 const gsl_vector *wQuad,
73 gsl_vector *ortho_basis,
74 const gsl_matrix *RB_space,
75 const gsl_vector *wQuad,
79 gsl_vector *ortho_basis,
80 const gsl_matrix *RB_space,
81 const gsl_vector *wQuad,
105 gsl_matrix *projections,
108 gsl_vector_view basis;
114 gsl_vector_view proj, model;
115 gsl_vector *basisscale;
118 XLAL_CALLGSL( basisscale = gsl_vector_calloc(TS->size2) );
124 XLAL_CALLGSL( gsl_vector_memcpy(basisscale, &basis.vector) );
126 XLAL_CALLGSL( gsl_vector_add(&proj.vector, basisscale) );
143 gsl_matrix_complex *RB,
144 gsl_matrix_complex *TS,
145 gsl_matrix_complex *projections,
148 gsl_vector_complex_view basis;
150 XLAL_CALLGSL( basis = gsl_matrix_complex_row(RB, idx) );
154 gsl_vector_complex_view proj, model;
155 gsl_vector_complex *basisscale;
158 XLAL_CALLGSL( basisscale = gsl_vector_complex_calloc(TS->size2) );
164 XLAL_CALLGSL( gsl_vector_complex_memcpy(basisscale, &basis.vector) );
165 XLAL_CALLGSL( gsl_vector_complex_scale(basisscale, cprod) );
166 XLAL_CALLGSL( gsl_vector_complex_add(&proj.vector, basisscale) );
182 gsl_vector *weighted;
190 if ( weight->size == 1 ){
191 XLAL_CALLGSL( gsl_vector_scale(weighted, gsl_vector_get(weight, 0)) );
193 else if ( weight->size ==
a->size ){
197 XLAL_ERROR_REAL8(
XLAL_EFUNC,
"Vector of weights must either contain a single value, or be the same length as the other input vectors." );
221 gsl_vector_complex *weighted;
223 if (
a->size != b->size ){
XLAL_PRINT_ERROR(
"Size of input vectors are not the same." ); }
225 XLAL_CALLGSL( weighted = gsl_vector_complex_calloc(
a->size) );
229 if ( weight->size == 1 ){
230 XLAL_CALLGSL( gsl_blas_zdscal(gsl_vector_get(weight, 0), weighted) );
232 else if ( weight->size ==
a->size ){
233 gsl_vector_view rview, iview;
235 XLAL_CALLGSL( rview = gsl_vector_complex_real(weighted) );
236 XLAL_CALLGSL( iview = gsl_vector_complex_imag(weighted) );
242 XLAL_PRINT_ERROR(
"Vector of weights must either contain a single value, or be the same length as the other input vectors." );
262 if ( weight->size == 1 ){
266 else if ( weight->size ==
a->size ){
271 XLAL_ERROR_VOID(
XLAL_EFUNC,
"Vector of weights must either contain a single value, or be the same length as the other input vectors." );
285 if ( weight->size == 1 ){
289 else if ( weight->size ==
a->size ){
294 XLAL_ERROR_VOID(
XLAL_EFUNC,
"Vector of weights must either contain a single value, or be the same length as the other input vectors." );
309 if ( weight->size == 1 ){
311 norm *= sqrt(gsl_vector_get(weight, 0));
313 else if ( weight->size ==
a->size ){
317 XLAL_ERROR_REAL8(
XLAL_EFUNC,
"Vector of weights must either contain a single value, or be the same length as the other input vectors." );
334 if ( weight->size == 1 ){
336 norm *= sqrt(gsl_vector_get(weight, 0));
338 else if ( weight->size ==
a->size ){
342 XLAL_ERROR_REAL8(
XLAL_EFUNC,
"Vector of weights must either contain a single value, or be the same length as the other input vectors." );
358 gsl_vector_view rowview;
360 for (
i=0;
i<TS->size1;
i++ ){
376 gsl_vector_complex_view rowview;
379 for (
i=0;
i<TS->size1;
i++ ){
399 gsl_matrix *invV, *LU;
401 gsl_matrix_view subRB;
421 dims->
data[1] = RB->size2;
424 gsl_matrix_view Bview;
425 Bview = gsl_matrix_view_array(
B->data,
n, RB->size2);
426 XLAL_CALLGSL( subRB = gsl_matrix_submatrix(RB, 0, 0,
n, RB->size2) );
427 XLAL_CALLGSL( gsl_blas_dgemm(CblasTrans, CblasNoTrans, 1.0, invV, &subRB.matrix, 0., &Bview.matrix) );
448 gsl_matrix_complex *invV, *LU;
450 gsl_matrix_complex_view subRB;
462 XLAL_CALLGSL( gsl_linalg_complex_LU_decomp(LU,
p, &signum) );
470 dims->
data[1] = RB->size2;
473 gsl_matrix_complex_view Bview;
474 Bview = gsl_matrix_complex_view_array((
double *)
B->data,
n, RB->size2);
475 XLAL_CALLGSL( subRB = gsl_matrix_complex_submatrix(RB, 0, 0,
n, RB->size2) );
476 XLAL_CALLGSL( gsl_blas_zgemm(CblasTrans, CblasNoTrans, GSL_COMPLEX_ONE, invV, &subRB.matrix, GSL_COMPLEX_ZERO, &Bview.matrix) );
490 double maxv = -INFINITY, absval = 0.;
494 for (
i=0;
i<
c->size;
i++ ){
495 XLAL_CALLGSL( absval = gsl_complex_abs(gsl_vector_complex_get(
c,
i)) );
497 if ( absval > maxv ){
519 gsl_vector_complex *ortho_basis,
520 const gsl_matrix_complex *RB_space,
521 const gsl_vector *wQuad,
523 INT4 quad_num = RB_space->size2;
525 gsl_vector_complex *basis;
527 basis = gsl_vector_complex_alloc(quad_num);
530 gsl_vector_complex_set_zero(ru);
532 for(
INT4 i = 0;
i < dim_RB;
i++){
533 gsl_matrix_complex_get_row(basis, RB_space,
i);
537 gsl_vector_complex_set(ru,
i, L2_proj);
538 gsl_vector_complex_scale(basis, L2_proj);
539 gsl_vector_complex_sub(ortho_basis, basis);
544 GSL_SET_COMPLEX(&nrmc, nrm, 0.0);
545 gsl_vector_complex_set(ru, dim_RB, nrmc);
549 gsl_vector_complex_free(basis);
565 gsl_vector *ortho_basis,
566 const gsl_matrix *RB_space,
567 const gsl_vector *wQuad,
569 INT4 quad_num = RB_space->size2;
573 basis = gsl_vector_alloc(quad_num);
576 gsl_vector_set_zero(ru);
578 for(
INT4 i = 0;
i < dim_RB;
i++){
579 gsl_matrix_get_row(basis, RB_space,
i);
583 gsl_vector_set(ru,
i, L2_proj);
584 gsl_vector_scale(basis, L2_proj);
585 gsl_vector_sub(ortho_basis, basis);
589 gsl_vector_set(ru, dim_RB, nrm);
593 gsl_vector_free(basis);
610 gsl_vector_complex *ortho_basis,
611 const gsl_matrix_complex *RB_space,
612 const gsl_vector *wQuad,
614 REAL8 ortho_condition = .5;
616 INT4 quad_num = RB_space->size2;
617 INT4 r_size = ru->size;
619 UINT4 flag = 0, iter = 0;
620 gsl_vector_complex *
e,*r_last;
621 REAL8 nrm_current = 0.;
622 gsl_complex nrmc_current;
625 e = gsl_vector_complex_alloc(quad_num);
626 r_last = gsl_vector_complex_alloc(r_size);
628 gsl_vector_complex_memcpy(
e,ortho_basis);
632 gsl_vector_complex_set_zero(ru);
635 gsl_vector_complex_memcpy(ortho_basis,
e);
636 gsl_vector_complex_set_zero(r_last);
640 gsl_vector_complex_add(ru, r_last);
641 nrmc_current = gsl_vector_complex_get(r_last, dim_RB);
642 nrm_current = GSL_REAL(nrmc_current);
644 gsl_vector_complex_scale(ortho_basis, nrmc_current);
646 if( nrm_current/nrm_prev <= ortho_condition ) {
647 nrm_prev = nrm_current;
649 gsl_vector_complex_memcpy(
e, ortho_basis);
654 GSL_SET_COMPLEX(&nrmc_current, nrm_current, 0.0);
655 gsl_vector_complex_set(ru, dim_RB, nrmc_current);
660 gsl_vector_complex_free(
e);
661 gsl_vector_complex_free(r_last);
678 gsl_vector *ortho_basis,
679 const gsl_matrix *RB_space,
680 const gsl_vector *wQuad,
682 REAL8 ortho_condition = .5;
684 INT4 quad_num = RB_space->size2;
685 INT4 r_size = ru->size;
687 UINT4 flag = 0, iter = 0;
688 gsl_vector *
e,*r_last;
689 REAL8 nrm_current = 0.;
692 e = gsl_vector_alloc(quad_num);
693 r_last = gsl_vector_alloc(r_size);
695 gsl_vector_memcpy(
e,ortho_basis);
699 gsl_vector_set_zero(ru);
702 gsl_vector_memcpy(ortho_basis,
e);
703 gsl_vector_set_zero(r_last);
705 modified_gs(r_last, ortho_basis, RB_space, wQuad, dim_RB);
707 gsl_vector_add(ru, r_last);
708 nrm_current = gsl_vector_get(r_last, dim_RB);
710 gsl_vector_scale(ortho_basis, nrm_current);
712 if( nrm_current/nrm_prev <= ortho_condition ) {
713 nrm_prev = nrm_current;
715 gsl_vector_memcpy(
e, ortho_basis);
720 gsl_vector_set(ru, dim_RB, nrm_current);
726 gsl_vector_free(r_last);
770 size_t cols =
ts->dimLength->data[1], rows =
ts->dimLength->data[0];
773 gsl_matrix_view TSview;
774 XLAL_CALLGSL( TSview = gsl_matrix_view_array((
double *)
ts->data, rows, cols) );
776 size_t max_RB = rows;
781 *greedypoints = gpts;
787 gsl_vector *ts_el, *last_rb, *ortho_basis, *ru;
788 gsl_matrix *R_matrix;
789 REAL8 A_row_norms2[rows];
790 REAL8 projection_norms2[rows];
795 gsl_matrix_view RBview;
798 ts_el = gsl_vector_alloc(cols);
799 last_rb = gsl_vector_alloc(cols);
800 ortho_basis = gsl_vector_alloc(cols);
801 ru = gsl_vector_alloc(max_RB);
804 REAL8 projection_coeff;
805 R_matrix = gsl_matrix_alloc(max_RB, max_RB);
808 for(
size_t i=0;
i<rows; ++
i){ projection_norms2[
i] = 0; }
810 gsl_vector_view deltaview;
817 for(
size_t i=0;
i<rows; ++
i) {
818 gsl_matrix_get_row(ts_el, &TSview.matrix,
i);
825 dims->
data[1] = cols;
830 gsl_matrix_get_row(ts_el, &TSview.matrix, 0);
831 gsl_matrix_set_row(&RBview.matrix, 0, ts_el);
833 gsl_matrix_set(R_matrix, 0, 0, tmpc);
841 gsl_matrix_get_row(last_rb, &RBview.matrix, dim_RB-1);
844 for(
size_t i = 0;
i < rows;
i++){
845 gsl_matrix_get_row(ts_el, &TSview.matrix,
i);
847 projection_norms2[
i] += (projection_coeff*projection_coeff);
848 errors[
i] = A_row_norms2[
i] - projection_norms2[
i];
853 for(
size_t i = 0;
i < rows;
i++) {
854 if(worst_err < errors[
i]) {
855 worst_err = errors[
i];
863 if ( tolerance == 0. ){
866 for(
size_t i = 0;
i < dim_RB;
i++) {
867 if ( worst_app == gpts->
data[
i] ){
875 UINT4 newidxexists = 0;
876 for (
size_t i = 0;
i < rows;
i++){
878 for (
size_t j = 0;
j < dim_RB;
j++){
879 if (
i == gpts->
data[
j] ){
884 if ( !newidxexists ){
893 gpts->
data[dim_RB] = worst_app;
896 gsl_matrix_get_row(ortho_basis, &TSview.matrix, worst_app);
901 if ( gsl_isnan(gsl_vector_get(ru, dim_RB)) ){
break; }
904 dims->
data[0] = dim_RB+1;
908 XLAL_CALLGSL( RBview = gsl_matrix_view_array((
double*)RB->
data, dim_RB+1, cols) );
910 gsl_matrix_set_row(&RBview.matrix, dim_RB, ortho_basis);
911 gsl_matrix_set_row(R_matrix, dim_RB, ru);
916 if( (dim_RB == max_RB) || (worst_err < tolerance) || (rows == dim_RB) ){
break; }
922 gsl_vector_free(ts_el);
923 gsl_vector_free(last_rb);
924 gsl_vector_free(ortho_basis);
926 gsl_matrix_free(R_matrix);
976 size_t cols =
ts->dimLength->data[1], rows =
ts->dimLength->data[0];
979 gsl_matrix_complex_view TSview;
980 XLAL_CALLGSL( TSview = gsl_matrix_complex_view_array((
double *)
ts->data, rows, cols) );
982 size_t max_RB = rows;
986 *greedypoints = gpts;
992 gsl_vector_complex *ts_el, *last_rb, *ortho_basis, *ru;
993 gsl_matrix_complex *R_matrix;
994 REAL8 A_row_norms2[rows];
995 REAL8 projection_norms2[rows];
1000 gsl_matrix_complex_view RBview;
1003 ts_el = gsl_vector_complex_alloc(cols);
1004 last_rb = gsl_vector_complex_alloc(cols);
1005 ortho_basis = gsl_vector_complex_alloc(cols);
1006 ru = gsl_vector_complex_alloc(max_RB);
1009 gsl_complex projection_coeff;
1010 R_matrix = gsl_matrix_complex_alloc(max_RB, max_RB);
1013 for(
size_t i=0;
i<rows; ++
i){ projection_norms2[
i] = 0; }
1015 gsl_vector_view deltaview;
1022 for(
size_t i=0;
i<rows; ++
i) {
1023 gsl_matrix_complex_get_row(ts_el, &TSview.matrix,
i);
1030 dims->
data[1] = cols;
1034 XLAL_CALLGSL( RBview = gsl_matrix_complex_view_array((
double*)RB->
data, 1, cols) );
1035 gsl_matrix_complex_get_row(ts_el, &TSview.matrix, 0);
1036 gsl_matrix_complex_set_row(&RBview.matrix, 0, ts_el);
1037 GSL_SET_COMPLEX(&tmpc, 1.0, 0.0);
1038 gsl_matrix_complex_set(R_matrix, 0, 0, tmpc);
1045 gsl_matrix_complex_get_row(last_rb, &RBview.matrix, dim_RB-1);
1048 for(
size_t i = 0;
i < rows;
i++){
1049 gsl_matrix_complex_get_row(ts_el, &TSview.matrix,
i);
1051 projection_norms2[
i] += (GSL_REAL(projection_coeff)*GSL_REAL(projection_coeff) + GSL_IMAG(projection_coeff)*GSL_IMAG(projection_coeff));
1052 errors[
i] = A_row_norms2[
i] - projection_norms2[
i];
1057 for(
size_t i = 0;
i < rows;
i++) {
1058 if(worst_err < errors[
i]) {
1059 worst_err = errors[
i];
1067 if ( tolerance == 0. ){
1069 UINT4 idxexists = 0;
1070 for(
size_t i = 0;
i < dim_RB;
i++) {
1071 if ( worst_app == gpts->
data[
i] ){
1079 UINT4 newidxexists = 0;
1080 for (
size_t i = 0;
i < rows;
i++){
1082 for (
size_t j = 0;
j < dim_RB;
j++){
1083 if (
i == gpts->
data[
j] ){
1088 if ( !newidxexists ){
1097 gpts->
data[dim_RB] = worst_app;
1100 gsl_matrix_complex_get_row(ortho_basis, &TSview.matrix, worst_app);
1105 gsl_complex
norm = gsl_vector_complex_get(ru, dim_RB);
1106 if ( gsl_isnan(GSL_REAL(
norm)) ){
break; }
1109 dims->
data[0] = dim_RB+1;
1113 XLAL_CALLGSL( RBview = gsl_matrix_complex_view_array((
double*)RB->
data, dim_RB+1, cols) );
1115 gsl_matrix_complex_set_row(&RBview.matrix, dim_RB, ortho_basis);
1116 gsl_matrix_complex_set_row(R_matrix, dim_RB, ru);
1121 if( (dim_RB == max_RB) || (worst_err < tolerance) || (rows == dim_RB) ){
break; }
1127 gsl_vector_complex_free(ts_el);
1128 gsl_vector_complex_free(last_rb);
1129 gsl_vector_complex_free(ortho_basis);
1130 gsl_vector_complex_free(ru);
1131 gsl_matrix_complex_free(R_matrix);
1172 gsl_vector *r_tmp, *testrow;
1175 gsl_vector_view deltaview;
1177 gsl_matrix_view testmodelsview;
1178 XLAL_CALLGSL( testmodelsview = gsl_matrix_view_array(tm->
data, nts, dlength) );
1181 gsl_matrix_view RBview;
1191 for (
k = 0;
k < nts;
k++ ){
1193 REAL8 r_tmp_nrm = 0.;
1195 XLAL_CALLGSL( gsl_matrix_get_row(testrow, &testmodelsview.matrix,
k) );
1200 if (
delta->length == 1 ){
1203 else if ( testrow->size == deltaview.vector.size ){
1204 XLAL_CALLGSL( gsl_vector_mul(testrow, &deltaview.vector) );
1207 XLAL_ERROR_VOID(
XLAL_EFUNC,
"Vector of weights must either contain a single value, or be the same length as the other input vectors.");
1211 XLAL_CALLGSL( gsl_blas_dgemv( CblasNoTrans, 1., &RBview.matrix, testrow, 0., r_tmp ) );
1213 r_tmp_nrm = gsl_blas_dnrm2( r_tmp );
1214 pe->
data[
k] = nrm - r_tmp_nrm*r_tmp_nrm;
1216 if ( pe->
data[
k] < 0. ) { pe->
data[
k] = 1.0e-16; }
1258 for (
k = 0;
k < nts;
k++ ){
1260 if ( projerr->
data[
k] > tolerance ) {
1303 REAL8 maxprojerr = 0.;
1310 tm = *testmodelsnew;
1316 gsl_vector_view deltaview;
1324 size_t keepcounter = 0;
1325 gsl_matrix_view tmview;
1326 tmview = gsl_matrix_view_array(tm->
data, nts, dlength);
1327 for (
k = 0;
k < projerr->
length;
k++ ){
1328 if ( projerr->
data[
k] > tolerance ){
1329 if ( keepcounter !=
k ){
1330 gsl_vector_view
row;
1331 row = gsl_matrix_row( &tmview.matrix,
k );
1334 if (
delta->length == 1 ){
1337 else if (
row.vector.size ==
delta->length ){
1341 XLAL_ERROR_REAL8(
XLAL_EFUNC,
"Vector of weights must either contain a single value, or be the same length as the other input vectors.");
1344 gsl_matrix_set_row( &tmview.matrix, keepcounter, &
row.vector );
1352 if ( keepcounter == 0 ){
return maxprojerr; }
1357 dims->
data[1] = dlength;
1359 tmview = gsl_matrix_view_array(tm->
data, dims->
data[0], dlength);
1361 gsl_matrix_view otmview;
1362 otmview = gsl_matrix_view_array(testmodels->
data, testmodels->
dimLength->
data[0], dlength);
1364 gsl_vector_view
row;
1365 row = gsl_matrix_row( &otmview.matrix, gp->
data[
k] );
1368 if (
delta->length == 1 ){
1371 else if (
row.vector.size ==
delta->length ){
1375 XLAL_ERROR_REAL8(
XLAL_EFUNC,
"Vector of weights must either contain a single value, or be the same length as the other input vectors.");
1378 gsl_matrix_set_row( &tmview.matrix, keepcounter +
k, &
row.vector );
1385 *greedypoints = NULL;
1428 size_t k = 0,
j = 0;
1429 gsl_vector_complex *r_tmp, *testrow;
1432 gsl_vector_view deltaview;
1434 gsl_matrix_complex_view testmodelsview;
1435 XLAL_CALLGSL( testmodelsview = gsl_matrix_complex_view_array((
double *)tm->
data, nts, dlength) );
1438 gsl_matrix_complex_view RBview;
1439 RBview = gsl_matrix_complex_view_array((
double *)RB->
data, RB->
dimLength->
data[0], dlength);
1441 XLAL_CALLGSL( testrow = gsl_vector_complex_alloc(dlength) );
1449 for (
k = 0;
k < nts;
k++ ){
1451 REAL8 r_tmp_nrm = 0.;
1453 XLAL_CALLGSL( gsl_matrix_complex_get_row(testrow, &testmodelsview.matrix,
k) );
1458 if (
delta->length == 1 || testrow->size == deltaview.vector.size ){
1459 for (
j = 0;
j < dlength;
j++ ){
1461 XLAL_CALLGSL( ctmp = gsl_vector_complex_get( testrow,
j ) );
1462 if (
delta->length == 1 ){
1472 XLAL_ERROR_VOID(
XLAL_EFUNC,
"Vector of weights must either contain a single value, or be the same length as the other input vectors." );
1476 for (
j = 0;
j < testrow->size;
j++ ){ testrow->data[2*
j+1] = -testrow->data[2*
j+1]; }
1479 XLAL_CALLGSL( gsl_blas_zgemv( CblasNoTrans, GSL_COMPLEX_ONE, &RBview.matrix, testrow, GSL_COMPLEX_ZERO, r_tmp ) );
1481 r_tmp_nrm = gsl_blas_dznrm2(r_tmp);
1482 pe->
data[
k] = nrm - r_tmp_nrm*r_tmp_nrm;
1484 if ( pe->
data[
k] < 0. ) { pe->
data[
k] = 1.0e-16; }
1526 for (
k = 0;
k < nts;
k++ ){
1528 if ( projerr->
data[
k] > tolerance ) {
1570 size_t k = 0,
j = 0;
1572 REAL8 maxprojerr = 0.;
1579 tm = *testmodelsnew;
1590 size_t keepcounter = 0;
1591 gsl_matrix_complex_view tmview;
1592 tmview = gsl_matrix_complex_view_array((
double *)tm->
data, nts, dlength);
1593 for (
k = 0;
k < projerr->
length;
k++ ){
1594 if ( projerr->
data[
k] > tolerance ){
1595 if ( keepcounter !=
k ){
1596 gsl_vector_complex_view
row;
1597 row = gsl_matrix_complex_row( &tmview.matrix,
k );
1600 if (
delta->length == 1 ||
row.vector.size ==
delta->length ){
1601 for (
j = 0;
j <
row.vector.size;
j++ ){
1604 if (
delta->length == 1 ){
1614 XLAL_ERROR_REAL8(
XLAL_EFUNC,
"Vector of weights must either contain a single value, or be the same length as the other input vectors." );
1616 gsl_matrix_complex_set_row( &tmview.matrix, keepcounter, &
row.vector );
1624 if ( keepcounter == 0 ){
return maxprojerr; }
1629 dims->
data[1] = dlength;
1631 tmview = gsl_matrix_complex_view_array((
double *)tm->
data, dims->
data[0], dlength);
1633 gsl_matrix_complex_view otmview;
1634 otmview = gsl_matrix_complex_view_array((
double *)testmodels->
data, nts, dlength);
1636 gsl_vector_complex_view
row;
1637 row = gsl_matrix_complex_row( &otmview.matrix, gp->
data[
k] );
1640 for (
j = 0;
j <
row.vector.size;
j++ ){
1643 if (
delta->length == 1 ){
1652 gsl_matrix_complex_set_row( &tmview.matrix, keepcounter +
k, &
row.vector );
1659 *greedypoints = NULL;
1684 size_t i=1,
j=0,
k=0;
1686 gsl_matrix_view Vview;
1689 int idmax = 0, newidx = 0;
1692 gsl_matrix_view RBview;
1693 RBview = gsl_matrix_view_array( RB->
data, RBsize, dlength );
1694 gsl_vector_view firstbasis = gsl_matrix_row(&RBview.matrix, 0);
1695 XLAL_CALLGSL( idmax = (
int)gsl_blas_idamax(&firstbasis.vector) );
1698 interp->
nodes[0] = idmax;
1700 for (
i=1;
i<RBsize;
i++ ){
1701 gsl_vector *interpolant, *subbasis;
1702 gsl_vector_view subview;
1704 Vview = gsl_matrix_view_array(
V,
i,
i);
1706 for (
j=0;
j<
i;
j++ ){
1707 for (
k=0;
k<
i;
k++ ){
1708 XLAL_CALLGSL( gsl_matrix_set(&Vview.matrix,
k,
j, gsl_matrix_get(&RBview.matrix,
j, interp->
nodes[
k])) );
1714 gsl_matrix_view Bview;
1715 Bview = gsl_matrix_view_array(
B->data,
B->dimLength->data[0],
B->dimLength->data[1]);
1718 XLAL_CALLGSL( interpolant = gsl_vector_calloc(dlength) );
1720 XLAL_CALLGSL( subview = gsl_matrix_row(&RBview.matrix,
i) );
1722 for (
k=0;
k<
i;
k++ ){
1723 XLAL_CALLGSL( gsl_vector_set(subbasis,
k, gsl_vector_get(&subview.vector, interp->
nodes[
k])) );
1726 XLAL_CALLGSL( gsl_blas_dgemv(CblasTrans, 1.0, &Bview.matrix, subbasis, 0., interpolant) );
1729 XLAL_CALLGSL( gsl_vector_sub(interpolant, &subview.vector) );
1731 XLAL_CALLGSL( newidx = (
int)gsl_blas_idamax(interpolant) );
1733 interp->
nodes[
i] = newidx;
1744 Vview = gsl_matrix_view_array(
V, RBsize, RBsize);
1745 for(
j=0;
j<RBsize;
j++ ){
1746 for(
k=0;
k<RBsize;
k++ ){
1747 XLAL_CALLGSL( gsl_matrix_set(&Vview.matrix,
k,
j, gsl_matrix_get(&RBview.matrix,
j, interp->
nodes[
k])) );
1752 interp->
B =
B_matrix(&Vview.matrix, &RBview.matrix);
1776 size_t i=1,
j=0,
k=0;
1778 gsl_matrix_complex_view Vview;
1781 int idmax = 0, newidx = 0;
1784 gsl_matrix_complex_view RBview;
1785 RBview = gsl_matrix_complex_view_array((
double *)RB->
data, RBsize, dlength);
1786 gsl_vector_complex_view firstbasis = gsl_matrix_complex_row(&RBview.matrix, 0);
1790 interp->
nodes[0] = idmax;
1792 for (
i=1;
i<RBsize;
i++ ){
1793 gsl_vector_complex *interpolant, *subbasis;
1794 gsl_vector_complex_view subview;
1796 Vview = gsl_matrix_complex_view_array(
V,
i,
i);
1798 for (
j=0;
j<
i;
j++ ){
1799 for (
k=0;
k<
i;
k++ ){
1800 XLAL_CALLGSL( gsl_matrix_complex_set(&Vview.matrix,
k,
j, gsl_matrix_complex_get(&RBview.matrix,
j, interp->
nodes[
k])) );
1806 gsl_matrix_complex_view Bview;
1807 Bview = gsl_matrix_complex_view_array((
double *)
B->data,
B->dimLength->data[0],
B->dimLength->data[1]);
1810 XLAL_CALLGSL( interpolant = gsl_vector_complex_calloc(dlength) );
1812 XLAL_CALLGSL( subview = gsl_matrix_complex_row(&RBview.matrix,
i) );
1814 for (
k=0;
k<
i;
k++ ){
1815 XLAL_CALLGSL( gsl_vector_complex_set(subbasis,
k, gsl_vector_complex_get(&subview.vector, interp->
nodes[
k])) );
1818 XLAL_CALLGSL( gsl_blas_zgemv(CblasTrans, GSL_COMPLEX_ONE, &Bview.matrix, subbasis, GSL_COMPLEX_ZERO, interpolant) );
1821 XLAL_CALLGSL( gsl_vector_complex_sub(interpolant, &subview.vector) );
1825 interp->
nodes[
i] = newidx;
1836 Vview = gsl_matrix_complex_view_array((
double*)
V, RBsize, RBsize);
1837 for(
j=0;
j<RBsize;
j++ ){
1838 for(
k=0;
k<RBsize;
k++ ){
1839 XLAL_CALLGSL( gsl_matrix_complex_set(&Vview.matrix,
k,
j, gsl_matrix_complex_get(&RBview.matrix,
j, interp->
nodes[
k])) );
1862 gsl_vector *datacopy;
1865 gsl_matrix_view Bview;
1866 XLAL_CALLGSL( Bview = gsl_matrix_view_array(
B->data,
B->dimLength->data[0],
B->dimLength->data[1]) );
1869 gsl_vector_view dataview, varsview;
1875 XLAL_CALLGSL( datacopy = gsl_vector_alloc(
B->dimLength->data[1]) );
1876 XLAL_CALLGSL( gsl_vector_memcpy(datacopy, &dataview.vector) );
1879 else{
XLAL_CALLGSL( gsl_vector_div( datacopy, &varsview.vector ) ); }
1883 gsl_vector_view weightsview;
1885 XLAL_CALLGSL( gsl_blas_dgemv(CblasNoTrans, 1.0, &Bview.matrix, datacopy, 0., &weightsview.vector) );
1901 gsl_vector *vecones = gsl_vector_alloc(
B->dimLength->data[1]);
1905 gsl_matrix_view Bview;
1906 XLAL_CALLGSL( Bview = gsl_matrix_view_array(
B->data,
B->dimLength->data[0],
B->dimLength->data[1]) );
1909 gsl_vector_view varsview;
1915 else{
XLAL_CALLGSL( gsl_vector_div( vecones, &varsview.vector ) ); }
1919 gsl_vector_view weightsview;
1921 XLAL_CALLGSL( gsl_blas_dgemv(CblasNoTrans, 1.0, &Bview.matrix, vecones, 0., &weightsview.vector) );
1938 gsl_vector_complex *conjdata;
1943 gsl_matrix_complex_view Bview;
1944 XLAL_CALLGSL( Bview = gsl_matrix_complex_view_array((
double *)
B->data,
B->dimLength->data[0],
B->dimLength->data[1]) );
1948 XLAL_CALLGSL( conjdata = gsl_vector_complex_alloc(
B->dimLength->data[1]) );
1951 for (
i=0;
i<conjdata->size;
i++ ){
1953 GSL_SET_COMPLEX(&cdata, creal(
data->data[
i]), cimag(
data->data[
i]));
1962 gsl_vector_complex_view weightsview;
1964 XLAL_CALLGSL( gsl_blas_zgemv(CblasNoTrans, GSL_COMPLEX_ONE, &Bview.matrix, conjdata, GSL_COMPLEX_ZERO, &weightsview.vector) );
1986 gsl_vector_view weightsview, modelview;
1989 XLAL_CALLGSL( gsl_blas_ddot(&weightsview.vector, &modelview.vector, &d_dot_m) );
2008 gsl_complex d_dot_m;
2009 gsl_vector_complex_view weightsview, modelview;
2012 XLAL_CALLGSL( gsl_blas_zdotu(&weightsview.vector, &modelview.vector, &d_dot_m) );
2014 return GSL_REAL(d_dot_m) + I*GSL_IMAG(d_dot_m);
2023 if (
a == NULL ) {
return; }
2026 if (
a->nodes != NULL ){
XLALFree(
a->nodes ); }
2037 if (
a == NULL ) {
return; }
2040 if (
a->nodes != NULL ){
XLALFree(
a->nodes ); }
void project_onto_basis(gsl_vector *weight, gsl_matrix *RB, gsl_matrix *TS, gsl_matrix *projections, INT4 idx)
Function to project the training set onto a given basis vector.
void complex_normalise_training_set(gsl_vector *weight, gsl_matrix_complex *TS)
Normalise the set of complex training waveforms.
INT4 LALInferenceTestCOMPLEX16OrthonormalBasis(const REAL8Vector *delta, REAL8 tolerance, const COMPLEX16Array *RB, COMPLEX16Array **testmodels)
Test the reduced basis against another set of waveforms.
COMPLEX16 LALInferenceROQCOMPLEX16DotProduct(COMPLEX16Vector *weights, COMPLEX16Vector *model)
Calculate the dot product of two complex vectors using the ROQ iterpolant.
void modified_gs(gsl_vector *ru, gsl_vector *ortho_basis, const gsl_matrix *RB_space, const gsl_vector *wQuad, const int dim_RB)
Modified Gram-Schmidt algorithm for real data.
REAL8 LALInferenceGenerateCOMPLEX16OrthonormalBasis(COMPLEX16Array **RBin, const REAL8Vector *delta, REAL8 tolerance, COMPLEX16Array **TS, UINT4Vector **greedypoints)
Create a orthonormal basis set from a training set of complex waveforms.
INT4 LALInferenceTestREAL8OrthonormalBasis(const REAL8Vector *delta, REAL8 tolerance, const REAL8Array *RB, REAL8Array **testmodels)
Test the reduced basis against another set of waveforms.
void normalise_training_set(gsl_vector *weight, gsl_matrix *TS)
Normalise the set of training waveforms.
REAL8 weighted_dot_product(const gsl_vector *weight, gsl_vector *a, gsl_vector *b)
The dot product of two real vectors scaled by a given weight factor.
void LALInferenceRemoveCOMPLEXROQInterpolant(LALInferenceCOMPLEXROQInterpolant *a)
Free memory for a LALInferenceCOMPLEXROQInterpolant.
double normalisation(const gsl_vector *weight, gsl_vector *a)
Get normalisation constant for a real vector.
void iterated_modified_gm_complex(gsl_vector_complex *ru, gsl_vector_complex *ortho_basis, const gsl_matrix_complex *RB_space, const gsl_vector *wQuad, const int dim_RB)
Iterated modified Gram-Schmidt algorithm for complex data.
int complex_vector_maxabs_index(gsl_vector_complex *c)
Get the index of the maximum absolute value for a complex vector.
void complex_normalise(const gsl_vector *weight, gsl_vector_complex *a)
Normalise a complex vector with a given (real) weighting.
COMPLEX16Vector * LALInferenceGenerateCOMPLEX16LinearWeights(COMPLEX16Array *B, COMPLEX16Vector *data, REAL8Vector *vars)
Create the weights for the ROQ interpolant for the complex data and model dot product <d|h>
REAL8Vector * LALInferenceGenerateREAL8LinearWeights(REAL8Array *B, REAL8Vector *data, REAL8Vector *vars)
Create the weights for the ROQ interpolant for the linear data and model dot product <d|h>
gsl_complex complex_weighted_dot_product(const gsl_vector *weight, gsl_vector_complex *a, gsl_vector_complex *b)
The dot product of two complex vectors scaled by a given weight factor.
REAL8 LALInferenceROQREAL8DotProduct(REAL8Vector *weights, REAL8Vector *model)
Calculate the dot product of two vectors using the ROQ iterpolant.
REAL8 LALInferenceEnrichCOMPLEX16Basis(const REAL8Vector *delta, REAL8 tolerance, COMPLEX16Array **RB, UINT4Vector **greedypoints, const COMPLEX16Array *testmodels, COMPLEX16Array **testmodelsnew)
Expand the complex training waveforms with ones from a set of new training waveforms.
double complex_normalisation(const gsl_vector *weight, gsl_vector_complex *a)
Get normalisation constant for a complex vector.
void complex_project_onto_basis(gsl_vector *weight, gsl_matrix_complex *RB, gsl_matrix_complex *TS, gsl_matrix_complex *projections, INT4 idx)
Function to project the complex training set onto a given basis vector.
REAL8Vector * LALInferenceGenerateQuadraticWeights(REAL8Array *B, REAL8Vector *vars)
Create the weights for the ROQ interpolant for the model quadratic model term real(<h|h>).
REAL8Array * B_matrix(gsl_matrix *V, gsl_matrix *RB)
Get the interpolant of a reduced basis set.
LALInferenceCOMPLEXROQInterpolant * LALInferenceGenerateCOMPLEXROQInterpolant(COMPLEX16Array *RB)
Create a complex empirical interpolant from a set of orthonormal basis functions.
void LALInferenceValidateCOMPLEX16OrthonormalBasis(REAL8Vector **projerr, const REAL8Vector *delta, const COMPLEX16Array *RB, COMPLEX16Array **testmodels)
Validate the complex reduced basis against another set of waveforms.
REAL8 LALInferenceGenerateREAL8OrthonormalBasis(REAL8Array **RBin, const REAL8Vector *delta, REAL8 tolerance, REAL8Array **TS, UINT4Vector **greedypoints)
Create a orthonormal basis set from a training set of real waveforms.
COMPLEX16Array * complex_B_matrix(gsl_matrix_complex *V, gsl_matrix_complex *RB)
Get the interpolant of a complex reduced basis set.
void LALInferenceValidateREAL8OrthonormalBasis(REAL8Vector **projerr, const REAL8Vector *delta, const REAL8Array *RB, REAL8Array **testmodels)
Validate the real reduced basis against another set of waveforms.
void LALInferenceRemoveREALROQInterpolant(LALInferenceREALROQInterpolant *a)
Free memory for a LALInferenceREALROQInterpolant.
void modified_gs_complex(gsl_vector_complex *ru, gsl_vector_complex *ortho_basis, const gsl_matrix_complex *RB_space, const gsl_vector *wQuad, const int dim_RB)
Modified Gram-Schmidt algorithm for complex data.
REAL8 LALInferenceEnrichREAL8Basis(const REAL8Vector *delta, REAL8 tolerance, REAL8Array **RB, UINT4Vector **greedypoints, const REAL8Array *testmodels, REAL8Array **testmodelsnew)
Expand the real training waveforms with ones from a set of new training waveforms.
void normalise(const gsl_vector *weight, gsl_vector *a)
Normalise a real vector with a given weighting.
LALInferenceREALROQInterpolant * LALInferenceGenerateREALROQInterpolant(REAL8Array *RB)
Create a real empirical interpolant from a set of orthonormal basis functions.
void iterated_modified_gm(gsl_vector *ru, gsl_vector *ortho_basis, const gsl_matrix *RB_space, const gsl_vector *wQuad, const int dim_RB)
Iterated modified Gram-Schmidt algorithm for real data.
static REAL8 norm(const REAL8 x[3])
static double double delta
#define XLAL_CALLGSL(statement)
REAL8Array * XLALResizeREAL8Array(REAL8Array *, UINT4Vector *)
void XLALDestroyREAL8Array(REAL8Array *)
COMPLEX16Array * XLALResizeCOMPLEX16Array(COMPLEX16Array *, UINT4Vector *)
COMPLEX16Array * XLALCreateCOMPLEX16Array(UINT4Vector *)
void XLALDestroyCOMPLEX16Array(COMPLEX16Array *)
REAL8Array * XLALCreateREAL8Array(UINT4Vector *)
void * XLALMalloc(size_t n)
void * XLALRealloc(void *p, size_t n)
void XLALDestroyUINT4Vector(UINT4Vector *vector)
UINT4Vector * XLALResizeUINT4Vector(UINT4Vector *vector, UINT4 length)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
COMPLEX16Vector * XLALCreateCOMPLEX16Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
UINT4Vector * XLALCreateUINT4Vector(UINT4 length)
#define XLAL_ERROR_VOID(...)
#define XLAL_ERROR_REAL8(...)
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_VOID(assertion,...)
#define XLAL_CHECK_REAL8(assertion,...)
#define XLAL_CHECK_NULL(assertion,...)
#define XLAL_PRINT_ERROR(...)
A structure to hold a complex (double precision) interpolant matrix and interpolation node indices.
COMPLEX16Array * B
The interpolant matrix.
UINT4 * nodes
The nodes (indices) for the interpolation.
A structure to hold a real (double precision) interpolant matrix and interpolation node indices.
UINT4 * nodes
The nodes (indices) for the interpolation.
REAL8Array * B
The interpolant matrix.