LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
map_bernstein.m
1function MAP = map_bernstein(f, n)
2% MAP = MAP_BERNSTEIN(F, N) - Convert distribution to MAP via Bernstein approximation
3%
4% This function implements Bernstein polynomial approximation to convert any
5% continuous distribution (specified by its PDF) to a Markovian Arrival Process
6% (MAP) representation.
7%
8% Input:
9% f: PDF function handle @(x) - probability density function
10% n: Number of phases for the approximation (default: 20)
11%
12% Output:
13% MAP: MAP representation {D0, D1}
14% Note: Caller must rescale to target mean using map_scale
15%
16% Example:
17% % Convert a gamma distribution with shape=2, scale=1
18% pdf_func = @(x) gampdf(x, 2, 1);
19% MAP = map_bernstein(pdf_func, 20);
20% MAP = map_scale(MAP, targetMean); % Rescale to desired mean
21%
22% Reference:
23% Bernstein polynomial approximation for phase-type distributions
24%
25% Copyright (c) 2012-2026, Imperial College London
26% All rights reserved.
27
28if nargin < 2
29 n = 20;
30end
31
32% Bernstein approximation of order n
33c = 0;
34for i = 1:n
35 xi = -log(i/n);
36 fi = f(xi);
37 if isfinite(fi) && fi > 0
38 c = c + fi / i;
39 end
40end
41
42% Handle case where normalizing constant is invalid
43if c <= 0 || ~isfinite(c)
44 % Fallback to Erlang-n with unit mean (caller will rescale)
45 MAP = map_erlang(1, n);
46 return;
47end
48
49% Build subgenerator T
50T = diag(-[1:n]) + diag([1:(n-1)], 1);
51
52% Build initial probability vector alpha
53alpha = zeros(1, n);
54for i = 1:n
55 xi = -log(i/n);
56 fi = f(xi);
57 if isfinite(fi) && fi > 0
58 alpha(i) = fi / (i * c);
59 end
60end
61
62% Normalize alpha to ensure it sums to 1
63if sum(alpha) > 0
64 alpha = alpha / sum(alpha);
65else
66 alpha(1) = 1; % Default to starting in first phase
67end
68
69% Conversion to MAP
70P = repmat(alpha, n, 1);
71MAP = {T, -T * P};
72
73end