wolffd@0: function plot_mixexp(theta, eta, data) wolffd@0: % PLOT_MIXEXP Plot the results for a piecewise linear regression model wolffd@0: % plot_mixexp(theta, eta, data) wolffd@0: % wolffd@0: % data(l,:) = [x y] for example l wolffd@0: % theta(i,:) = regression vector for expert i wolffd@0: % eta(i,:) = softmax (gating) params for expert i wolffd@0: wolffd@0: numexp = size(theta, 1); wolffd@0: wolffd@0: mn = min(data); wolffd@0: mx = max(data); wolffd@0: xa = mn(1):0.01:mx(1); wolffd@0: x = [ones(length(xa),1) xa']; wolffd@0: % pr(i,l) = posterior probability of expert i on example l wolffd@0: pr = exp(eta * x'); wolffd@0: pr = pr ./ (ones(numexp,1) * sum(pr)); wolffd@0: % y(i,l) = prediction of expert i for example l wolffd@0: y = theta * x'; wolffd@0: % yg(l) = weighted prediction for example l wolffd@0: yg = sum(y .* pr)'; wolffd@0: wolffd@0: subplot(3,2,1); wolffd@0: plot(xa, y(1,:)); wolffd@0: title('expert 1'); wolffd@0: wolffd@0: subplot(3,2,2); wolffd@0: plot(xa, y(2,:)); wolffd@0: title('expert 2'); wolffd@0: wolffd@0: subplot(3,2,3); wolffd@0: plot(xa, pr(1,:)); wolffd@0: title('gating 1'); wolffd@0: wolffd@0: subplot(3,2,4); wolffd@0: plot(xa, pr(2,:)); wolffd@0: title('gating 2'); wolffd@0: wolffd@0: subplot(3,2,5); wolffd@0: plot(xa, yg); wolffd@0: axis([-1 1 -1 2]) wolffd@0: title('prediction'); wolffd@0: wolffd@0: subplot(3,2,6); wolffd@0: title('data'); wolffd@0: hold on wolffd@0: plot(data(:,1), data(:,2), '+'); wolffd@0: hold off wolffd@0: