`utils` object


The utils object contains some useful helper functions which are used by a number of API components of DynaML.

String/File Processing

Load File into a Stream

val content = utils.textFileToStream("data.csv")

String Replace

Replace all occurrences of a string (or regular expression) in a target string

val new_str = utils.replace(find = ",")(replace = "|")(input = "1,2,3,4")

URL download

Download the content of a url to a specified location on disk.

utils.downloadURL("www.google.com", "google_home_page.html")

Write to File

val content: Stream[String] = _



Calculates log_{e}(1+x).

val l = utils.log1pExp(0.02)

Haar DWT Matrix

Constructs the Haar discrete wavelet transform matrix for orders which are powers of two.

val dwt_mat = utils.haarMatrix(math.pow(2, 3).toInt)

Hermite Polynomials

The Hermite polynomials are an important class of orthogonal polynomials used in numerical analysis. There are two definitions of the Hermite polynomials i.e. the probabilist and physicist definitions, which are equivalent up-to a scale factor. The the utils object, the probabilist polynomials are calculated.

//Calculate the 3rd order Hermite polynomial

val h3 = (x: Double) => utils.hermite(3, x)


Chebyshev Polynomials

Chebyshev polynomials are another important class of orthogonal polynomials used in numerical analysis. There are two types, the first kind and second kind.

//Calculate the Chebyshev polynomial of second kind order 3

val c23 = (x: Double) => utils.chebyshev(3, x, kind = 2)


Quick Select

The quick select aims to find the k^{th} smallest element of a list of numbers.

val second = utils.quickselect(List(3,2,4,5,1,6), 2)


val second = utils.median(List(3,2,4,5,1,6))

Sample Statistics

Calculate the mean and variance (or covariance), minimum, maximum of a list of DenseVector[Double] instances.

val data: List[DenseVector[Double]] = _

val (mu, vard): (DenseVector[Double], DenseVector[Double]) =

val (mean, cov): (DenseVector[Double], DenseMatrix[Double]) =

val (min, max) = utils.getMinMax(data)