The BetaML.Utils Module

BetaML.UtilsModule
Utils 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

Detailed API

Base.errorMethod

Categorical error with probabilistic prediction of a single datapoint.

Base.errorMethod

Categorical error with probabilistic predictions of a dataset.

Base.reshapeMethod

reshape(myNumber, dims..) - Reshape a number as a n dimensional Array

BetaML.Utils.accuracyMethod
accuracy(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.accuracyMethod

accuracy(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.autoJacobianMethod

autoJacobian(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 Jacobian
  • x: The input to the function where the jacobian has to be computed
  • nY: The number of outputs of the function f [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 compute f(x)
BetaML.Utils.batchMethod

batch(n,bSize;sequential=false)

Return a vector of bSize indeces from 1 to n. Randomly unless the optional parameter sequential is used.

BetaML.Utils.getScaleFactorsMethod
getScaleFactors(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 d
  • skip: 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.lseMethod

LogSumExp for efficiently computing log(sum(exp.(x)))

BetaML.Utils.oneHotEncoderFunction
oneHotEncoder(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.polynomialKernelMethod

Polynomial 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.radialKernelMethod

Radial 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.scaleFunction
scale(x;scalingFactors)

Perform a linear scaling of x using scaling factors scalingFactors.

Parameters

  • x: the (n × d) dimension matrix to scale on each dimension d
  • scalingFactors: 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.