From d98003fc0ed145f797ff3bddbc601822b3ab7363 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Tue, 19 Mar 2019 08:35:41 +0100 Subject: [PATCH] Introduce lambda constant in Loess --- src/Data/Statistics/Loess.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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))