diff --git a/src/Data/Statistics/Loess.hs b/src/Data/Statistics/Loess.hs index 96afa10..5700d26 100644 --- a/src/Data/Statistics/Loess.hs +++ b/src/Data/Statistics/Loess.hs @@ -6,6 +6,8 @@ import Statistics.Regression (ols) import Data.Vector.Unboxed((!), zipWith, length, (++), map) import Statistics.Matrix(transpose) +lambda :: Double +lambda = 1.0 triCube :: Double -> Double triCube d = (1.0 - (abs d) ** 3) ** 3 @@ -15,7 +17,7 @@ loess inputs outputs x = a * x + b where a = params ! 1 b = params ! 0 params = ols inputMatrix scaledOutputs - weights = Data.Vector.Unboxed.map (\v -> triCube (x - v)) inputs + weights = Data.Vector.Unboxed.map (\v -> lambda * triCube (lambda * (x - v))) inputs scaledOutputs = Data.Vector.Unboxed.zipWith (*) outputs weights scaledInputs = Data.Vector.Unboxed.zipWith (*) inputs weights inputMatrix = transpose (SMT.Matrix 2 (Data.Vector.Unboxed.length inputs) 1000 (weights Data.Vector.Unboxed.++ scaledInputs))