I think I fixed my integrand and I did confirm that it works fine using R’s integrate()
function. I’m not hitting a complier error when I use stan_model()
on my model file. This is what my functions now look like:
real expected_delta_part(real v, real xc, real[] theta, data real[] x_r, data int[] x_i) {
real w = theta[1];
real u_sd = theta[2];
return v * exp(normal_lcdf(w - v | 0, u_sd) + normal_lpdf(v | 0, 1));
}
real expected_delta(real w, real u_sd) {
real delta_part = integrate_1d(expected_delta_part, negative_infinity(), positive_infinity(), { w, u_sd }, { 0.0 }, { 0 }, 0.01);
real F_w = Phi_approx(w / u_sd);
return - delta_part / (F_w * (1 - F_w));
}
vector v_fixedpoint_solution_normal(vector model_param, vector theta, data real[] x_r, data int[] x_i) {
real cutoff = model_param[1];
real benefit_cost = theta[1];
real mu = theta[2];
int num_v_mix = x_i[1];
int use_u_in_delta = x_i[2];
vector[num_v_mix] lambda = theta[3:(3 + num_v_mix - 1)];
vector[num_v_mix] mix_mean = theta[(3 + num_v_mix):(3 + 2 * num_v_mix - 1)];
vector[num_v_mix] mix_sd = theta[(3 + 2 * num_v_mix):(3 + 3 * num_v_mix - 1)];
real u_sd = theta[3 + 3 * num_v_mix];
if (use_u_in_delta && u_sd > 0) {
return [ cutoff + benefit_cost + mu * expected_delta(cutoff, u_sd) ]';
} else {
return [ cutoff + benefit_cost + mu * reputational_returns_normal(cutoff, lambda, mix_mean, mix_sd) ]';
}
}
I’m getting the below error message. It goes away if I remove the line that calls expected_delta()
above.
> stan_model("stan_models/takeup_struct.stan")
DIAGNOSTIC(S) FROM PARSER:
Info: integer division implicitly rounds to integer. Found int division: num_elements(to_index) / num_indices
Positive values rounded down, negative values rounded up or down in platform-dependent way.
Info: integer division implicitly rounds to integer. Found int division: sample_size - 1 * quants[quant_index] / 100
Positive values rounded down, negative values rounded up or down in platform-dependent way.
Info: integer division implicitly rounds to integer. Found int division: sample_size - 1 * quants[quant_index] / 100
Positive values rounded down, negative values rounded up or down in platform-dependent way.
Info: integer division implicitly rounds to integer. Found int division: 1 - 2 * reverse * to - from / by
Positive values rounded down, negative values rounded up or down in platform-dependent way.
When you compile models, you are also contributing to development of the NEXT
Stan compiler. In this version of rstan, we compile your model as usual, but
also test our new compiler on your syntactically correct model. In this case,
the new compiler did not work like we hoped. By filing an issue at
https://github.com/stan-dev/stanc3/issues with your model
or a minimal example that shows this warning you will be contributing
valuable information to Stan and ensuring your models continue working. Thank you!
This message can be avoided by wrapping your function call inside suppressMessages()
or by first calling rstan_options(javascript = FALSE).
Error in context_eval(join(src), private$context, serialize) :
0,248,Frontend.Errors.SyntaxError,178,1,Could not find include file takeup_header.stan in specified include paths.
,0,string,1,0,0
hash mismatch so recompiling; make sure Stan code ends with a blank line
make cmd is
make -f '/opt/R/4.0.3/lib/R/etc/Makeconf' -f '/opt/R/4.0.3/lib/R/share/make/shlib.mk' -f '/home/karim/.R/Makevars' CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB='file21adf7c88bef6.so' OBJECTS='file21adf7c88bef6.o'
make would use
g++ -std=gnu++14 -I"/opt/R/4.0.3/lib/R/include" -DNDEBUG -I"/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/Rcpp/1.0.5/125dc7a0ed375eb68c0ce533b48d291f/Rcpp/include/" -I"/media/karim/Code Drive/karimn-code/takeup/renv/library/R-4.0/x86_64-pc-linux-gnu/RcppEigen/include/" -I"/media/karim/Code Drive/karimn-code/takeup/renv/library/R-4.0/x86_64-pc-linux-gnu/RcppEigen/include/unsupported" -I"/media/karim/Code Drive/karimn-code/takeup/renv/library/R-4.0/x86_64-pc-linux-gnu/BH/include" -I"/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/StanHeaders/2.21.0-6/9da8818e00c8e3fc7c94d707523a0009/StanHeaders/include/src/" -I"/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/StanHeaders/2.21.0-6/9da8818e00c8e3fc7c94d707523a0009/StanHeaders/include/" -I"/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/RcppParallel/5.0.2/551d50addb18c7b99637aa377a25afc8/RcppParallel/include/" -I"/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/rstan/2.21.2/52772d81aa532a6331fd535701882c12/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/StanHeaders/2.21.0-6/9da8818e00c8e3fc7c94d707523a0009/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fpic -O3 -march=native -mtune=native -fPIC -DSTAN_THREADS -pthread -c file21adf7c88bef6.cpp -o file21adf7c88bef6.o
if test "zfile21adf7c88bef6.o" != "z"; then \
echo g++ -std=gnu++14 -shared -L"/opt/R/4.0.3/lib/R/lib" -L/usr/local/lib -o file21adf7c88bef6.so file21adf7c88bef6.o '/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/rstan/2.21.2/52772d81aa532a6331fd535701882c12/rstan/lib//libStanServices.a' -L'/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/StanHeaders/2.21.0-6/9da8818e00c8e3fc7c94d707523a0009/StanHeaders/lib/' -lStanHeaders -L'/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/RcppParallel/5.0.2/551d50addb18c7b99637aa377a25afc8/RcppParallel/lib/' -ltbb -L"/opt/R/4.0.3/lib/R/lib" -lR; \
g++ -std=gnu++14 -shared -L"/opt/R/4.0.3/lib/R/lib" -L/usr/local/lib -o file21adf7c88bef6.so file21adf7c88bef6.o '/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/rstan/2.21.2/52772d81aa532a6331fd535701882c12/rstan/lib//libStanServices.a' -L'/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/StanHeaders/2.21.0-6/9da8818e00c8e3fc7c94d707523a0009/StanHeaders/lib/' -lStanHeaders -L'/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/RcppParallel/5.0.2/551d50addb18c7b99637aa377a25afc8/RcppParallel/lib/' -ltbb -L"/opt/R/4.0.3/lib/R/lib" -lR; \
fi
Error in compileCode(f, code, language = language, verbose = verbose) :
/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/StanHeaders/2.21.0-6/9da8818e00c8e3fc7c94d707523a0009/StanHeaders/include/stan/math/rev/mat/fun/multiply.hpp:131:9: required from ‘void stan::math::multiply_mat_vari<Ta, Ra, Ca, Tb, Cb>::chain() [with Ta = stan::math::var; int Ra = -1; int Ca = -1; Tb = stan::math::var; int Cb = -1]’/home/karim/.local/share/renv/cache/v5/R-4.0/x86_64-pc-linux-gnu/StanHeaders/2.21.0-6/9da8818e00c8e3fc7c94d707523a0009/StanHeaders/include/stan/math/rev/mat/fun/multiply.hpp:107:16: required from here/media/karim/Code Drive/karimn-code/takeup/renv/library/R-4.0/x86_64-pc-linux-gnu/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:55:30: warning: ignoring attributes on template argument ‘Eigen::internal::packet_traits<double>::type’ {aka ‘__m256d’} [-Wignored-attributes] 55 | >::type PacketReturnType; | ^~~~~~~~~~~~~~~~make: *** [/opt/R/4.0.3/lib/R/etc/Makeconf:
Error in sink(type = "output") : invalid connection
The integration I’m doing can be replicated in R like this:
delta_part <- function(v, w, u_sd, lower.tail = TRUE) v * pnorm(w - v, sd = u_sd, lower.tail = lower.tail) * dnorm(v)
integrate(delta_part, w = 2, u_sd = 2, -Inf, Inf)
I appreciate all your help! Please let me know if I can help investigating this problem. Also, I’m kind of re-using an old discussion. Let me know if you want me to start a new one.