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