Added TRSVD first draft
This commit is contained in:
parent
0941657ced
commit
25eb5a7c2a
2 changed files with 67 additions and 0 deletions
|
|
@ -35,10 +35,21 @@ export calculateRMSECV
|
|||
export PCR
|
||||
export bidiag2
|
||||
|
||||
export regularizationMatrix
|
||||
export TRSVDDecomp
|
||||
export TRRegCoeffs
|
||||
export TRPress
|
||||
export TRGCV
|
||||
export TRLooCV
|
||||
export PlotTRLooCV
|
||||
export TRLooCVNum
|
||||
export TRGCVNum
|
||||
|
||||
|
||||
include("preprocessing.jl")
|
||||
include("convenience.jl")
|
||||
include("conveniencePlots.jl")
|
||||
include("variousRegressionFunctions.jl")
|
||||
include("TR.jl")
|
||||
|
||||
end
|
||||
56
src/TR.jl
Normal file
56
src/TR.jl
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
using Optimization
|
||||
using OptimizationOptimJL
|
||||
|
||||
|
||||
"""
|
||||
### TO DO: ADD FRACTIONAL DERIVATIVE REGULARIZATION ###
|
||||
|
||||
regularizationMatrix(X; regType="legendre", regParam1=0, regParam2=1e-14)
|
||||
regularizationMatrix(p::Int64; regType="legendre", regParam1=0, regParam2=1e-14)
|
||||
|
||||
Calculates and returns square regularization matrix.
|
||||
|
||||
Inputs:
|
||||
- X/p : Size of regularization matrix or data matrix (size of reg. mat. will then be size(X,2)
|
||||
- regType : "L2" (returns identity matrix)
|
||||
"bc" (boundary condition, forces zero on right endpoint for derivative regularization) or
|
||||
"legendre" (no boundary condition, but fills out reg. mat. with lower order polynomial trends to get square matrix)
|
||||
"std" (standardization, FILL OUT WHEN DONE)
|
||||
- regParam1 : Int64, Indicates degree of derivative regularization (0 gives L\\_2)
|
||||
- regParam2 : For regType=="plegendre" added polynomials are multiplied by sqrt(regParam2)
|
||||
|
||||
Output: Square regularization matrix
|
||||
"""
|
||||
function regularizationMatrix(X; regType="L2", regParam1=0, regParam2=1e-14)
|
||||
|
||||
if regType == "std"
|
||||
regParam2 = Diagonal(vec(std(X, dims=1)));
|
||||
end
|
||||
|
||||
regMat = regularizationMatrix(size(X,2); regType, regParam1, regParam2)
|
||||
|
||||
return regMat
|
||||
end
|
||||
|
||||
function regularizationMatrix(p::Int64; regType="L2", regParam1=0, regParam2=1e-14)
|
||||
|
||||
if regType == "bc"
|
||||
regMat = [I(p); zeros(regParam1,p)]; for i = 1:regParam1 regMat = diff(regMat, dims = 1); end
|
||||
elseif regType == "legendre"
|
||||
regMat = [I(p); zeros(regParam1,p)]; for i = 1:regParam1 regMat = diff(regMat, dims = 1); end
|
||||
P, _ = plegendre(regParam1-1, p);
|
||||
regMat[end-regParam1+1:end,:] = sqrt(regParam2) * P;
|
||||
elseif regType == "L2"
|
||||
regMat = I(size(X,2));
|
||||
elseif regType == "std"
|
||||
regMat = regParam2;
|
||||
end
|
||||
|
||||
return regMat
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue