Description Usage Arguments Value Author(s) Examples
A fixed point is defined by f(x)=x. Often this condition can't be fulfilled exactly, and so we must check convergence using a looser criterion, like abs(f(x)-x) < tol. The convergence criterion can be specified using a function of two arguments: d(x,x'), returning either a logical value or a positive scalar, to be checked against the tolerance 'tol'. The predefined convergence functions are: mse=function(a,b) mean((a-b)^2) rmse=function(a,b) sqrt(mean((a-b)^2)) mad=function(a,b) mean(abs(a-b)) mre=function(a,b) mean(abs(a-b)/abs(a+b) If convergence can't be reached at all, we interrupt the search after a maximum number of iterations (set by maxIter).
1 | convergence(fun, tol, maxIter)
|
fun |
convergence check: either a function with two arguments or a character string like "rmse" |
tol |
tolerance |
maxIter |
used for side effects
Simon Barthelme
1 2 3 4 5 6 7 8 | f <- function(x) x/2
g <- fp(f)
g(3) #by default convergence is assessed using all.equal
(g+convergence("rmse",tol=.1))(3) #root-mean-square less than .1
(g+convergence("rmse",tol=.01))(3) #root-mean-square less than .01
#Custom function
d = function(a,b) sum(abs(log(a)-log(b)))
(g+convergence(d,tol=.01))(3) #can't converge because fixed point is at 0
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.