Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/Misc/mixexp_plot.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
rev | line source |
---|---|
wolffd@0 | 1 function plot_mixexp(theta, eta, data) |
wolffd@0 | 2 % PLOT_MIXEXP Plot the results for a piecewise linear regression model |
wolffd@0 | 3 % plot_mixexp(theta, eta, data) |
wolffd@0 | 4 % |
wolffd@0 | 5 % data(l,:) = [x y] for example l |
wolffd@0 | 6 % theta(i,:) = regression vector for expert i |
wolffd@0 | 7 % eta(i,:) = softmax (gating) params for expert i |
wolffd@0 | 8 |
wolffd@0 | 9 numexp = size(theta, 1); |
wolffd@0 | 10 |
wolffd@0 | 11 mn = min(data); |
wolffd@0 | 12 mx = max(data); |
wolffd@0 | 13 xa = mn(1):0.01:mx(1); |
wolffd@0 | 14 x = [ones(length(xa),1) xa']; |
wolffd@0 | 15 % pr(i,l) = posterior probability of expert i on example l |
wolffd@0 | 16 pr = exp(eta * x'); |
wolffd@0 | 17 pr = pr ./ (ones(numexp,1) * sum(pr)); |
wolffd@0 | 18 % y(i,l) = prediction of expert i for example l |
wolffd@0 | 19 y = theta * x'; |
wolffd@0 | 20 % yg(l) = weighted prediction for example l |
wolffd@0 | 21 yg = sum(y .* pr)'; |
wolffd@0 | 22 |
wolffd@0 | 23 subplot(3,2,1); |
wolffd@0 | 24 plot(xa, y(1,:)); |
wolffd@0 | 25 title('expert 1'); |
wolffd@0 | 26 |
wolffd@0 | 27 subplot(3,2,2); |
wolffd@0 | 28 plot(xa, y(2,:)); |
wolffd@0 | 29 title('expert 2'); |
wolffd@0 | 30 |
wolffd@0 | 31 subplot(3,2,3); |
wolffd@0 | 32 plot(xa, pr(1,:)); |
wolffd@0 | 33 title('gating 1'); |
wolffd@0 | 34 |
wolffd@0 | 35 subplot(3,2,4); |
wolffd@0 | 36 plot(xa, pr(2,:)); |
wolffd@0 | 37 title('gating 2'); |
wolffd@0 | 38 |
wolffd@0 | 39 subplot(3,2,5); |
wolffd@0 | 40 plot(xa, yg); |
wolffd@0 | 41 axis([-1 1 -1 2]) |
wolffd@0 | 42 title('prediction'); |
wolffd@0 | 43 |
wolffd@0 | 44 subplot(3,2,6); |
wolffd@0 | 45 title('data'); |
wolffd@0 | 46 hold on |
wolffd@0 | 47 plot(data(:,1), data(:,2), '+'); |
wolffd@0 | 48 hold off |
wolffd@0 | 49 |