aerial.utils.math
Various math functions that don't quite have enough totality to
have their own home namespace just yet.
cos-vangle
(cos-vangle v1 v2)
cumsum
(cumsum coll)
(cumsum f coll)
(cumsum f coll1 coll2 & colls)
Cumulative sum of values in COLL. If COLL is a map, return the
cumulative sum of the (presumed all numbers) in (vals coll). For
function F versions, return the cumulative sum of x in COLL (f x)
or the cumulative sum of x1 in COLL1, x2 in COLL2, ... xn in
COLLn (f x1 ... xn).
The cumulative sum is the seq of partial sums across COLL treated
as a vector for each (i (range (count COLL))), effectively:
[(coll 0) (sum (subvec coll 0 2)) .. (sum (subvec coll 0 (count coll)))]
Except actual computational time is linear.
div
(div n d)
Integer division. Return [q r], such that floor(n / d) * q + r = q
ln
(ln x)
Return the natural log of x
log
(log x)
Return the natural log of x
log10
(log10 x)
Named version of (logb 10). Important enough to have a named top
level function
log2
(log2 x)
Named version of (logb 2). Important enough to have a named top
level function
logb
(logb b)
Return the log to the base b _function_ of x
logistic
(logistic x)
Compute logistic of X (a number which will be cast as a double.
Returns 1.0 / (1.0 + e^-x) = e^x / (e^x + 1.0)
logit
(logit p & {:keys [logfn], :or {logfn log2}})
Compute the log odds of P an element of interval [0..1]. LOGFN is
the logarithmic function to use and defaults to log2, log base 2.
Other directly available log functions are ln (or simply log) and
log10; for any other base see logb which can generate a log
function of base b. Returns logfn (p / (1 - p)), the inverse of
logistic.
prime-factors
(prime-factors num)
Return the prime factorization of num as a seq of pairs [p n],
where p is a prime and n is the number of times it is a factor.
Ex: (prime-factors 510) => [[2 1] [3 1] [5 1] [17 1]]
primes
(primes n)
RHickey paste.lisp.org with some fixes by jsa. Returns a list of
all primes from 2 to n. Wicked fast!
prod
(prod coll)
(prod f coll)
(prod f coll1 coll2 & colls)
Return the product of the numbers in COLL. If COLL is a map,
return the product of the (presumed all numbers) in (vals coll).
For function F versions, return the product of x in COLL (f x) or
prod x in COLL1, y in COLL2 (f x y) or prod x1 in C1, x2 in C2,
... xn in Cn (f x1 ... xn).
By default, multiplication proceeds on the results of F applied
over the _cross product_ of the collections. If multiplication
should proceed over the collections in parallel, the first "coll"
given should be the special keyword :||. If given, this causes F
to be applied to the elements of colls as stepped in parallel:
f(coll1[i] coll2[i] .. colln[i]), i in [0 .. (count smallest-coll)].
Examples:
(prod + [1 2 3] [1 2 3])
=> 172800 ; product of all [1 2 3] X [1 2 3] pairwise sums
(prod + :|| [1 2 3] [1 2 3])
=> 48 ; product of [(+ 1 1) (+ 2 2) (+ 3 3)]
sqr
(sqr x)
Square x, i.e., returns (* x x)
sum
(sum coll)
(sum f coll)
(sum f coll1 coll2 & colls)
Return the sum of the numbers in COLL. If COLL is a map, return
the sum of the (presumed all numbers) in (vals coll). For function
F versions, return the sum x in COLL (f x) or sum x in COLL1, y in
COLL2 (f x y) or sum x1 in C1, x2 in C2, ... xn in Cn (f x1 ... xn).
By default, summation proceeds on the results of F applied over the
_cross product_ of the collections. If summation should proceed
over the collections in parallel, the first "coll" given should
be the special keyword :||. If given this causes F to be applied
to the elements of colls as stepped in parallel: f(coll1[i]
coll2[i] .. colln[i]), i in [0 .. (count smallest-given-coll)].
Examples:
(sum + [1 2 3] [1 2 3])
=> 36 ; sum of all [1 2 3] X [1 2 3] pairwise sums
(sum + :|| [1 2 3] [1 2 3])
=> 12 ; sum of [(+ 1 1) (+ 2 2) (+ 3 3)]
(sum (fn[x y] (* x (log2 y))) :|| [1 2 3] [1 2 3])
=> 6.754887502163469
vangle-dist
(vangle-dist v1 v2)
vecmean
(vecmean v1 v2)
(vecmean vs)