46 kexp.Centers.xi= rand(400,40);
48 o = general.Orthonormalizer;
49 A = o.orthonormalize(rand(40,40));
50 L = chol(A^
t*diag(randi(10,1,40))*A);
54 if ~kexp.HasCustomBase
55 error(
" No custom base set to compare to. ");
57 x = rand(size(kexp.Centers.xi,1),numpts);
58 dbase = kexp.toTranslateBase;
64 fx1 = kexp.evaluate(x);
67 fx2 = dbase.evaluate(x);
73 e(2,r) = max(er./fxin);
149 pt.HasRowHeader=
true;
150 pt.addRow(,
" Plain for ",
" try(for) ",
" for(try) ",
" for(if) ");
152 pt.addRow(
" Time ",tc[:],[
" %6gs "]);
153 reltimes = num2cell(
t./min(
t));
154 pt.addRow(
" Rel factor ",reltimes[:],[
" %3.3g "]);
188 pt.
addRow(,
" Direct ",
" -v4 ",
" -v6 ",
" binary ");
190 pt.HasRowHeader=
true;
192 A = full(sprand(n,m,fill));
194 f = fullfile(a.DataDirectory,
" tmp.mat ");
202 f = fullfile(a.DataDirectory,
" tmp2.mat ");
204 save(f,
" A ",
" -v4 ");
210 f = fullfile(a.DataDirectory,
" tmp3.mat ");
212 save(f,
" A ",
" -v6 ");
218 f = fullfile(a.DataDirectory,
" tmp4.mat ");
220 fh = fopen(f,
" w+ ");
221 fwrite(fh,A,
" double ");
227 pt.addRow(
" Time ",
t[:],[
" %6gs "]);
228 pt.addRow(
" Size ",s[:],[@(v)sprintf(
" %5gk ",v/1024)]);
265 pos = [1 round(m/2) m];
270 hlp = bsxfun(@eq,A,b);
271 i = find(sum(hlp,1) == n,1);
275 i = find(sum(A == repmat(b,1,m)) == n,1);
279 ind = strfind(reshape(A,1,[]),b^
t);
283 fprintf(
" Dims: %dx%d, match pos: %d, bsxfun time: %f, repmat time: %f, strfind time: %f\n ",...
284 n,m,pos(kpos), time1,time2,time3);
308 str = [
" 4*t ",
" 4*t + mu(1) ",
" exp(sum(mu)) ",
" sin(t) ",
" exp(-t)*mu(2) ",
" t*mu(2) ",
" cos(t) ",
" exp(-mu(2)) "];
309 theta[1] = @(
t,mu)4*
t;
310 theta[2] = @(
t,mu)4*
t + mu(1);
311 theta[3] = @(
t,mu)exp(sum(mu));
312 theta[4] = @(
t,mu)sin(
t);
313 theta[5] = @(
t,mu)exp(-
t)*mu(2);
314 theta[6] = @(
t,mu)
t*mu(2);
315 theta[7] = @(
t,mu)cos(
t);
316 theta[8] = @(
t,mu)exp(-mu(2));
319 am = general.AffParamMatrix;
324 am.addMatrix(str[i], mat[i]);
331 fprintf(
" Testing linear case...\n ");
337 coeff(
k) = fun(params(1,i),params(2:3,i));
339 dummy = lincomb_sequence(mat,coeff)*v;
346 dummy = am.compose(params(1,i),params(2:3,i))*v;
351 fprintf(
" Direct: %gs, AffParamMatrix: %gs\n ",t1,t2);
354 fprintf(
" Testing quadratic case...\n ");
358 mat2[i,j] = mat[i]*mat[j];
366 coeff(
k) = fun(params(1,i),params(2:3,i));
368 dummy = lincomb_sequence2(mat2,coeff,coeff)*v;
376 dummy = am.compose(params(1,i),params(2:3,i))*v;
382 fprintf(
" Direct: %gs, AffParamMatrix: %gs\n ",t1,t2);
384 function res = lincomb_sequence(seq,sigma)
396 res = seq[1]* sigma(1);
399 res = res + sigma(q)*seq[q];
404 function res = lincomb_sequence2(seq,sigma1,sigma2)
418 res = zeros(size(seq[1,1]));
423 res = res + sigma1(q1)*sigma2(q2)*seq[q1,q2];
455 k = kernels.GaussKernel(1);
458 fprintf(
" One argument speed test with sx=%d, sy=%d and %d iterations\n ",sx,sy,iter);
459 tmex = zeros(1,iter); tmex2 = zeros(1,iter);
460 tmexp = zeros(1,iter); tmat = zeros(1,iter);
464 Kmex = k.dontuse_evaluate(x);
469 Kmex2 = k.dontuse_evaluateDirect(x);
473 KmexP = k.evaluateMex(x);
477 K = k.evaluate(x,[]);
482 fprintf([
" 1: %1.5fs - Mex straight\n2: %1.5fs - Mex time opt\n "...
483 " 3: %1.5fs - Mex time opt openmp\n4: %1.5fs - Matlab time\n "...
484 " Difference norms: 1-4=%1.5f, 2-4=%1.5f, 3-4=%1.5f\n "],...
485 mean(tmex2),mean(tmex),mean(tmexp),mean(tmat),...
486 norm(Kmex2-K),norm(Kmex-K),norm(KmexP-K));
518 k = kernels.GaussKernel(1);
522 fprintf(
" Two argument speed test with sx=%d, sy1=%d, sy2=%d and %d iterations\n ",sx,sy1,sy2,iter);
523 tmex = zeros(1,iter); tmex2 = zeros(1,iter);
524 tmexp = zeros(1,iter); tmat = zeros(1,iter);
525 fprintf(
" Iteration ");
530 Kmex = k.dontuse_evaluate(x,y);
535 Kmex2 = k.dontuse_evaluateDirect(x,y);
539 KmexP = k.evaluateMex(x,y);
547 fprintf(
" done!\n ");
548 fprintf([
" 1: %1.5fs - Mex straight\n2: %1.5fs - Mex time opt\n "...
549 " 3: %1.5fs - Mex time opt openmp\n4: %1.5fs - Matlab time\n "...
550 " Difference norms: 1-4=%1.5f, 2-4=%1.5f, 3-4=%1.5f\n "],...
551 mean(tmex2),mean(tmex),mean(tmexp),mean(tmat),...
552 norm(Kmex2-K),norm(Kmex-K),norm(KmexP-K));
logical HasHeader
Flag that determines if the first row should be used as table header.
Speed: Collects tests regarding speed of different methods and strategies.
static function [ colvec< double > times , double e ] = KernelExpCustomBaseEval(kernels.KernelExpansion kexp,integer numpts)
Tests the evaluation speed and determines the evaluation error of a kernel expansion and this expansi...
static function res = GaussMexSpeedTest1Arg(sx, sy, iter)
Tests the speed of the c implementations of evaluate for gaussians.
static function res = GaussMexSpeedTest2Arg(sx, sy1, sy2, iter)
Tests the speed of the c implementations of evaluate for gaussians.
static function pt = BinaryvsMatSave(double fill,integer n,integer m)
BinaryvsMatSaveSpeed: Tests the speeds and storage size required for storing double matrices...
KernelExpansion()
Default constructor.
static function FindVecInMatrix(integer n,integer m)
Created for test purposes of finding a vector in a matrix.
static function AffParamMatrix(integer n)
Tests the evaluation speed of the general.AffParamMatrix compared to loop-type evaluations of affine ...
PrintTable: Class that allows table-like output spaced by tabs for multiple rows. ...
function addRow(varargin)
Adds a row to the current table.
static function rowvec< double > n = L2(matrix< double > x)
Returns the discrete norm for each column vector in x.
Global configuration class for all KerMor run-time settings.
static function KerMor theinstance = App()
The singleton KerMor instance.
Norm: Static class for commonly used norms on sets of vectors.
static function pt = TryCatch(loopsize)
TryCatch: Demonstrate how slow try-catch blocks are.
ProcessIndicator: A simple class that indicates process either via waitbar or text output...
KernelExpansion: Base class for state-space kernel expansions.