swh:1:snp:81eadaa089e8253d8469bcef66aa332632c6c669
Raw File
Tip revision: fdf16693b000f3e309c56091892c61f0ec9fd670 authored by Hans W. Borchers on 21 November 2017, 16:15:00 UTC
version 2.1.1
Tip revision: fdf1669
sigmoid.R
##
##  s i g m o i d . R  Sigmoid Function
##


sigmoid <- function(x, a = 1, b = 0) {
    if (length(x) == 0) return(c())
    stopifnot(is.numeric(x), is.numeric(a), is.numeric(b))
    a <- a[1]; b <- b[1]

    1 / (1 + exp(-a*(x-b)))
}


logit <- function(x, a = 1, b = 0) {
    if (length(x) == 0) return(c())
    stopifnot(is.numeric(x), is.numeric(a), is.numeric(b))
    a <- a[1]; b <- b[1]

    if (x < 0 || x > 1) return(NaN)
    if (x >= 0 && x <= 1)
        return(b + log(x/(1-x))/a)
    else
        return(NaN)
}
back to top