module Numerics.Functions (
logisticRamp
, smoothstep
, gaussianFalloff
, logisticFalloff
, cauchyFalloff
, smoothBump
) where
import Data.Ord.Extended
import Numerics.Interpolation
logisticRamp
:: Double
-> Double
-> Double
-> Double
logisticRamp :: Double -> Double -> Double -> Double
logisticRamp Double
center Double
beta Double
x = Double
1Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/(Double
1Double -> Double -> Double
forall a. Num a => a -> a -> a
+Double -> Double
forall a. Floating a => a -> a
exp(-(Double
xDouble -> Double -> Double
forall a. Num a => a -> a -> a
-Double
center)Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
beta))
smoothstep
:: Double
-> Double
-> Double
-> Double
smoothstep :: Double -> Double -> Double -> Double
smoothstep Double
lo Double
hi =
let smoothstep01 :: a -> a
smoothstep01 a
x = a
xa -> a -> a
forall a. Num a => a -> a -> a
*a
xa -> a -> a
forall a. Num a => a -> a -> a
*a
xa -> a -> a
forall a. Num a => a -> a -> a
*(a
xa -> a -> a
forall a. Num a => a -> a -> a
*(a
xa -> a -> a
forall a. Num a => a -> a -> a
*a
6a -> a -> a
forall a. Num a => a -> a -> a
-a
15)a -> a -> a
forall a. Num a => a -> a -> a
+a
10)
in Double -> Double
forall {a}. Num a => a -> a
smoothstep01 (Double -> Double) -> (Double -> Double) -> Double -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Double, Double) -> (Double, Double) -> Double -> Double
forall vec.
VectorSpace vec =>
(Double, Double) -> (vec, vec) -> Double -> vec
lerp (Double
lo, Double
hi) (Double
0, Double
1) (Double -> Double) -> (Double -> Double) -> Double -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Double, Double) -> Double -> Double
forall a. Ord a => (a, a) -> a -> a
clamp (Double
lo,Double
hi)
smoothBump :: Double -> Double
smoothBump :: Double -> Double
smoothBump Double
x
| -Double
1 Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
x Bool -> Bool -> Bool
&& Double
x Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
1 = Double -> Double
forall a. Floating a => a -> a
exp(-Double
1Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/(Double
1Double -> Double -> Double
forall a. Num a => a -> a -> a
-Double
xDouble -> Integer -> Double
forall a b. (Num a, Integral b) => a -> b -> a
^Integer
2))
| Bool
otherwise = Double
0
gaussianFalloff
:: Double
-> Double
-> Double
-> Double
gaussianFalloff :: Double -> Double -> Double -> Double
gaussianFalloff Double
mu Double
sigma Double
x = Double -> Double
forall a. Floating a => a -> a
exp (-Double
1Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
2Double -> Double -> Double
forall a. Num a => a -> a -> a
*((Double
xDouble -> Double -> Double
forall a. Num a => a -> a -> a
-Double
mu)Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
sigma)Double -> Integer -> Double
forall a b. (Num a, Integral b) => a -> b -> a
^Integer
2)
logisticFalloff
:: Double
-> Double
-> Double
-> Double
logisticFalloff :: Double -> Double -> Double -> Double
logisticFalloff Double
center Double
beta Double
x =
let expTerm :: Double
expTerm = Double -> Double
forall a. Floating a => a -> a
exp (-(Double
xDouble -> Double -> Double
forall a. Num a => a -> a -> a
-Double
center)Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
beta)
in Double
expTerm Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
expTerm)Double -> Integer -> Double
forall a b. (Num a, Integral b) => a -> b -> a
^Integer
2
cauchyFalloff
:: Double
-> Double
-> Double
-> Double
cauchyFalloff :: Double -> Double -> Double -> Double
cauchyFalloff Double
mu Double
gamma Double
x = Double
1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ ((Double
xDouble -> Double -> Double
forall a. Num a => a -> a -> a
-Double
mu)Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
gamma)Double -> Integer -> Double
forall a b. (Num a, Integral b) => a -> b -> a
^Integer
2)