From 6b1916b8cdafe289914c43d42d1b0efdbc2666c3 Mon Sep 17 00:00:00 2001 From: Joakim Skogholt Date: Sat, 15 Jun 2024 15:53:40 +0200 Subject: [PATCH] Added EMSC --- src/Ting.jl | 2 ++ src/variousRegressionFunctions.jl | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Ting.jl b/src/Ting.jl index 4bbf598..4b98f8e 100644 --- a/src/Ting.jl +++ b/src/Ting.jl @@ -30,6 +30,8 @@ export TRLooCVUpdateNaive export TRLooCVUpdateExperimental # From "variousRegressionFunctions.jl" +export EMSC +export EMSCCorrection export cVals export calculateRMSE export oldRegCoeffs diff --git a/src/variousRegressionFunctions.jl b/src/variousRegressionFunctions.jl index b46c1d1..8307bd3 100644 --- a/src/variousRegressionFunctions.jl +++ b/src/variousRegressionFunctions.jl @@ -1,3 +1,24 @@ +function EMSCCorrection(X, basis) + + coeffs = basis \ X'; + X_Cor = (X - coeffs[2:end,:]' * basis[:,2:end]') ./ coeffs[1,:]; + + return X_Cor +end + +function EMSC(X, polDeg=2) + +n, p = size(X); +P = zeros(p, polDeg+1); +[P[:,i] = LinRange(-1, 1, p).^(i-1) for i in 1:polDeg+1]; +refSpec = mean(X, dims=1)'; +basis = [refSpec P]; + +X_Cor = EMSCCorrection(X, basis); + +return X_Cor, basis +end + """ crit1minInd, crit2minInd, CvalCrit1, CvalCrit2 = function cVals(bcoeffs, rmsecv) Crit1 = 'norm(regcoeffs) + cverror'