--
To post to this group, send email to us...@tmb-project.org. Before posting, please check the wiki and issuetracker at https://github.com/kaskr/adcomp/. Please try to create a simple repeatable example to go with your question (e.g issues 154, 134, 51). Use the issuetracker to report bugs.
---
You received this message because you are subscribed to the Google Groups "TMB Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmb-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tmb-users/a74eac7f-b88d-4cc5-adaa-6ebbcd583c47%40googlegroups.com.
--
To post to this group, send email to us...@tmb-project.org. Before posting, please check the wiki and issuetracker at https://github.com/kaskr/adcomp/. Please try to create a simple repeatable example to go with your question (e.g issues 154, 134, 51). Use the issuetracker to report bugs.
---
You received this message because you are subscribed to the Google Groups "TMB Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmb-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tmb-users/1d08799c-fcdf-4989-8c23-e26f42a37ac5%40googlegroups.com.
template<class Type>
Type objective_function<Type>::operator() ()
{
PARAMETER(beta);
PARAMETER_VECTOR(betas);
DATA_VECTOR(x0);
DATA_VECTOR(x1);
DATA_VECTOR(boundaryKnots);
DATA_VECTOR(interiorKnots);
bs<Type> s1(boundaryKnots,interiorKnots,1);
vector<Type> xs = x0 + x1 * beta;
matrix<Type> Xs = s1.basis(xs);
REPORT(Xs);
Type f = (Xs*betas).sum();
return f;
}
for some given inputs, I get the correct spline basis (Xs) and function
value at the initial values. When I evaluate at a different value, I
also get the correct spline basis (ok), however I get an incorrect
objective function. This is particularly strange, as the objective is
only the sum of the basis matrix (which is correct) times the betas
vector...
Re-coding this with RcppEigen gives the correct objective function with
no evidence of a memory leak from valgrind (code available).
Is my implementation compatible with TMB? Any help with this would be
appreciated - I have been struggling with this for a while.
Kindly, Mark.
The spline knots are external and do not depend on the parameters, while
the spline evaluation points and spline basis do depend on the
parameters. In summary, splines with accelerated failure time models
probably do not fit within the current TMB framework. Out of interest,
would this work in ADMB?
As an aside, extracting the Q matrix from a QR decomposition is possible
with TMB. The main trick was to #include <R_ext/Applic.h> before
#include <TMB.hpp>. The code is:
MatrixXd qr_q(const MatrixXd& X, double tol = 1E-12)
{
// Initialize member data and allocate heap memory
int n=X.rows(), p=X.cols(), rank=0;
MatrixXd qr = X, y(n,n), q(n,n);
int* pivot=(int*)R_alloc(p,sizeof(int));
double* tau=(double*)R_alloc(p,sizeof(double));
double* work=(double*)R_alloc(p*2,sizeof(double));
for(int i=0;i<p;i++)
pivot[i]=i+1;
y.setIdentity();
// LINPACK QR factorization via householder transformations
F77_CALL(dqrdc2)(qr.data(), &n, &n, &p, &tol, &rank, tau, pivot,
work);
// Compute orthogonal factor Q
F77_CALL(dqrqy)(qr.data(), &n, &rank, tau, y.data(), &n, q.data());
return q;
}
Kindly, Mark.
Other options to deal with parameter dependent branching in TMB:
1. Use conditional expressions. E.g. CppAD::CondExpGt(x, y, expr_true, expr_false) returns 'expr_true' if x>y and 'expr_false' otherwise. variants 'Gt' (>), 'Ge' (>=), 'Lt' (<), 'Le' (<=), 'Eq' (==) exist. However, this approach would require major re-write of the spline code. Especially all parts depending on the 'cursor'.
2. In principle one could implement an 'atomic function' that automatically re-builds the computational graph of the spline for each function evaluation (which is much cheaper than rebuilding the entire graph). This is in principle possible but there is not yet an example that demonstrates it.
________________________________________
From: tmb-...@googlegroups.com [tmb-...@googlegroups.com] on behalf of Mark Clements [mark.c...@ki.se]
Sent: Tuesday, July 25, 2017 8:42 PM
To: Hans Skaug; TMB Users
Subject: Re: [TMB users] Re: B-splines / QR decomposition
Kindly, Mark.
--
To post to this group, send email to us...@tmb-project.org. Before posting, please check the wiki and issuetracker at https://github.com/kaskr/adcomp/. Please try to create a simple repeatable example to go with your question (e.g issues 154, 134, 51). Use the issuetracker to report bugs.
---
You received this message because you are subscribed to the Google Groups "TMB Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmb-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tmb-users/6E62DCB74E59D246B410609BB7A9D723018F24EC53%40KIMSX02.user.ki.se.