1 | function [X,Y,Z]=epdf_2dplot(pdf,xlims,ylims, points) |
---|
2 | % function evaluates given pdf on support |
---|
3 | % xlims = [x_begin, x_end] --or-- empty |
---|
4 | % ylims = [x_begin, x_end] --or-- empty |
---|
5 | % points = if not given, 100 |
---|
6 | |
---|
7 | if nargin<4 |
---|
8 | points = [100,100]; |
---|
9 | end |
---|
10 | |
---|
11 | if length(points) ==1 |
---|
12 | points = points*[1 1]; |
---|
13 | end |
---|
14 | |
---|
15 | if nargin<3 | isempty(ylims) |
---|
16 | p_mean = epdf_mean(pdf); |
---|
17 | p_var = epdf_variance(pdf); |
---|
18 | ylims = p_mean(2)*[1 1] + [-3 3]*sqrt(p_var(2)); |
---|
19 | end |
---|
20 | if nargin<2 | isempty(xlims) |
---|
21 | p_mean = epdf_mean(pdf); |
---|
22 | p_var = epdf_variance(pdf); |
---|
23 | xlims = p_mean(1)*[1 1] + [-3 3]*sqrt(p_var(1)); |
---|
24 | end |
---|
25 | |
---|
26 | steps = [xlims(2)-xlims(1), ylims(2)-ylims(1)]; |
---|
27 | [X,Y]=meshgrid(xlims(1):steps(1)/(points(1)-1):xlims(2), ... |
---|
28 | ylims(1):steps(2)/(points(2)-1):ylims(2)); |
---|
29 | data = [reshape(X, 1, prod(points)); reshape(Y,1,prod(points))]; |
---|
30 | v = epdf_evallog_mat(pdf,data); |
---|
31 | Z = reshape(exp(v), points(1), points(2)); |
---|
32 | |
---|
33 | if 0 |
---|
34 | vol = prod(steps./(points-1)); |
---|
35 | nc = sum(sum(Z))*vol |
---|
36 | % renormalize |
---|
37 | p = exp(v)/nc; |
---|
38 | num_mean = vol*data*p |
---|
39 | num_cov = vol*data*(p*ones(1,2).*data') - num_mean * num_mean' |
---|
40 | end |
---|
41 | contour(X,Y,Z); |
---|