3 %> @brief Estimates the univariate
distribution of a data vector.
5 %> Uses a
"Gaussian lump" aka kernel to estimate the
distribution of a data vector.
7 %> The lump aka kernel centered at each x(i) is given by the formula exp(-(xa-x(i)).^2/(2*wid^2)) .
9 %> @param x Data vector
10 %> @param no_points=100 Number of points in outputs. Similar to number of bins of a histogram. It is the resolution of the outputs.
11 %> @param range=(autocalculated) Initial and final x-axis points
12 %> @param wid=str(x)/sqrt(10) "Lump" width
14 function [xa, ya] =
distribution(x, no_points, range, wid)
16 if ~exist('no_points', 'var') || isempty(no_points)
20 if ~exist('range', 'var') || isempty(range)
22 extent = max(x)-min(x);
23 range = [min(x)-extent*k, max(x)+extent*k];
26 if ~exist('wid', 'var') || isempty(wid)
27 wid = std(x)/sqrt(10); % lump width
30 xa = linspace(range(1), range(2), no_points);
31 ya = zeros(1, no_points);
34 ya = ya+exp(-(xa-x(i)).^2/(2*wid^2));
40 delta_x = xa(2)-xa(1);
41 ya = ya/(sum(ya)*delta_x); % sum is rough integration
function distribution(in x, in no_points, in range, in wid)