fastmath.protocols

Set of protocols for fastmath.

Includes:

  • random generator protocol
  • distribution protocols
  • vector protocol

DistributionIdProto

protocol

Get name and parameter names from distribution

members

distribution-id

(distribution-id d)

Distribution id as keyword

distribution-parameters

(distribution-parameters d)

List of distribution parameter names

DistributionProto

protocol

Get information from distributions.

members

cdf

(cdf d v)(cdf d v1 v2)

Cumulative probability.

continuous?

(continuous? d)

Does distribution support continuous range?

dimensions

(dimensions d)

Returns dimensions

icdf

(icdf d p)

Inverse cumulative probability

lpdf

(lpdf d v)

Log density

pdf

(pdf d v)

Density

probability

(probability d v)

Probability (PMF)

sample

(sample d)

Returns random sample.

source-object

(source-object d)

Returns Java object from backend library

GPProto

protocol

members

posterior-samples

(posterior-samples gp vs stddev?)

Draw samples from posterior for given vs

prior-samples

(prior-samples _ vs)

Draw samples from prior for given vs

GridProto

protocol

Common grid conversion functions.

members

cell->anchor

(cell->anchor g cell)

Converts cell coordinates to anchor coordinates.

coords->cell

(coords->cell g coords)

Converts 2d space coordinates to cell coordinates.

coords->mid

(coords->mid g coords)

Converts 2d space into cell midpoint.

corners

(corners g coords)(corners g coords scale)

Returns list of cell vertices for given 2d space coordinates.

grid-type

(grid-type g)

Returns type of the cell.

MultivariateDistributionProto

protocol

Get information from distributions.

members

covariance

(covariance d)

Variance

means

(means d)

Mean

PredictorProto

protocol

members

backend

(backend _)

Return name of backend library

cv

(cv _)(cv _ params)

Cross-validation

data-native

(data-native _)

Return data transformed for backend library.

model-native

(model-native _)

Return trained model as a backend class.

predict

(predict _ v info?)

Predict for given vector. Additional info may be returned on request.

predict-all

(predict-all _ v info?)

Predict for given sequence of vectors. Additional info may be returned on request.

train

(train _)(train _ x y)

Train another set of data for given model or force training already given data.

RNGProto

protocol

Defines set of random functions for different RNGs or distributions returning primitive values.

members

->seq

(->seq rng)(->seq rng n)

Returns lazy sequence of random samples (can be limited to optional n values).

brandom

(brandom rng)(brandom rng p)

Boolean random.

Returns true or false with equal probability. You can set p probability for true

drandom

(drandom rng)(drandom rng mx)(drandom rng mn mx)

Random double.

As default returns random double from [0,1) range. When mx is passed, range is set to [0, mx). When mn is passed, range is set to [mn, mx).

frandom

(frandom rng)(frandom rng mx)(frandom rng mn mx)

Random float.

As default returns random float from [0,1) range. When mx is passed, range is set to [0, mx). When mn is passed, range is set to [mn, mx).

grandom

(grandom rng)(grandom rng std)(grandom rng mean std)

Random double from gaussian distribution.

As default returns random double from N(0,1). When std is passed, N(0,std) is used. When mean is passed, distribution is set to N(mean, std).

irandom

(irandom rng)(irandom rng mx)(irandom rng mn mx)

Random integer.

As default returns random integer from full integer range. When mx is passed, range is set to [0, mx). When mn is passed, range is set to [mn, mx).

lrandom

(lrandom rng)(lrandom rng mx)(lrandom rng mn mx)

Random long.

As default returns random long from full long range. When mx is passed, range is set to [0, mx). When mn is passed, range is set to [mn, mx).

set-seed!

(set-seed! rng v)

Sets seed. Returns rng

TransformProto

protocol

Transformer functions.

members

forward-1d

(forward-1d t xs)

Forward transform of sequence or array.

forward-2d

(forward-2d t xss)

Forward transform of sequence of sequences.

reverse-1d

(reverse-1d t xs)

Reverse transform of sequence or array.

reverse-2d

(reverse-2d t xss)

Reverse transform of sequence of sequences.

UnivariateDistributionProto

protocol

members

lower-bound

(lower-bound d)

Lower value

mean

(mean d)

Mean

upper-bound

(upper-bound d)

Higher value

variance

(variance d)

Variance

VectorProto

protocol

Vector operations

members

abs

(abs v1)

Absolute value of vector elements

add

(add v1)(add v1 v2)

Sum of two vectors.

approx

(approx v)(approx v d)

Round to 2 (or d) decimal places

as-vec

(as-vec v)(as-vec v xs)

Create vector from sequence as given type.

axis-rotate

(axis-rotate v1 angle axis)(axis-rotate v1 angle axis pivot)

Rotate around axis, 3d only

base-from

(base-from v)

List of perpendicular vectors (basis)

cross

(cross v1 v2)

Cross product

dot

(dot v1 v2)

Dot product of two vectors.

econstrain

(econstrain v val1 val2)

Element-wise constrain

einterpolate

(einterpolate v1 v2 v f)

Interpolate vectors element-wise, optionally set interpolation fn

emn

(emn v1 v2)

Element-wise min from two vectors.

emult

(emult v1 v2)

Element-wise vector multiplication (Hadamard product).

emx

(emx v1 v2)

Element-wise max from two vectors.

fmap

(fmap v f)

Apply function to all vector values (like map but returns the same type).

from-polar

(from-polar v1)

From polar coordinates (2d, 3d only)

heading

(heading v1)

Angle between vector and unit vector [1,0,...]

interpolate

(interpolate v1 v2 t f)

Interpolate vectors, optionally set interpolation fn

is-near-zero?

(is-near-zero? v1)(is-near-zero? v1 tol)

Is vector almost zero? (all absolute values of elements are less than tol tolerance or 1.0e-6)

is-zero?

(is-zero? v1)

Is vector zero?

mag

(mag v1)

length of the vector.

magsq

(magsq v1)

Length of the vector squared.

maxdim

(maxdim v)

Index of maximum value.

mindim

(mindim v)

Index of minimum value.

mn

(mn v1)

Minimum value of vector elements

mult

(mult v1 v)

Multiply vector by number v.

mx

(mx v1)

Maximum value of vector elements

permute

(permute v idxs)

Permute vector elements with given indices.

perpendicular

(perpendicular v1)(perpendicular v1 v2)

Perpendicular vector (only 2d).

reciprocal

(reciprocal v)

Reciprocal of elements.

rotate

(rotate v1 angle)(rotate v1 anglex angley anglez)

Rotate vector

sub

(sub v1)(sub v1 v2)

Subtraction of two vectors.

sum

(sum v1)

Sum of elements

to-polar

(to-polar v1)

To polar coordinates (2d, 3d only), first element is length, the rest angle.

to-vec

(to-vec v)

Convert to Clojure primitive vector Vec.

transform

(transform v1 o vx vy)(transform v1 o vx vy vz)

Transform vector; map point to coordinate system defined by origin, vx and vy (as bases), d and 3d only.