Introduce lambda constant in Loess

This commit is contained in:
Filip Gralinski 2019-03-19 08:35:41 +01:00
parent 4a8b382669
commit d98003fc0e

View File

@ -6,6 +6,8 @@ import Statistics.Regression (ols)
import Data.Vector.Unboxed((!), zipWith, length, (++), map) import Data.Vector.Unboxed((!), zipWith, length, (++), map)
import Statistics.Matrix(transpose) import Statistics.Matrix(transpose)
lambda :: Double
lambda = 1.0
triCube :: Double -> Double triCube :: Double -> Double
triCube d = (1.0 - (abs d) ** 3) ** 3 triCube d = (1.0 - (abs d) ** 3) ** 3
@ -15,7 +17,7 @@ loess inputs outputs x = a * x + b
where a = params ! 1 where a = params ! 1
b = params ! 0 b = params ! 0
params = ols inputMatrix scaledOutputs 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 scaledOutputs = Data.Vector.Unboxed.zipWith (*) outputs weights
scaledInputs = Data.Vector.Unboxed.zipWith (*) inputs weights scaledInputs = Data.Vector.Unboxed.zipWith (*) inputs weights
inputMatrix = transpose (SMT.Matrix 2 (Data.Vector.Unboxed.length inputs) 1000 (weights Data.Vector.Unboxed.++ scaledInputs)) inputMatrix = transpose (SMT.Matrix 2 (Data.Vector.Unboxed.length inputs) 1000 (weights Data.Vector.Unboxed.++ scaledInputs))