annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/Misc/mixexp_plot.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function plot_mixexp(theta, eta, data)
Daniel@0 2 % PLOT_MIXEXP Plot the results for a piecewise linear regression model
Daniel@0 3 % plot_mixexp(theta, eta, data)
Daniel@0 4 %
Daniel@0 5 % data(l,:) = [x y] for example l
Daniel@0 6 % theta(i,:) = regression vector for expert i
Daniel@0 7 % eta(i,:) = softmax (gating) params for expert i
Daniel@0 8
Daniel@0 9 numexp = size(theta, 1);
Daniel@0 10
Daniel@0 11 mn = min(data);
Daniel@0 12 mx = max(data);
Daniel@0 13 xa = mn(1):0.01:mx(1);
Daniel@0 14 x = [ones(length(xa),1) xa'];
Daniel@0 15 % pr(i,l) = posterior probability of expert i on example l
Daniel@0 16 pr = exp(eta * x');
Daniel@0 17 pr = pr ./ (ones(numexp,1) * sum(pr));
Daniel@0 18 % y(i,l) = prediction of expert i for example l
Daniel@0 19 y = theta * x';
Daniel@0 20 % yg(l) = weighted prediction for example l
Daniel@0 21 yg = sum(y .* pr)';
Daniel@0 22
Daniel@0 23 subplot(3,2,1);
Daniel@0 24 plot(xa, y(1,:));
Daniel@0 25 title('expert 1');
Daniel@0 26
Daniel@0 27 subplot(3,2,2);
Daniel@0 28 plot(xa, y(2,:));
Daniel@0 29 title('expert 2');
Daniel@0 30
Daniel@0 31 subplot(3,2,3);
Daniel@0 32 plot(xa, pr(1,:));
Daniel@0 33 title('gating 1');
Daniel@0 34
Daniel@0 35 subplot(3,2,4);
Daniel@0 36 plot(xa, pr(2,:));
Daniel@0 37 title('gating 2');
Daniel@0 38
Daniel@0 39 subplot(3,2,5);
Daniel@0 40 plot(xa, yg);
Daniel@0 41 axis([-1 1 -1 2])
Daniel@0 42 title('prediction');
Daniel@0 43
Daniel@0 44 subplot(3,2,6);
Daniel@0 45 title('data');
Daniel@0 46 hold on
Daniel@0 47 plot(data(:,1), data(:,2), '+');
Daniel@0 48 hold off
Daniel@0 49