-
Notifications
You must be signed in to change notification settings - Fork 1
/
SumOfExpOffSet.m
50 lines (38 loc) · 1.15 KB
/
SumOfExpOffSet.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function [y,J] = SumOfExpOffSet(theta,x)
% Sum of exponentials with bias y = U + sum_i^M aexp(bx).
%
% Input arguments:
% theta: [U, a1,...,aM,b1,...,bM], size M+1 x 1 with M the number of
% exponentials
% x: Exponent values, size N x 1
%
% Output
% y: function value size N x 1
% J: Jacobian matrix size N x M+1
%
% Copyright (C) W. D. Widanage - WMG, University of Warwick, U.K. 25/12/2016 (Heavy!)
% All Rights Reserved
% Software may be used freely for non-comercial purposes only
p = inputParser; % Create an input parse object to handle positional and property-value arguments
% Create variable names and assign default values after checking the value
addRequired(p,'theta', @isnumeric);
addRequired(p,'x', @isnumeric);
% Re-parse parObj
parse(p, theta, x)
x = p.Results.x(:);
theta = p.Results.theta(:);
nData = length(x);
nExp = length(theta(2:end))/2; % Number of exponentials
U = theta(1);
a = theta(2:nExp+1);
b = theta(nExp+2:end);
y = zeros(nData,1);
for ii = 1:nExp
yTmp = a(ii)*exp(b(ii)*x);
y = y + yTmp;
J1(:,ii) = exp(b(ii)*x);
J2(:,ii) = a(ii)*x.*exp(b(ii)*x);
end
y = y + U;
J = [ones(nData,1),J1,J2];
end