Most of the functions from BUGS have been implemented.
JuliaBUGS directly utilizes functions from the Julia Standard Library when they share the same names and functionalities. For functions not available in the Julia Standard Library and other popular libraries, we have developed equivalents within JuliaBUGS.BUGSPrimitives.
Function defined in Julia Standard Library
Please note that some functions listed may accept additional arguments (e.g. trunc) and/or keyword arguments (e.g. sum, sort, mean). However, at the moment JuliaBUGS only supports function arguments of type Real or AbstractArray{Real}. Furthermore, JuliaBUGS does not accommodate the use of keyword argument syntax. Thus, the default values for any optional or keyword arguments will be automatically applied.
Base.abs — Functionabs(x)The absolute value of x.
When abs is applied to signed integers, overflow may occur, resulting in the return of a negative value. This overflow occurs only when abs is applied to the minimum representable value of a signed integer. That is, when x == typemin(typeof(x)), abs(x) == x < 0, not -x as might be expected.
See also: abs2, unsigned, sign.
Examples
julia> abs(-3)
3
julia> abs(1 + im)
1.4142135623730951
julia> abs.(Int8[-128 -127 -126 0 126 127]) # overflow at typemin(Int8)
1×6 Matrix{Int8}:
-128 127 126 0 126 127
julia> maximum(abs, [1, -2, 3, -4])
4Base.exp — Methodexp(x)Compute the natural base exponential of x, in other words $ℯ^x$.
Examples
julia> exp(1.0)
2.718281828459045
julia> exp(im * pi) ≈ cis(pi)
trueBase.log — Methodlog(x)Compute the natural logarithm of x.
Throws DomainError for negative Real arguments. Use complex arguments to obtain complex results. Has a branch cut along the negative real axis, for which -0.0im is taken to be below the axis.
See also ℯ, log1p, log2, log10.
Examples
julia> log(2)
0.6931471805599453
julia> log(-3)
ERROR: DomainError with -3.0:
log was called with a negative real argument but will only return a complex result if called with a complex argument. Try log(Complex(x)).
Stacktrace:
[1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
[...]
julia> log(-3 + 0im)
1.0986122886681098 + 3.141592653589793im
julia> log(-3 - 0.0im)
1.0986122886681098 - 3.141592653589793im
julia> log.(exp.(-1:1))
3-element Vector{Float64}:
-1.0
0.0
1.0Base.sqrt — Methodsqrt(x)Return $\sqrt{x}$.
Throws DomainError for negative Real arguments. Use complex negative arguments instead. Note that sqrt has a branch cut along the negative real axis.
The prefix operator √ is equivalent to sqrt.
See also: hypot.
Examples
julia> sqrt(big(81))
9.0
julia> sqrt(big(-81))
ERROR: DomainError with -81.0:
NaN result for non-NaN input.
Stacktrace:
[1] sqrt(::BigFloat) at ./mpfr.jl:501
[...]
julia> sqrt(big(complex(-81)))
0.0 + 9.0im
julia> sqrt(-81 - 0.0im) # -0.0im is below the branch cut
0.0 - 9.0im
julia> .√(1:4)
4-element Vector{Float64}:
1.0
1.4142135623730951
1.7320508075688772
2.0Base.trunc — Functiontrunc([T,] x)
trunc(x; digits::Integer= [, base = 10])
trunc(x; sigdigits::Integer= [, base = 10])trunc(x) returns the nearest integral value of the same type as x whose absolute value is less than or equal to the absolute value of x.
trunc(T, x) converts the result to type T, throwing an InexactError if the truncated value is not representable a T.
Keywords digits, sigdigits and base work as for round.
To support trunc for a new type, define Base.round(x::NewType, ::RoundingMode{:ToZero}).
See also: %, floor, unsigned, unsafe_trunc.
Examples
julia> trunc(2.22)
2.0
julia> trunc(-2.22, digits=1)
-2.2
julia> trunc(Int, -2.22)
-2Base.min — Methodmin(x, y, ...)Return the minimum of the arguments, with respect to isless. If any of the arguments is missing, return missing. See also the minimum function to take the minimum element from a collection.
Examples
julia> min(2, 5, 1)
1
julia> min(4, missing, 6)
missingBase.max — Methodmax(x, y, ...)Return the maximum of the arguments, with respect to isless. If any of the arguments is missing, return missing. See also the maximum function to take the maximum element from a collection.
Examples
julia> max(2, 5, 1)
5
julia> max(5, missing, 6)
missingBase.sum — Methodsum(A::AbstractArray; dims)Sum elements of an array over the given dimensions.
Examples
julia> A = [1 2; 3 4]
2×2 Matrix{Int64}:
1 2
3 4
julia> sum(A, dims=1)
1×2 Matrix{Int64}:
4 6
julia> sum(A, dims=2)
2×1 Matrix{Int64}:
3
7Base.sort — Methodsort(A; dims::Integer, alg::Algorithm=defalg(A), lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward)Sort a multidimensional array A along the given dimension. See sort! for a description of possible keyword arguments.
To sort slices of an array, refer to sortslices.
Examples
julia> A = [4 3; 1 2]
2×2 Matrix{Int64}:
4 3
1 2
julia> sort(A, dims = 1)
2×2 Matrix{Int64}:
1 2
4 3
julia> sort(A, dims = 2)
2×2 Matrix{Int64}:
3 4
1 2Base.sin — Methodsin(x)Compute sine of x, where x is in radians.
See also sind, sinpi, sincos, cis, asin.
Examples
julia> round.(sin.(range(0, 2pi, length=9)'), digits=3)
1×9 Matrix{Float64}:
0.0 0.707 1.0 0.707 0.0 -0.707 -1.0 -0.707 -0.0
julia> sind(45)
0.7071067811865476
julia> sinpi(1/4)
0.7071067811865475
julia> round.(sincos(pi/6), digits=3)
(0.5, 0.866)
julia> round(cis(pi/6), digits=3)
0.866 + 0.5im
julia> round(exp(im*pi/6), digits=3)
0.866 + 0.5imBase.cos — MethodBase.tan — Methodtan(x)Compute tangent of x, where x is in radians.
Base.asin — Methodasin(x)Compute the inverse sine of x, where the output is in radians.
See also asind for output in degrees.
Examples
julia> asin.((0, 1/2, 1))
(0.0, 0.5235987755982989, 1.5707963267948966)
julia> asind.((0, 1/2, 1))
(0.0, 30.000000000000004, 90.0)Base.acos — Methodacos(x)Compute the inverse cosine of x, where the output is in radians
Base.atan — Methodatan(y)
atan(y, x)Compute the inverse tangent of y or y/x, respectively.
For one real argument, this is the angle in radians between the positive x-axis and the point (1, y), returning a value in the interval $[-\pi/2, \pi/2]$.
For two arguments, this is the angle in radians between the positive x-axis and the point (x, y), returning a value in the interval $[-\pi, \pi]$. This corresponds to a standard atan2 function. Note that by convention atan(0.0,x) is defined as $\pi$ and atan(-0.0,x) is defined as $-\pi$ when x < 0.
See also atand for degrees.
Examples
julia> rad2deg(atan(-1/√3))
-30.000000000000004
julia> rad2deg(atan(-1, √3))
-30.000000000000004
julia> rad2deg(atan(1, -√3))
150.0Base.asinh — Methodasinh(x)Compute the inverse hyperbolic sine of x.
Base.acosh — Methodacosh(x)Compute the inverse hyperbolic cosine of x.
Base.atanh — Methodatanh(x)Compute the inverse hyperbolic tangent of x.
Statistics.mean — Methodmean(A::AbstractArray; dims)Compute the mean of an array over the given dimensions.
Examples
julia> using Statistics
julia> A = [1 2; 3 4]
2×2 Matrix{Int64}:
1 2
3 4
julia> mean(A, dims=1)
1×2 Matrix{Float64}:
2.0 3.0
julia> mean(A, dims=2)
2×1 Matrix{Float64}:
1.5
3.5Function defined in LogExpFunctions
LogExpFunctions.cloglog — Functioncloglog(x)
Compute the complementary log-log, log(-log(1 - x)).
LogExpFunctions.cexpexp — Functioncexpexp(x)
Compute the complementary double exponential, 1 - exp(-exp(x)).
LogExpFunctions.logit — Functionlogit(x)
The logit or log-odds transformation, defined as
\[\operatorname{logit}(x) = \log\left(\frac{x}{1-x}\right)\]
for $0 < x < 1$.
Its inverse is the logistic function.
LogExpFunctions.logistic — Functionlogistic(x)
The logistic sigmoid function mapping a real number to a value in the interval $[0,1]$,
\[\sigma(x) = \frac{1}{e^{-x} + 1} = \frac{e^x}{1+e^x}.\]
Its inverse is the logit function.
Function defined in JuliaBUGS.BUGSPrimitives
JuliaBUGS.BUGSPrimitives.equals — Functionequals(x, y)Returns 1 if $x$ is equal to $y$, 0 otherwise.
JuliaBUGS.BUGSPrimitives.inprod — Functioninprod(a, b)Inner product of $a$ and $b$.
JuliaBUGS.BUGSPrimitives.inverse — Functioninverse(m::AbstractMatrix)Inverse of matrix $\mathbf{m}$.
JuliaBUGS.BUGSPrimitives.logdet — Functionlogdet(::AbstractMatrix)Logarithm of the determinant of matrix $\mathbf{v}$.
JuliaBUGS.BUGSPrimitives.logfact — Functionlogfact(x)Logarithm of the factorial of $x$.
JuliaBUGS.BUGSPrimitives.loggam — Functionloggam(x)Logarithm of the gamma function of $x$.
JuliaBUGS.BUGSPrimitives.icloglog — Functionicloglog(x)Inverse complementary log-log function of $x$. Alias for cexpexp(x).
JuliaBUGS.BUGSPrimitives.ilogit — Functionilogit(x)Inverse logit function of $x$. Alias for logistic(x).
JuliaBUGS.BUGSPrimitives.mexp — Functionmexp(x::AbstractMatrix)Matrix exponential of $\mathbf{x}$.
JuliaBUGS.BUGSPrimitives.phi — Functionphi(x)Cumulative distribution function (CDF) of the standard normal distribution evaluated at $x$.
JuliaBUGS.BUGSPrimitives.probit — FunctionprobitInverse of phi.
JuliaBUGS.BUGSPrimitives.pow — Functionpow(a, b)Return $a$ raised to the power of $b$.
JuliaBUGS.BUGSPrimitives.rank — Functionrank(v::AbstractVector, i::Integer)Return the rank of the $i$-th element of $\mathbf{v}$.
JuliaBUGS.BUGSPrimitives.ranked — Functionranked(v::AbstractVector, i::Integer)Return the $i$-th element of $\mathbf{v}$ sorted in ascending order.
JuliaBUGS.BUGSPrimitives.sd — Functionsd(v::AbstractVector)Return the standard deviation of the input vector $\mathbf{v}$.
JuliaBUGS.BUGSPrimitives.softplus — Functionsoftplus(x)Return the softplus function of x, defined as $\log(1 + \exp(x))$.
JuliaBUGS.BUGSPrimitives._step — Function_step(x)Return 1 if $x$ is greater than 0, and 0 otherwise.
JuliaBUGS.BUGSPrimitives.arcsin — Functionarcsin(x)See asin.
JuliaBUGS.BUGSPrimitives.arcsinh — Functionarcsinh(x)See asinh.
JuliaBUGS.BUGSPrimitives.arccos — Functionarccos(x)See acos.
JuliaBUGS.BUGSPrimitives.arccosh — Functionarccosh(x)See acosh.
JuliaBUGS.BUGSPrimitives.arctan — Functionarctan(x)See atan.
JuliaBUGS.BUGSPrimitives.arctanh — Functionarctanh(x)See atanh.