The BetaML.Utils Module
BetaML.Utils
— ModuleUtils module
Provide shared utility functions for various machine learning algorithms. You don't usually need to import from this module, as each other module (Nn, Perceptron, Clusters,...) reexport it.
Module Index
BetaML.Utils.accuracy
BetaML.Utils.accuracy
BetaML.Utils.accuracy
BetaML.Utils.autoJacobian
BetaML.Utils.batch
BetaML.Utils.cosine_distance
BetaML.Utils.dSoftMax
BetaML.Utils.getScaleFactors
BetaML.Utils.l1_distance
BetaML.Utils.l2_distance
BetaML.Utils.l2²_distance
BetaML.Utils.logNormalFixedSd
BetaML.Utils.lse
BetaML.Utils.makeMatrix
BetaML.Utils.normalFixedSd
BetaML.Utils.oneHotEncoder
BetaML.Utils.polynomialKernel
BetaML.Utils.radialKernel
BetaML.Utils.scale
BetaML.Utils.sterling
Detailed API
Base.error
— MethodCategorical error
Base.error
— MethodCategorical error with probabilistic prediction of a single datapoint.
Base.error
— MethodCategorical error with probabilistic predictions of a dataset.
Base.reshape
— Methodreshape(myNumber, dims..) - Reshape a number as a n dimensional Array
BetaML.Utils.accuracy
— MethodCategorical accuracy
BetaML.Utils.accuracy
— Methodaccuracy(x,y;tol)
Categorical accuracy with probabilistic prediction of a single datapoint.
Use the parameter tol [def: 1
] to determine the tollerance of the prediction, i.e. if considering "correct" only a prediction where the value with highest probability is the true value (tol
= 1), or consider instead the set of tol
maximum values.
BetaML.Utils.accuracy
— Methodaccuracy(x,y;tol)
Categorical accuracy with probabilistic predictions of a dataset.
Use the parameter tol [def: 1
] to determine the tollerance of the prediction, i.e. if considering "correct" only a prediction where the value with highest probability is the true value (tol
= 1), or consider instead the set of tol
maximum values.
BetaML.Utils.autoJacobian
— MethodautoJacobian(f,x;nY)
Evaluate the Jacobian using AD in the form of a (nY,nX) madrix of first derivatives
Parameters:
f
: The function to compute the Jacobianx
: The input to the function where the jacobian has to be computednY
: The number of outputs of the functionf
[def:length(f(x))
]
Return values:
- An
Array{Float64,2}
of the locally evaluated Jacobian
Notes:
- The
nY
parameter is optional. If provided it avoids having to computef(x)
BetaML.Utils.batch
— Methodbatch(n,bSize;sequential=false)
Return a vector of bSize
indeces from 1
to n
. Randomly unless the optional parameter sequential
is used.
BetaML.Utils.cosine_distance
— MethodCosine distance
BetaML.Utils.dSoftMax
— MethoddSoftMax(x;β) - Derivative of the softMax function
BetaML.Utils.getScaleFactors
— MethodgetScaleFactors(x;skip)
Return the scale factors (for each dimensions) in order to scale a matrix X (n,d) such that each dimension has mean 0 and variance 1.
Parameters
x
: the (n × d) dimension matrix to scale on each dimension dskip
: an array of dimension index to skip the scaling [def:[]
]
Return
- A touple whose first elmement is the shift and the second the multiplicative
term to make the scale.
BetaML.Utils.l1_distance
— MethodL1 norm distance (aka Manhattan Distance)
BetaML.Utils.l2_distance
— MethodEuclidean (L2) distance
BetaML.Utils.l2²_distance
— MethodSquared Euclidean (L2) distance
BetaML.Utils.logNormalFixedSd
— Methodlog-PDF of a multidimensional normal with no covariance and shared variance across dimensions
BetaML.Utils.lse
— MethodLogSumExp for efficiently computing log(sum(exp.(x)))
BetaML.Utils.makeMatrix
— MethodTransform an Array{T,1} in an Array{T,2} and leave unchanged Array{T,2}.
BetaML.Utils.normalFixedSd
— MethodPDF of a multidimensional normal with no covariance and shared variance across dimensions
BetaML.Utils.oneHotEncoder
— FunctiononeHotEncoder(y,d;count)
Encode arrays (or arrays of arrays) of integer data as 0/1 matrices
Parameters:
y
: The data to convert (integer, array or array of arrays of integers)d
: The number of dimensions in the output matrik. [def:maximum(maximum.(Y))
]count
: Wether to count multiple instances on the same dimension/record or indicate just presence. [def:false
]
BetaML.Utils.polynomialKernel
— MethodPolynomial kernel parametrised with c=0
and d=2
(i.e. a quadratic kernel). For other cᵢ
and dᵢ
use K = (x,y) -> polynomialKernel(x,y,c=cᵢ,d=dᵢ)
as kernel function in the supporting algorithms
BetaML.Utils.radialKernel
— MethodRadial Kernel (aka RBF kernel) parametrised with γ=1/2. For other gammas γᵢ use K = (x,y) -> radialKernel(x,y,γ=γᵢ)
as kernel function in the supporting algorithms
BetaML.Utils.scale
— Functionscale(x;scalingFactors)
Perform a linear scaling of x using scaling factors scalingFactors
.
Parameters
x
: the (n × d) dimension matrix to scale on each dimension dscalingFactors
: an tuple of the constant and multiplicative scaling factor
respectively [def: the scaling factors needed to scale x to mean 0 and variance 1]
Return
- The scaled matrix
Notes:
- also available
scale!(x;scalingFactors)
for in-place scaling.
BetaML.Utils.sterling
— MethodSterling number: number of partitions of a set of n elements in k sets