aboutsummaryrefslogtreecommitdiff
path: root/src/logistic.cpp
diff options
context:
space:
mode:
authorPjotr Prins2017-10-18 12:36:39 +0000
committerPjotr Prins2017-10-18 12:36:39 +0000
commit24a4a5132a07ee6a8717844e3c5862882c88b25a (patch)
tree00d11c524b256790c8ec1cdcdb9e2da8682bdb69 /src/logistic.cpp
parentb3e613a67c2a8cc6c7e910b5120618724392bf7a (diff)
downloadpangemma-24a4a5132a07ee6a8717844e3c5862882c88b25a.tar.gz
Tests still pass with safe_alloc (which sets the buffers to NaNs on allocation)
Diffstat (limited to 'src/logistic.cpp')
-rw-r--r--src/logistic.cpp29
1 files changed, 15 insertions, 14 deletions
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 <stdio.h>
#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.