IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
distribution.m
Go to the documentation of this file.
1 %>@ingroup maths
2 %> @file
3 %> @brief Estimates the univariate distribution of a data vector.
4 %>
5 %> Uses a "Gaussian lump" aka kernel to estimate the distribution of a data vector.
6 %>
7 %> The lump aka kernel centered at each x(i) is given by the formula exp(-(xa-x(i)).^2/(2*wid^2)) .
8 %
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
13 %> @return [xa, ya]
14 function [xa, ya] = distribution(x, no_points, range, wid)
15 
16 if ~exist('no_points', 'var') || isempty(no_points)
17  no_points = 100;
18 end;
19 
20 if ~exist('range', 'var') || isempty(range)
21  k = 0;
22  extent = max(x)-min(x);
23  range = [min(x)-extent*k, max(x)+extent*k];
24 end;
25 
26 if ~exist('wid', 'var') || isempty(wid)
27  wid = std(x)/sqrt(10); % lump width
28 end;
29 
30 xa = linspace(range(1), range(2), no_points);
31 ya = zeros(1, no_points);
32 
33 for i = 1:length(x)
34  ya = ya+exp(-(xa-x(i)).^2/(2*wid^2));
35 % if any(isnan(ya))
36 % keyboard;
37 % end;
38 end;
39 
40 delta_x = xa(2)-xa(1);
41 ya = ya/(sum(ya)*delta_x); % sum is rough integration
42 
function distribution(in x, in no_points, in range, in wid)