LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Lognormal.m
1classdef Lognormal < ContinuousDistribution
2 % The Lognormal statistical distribution
3 %
4 % Copyright (c) 2012-2026, Imperial College London
5 % All rights reserved.
6
7 methods
8 function self = Lognormal(mu, sigma)
9 % SELF = LOGNORMAL(MU, SIGMA)
10
11 % Constructs a Lognormal distribution with given mu and sigma
12 % parameters
13 self@ContinuousDistribution('Lognormal',2,[0,Inf]);
14 if sigma < 0
15 line_error(mfilename,'sigma parameter must be >= 0.0');
16 end
17 setParam(self, 1, 'mu', mu);
18 setParam(self, 2, 'sigma', sigma);
19 end
20
21 function ex = getMean(self)
22 % EX = GETMEAN()
23
24 % Get distribution mean
25 mu = self.getParam(1).paramValue;
26 sigma = self.getParam(2).paramValue;
27 ex = exp(mu+sigma*sigma/2);
28 end
29
30 function SCV = getSCV(self)
31 % SCV = GETSCV()
32
33 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
34 mu = self.getParam(1).paramValue;
35 sigma = self.getParam(2).paramValue;
36 ex = exp(mu+sigma*sigma/2);
37 VAR = (exp(sigma*sigma)-1)*exp(2*mu+sigma*sigma);
38 SCV = VAR / ex^2;
39 end
40
41 function X = sample(self, n)
42 % X = SAMPLE(N)
43
44 % Get n samples from the distribution
45 if nargin<2 %~exist('n','var'),
46 n = 1;
47 end
48 mu = self.getParam(1).paramValue;
49 sigma = self.getParam(2).paramValue;
50 X = lognrnd(mu,sigma,n,1);
51 end
52
53 function Ft = evalCDF(self,t)
54 % FT = EVALCDF(SELF,T)
55
56 % Evaluate the cumulative distribution function at t
57 % AT T
58 mu = self.getParam(1).paramValue;
59 sigma = self.getParam(2).paramValue;
60 Ft = logncdf(t,mu,sigma);
61 end
62
63 function L = evalLST(self, s)
64 % L = EVALST(S)
65 % Evaluate the Laplace-Stieltjes transform of the distribution function at s
66 % The LST of Lognormal distribution doesn't have a simple closed form.
67 % We compute it numerically using the definition: E[e^(-sX)] = ∫₀^∞ e^(-sx) f(x) dx
68 % where f(x) is the lognormal PDF
69
70 mu = self.getParam(1).paramValue;
71 sigma = self.getParam(2).paramValue;
72
73 % Use numerical integration
74 % For practical purposes, we integrate up to a reasonable upper bound
75 upperBound = exp(mu + 5 * sigma); % covers most of the distribution
76 n = 1000;
77 dx = upperBound / n;
78 L = 0.0;
79
80 for i = 1:n
81 x = i * dx;
82 if x > 0
83 logx = log(x);
84 % Lognormal PDF: exp(-(log(x)-μ)²/(2σ²)) / (x*σ*√(2π))
85 pdf = exp(-(logx - mu)^2 / (2 * sigma^2)) / (x * sigma * sqrt(2 * pi));
86 L = L + exp(-s * x) * pdf;
87 end
88 end
89
90 L = L * dx;
91 end
92
93 function proc = getProcess(self)
94 % PROC = GETPROCESS()
95
96 % Get process representation with actual distribution parameters
97 % Returns {mu, sigma} for lognormal distribution
98 proc = {self.getParam(1).paramValue, self.getParam(2).paramValue};
99 end
100 end
101
102 methods (Static)
103 function pa = fitMeanAndSCV(MEAN, SCV)
104 % PA = FITMEANANDSCV(MEAN, SCV)
105
106 % Fit distribution with given mean and squared coefficient of variation (SCV=variance/mean^2)
107 c = sqrt(SCV);
108 mu = log(MEAN / sqrt(c*c + 1));
109 sigma = sqrt(log(c*c + 1));
110 pa = Lognormal(mu,sigma);
111 end
112 end
113
114end