I realize this is a pretty niche problem, but I figure it's worth asking anyway.
I'm working on a program that does root-finding, and the function that it's trying to find a root for involves computing Fresnel integrals, which are implemented using erf(). I thought I'd try using the IntervalRootFinding package, but haven't gotten very far with it. I get a MethodError exception, which looks like:
MethodError: no method matching _erf(::Complex{IntervalArithmetic.Interval{Float64}})
Any advice?
IntervalArithmatic requires that your functions know how to work with intervals. Since erf is monotonic, you could define your own implimentation
using IntervalArithmatic
erf(x::Interval{T}) where T = Interval(prevfloat(erf(x.lo)), nextfloat(erf(x.hi)))
Related
I am trying to use the ebirdst package for some exploratory data analysis, following this tutorial. Everything going according to plan until I run this line:
week_ext <- calc_full_extent(occ_proj)
and get this error:
Error in calc_full_extent(occ_proj) : could not find function "calc_full_extent"
I know sometimes new functions won't show up, or it can be a version issue, but the tutorial I'm referencing is from 2018 and everything else works perfectly. Does anyone know why a crucial function would just not be there? Or what steps to take? I've looked to see if there are any analogous functions and can't find any.
Also this is my first stackoverflow question--I've always been able to solve my issues based on existing questions, but there seems to be very little out there on ebirdst--so please let me know if I need to provide more info/context.
Thanks!
I am learning R package SimInf to simulate data-driven stochastic epidemiological models. As I was reading the documentation I came across an unrecognized funcion Nn when defining a function for epicurves. Specifically, this line:
j <- sample(seq_len(Nn(model)), 1)
Values of model are integers. My guess is that Nn selects non-negative values, however my R does not recognize this function. From documentation it does not look like they pre-defined Nn either. Can someone please tell if they know what "Nn" is for? Thank you.
A way to go is always taking the package-name and triple-":" it, such that you can find nearly all functions inside the package. Maybe you are familiar with namespacing a function via packageName::functionFrompackageTocall. The packageName::: shows (nearly) all functions defined in this package. If you do this in R-Studio with SimInf:: and SimInf:::, you will see that the latter gives much more functions. But you can only find the functions SimInf:::Nd and SimInf:::Nc, not the Nn-function. Hence you will have to go to the github-sources of the package, in this case https://github.com/stewid/SimInf .Then search for Nn the whole repository. You will see that it seems like it is always an int, but this doesn't help you since you want to get ii as a function, not as a variable. Scrolling further down in the search-results, you will find the NEWS.md-file which mentions The 'Nn' function to determine the number of nodes in a model has been replaced with the S4 method 'n_nodes'. in the https://github.com/stewid/SimInf/blob/fd7eb4a29b82a4a97f64b528bb0e78e5474aa8a5/NEWS.md file under SimInf 8.0.0 (2020-09-13). Hence having a current version of SimInf installed, it shouldn't use the method Nn anymore. If you use it in your code, replace it by n_nodes. If you find it in current package code, you can email the package-maintainer that you found a bug in his code.
TLDR: Nn is an outdated version of n_nodes
I currently have an issue with a new project, because I need a solution for a LCP. I know there are
algorithms like Lemke etc. But each of them seems to be written in C++ or Python(using numpy).
I am not really able to implement an algorithm by myself, because I'm not completely familiar with all the math behind it.
So my question is if there is any LCP solver for Java which I can just use by calling something like
SolveLCP(Matrix M, Vector q, Vector w, Vector z)
for computing w and z from M and q ?
I found an algorithm at
https://www.geometrictools.com/GTE/Mathematics/LCPSolver.h
which seems to work pretty good, but unfortunately it's C++ and I failed to convert it into java(actually I use kotlin). My version has the correct results sometimes, but not every time compared with the C++ implementation.
I implemented it in kotlin, you can find it here:
https://github.com/mihisg/LCPSolver_Kotlin/tree/main
I would really appreciate it if someone could help finding the errors. I think I did something wrong with representing all those pointers, but in fact, it only works sometimes.
I am trying to solve a numerical equation in R but would want a method which perform similar to vpasolve in Matlab. I have a non linear equation (involving lot of log functions) which when solve in R with uniroot gives me complete different answer compared to what vpasolve gives in matlab.
First, a word of caution: it's often much more productive to learn that there's a better way to do something than the way you are used to doing.
edit
I went back to MATLAB and realized that the "vpa" collection is using extended precision. Is that absolutely necessary for your purposes? If not, then my suggestions below may suffice.
If you do require extended precision, then perhaps Rmpfr::unirootR function will suffice. I would like to point out that, since all these solvers are generating an approximate solution (as opposed to analytic), the use of extended precision operations seems a bit pointless.
Next, you need to determine whether MATLAB::vpasolve or uniroot is getting you the correct answer. Or maybe you simply are converging to a root that's not the one you want, in which case you need to read up on setting limits on the starting conditions or the search region.
Finally, in addition to uniroot, I recommend you learn to use the R packages BBsolve , nleqslv, rootsolve, and ktsolve (disclaimer: I am the owner and maintainer of ktsolve). These packages are pretty flexible and may lead you to better solutions to your original problem.
I want to follow the tutorial found on this site, but despite being thorough in all other aspects, the author has not included information on what packages need to be used for the code to function.
As far as I understand one of them will be the PerformanceAnalytics package, yet my inexperienced eye is not sure about what else I will need to include.
The fapply function used in the code is one example that I cannot find.
fapply()
Error: could not find function "fapply"
library(sos)
findFn("fapply", sortby = "Function")
The findFN(...) function is great. It should open an internet browser window with the search results by itself at least it does for me.
The tutorial on Backtesting a Trading Strategy uses time series data as seen its part 1 and part 2. fapply is also used in part 2
As the data being collected and processed is time-series data, fapply() function belongs to far package which is used for Modelization for Functional AutoRegressive Processes.
I hope this helps.