KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FrequencyLearning.m
Go to the documentation of this file.
1 namespace models{
2 namespace motoneuron{
3 namespace experiments{
4 
5 
6 /* (Autoinserted by mtoc++)
7  * This source code has been filtered by the mtoc++ executable,
8  * which generates code that can be processed by the doxygen documentation tool.
9  *
10  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
11  * Except for the comments, the function bodies of your M-file functions are untouched.
12  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
13  * attached source files that are highly readable by humans.
14  *
15  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
16  * the correct locations in the source code browser.
17  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
18  */
19 
20 function FrequencyLearning() {
21 clear classes;
22 basedir = fileparts(mfilename(" fullpath "));
23 
24 file = fullfile(basedir, " paramdomaindetection_withnoise.mat ");
25 load(file);
26 
27 /* % Plot raw data */
28 pm = PlotManager;
29 pm.FigureSize= [1024 768];
30 ax = pm.nextPlot(" raw_data "," Frequencies by detector "," Fibre type \tau "," Mean current \kappa ");
31 tri = delaunay(ps(1,:),ps(2,:));
32 trisurf(tri,ps(1,:),ps(2,:),Hz," Parent ",ax," FaceColor "," interp "," EdgeColor "," interp ");
33 
34 /* % assemble training data */
35 m = min(ps,[],2);
36 M = max(ps,[],2);
37 n = 200;
38 ft = linspace(m(1),M(1),n);
39 mc = linspace(m(2),M(2),n);
40 [FT,MC] = meshgrid(ft,mc);
41 HZ = griddata(ps(1,:),ps(2,:),Hz,FT,MC," nearest ");
42 
43 /* % smooth out data */
44 padsize = 6;
45 stencil = [0 0 1 0 0; 0 1 1 1 0; 1 1 1 1 1; 0 1 1 1 0; 0 0 1 0 0];
46 /* stencil = [1 1 1; 1 1 1; 1 1 1];
47  * stencil = [0 1 0; 1 1 1; 0 1 0]; */
48 stencil = stencil/sum(stencil(:));
49 HZ = padarray(HZ,[padsize padsize]," replicate ");
50 runs = 10;
51 for k = 1:runs
52  HZ = conv2(HZ,stencil," same ");
53 end
54 HZ = HZ(padsize+1:end-padsize,padsize+1:end-padsize);
55 ax2 = pm.nextPlot(" smoothed "," Smoothed frequency surface "," Fibre type \tau "," Mean current \kappa ");
56 surf(ax2,FT,MC,HZ," FaceColor "," interp "," EdgeColor "," interp ");
57 axis(ax2," tight ");
58 
59 /* % Init */
60 s = load(fullfile(basedir," ../ "," upperlimitpoly.mat "));
61 maxv = polyval(s.upperlimit_poly,FT);
62 valid = MC <= maxv;
63 atd = data.ApproxTrainData([FT(valid) MC(valid)]^t,[],[]);
64 atd.fxi= HZ(valid)^t;
65 
66 /* % init algorithm */
67 alg = approx.algorithms.VKOGA;
68 ec = kernels.config.ExpansionConfig;
69 comb = Utils.createCombinations([1 2 3 4],[1 2 3]);
70 sc = kernels.config.WendlandConfig(" G ",comb(1,:)," S ",comb(2,:));
71 ec.StateConfig= sc;
72 alg.ExpConfig= ec;
73 alg.MaxExpansionSize= 1000;
74 
75 /* % compute */
76 kexp = alg.computeApproximation(atd);
77 
78 /* % plot */
79 afx = kexp.evaluate([FT(:) MC(:)]^t);
80 FX = reshape(afx,200,[]);
81 FX(~valid) = Inf;
82 ax3 = pm.nextPlot(" approx "," Learned smoothed frequency surface "," Fibre type \tau "," Mean current \kappa ");
83 surf(ax3,FT,MC,FX," FaceColor "," interp "," EdgeColor "," interp ");
84 axis(ax3," tight ");
85 
86 /* % Save stuff */
87 pm.UseFileTypeFolders= false;
88 pm.ExportDPI= 150;
89 pm.FilePrefix= " freq ";
90 pm.NoTitlesOnSave= true;
91 zlim(ax2,zlim(ax));
92 zlim(ax3,zlim(ax));
93 pm.savePlots(basedir," Format "," jpg "," Close ",true);
94 file = fullfile(basedir, " FreqencyLearning.mat ");
95 save(file, " alg ", " atd ", " HZ ", " FT ", " MC ", " valid ");
96 file = fullfile(basedir, " FrequencyKexp.mat ");
97 save(file, " kexp ");
98 }
99 
100 };
101 };
102 };
Collection of generally useful functions.
Definition: Utils.m:17
static function comb = createCombinations(ranges, varargin)
Creates the cartesian product of the vectors passed as a matrix containing elements of each vector pe...
Definition: Utils.m:114
* polyval(pol, slen)
rowvec< double > FigureSize
The figure size for each newly created figure. Set to [] to use system default.
Definition: PlotManager.m:133
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
Definition: PlotManager.m:17