Code covered by the BSD License
-
crossValidate(y,X,lambda0,fit...
-
cvglmfitqp(y,X,qf,folds,opts)
-
evalGlmLikelihood(y,X,w,b,fam...
-
evalMaxGlmLikelihood(y,family...
-
evidenceglmfitqp(y,X,qfs,opts)
Computes the negative log-evidence and its derivatives
-
getcvfolds(N,k,seed)
-
glmfitqp(y,X,qf,opts)
-
qfsmooth(numx,numy)
-
qfsmooth1D(numx)
-
setdefaults(opts,defaults,now...
-
TestGlmQp.m
-
View all files
from
Fit GLM with quadratic penalty
by Patrick Mineault
Fits GLM with a quadratic penalty, determines hyperparams through cross-validation or evidence
|
| getcvfolds(N,k,seed) |
function [folds] = getcvfolds(N,k,seed)
% function [folds] = getcvfolds(N,k,seed)
%
% Creates a random folds matrix suitable for cross-validation.
% folds(i,j) = 1 when the i'th observation should be included in the j'th
% fit fold, while folds(i,j) = 0 when the observation should be included in
% the j'th validation fold. By construction the i'th observation is in only
% one validation fold.
%
% N: number of observations (ie: length(y))
% k: number of cross-validation folds
% seed: (optional) a seed to reset the random number generator with
%
if nargin > 2
%Re-seed random number generator
rand('twister',seed);
end
folds = ones(N,k) == 1;
%Shuffle integers from 1 to N
idx = randperm(N);
rg = [0,ceil((1:k)*N/k)];
for ii = 1:k
folds(idx(rg(ii)+1:rg(ii+1)),ii) = 0;
end
folds = folds == 1;
end
|
|
Contact us at files@mathworks.com