From 24a4a5132a07ee6a8717844e3c5862882c88b25a Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Wed, 18 Oct 2017 12:36:39 +0000 Subject: Tests still pass with safe_alloc (which sets the buffers to NaNs on allocation) --- src/logistic.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/logistic.cpp') diff --git a/src/logistic.cpp b/src/logistic.cpp index 2dd0402..a936682 100644 --- a/src/logistic.cpp +++ b/src/logistic.cpp @@ -7,6 +7,7 @@ #include #include "logistic.h" +#include "debug.h" // I need to bundle all the data that goes to the function to optimze // together. @@ -135,7 +136,7 @@ void wgsl_mixed_optim_hessian(const gsl_vector *beta, void *params, int K = p->X->size2; int Kc = p->Xc->size2; int npar = beta->size; - gsl_vector *gn = gsl_vector_alloc(npar); // gn + gsl_vector *gn = gsl_vector_safe_alloc(npar); // gn // Intitialize Hessian out necessary ??? gsl_matrix_set_zero(out); @@ -226,11 +227,11 @@ int logistic_mixed_fit(gsl_vector *beta, gsl_matrix_int *X, // Initial fit. mLogLik = wgsl_mixed_optim_f(beta, &p); - gsl_matrix *myH = gsl_matrix_alloc(npar, npar); // Hessian matrix. - gsl_vector *stBeta = gsl_vector_alloc(npar); // Direction to move. + gsl_matrix *myH = gsl_matrix_safe_alloc(npar, npar); // Hessian matrix. + gsl_vector *stBeta = gsl_vector_safe_alloc(npar); // Direction to move. - gsl_vector *myG = gsl_vector_alloc(npar); // Gradient. - gsl_vector *tau = gsl_vector_alloc(npar); // tau for QR. + gsl_vector *myG = gsl_vector_safe_alloc(npar); // Gradient. + gsl_vector *tau = gsl_vector_safe_alloc(npar); // tau for QR. for (iter = 0; iter < 100; iter++) { wgsl_mixed_optim_hessian(beta, &p, myH); // Calculate Hessian. @@ -456,11 +457,11 @@ int logistic_cat_fit(gsl_vector *beta, gsl_matrix_int *X, gsl_vector_int *nlev, // Initial fit. mLogLik = wgsl_cat_optim_f(beta, &p); - gsl_matrix *myH = gsl_matrix_alloc(npar, npar); // Hessian matrix. - gsl_vector *stBeta = gsl_vector_alloc(npar); // Direction to move. + gsl_matrix *myH = gsl_matrix_safe_alloc(npar, npar); // Hessian matrix. + gsl_vector *stBeta = gsl_vector_safe_alloc(npar); // Direction to move. - gsl_vector *myG = gsl_vector_alloc(npar); // Gradient. - gsl_vector *tau = gsl_vector_alloc(npar); // tau for QR. + gsl_vector *myG = gsl_vector_safe_alloc(npar); // Gradient. + gsl_vector *tau = gsl_vector_safe_alloc(npar); // tau for QR. for (iter = 0; iter < 100; iter++) { wgsl_cat_optim_hessian(beta, &p, myH); // Calculate Hessian. @@ -596,7 +597,7 @@ void wgsl_cont_optim_hessian(const gsl_vector *beta, void *params, int n = p->y->size; int Kc = p->Xc->size2; int npar = beta->size; - gsl_vector *gn = gsl_vector_alloc(npar); // gn. + gsl_vector *gn = gsl_vector_safe_alloc(npar); // gn. // Intitialize Hessian out necessary ??? @@ -673,11 +674,11 @@ int logistic_cont_fit(gsl_vector *beta, // Initial fit. mLogLik = wgsl_cont_optim_f(beta, &p); - gsl_matrix *myH = gsl_matrix_alloc(npar, npar); // Hessian matrix. - gsl_vector *stBeta = gsl_vector_alloc(npar); // Direction to move. + gsl_matrix *myH = gsl_matrix_safe_alloc(npar, npar); // Hessian matrix. + gsl_vector *stBeta = gsl_vector_safe_alloc(npar); // Direction to move. - gsl_vector *myG = gsl_vector_alloc(npar); // Gradient. - gsl_vector *tau = gsl_vector_alloc(npar); // tau for QR. + gsl_vector *myG = gsl_vector_safe_alloc(npar); // Gradient. + gsl_vector *tau = gsl_vector_safe_alloc(npar); // tau for QR. for (iter = 0; iter < 100; iter++) { wgsl_cont_optim_hessian(beta, &p, myH); // Calculate Hessian. -- cgit v1.2.3