generative-art-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Why

Description

Not sure why I wanted these functions, but here they are.

Synopsis

Documentation

fareyApproximate Source #

Arguments

:: Integer

Maximum denominator

-> Ratio Integer

Number to approximate

-> Ratio Integer 

Approximate a rational number with one that has a maximum denominator.

This can be used to implement explitit rounding when building geometry with rational numbers, which have the advantage of exact calculations, in contrast to Double: the algorithm can be exact, and rounding can happen after the fact.

divideOnIndex :: Int -> Vector a -> (Vector a, a, Vector a) Source #

Split a Vector at an index into the slice before, the value at the index, and the slice after.

>>> divideOnIndex 0 (V.fromList [0..10])
([],0,[1,2,3,4,5,6,7,8,9,10])
>>> divideOnIndex 3 (V.fromList [0..10])
([0,1,2],3,[4,5,6,7,8,9,10])
>>> divideOnIndex 10 (V.fromList [0..10])
([0,1,2,3,4,5,6,7,8,9],10,[])

bhattacharyyaDistance :: Vector Double -> Vector Double -> Double Source #

The Bhattacharyya distance measures the similarity of two probability distributions.

I’ve added it here because I’m hoping to use it to implement a distance metric between two pictures at some point.

\[ D_{B}(p,q)=-\ln \left(BC(p,q)\right) \\ BC(p,q)=\sum _{{x\in X}}{\sqrt {p(x)q(x)}} \]

See https://en.wikipedia.org/wiki/Bhattacharyya_distance

bhattacharyyaCoefficient :: Vector Double -> Vector Double -> Double Source #

The Bhattacharyya coefficient is an approximate measurement of the amount of overlap between two statistical samples.

\[ BC(p,q)=\sum _{{x\in X}}{\sqrt {p(x)q(x)}} \]

See https://en.wikipedia.org/wiki/Bhattacharyya_distance#Bhattacharyya_coefficient

hellingerDistance :: Vector Double -> Vector Double -> Double Source #

The Hellinger distance measures the similarity of two probability distributions.

I’ve added it here because I’m hoping to use it to implement a distance metric between two pictures at some point.

\[ H(p,q)={\sqrt {1-BC(p,q)}} \\ BC(p,q)=\sum _{{x\in X}}{\sqrt {p(x)q(x)}} \]

See https://en.wikipedia.org/wiki/Hellinger_distance