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
distribution?
(distribution? d)
Returns true if the object is distribution
DistributionProto
protocol
Get information from distributions.
members
cdf
(cdf d v)(cdf d v1 v2)
continuous?
(continuous? d)
Does distribution support continuous range?
icdf
(icdf d p)
Inverse cumulative probability
probability
(probability d v)
source-object
(source-object d)
Returns Java object from backend library
GridProto
protocol
Common grid conversion functions.
members
cell->anchor
(cell->anchor g cell)(cell->anchor g q r)
Converts cell coordinates to anchor coordinates.
cell->mid
(cell->mid g cell)(cell->mid g q r)
Converts cell coordinates to cell midpoint
coords->cell
(coords->cell g coords)(coords->cell g x y)
Converts 2d space coordinates to cell coordinates.
coords->mid
(coords->mid g coords)(coords->mid g x y)
Converts 2d space into cell midpoint.
corners
(corners g coords)(corners g coords scale)(corners g x y 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
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 new rng object
set-seed!
(set-seed! rng v)
TransformProto
protocol
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)
upper-bound
(upper-bound d)
VectorProto
protocol
members
abs
(abs v1)
Absolute value of vector elements
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)
dot
(dot v1 v2)
Dot product of two vectors.
econstrain
(econstrain v val1 val2)
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)
magsq
(magsq v1)
Length of the vector squared.
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).
rotate
(rotate v1 angle)(rotate v1 anglex angley anglez)
shift
(shift v1 v)
Add v value to every vector element.
sub
(sub v1)(sub v1 v2)
Subtraction of two vectors.
to-acm-vec
(to-acm-vec v)
Convert to Apache Commons Math ArrayRealVector
to-double-array
(to-double-array v)
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.