1 | function out = lessfx(par,x) |
---|
2 | %LESSFX simple dataset mappings |
---|
3 | % |
---|
4 | % PAR = LESSFX(TYPE,X) |
---|
5 | % |
---|
6 | % 'Train' or define a mapping of different types. |
---|
7 | % TYPE can be: |
---|
8 | % 1: (x - m_2).^2 - (x - m_1).^2 normal nearest means |
---|
9 | % 2: ((x-m_2).^2)/s1 - ((x-m_1).^2)/s2 weighted nearest means |
---|
10 | % 3: (x-|m|_2).^2 - (x-|m|_1).^2 nearest medians |
---|
11 | % 4: exp(-((x-M1).^2)./S1) - exp(-((x-M2).^2)./S2); |
---|
12 | % 5: " " with medians instead of % avergs |
---|
13 | % |
---|
14 | % New data is mapped using: |
---|
15 | % Y = LESSFX(PAR,X) |
---|
16 | % where X in the input dataset, and PAR is obtained as above... |
---|
17 | % |
---|
18 | % This is used in LESS.M |
---|
19 | |
---|
20 | |
---|
21 | if ~isstruct(par) % we train the parameters of the function |
---|
22 | out = []; |
---|
23 | out.type = par; |
---|
24 | switch out.type |
---|
25 | case 0 |
---|
26 | out.bla = []; |
---|
27 | case 1 % basic version |
---|
28 | out.u = +meancov(x); |
---|
29 | case 2 % mean-var |
---|
30 | [u,g] = meancov(x); |
---|
31 | out.u = +u; |
---|
32 | out.g(1,:) = diag(g(:,:,1)) + mean(diag(g(:,:,1))); |
---|
33 | out.g(2,:) = diag(g(:,:,2)) + mean(diag(g(:,:,2))); |
---|
34 | case 3 % median |
---|
35 | out.u(1,:) = med(+seldat(x,1)); |
---|
36 | out.u(2,:) = med(+seldat(x,2)); |
---|
37 | case 4 % mean-var |
---|
38 | [u,g] = meancov(x); |
---|
39 | out.u = +u; |
---|
40 | out.g(1,:) = diag(g(:,:,1)) + mean(diag(g(:,:,1))); |
---|
41 | out.g(2,:) = diag(g(:,:,2)) + mean(diag(g(:,:,2))); |
---|
42 | case 5 % median-MSD |
---|
43 | [u,g] = meancov(x); |
---|
44 | X1 = seldat(x,1); |
---|
45 | X2 = seldat(x,2); |
---|
46 | out.u(1,:) = med(+X1); |
---|
47 | out.u(2,:) = med(+X2); |
---|
48 | out.g(1,:) = medstd(+X1,out.u(1,:)) + mean(diag(g(:,:,1))); |
---|
49 | out.g(2,:) = medstd(+X2,out.u(2,:)) + mean(diag(g(:,:,2))); |
---|
50 | case 6 % median-MSD |
---|
51 | X1 = seldat(x,1); |
---|
52 | X2 = seldat(x,2); |
---|
53 | out.u(1,:) = med(+X1); |
---|
54 | out.u(2,:) = med(+X2); |
---|
55 | out.g(1,:) = medstd(+X1,out.u(1,:)); |
---|
56 | out.g(2,:) = medstd(+X2,out.u(2,:)); |
---|
57 | otherwise |
---|
58 | error('This function is not defined'); |
---|
59 | end |
---|
60 | else % we evaluate the function on new data: |
---|
61 | [m,k] = size(x); |
---|
62 | switch par.type |
---|
63 | case 0 |
---|
64 | out = +x; |
---|
65 | case 1 |
---|
66 | M1 = repmat(par.u(1,:),m,1); |
---|
67 | M2 = repmat(par.u(2,:),m,1); |
---|
68 | out = -(2*(+x).*(M2-M1) + M1.*M1 - M2.*M2); |
---|
69 | case 2 |
---|
70 | M1 = repmat(par.u(1,:),m,1); |
---|
71 | M2 = repmat(par.u(2,:),m,1); |
---|
72 | S1 = repmat(par.g(1,:),m,1); |
---|
73 | S2 = repmat(par.g(2,:),m,1); |
---|
74 | out = ((x-M2).^2)./S2 - ((x-M1).^2)./S1; |
---|
75 | case 3 |
---|
76 | M1 = repmat(par.u(1,:),m,1); |
---|
77 | M2 = repmat(par.u(2,:),m,1); |
---|
78 | out = -(2*(+x).*(M2-M1) + M1.*M1 - M2.*M2); |
---|
79 | case 4 |
---|
80 | M1 = repmat(par.u(1,:),m,1); |
---|
81 | M2 = repmat(par.u(2,:),m,1); |
---|
82 | S1 = repmat(par.g(1,:),m,1); |
---|
83 | S2 = repmat(par.g(2,:),m,1); |
---|
84 | out = exp(-((x-M1).^2)./S1) - exp(-((x-M2).^2)./S2); |
---|
85 | case 5 |
---|
86 | M1 = repmat(par.u(1,:),m,1); |
---|
87 | M2 = repmat(par.u(2,:),m,1); |
---|
88 | S1 = repmat(par.g(1,:),m,1); |
---|
89 | S2 = repmat(par.g(2,:),m,1); |
---|
90 | out = ((x-M2).^2)./S2 - ((x-M1).^2)./S1; |
---|
91 | case 6 |
---|
92 | M1 = repmat(par.u(1,:),m,1); |
---|
93 | M2 = repmat(par.u(2,:),m,1); |
---|
94 | S1 = repmat(par.g(1,:),m,1); |
---|
95 | S2 = repmat(par.g(2,:),m,1); |
---|
96 | %out = ((x-M2).^2)./S2 - ((x-M1).^2)./S1; |
---|
97 | out = (sigm(10-((x-M1).^2)./(1*S1)) - sigm(10-((x-M2).^2)./(1*S2))); |
---|
98 | otherwise |
---|
99 | error('This function is not defined'); |
---|
100 | end |
---|
101 | |
---|
102 | end |
---|
103 | |
---|
104 | return |
---|