├── model1 ├── pf.tif ├── result.mat ├── SteelBeam.m └── model1.m ├── model2 ├── pf.tif ├── result.mat ├── CantileverBeam.m └── model2.m ├── model3 ├── RI.tif ├── pf.tif ├── MSE.tif ├── result.mat ├── blade.m └── model3.m ├── model4 ├── pf.tif ├── w.mat ├── result.mat ├── engine.m └── model4.m ├── tools ├── dace │ ├── dace.pdf │ ├── data1.mat │ ├── run.m │ ├── regpoly0.m │ ├── regpoly1.m │ ├── lhsamp.m │ ├── regpoly2.m │ ├── corrgauss.m │ ├── correxp.m │ ├── corrlin.m │ ├── correxpg.m │ ├── Contents.m │ ├── corrcubic.m │ ├── gridsamp.m │ ├── corrspherical.m │ ├── corrspline.m │ ├── dsmerge.m │ ├── changelog │ ├── predictor.m │ └── dacefit.m ├── SearchMPP.m ├── GenerateRV.m ├── GenerateGP.m ├── NatafTransformation.m ├── CalculatePf.m └── DE_Canonical.m ├── init.m ├── README.md └── methods ├── MCS.m ├── TDTRA.m └── AMPPT.m /model1/pf.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/model1/pf.tif -------------------------------------------------------------------------------- /model2/pf.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/model2/pf.tif -------------------------------------------------------------------------------- /model3/RI.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/model3/RI.tif -------------------------------------------------------------------------------- /model3/pf.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/model3/pf.tif -------------------------------------------------------------------------------- /model4/pf.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/model4/pf.tif -------------------------------------------------------------------------------- /model4/w.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/model4/w.mat -------------------------------------------------------------------------------- /model3/MSE.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/model3/MSE.tif -------------------------------------------------------------------------------- /model1/result.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/model1/result.mat -------------------------------------------------------------------------------- /model2/result.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/model2/result.mat -------------------------------------------------------------------------------- /model3/result.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/model3/result.mat -------------------------------------------------------------------------------- /model4/result.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/model4/result.mat -------------------------------------------------------------------------------- /tools/dace/dace.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/tools/dace/dace.pdf -------------------------------------------------------------------------------- /tools/dace/data1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanZhangNpu/TRA/HEAD/tools/dace/data1.mat -------------------------------------------------------------------------------- /tools/dace/run.m: -------------------------------------------------------------------------------- 1 | theta = [10 10]; lob = [1e-1 1e-1]; upb = [20 20]; 2 | [dmodel, perf] = dacefit(S, Y, @regpoly0, @corrgauss, theta, lob, upb); 3 | -------------------------------------------------------------------------------- /init.m: -------------------------------------------------------------------------------- 1 | addpath('model1'); 2 | addpath('model2'); 3 | addpath('model3'); 4 | addpath('model4'); 5 | 6 | addpath('methods'); 7 | 8 | addpath('tools'); 9 | addpath('tools/dace'); 10 | 11 | rng('shuffle'); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Time-variant Reliability Analysis (TRA) 2 | This repository contains the source code of three TRA methods (MCS, TDTRA, and AMPPT) and four test examples (a steel beam, a cantilever tube, a hydrokinetic turbine blade, and a solid rocket engine). -------------------------------------------------------------------------------- /model3/blade.m: -------------------------------------------------------------------------------- 1 | function g = blade(t, random_variable, stochastic_process) 2 | l1 = random_variable(:,1); 3 | t1 = random_variable(:,2); 4 | t2 = random_variable(:,3); 5 | e_allowable = random_variable(:,4); 6 | 7 | v_t = stochastic_process; 8 | 9 | rho = 1e3; 10 | Cm = 0.3422; 11 | 12 | M_flap = 0.5 * rho .* v_t.^2 .* Cm; 13 | E = 14e9; 14 | I = 2/3*l1.*(t1.^3 - t2.^3); 15 | 16 | a = M_flap.*t1 ./ (E.*I); 17 | g = e_allowable - a; 18 | g = -g; 19 | end 20 | 21 | 22 | -------------------------------------------------------------------------------- /tools/dace/regpoly0.m: -------------------------------------------------------------------------------- 1 | function [f, df] = regpoly0(S) 2 | %REGPOLY0 Zero order polynomial regression function 3 | % 4 | % Call: f = regpoly0(S) 5 | % [f, df] = regpoly0(S) 6 | % 7 | % S : m*n matrix with design sites 8 | % f : ones(m,1) 9 | % df : Jacobian at the first point (first row in S) 10 | 11 | % hbn@imm.dtu.dk 12 | % Last update April 12, 2002 13 | 14 | [m n] = size(S); 15 | f = ones(m,1); 16 | if nargout > 1 17 | df = zeros(n,1); 18 | end 19 | -------------------------------------------------------------------------------- /tools/dace/regpoly1.m: -------------------------------------------------------------------------------- 1 | function [f, df] = regpoly1(S) 2 | %REGPOLY1 First order polynomial regression function 3 | % 4 | % Call: f = regpoly1(S) 5 | % [f, df] = regpoly1(S) 6 | % 7 | % S : m*n matrix with design sites 8 | % f = [1 s] 9 | % df : Jacobian at the first point (first row in S) 10 | 11 | % hbn@imm.dtu.dk 12 | % Last update April 12, 2002 13 | 14 | [m n] = size(S); 15 | f = [ones(m,1) S]; 16 | if nargout > 1 17 | df = [zeros(n,1) eye(n)]; 18 | end -------------------------------------------------------------------------------- /model1/SteelBeam.m: -------------------------------------------------------------------------------- 1 | function [ G ] = SteelBeam( t, random_variable, stochastic_processes ) 2 | %STEELBEAM 3 | 4 | % b0, h0, sigmay, Ft 5 | b0 = random_variable(:,1); 6 | h0 = random_variable(:,2); 7 | sigmay = random_variable(:,3); 8 | Ft = stochastic_processes; 9 | 10 | k=5e-5; 11 | L=5; 12 | rho=78.5e3; 13 | 14 | bt = b0 - 2*k*t; 15 | ht = h0 - 2*k*t; 16 | 17 | term1 = bt .* ht .^ 2 .* sigmay ./ 4; 18 | term2 = Ft.*L./4 + rho .* b0 .* h0 .* L.^2 ./ 8; 19 | G = term2 - term1; 20 | end -------------------------------------------------------------------------------- /model4/engine.m: -------------------------------------------------------------------------------- 1 | function P = engine(t, C_star, rho, Dt, w) 2 | % response surface of P(t) in the 3 | % solid rocket engine problem 4 | 5 | func = { 6 | % @(x1,x2,x3) x1.^2; 7 | % @(x1,x2,x3) x2.^2; 8 | @(x1,x2,x3) x3.^2; 9 | % @(x1,x2,x3) x1.*x2; 10 | @(x1,x2,x3) x1.*x3; 11 | @(x1,x2,x3) x2.*x3; 12 | % @(x1,x2,x3) x1; 13 | % @(x1,x2,x3) x2; 14 | @(x1,x2,x3) x3; 15 | @(x1,x2,x3) 1; }; 16 | 17 | w_t = 0; 18 | for jj = 1:length(func) 19 | w_t = w_t + w(jj,:) * func{jj}(C_star, rho, Dt); 20 | end 21 | P = w_t(1).*t.^2 + w_t(2).*t + w_t(3); 22 | end -------------------------------------------------------------------------------- /tools/dace/lhsamp.m: -------------------------------------------------------------------------------- 1 | function S = lhsamp(m, n) 2 | %LHSAMP Latin hypercube distributed random numbers 3 | % 4 | % Call: S = lhsamp 5 | % S = lhsamp(m) 6 | % S = lhsamp(m, n) 7 | % 8 | % m : number of sample points to generate, if unspecified m = 1 9 | % n : number of dimensions, if unspecified n = m 10 | % 11 | % S : the generated n dimensional m sample points chosen from 12 | % uniform distributions on m subdivions of the interval (0.0, 1.0) 13 | 14 | % hbn@imm.dtu.dk 15 | % Last update April 12, 2002 16 | 17 | if nargin < 1, m = 1; end 18 | if nargin < 2, n = m; end 19 | 20 | S = zeros(m,n); 21 | for i = 1 : n 22 | S(:, i) = (rand(1, m) + (randperm(m) - 1))' / m; 23 | end -------------------------------------------------------------------------------- /tools/SearchMPP.m: -------------------------------------------------------------------------------- 1 | function [MPP, funccout] = SearchMPP(performanceFunc, variable_table, x0) 2 | % search MPP 3 | 4 | ub = 10 * ones(1,size(variable_table,1)); 5 | options = optimoptions('fmincon','Display','none'); 6 | [MPP,fval,exitflag,output] = fmincon(@obj,x0,[],[],[],[],-ub,ub,@con,options); 7 | if exitflag ~= 1 && output.constrviolation > 1e-5 && fval< -norminv(1e-4) 8 | warning(['Failed to search the MPP: ' output.message]); 9 | end 10 | funccout = output.funcCount; 11 | 12 | function f = obj(u) 13 | f = norm(u); 14 | end 15 | 16 | function [c,ceq] = con(u) 17 | c = []; 18 | x = NatafTransformation(u, variable_table, -1); 19 | ceq = performanceFunc(x); 20 | end 21 | end 22 | 23 | -------------------------------------------------------------------------------- /tools/GenerateRV.m: -------------------------------------------------------------------------------- 1 | function res = GenerateRV( method, mean_value, std_value, row_count, col_count ) 2 | % generate random variables 3 | 4 | if nargin == 3 5 | row_count = 1e6; 6 | col_count = 1; 7 | end 8 | 9 | if nargin == 4 10 | col_count = 1; 11 | end 12 | 13 | if strcmp(method, 'normal') 14 | res = normrnd(mean_value,std_value,row_count,col_count); 15 | 16 | elseif strcmp(method, 'lognormal') 17 | V = std_value^2; 18 | MU = log(mean_value^2 / sqrt(V+mean_value^2)); 19 | SIGMA = sqrt(log(V/mean_value^2 + 1)); 20 | res = lognrnd(MU, SIGMA, row_count,col_count); 21 | 22 | elseif strcmp(method, 'gumbel') 23 | gama = -psi(1); 24 | alpha = sqrt(6)*std_value/pi; 25 | u = gama*alpha + mean_value; 26 | res = evrnd(u,alpha,row_count, col_count); 27 | end 28 | 29 | end 30 | 31 | -------------------------------------------------------------------------------- /model2/CantileverBeam.m: -------------------------------------------------------------------------------- 1 | function g = CantileverBeam( t, random_variables, stochastic_processes ) 2 | % performance function of the cantilever beam 3 | 4 | d = random_variables(:,1); 5 | h = random_variables(:,2); 6 | R0 = random_variables(:,3); 7 | F2 = random_variables(:,4); 8 | P = random_variables(:,5); 9 | 10 | F1 = stochastic_processes(1,:); 11 | T_t = stochastic_processes(2,:); 12 | 13 | L1 = 0.06; 14 | L2 = 0.12; 15 | theta1 = deg2rad(10); 16 | theta2 = deg2rad(5); 17 | 18 | A = pi/4 .*(d.^2 - (d-2*h).^2); 19 | I = pi/64 .*(d.^4 - (d-2*h).^4); 20 | M = F1.*cos(theta1).*L1 + F2.*cos(theta2).*L2; 21 | sigma_t = (F1.*sin(theta1) + F2.*sin(theta2) + P) ./ A + M.*d ./ (2*I); 22 | tao_t = T_t .* d ./ (4*I); 23 | sigma_max_t = sqrt(sigma_t.^2 + 3*tao_t.^2); 24 | R_t = R0.*(1 - 0.01*t); 25 | g = sigma_max_t - R_t; 26 | 27 | function rad = deg2rad(deg) 28 | rad = deg ./ 180 .* pi; 29 | end 30 | 31 | end -------------------------------------------------------------------------------- /tools/dace/regpoly2.m: -------------------------------------------------------------------------------- 1 | function [f, df] = regpoly2(S) 2 | %REGPOLY2 Second order polynomial regression function 3 | % Call: f = regpoly2(S) 4 | % [f, df] = regpoly2(S) 5 | % 6 | % S : m*n matrix with design sites 7 | % f = [1 S S(:,1)*S S(:,2)S(:,2:n) ... S(:,n)^2] 8 | % df : Jacobian at the first point (first row in S) 9 | 10 | % hbn@imm.dtu.dk 11 | % Last update September 4, 2002 12 | 13 | [m n] = size(S); 14 | nn = (n+1)*(n+2)/2; % Number of columns in f 15 | % Compute f 16 | f = [ones(m,1) S zeros(m,nn-n-1)]; 17 | j = n+1; q = n; 18 | for k = 1 : n 19 | f(:,j+(1:q)) = repmat(S(:,k),1,q) .* S(:,k:n); 20 | j = j+q; q = q-1; 21 | end 22 | 23 | if nargout > 1 24 | df = [zeros(n,1) eye(n) zeros(n,nn-n-1)]; 25 | j = n+1; q = n; 26 | for k = 1 : n 27 | df(k,j+(1:q)) = [2*S(1,k) S(1,k+1:n)]; 28 | for i = 1 : n-k, df(k+i,j+1+i) = S(1,k); end 29 | j = j+q; q = q-1; 30 | end 31 | end -------------------------------------------------------------------------------- /tools/GenerateGP.m: -------------------------------------------------------------------------------- 1 | function [ realization ] = GenerateGP( type, meanFunc, stdFunc, autocorrelationCoefFunc, time_series, n ) 2 | % generate Gaussian Processes 3 | 4 | is_stationary = strcmp(type, 'stationary'); 5 | nnode = length(time_series); 6 | 7 | % calculate the mean value vector 8 | if is_stationary 9 | mu = meanFunc * ones(size(time_series)); 10 | else 11 | mu = zeros(size(time_series)); 12 | for ii=1:nnode 13 | mu(ii) = meanFunc(time_series(ii)); 14 | end 15 | end 16 | 17 | % calculate the covariance matrix 18 | sigma = zeros(nnode, nnode); 19 | for ii = 1 : nnode 20 | t1 = time_series(ii); 21 | if is_stationary 22 | sigma(ii,:) = stdFunc .* stdFunc .* autocorrelationCoefFunc(t1, time_series); 23 | else 24 | sigma(ii,:) = stdFunc(t1) .* stdFunc(time_series) .* autocorrelationCoefFunc(t1, time_series); 25 | end 26 | end 27 | 28 | % generate the normally distributed variables 29 | realization = mvnrnd(mu, sigma, n); 30 | 31 | end -------------------------------------------------------------------------------- /tools/dace/corrgauss.m: -------------------------------------------------------------------------------- 1 | function [r, dr] = corrgauss(theta, d) 2 | %CORRGAUSS Gaussian correlation function, 3 | % 4 | % n 5 | % r_i = prod exp(-theta_j * d_ij^2) , i = 1,...,m 6 | % j=1 7 | % 8 | % If length(theta) = 1, then the model is isotropic: 9 | % all theta_j = theta . 10 | % 11 | % Call: r = corrgauss(theta, d) 12 | % [r, dr] = corrgauss(theta, d) 13 | % 14 | % theta : parameters in the correlation function 15 | % d : m*n matrix with differences between given data points 16 | % r : correlation 17 | % dr : m*n matrix with the Jacobian of r at x. It is 18 | % assumed that x is given implicitly by d(i,:) = x - S(i,:), 19 | % where S(i,:) is the i'th design site. 20 | 21 | % hbn@imm.dtu.dk 22 | % Last update June 2, 2002 23 | 24 | [m n] = size(d); % number of differences and dimension of data 25 | if length(theta) == 1 26 | theta = repmat(theta,1,n); 27 | elseif length(theta) ~= n 28 | error(sprintf('Length of theta must be 1 or %d',n)) 29 | end 30 | 31 | td = d.^2 .* repmat(-theta(:).',m,1); 32 | r = exp(sum(td, 2)); 33 | 34 | if nargout > 1 35 | dr = repmat(-2*theta(:).',m,1) .* d .* repmat(r,1,n); 36 | end -------------------------------------------------------------------------------- /tools/dace/correxp.m: -------------------------------------------------------------------------------- 1 | function [r, dr] = correxp(theta, d) 2 | %CORREXP Exponential correlation function 3 | % 4 | % n 5 | % r_i = prod exp(-theta_j * |d_ij|) 6 | % j=1 7 | % 8 | % If length(theta) = 1, then the model is isotropic: 9 | % theta_j = theta(1), j=1,...,n 10 | % 11 | % Call: r = correxp(theta, d) 12 | % [r, dr] = correxp(theta, d) 13 | % 14 | % theta : parameters in the correlation function 15 | % d : m*n matrix with differences between given data points 16 | % r : correlation 17 | % dr : m*n matrix with the Jacobian of r at x. It is 18 | % assumed that x is given implicitly by d(i,:) = x - S(i,:), 19 | % where S(i,:) is the i'th design site. 20 | 21 | % hbn@imm.dtu.dk 22 | % Last update April 12, 2002 23 | 24 | [m n] = size(d); % number of differences and dimension of data 25 | lt = length(theta); 26 | if lt == 1, theta = repmat(theta,1,n); 27 | elseif lt ~= n 28 | error(sprintf('Length of theta must be 1 or %d',n)) 29 | else 30 | theta = theta(:).'; 31 | end 32 | 33 | td = abs(d) .* repmat(-theta, m, 1); 34 | r = exp(sum(td,2)); 35 | 36 | if nargout > 1 37 | dr = repmat(-theta,m,1) .* sign(d) .* repmat(r,1,n); 38 | end -------------------------------------------------------------------------------- /tools/dace/corrlin.m: -------------------------------------------------------------------------------- 1 | function [r, dr] = corrlin(theta, d) 2 | %CORRLIN Linear correlation function, 3 | % 4 | % n 5 | % r_i = prod max(0, 1 - theta_j * d_ij) , i = 1,...,m 6 | % j=1 7 | % 8 | % If length(theta) = 1, then the model is isotropic: 9 | % all theta_j = theta . 10 | % 11 | % Call: r = corrlin(theta, d) 12 | % [r, dr] = corrlin(theta, d) 13 | % 14 | % theta : parameters in the correlation function 15 | % d : m*n matrix with differences between given data points 16 | % r : correlation 17 | % dr : m*n matrix with the Jacobian of r at x. It is 18 | % assumed that x is given implicitly by d(i,:) = x - S(i,:), 19 | % where S(i,:) is the i'th design site. 20 | 21 | % hbn@imm.dtu.dk 22 | % Last update April 12, 2002 23 | 24 | [m n] = size(d); % number of differences and dimension of data 25 | if length(theta) == 1 26 | theta = repmat(theta,1,n); 27 | elseif length(theta) ~= n 28 | error(sprintf('Length of theta must be 1 or %d',n)) 29 | end 30 | 31 | td = max(1 - abs(d) .* repmat(theta(:).',m,1), 0); 32 | r = prod(td, 2); 33 | 34 | if nargout > 1 35 | dr = zeros(m,n); 36 | for j = 1 : n 37 | dr(:,j) = prod(td(:,[1:j-1 j+1:n]),2) .* (-theta(j) * sign(d(:,j))); 38 | end 39 | end -------------------------------------------------------------------------------- /tools/dace/correxpg.m: -------------------------------------------------------------------------------- 1 | function [r, dr] = correxpg(theta, d) 2 | %CORREXPG General exponential correlation function 3 | % 4 | % n 5 | % r_i = prod exp(-theta_j * d_ij^theta_n+1) 6 | % j=1 7 | % 8 | % If n > 1 and length(theta) = 2, then the model is isotropic: 9 | % theta_j = theta(1), j=1,...,n; theta_(n+1) = theta(2) 10 | % 11 | % Call: r = correxpg(theta, d) 12 | % [r, dr] = correxpg(theta, d) 13 | % 14 | % theta : parameters in the correlation function 15 | % d : m*n matrix with differences between given data points 16 | % r : correlation 17 | % dr : m*n matrix with the Jacobian of r at x. It is 18 | % assumed that x is given implicitly by d(i,:) = x - S(i,:), 19 | % where S(i,:) is the i'th design site. 20 | 21 | % hbn@imm.dtu.dk 22 | % Last update April 12, 2002 23 | 24 | [m n] = size(d); % number of differences and dimension of data 25 | lt = length(theta); 26 | if n > 1 & lt == 2 27 | theta = [repmat(theta(1),1,n) theta(2)]; 28 | elseif lt ~= n+1 29 | error(sprintf('Length of theta must be 2 or %d',n+1)) 30 | else 31 | theta = theta(:).'; 32 | end 33 | 34 | pow = theta(end); tt = repmat(-theta(1:n), m, 1); 35 | td = abs(d).^pow .* tt; 36 | r = exp(sum(td,2)); 37 | 38 | if nargout > 1 39 | dr = pow * tt .* sign(d) .* (abs(d) .^ (pow-1)) .* repmat(r,1,n); 40 | end 41 | -------------------------------------------------------------------------------- /tools/dace/Contents.m: -------------------------------------------------------------------------------- 1 | % DACE (Design and Analysis of Computer Experiments) Toolbox 2 | % Version 2.5, September 4, 2002 3 | % Copyright (c) 2002 by Hans Bruun Nielsen and IMM. 4 | % 5 | % Model construction 6 | % dacefit - Constrained non-linear least-squares fit of a given 7 | % correlation model to the provided data set and 8 | % regression model. 9 | % 10 | % Model prediction 11 | % predictor - Model predictor with mean squared error estimate. 12 | % 13 | % Regression functions 14 | % regpoly0 - Zero order polynomial. 15 | % regpoly1 - First order polynomial. 16 | % regpoly2 - Second order polynomial. 17 | % 18 | % Correlation functions 19 | % corrcubic - Local support, cubic polynomial 20 | % correxp - Exponential. 21 | % correxpg - General exponential. 22 | % corrgauss - Gaussian. 23 | % corrlin - Local support, linear. 24 | % corrspherical - Local support, spherical. 25 | % corrspline - Local support, cubic spline. 26 | % 27 | % Experimental Design 28 | % gridsamp - Points in a regular grid. 29 | % lhsamp - Latin hypercube distributed random numbers. 30 | % 31 | % Auxiliary functions 32 | % dsmerge - Merge data for multiple design sites. 33 | % 34 | % Data files 35 | % data1.mat - Example data S and Y 36 | 37 | -------------------------------------------------------------------------------- /tools/dace/corrcubic.m: -------------------------------------------------------------------------------- 1 | function [r, dr] = corrcubic(theta, d) 2 | %CORRCUBIC Cubic correlation function, 3 | % 4 | % n 5 | % r_i = prod max(0, 1 - 3(theta_j*d_ij)^2 + 2(theta_j*d_ij)^3) , i = 1,...,m 6 | % j=1 7 | % 8 | % If length(theta) = 1, then the model is isotropic: 9 | % all theta_j = theta. 10 | % 11 | % Call: r = corrcubic(theta, d) 12 | % [r, dr] = corrcubic(theta, d) 13 | % 14 | % theta : parameters in the correlation function 15 | % d : m*n matrix with differences between given data points 16 | % r : correlation 17 | % dr : m*n matrix with the Jacobian of r at x. It is 18 | % assumed that x is given implicitly by d(i,:) = x - S(i,:), 19 | % where S(i,:) is the i'th design site. 20 | 21 | % hbn@imm.dtu.dk 22 | % Last update June 25, 2002 23 | 24 | [m n] = size(d); % number of differences and dimension of data 25 | if length(theta) == 1 26 | theta = repmat(theta,1,n); 27 | elseif length(theta) ~= n 28 | error(sprintf('Length of theta must be 1 or %d',n)) 29 | else 30 | theta = theta(:).'; 31 | end 32 | td = min(abs(d) .* repmat(theta,m,1), 1); 33 | ss = 1 - td.^2 .* (3 - 2*td); 34 | r = prod(ss, 2); 35 | 36 | if nargout > 1 37 | dr = zeros(m,n); 38 | for j = 1 : n 39 | dd = 6*theta(j) * sign(d(:,j)) .* td(:,j) .* (td(:,j) - 1); 40 | dr(:,j) = prod(ss(:,[1:j-1 j+1:n]),2) .* dd; 41 | end 42 | end -------------------------------------------------------------------------------- /tools/dace/gridsamp.m: -------------------------------------------------------------------------------- 1 | function S = gridsamp(range, q) 2 | %GRIDSAMP n-dimensional grid over given range 3 | % 4 | % Call: S = gridsamp(range, q) 5 | % 6 | % range : 2*n matrix with lower and upper limits 7 | % q : n-vector, q(j) is the number of points 8 | % in the j'th direction. 9 | % If q is a scalar, then all q(j) = q 10 | % S : m*n array with points, m = prod(q) 11 | 12 | % hbn@imm.dtu.dk 13 | % Last update June 25, 2002 14 | 15 | [mr n] = size(range); dr = diff(range); 16 | if mr ~= 2 | any(dr < 0) 17 | error('range must be an array with two rows and range(1,:) <= range(2,:)') 18 | end 19 | sq = size(q); 20 | if min(sq) > 1 | any(q <= 0) 21 | error('q must be a vector with non-negative elements') 22 | end 23 | p = length(q); 24 | if p == 1, q = repmat(q,1,n); 25 | elseif p ~= n 26 | error(sprintf('length of q must be either 1 or %d',n)) 27 | end 28 | 29 | % Check for degenerate intervals 30 | i = find(dr == 0); 31 | if ~isempty(i), q(i) = 0*q(i); end 32 | 33 | % Recursive computation 34 | if n > 1 35 | A = gridsamp(range(:,2:end), q(2:end)); % Recursive call 36 | [m p] = size(A); q = q(1); 37 | S = [zeros(m*q,1) repmat(A,q,1)]; 38 | y = linspace(range(1,1),range(2,1), q); 39 | k = 1:m; 40 | for i = 1 : q 41 | S(k,1) = repmat(y(i),m,1); k = k + m; 42 | end 43 | else 44 | S = linspace(range(1,1),range(2,1), q).'; 45 | end -------------------------------------------------------------------------------- /tools/dace/corrspherical.m: -------------------------------------------------------------------------------- 1 | function [r, dr] = corrspherical(theta, d) 2 | %CORRSPHERICAL Spherical correlation function, 3 | % 4 | % n 5 | % r_i = prod max(0, 1 - 1.5(theta_j*d_ij) + .5(theta_j*d_ij)^3) , i = 1,...,m 6 | % j=1 7 | % 8 | % If length(theta) = 1, then the model is isotropic: 9 | % all theta_j = theta . 10 | % 11 | % Call: r = corrspherical(theta, d) 12 | % [r, dr] = corrspherical(theta, d) 13 | % 14 | % theta : parameters in the correlation function 15 | % d : m*n matrix with differences between given data points 16 | % r : correlation 17 | % dr : m*n matrix with the Jacobian of r at x. It is 18 | % assumed that x is given implicitly by d(i,:) = x - S(i,:), 19 | % where S(i,:) is the i'th design site. 20 | 21 | % hbn@imm.dtu.dk 22 | % Last update April 12, 2002 23 | 24 | [m n] = size(d); % number of differences and dimension of data 25 | if length(theta) == 1 26 | theta = repmat(theta,1,n); 27 | elseif length(theta) ~= n 28 | error(sprintf('Length of theta must be 1 or %d',n)) 29 | else 30 | theta = theta(:).'; 31 | end 32 | td = min(abs(d) .* repmat(theta,m,1), 1); 33 | ss = 1 - td .* (1.5 - .5*td.^2); 34 | r = prod(ss, 2); 35 | 36 | if nargout > 1 37 | dr = zeros(m,n); 38 | for j = 1 : n 39 | dd = 1.5*theta(j) * sign(d(:,j)).*(td(:,j).^2 - 1); 40 | dr(:,j) = prod(ss(:,[1:j-1 j+1:n]),2) .* dd; 41 | end 42 | end -------------------------------------------------------------------------------- /tools/dace/corrspline.m: -------------------------------------------------------------------------------- 1 | function [r, dr] = corrspline(theta, d) 2 | %CORRSPLINE Cubic spline correlation function, 3 | % 4 | % n 5 | % r_i = prod S(theta_j*d_ij) , i = 1,...,m 6 | % j=1 7 | % 8 | % with 9 | % 1 - 15x^2 + 30x^3 for 0 <= x <= 0.5 10 | % S(x) = 1.25(1 - x)^3 for 0.5 < x < 1 11 | % 0 for x >= 1 12 | % If length(theta) = 1, then the model is isotropic: 13 | % all theta_j = theta. 14 | % 15 | % Call: r = corrspline(theta, d) 16 | % [r, dr] = corrspline(theta, d) 17 | % 18 | % theta : parameters in the correlation function 19 | % d : m*n matrix with differences between given data points 20 | % r : correlation 21 | % dr : m*n matrix with the Jacobian of r at x. It is 22 | % assumed that x is given implicitly by d(i,:) = x - S(i,:), 23 | % where S(i,:) is the i'th design site. 24 | 25 | % hbn@imm.dtu.dk 26 | % Last update May 30, 2002 27 | 28 | [m n] = size(d); % number of differences and dimension of data 29 | if length(theta) == 1 30 | theta = repmat(theta,1,n); 31 | elseif length(theta) ~= n 32 | error(sprintf('Length of theta must be 1 or %d',n)) 33 | else 34 | theta = theta(:).'; 35 | end 36 | mn = m*n; ss = zeros(mn,1); 37 | xi = reshape(abs(d) .* repmat(theta,m,1), mn,1); 38 | % Contributions to first and second part of spline 39 | i1 = find(xi <= 0.2); 40 | i2 = find(0.2 < xi & xi < 1); 41 | if ~isempty(i1) 42 | ss(i1) = 1 - xi(i1).^2 .* (15 - 30*xi(i1)); 43 | end 44 | if ~isempty(i2) 45 | ss(i2) = 1.25 * (1 - xi(i2)).^3; 46 | end 47 | % Values of correlation 48 | ss = reshape(ss,m,n); 49 | r = prod(ss, 2); 50 | 51 | if nargout > 1 % get Jacobian 52 | u = reshape(sign(d) .* repmat(theta,m,1), mn,1); 53 | dr = zeros(mn,1); 54 | if ~isempty(i1) 55 | dr(i1) = u(i1) .* ( (90*xi(i1) - 30) .* xi(i1) ); 56 | end 57 | if ~isempty(i2) 58 | dr(i2) = -3.75 * u(i2) .* (1 - xi(i2)).^2; 59 | end 60 | ii = 1 : m; 61 | for j = 1 : n 62 | sj = ss(:,j); ss(:,j) = dr(ii); 63 | dr(ii) = prod(ss,2); 64 | ss(:,j) = sj; ii = ii + m; 65 | end 66 | dr = reshape(dr,m,n); 67 | end % Jacobian -------------------------------------------------------------------------------- /tools/NatafTransformation.m: -------------------------------------------------------------------------------- 1 | function u = NatafTransformation( x, variable_table, ~ ) 2 | %Nataf transformation 3 | % transform the input variables into 4 | % the standard normal space (u space) 5 | 6 | if nargin == 2 7 | forward = 1; 8 | else 9 | forward = 0; 10 | end 11 | u = zeros(size(x)); 12 | for variable_id = 1:size(variable_table,1) 13 | if forward 14 | func = @Nataf; 15 | else 16 | func = @invNataf; 17 | end 18 | u(:, variable_id) = func(x(:, variable_id), ... 19 | variable_table{variable_id, 1}, ... 20 | variable_table{variable_id, 2}, ... 21 | variable_table{variable_id, 3}); 22 | end 23 | return; 24 | end 25 | 26 | function u = Nataf(x, distribution, mu, sigma) 27 | mid = mycdf(x, distribution, mu, sigma); 28 | u = mycdf(mid, 'normalinv'); 29 | end 30 | 31 | function x = invNataf(u, distribution, mu, sigma) 32 | mid = mycdf(u); 33 | x = mycdf(mid, [distribution 'inv'], mu, sigma); 34 | end 35 | 36 | 37 | %% CDF 38 | function p = mycdf(x, distribution, mu, sigma) 39 | if nargin == 1 40 | distribution = 'normal'; 41 | mu = 0; 42 | sigma = 1; 43 | end 44 | if nargin == 2 45 | mu = 0; 46 | sigma = 1; 47 | end 48 | 49 | if strcmp(distribution, 'normal') || strcmp(distribution, 'stationary') 50 | p = normcdf(x, mu, sigma); 51 | elseif strcmp(distribution, 'normalinv') || strcmp(distribution, 'stationaryinv') 52 | p = norminv(x, mu, sigma); 53 | 54 | elseif strcmp(distribution, 'lognormal') 55 | [mu, sigma] = lognormtrans(mu, sigma); 56 | p = logncdf(x, mu, sigma); 57 | elseif strcmp(distribution, 'lognormalinv') 58 | [mu, sigma] = lognormtrans(mu, sigma); 59 | p = logninv(x, mu, sigma); 60 | 61 | elseif strcmp(distribution, 'gumbel') 62 | [u, alpha] = gumbeltrans(mu, sigma); 63 | p = evcdf(x, u, alpha); 64 | elseif strcmp(distribution, 'gumbelinv') 65 | [u, alpha] = gumbeltrans(mu, sigma); 66 | p = evinv(x, u, alpha); 67 | 68 | else 69 | error(['Unkonwn distribution: ' distribution]); 70 | end 71 | end 72 | 73 | function [u, alpha] = gumbeltrans(mean_value, std_value) 74 | gama = -psi(1); 75 | alpha = sqrt(6)*std_value/pi; 76 | u = gama*alpha + mean_value; 77 | end 78 | 79 | function [MU, SIGMA] = lognormtrans(mean_value, std_value) 80 | % transformation for lognormal distribution 81 | V = std_value^2; % variance 82 | MU = log(mean_value^2 / sqrt(V+mean_value^2)); 83 | SIGMA = sqrt(log(V/mean_value^2 + 1)); 84 | end 85 | -------------------------------------------------------------------------------- /tools/CalculatePf.m: -------------------------------------------------------------------------------- 1 | function Pf = CalculatePf(MPPList, time_series, ACF, inverse) 2 | % calculate the probability of failure 3 | 4 | % step 1: calculate ALPHA and BETA 5 | [n_MPP, n_var] = size(MPPList); 6 | BETA = zeros(1,n_MPP); 7 | ALPHA = zeros(size(MPPList)); 8 | for i=1:n_MPP 9 | BETA(i) = norm(MPPList(i,:)); 10 | ALPHA(i,:) = MPPList(i,:) / BETA(i); 11 | end 12 | 13 | % step 2: calculate the covariance matrix SIGMA 14 | SIGMA = ones(n_MPP,n_MPP); 15 | for i=1:n_MPP 16 | for j=1:n_MPP 17 | if i ~= j 18 | t1 = time_series(i); 19 | t2 = time_series(j); 20 | alpha1 = ALPHA(i,:); 21 | alpha2 = ALPHA(j,:); 22 | SIGMA(i,j) = calResponseCC(t1, alpha1, t2, alpha2); 23 | end 24 | end 25 | end 26 | 27 | % step 3: 28 | if nargin == 4 && inverse 29 | BETA = -BETA; 30 | end 31 | Pf = 1 - mymvncdf(BETA, SIGMA); 32 | return; 33 | 34 | function rho = calResponseCC(t1, alpha1, t2, alpha2) 35 | C = eye(n_var); % identify matrix 36 | for ii = 1:n_var 37 | if ~isempty(ACF{ii}) 38 | rho_x = ACF{ii}(t1, t2); 39 | rho_u = rho_x; % NOTE: only for Gaussin process 40 | C(ii, ii) = rho_u; 41 | end 42 | end 43 | rho = alpha1 * C * alpha2'; 44 | end 45 | end 46 | 47 | 48 | %% CDF for multivariant normal distribution through MCS 49 | function p = mymvncdf(beta, SIGMA) 50 | % the following command is not reliable when 51 | % the dimension is high 52 | % p = mvncdf(beta, zeros(1,length(beta)), SIGMA); 53 | 54 | p_list = zeros(10,1); 55 | for trial_id = 1:length(p_list) 56 | p_list(trial_id) = MCS(beta, SIGMA); 57 | end 58 | p = mean(p_list); 59 | return; 60 | 61 | function p = MCS(beta, SIGMA) 62 | n_total = 1e6; 63 | sample = mvnrnd(zeros(1,length(beta)), SIGMA, n_total); 64 | label = sum(sample < beta,2) ~= length(beta); 65 | n_fail = sum(label); 66 | n_rare_event = min(n_fail, n_total - n_fail); 67 | while n_rare_event < 100 && n_total < 1e7 68 | if n_rare_event == 0 69 | n_rare_event = 1; 70 | end 71 | n_additional_MCS = ceil(n_total * (150/n_rare_event - 1)); 72 | 73 | % considering the memory limit 74 | n_additional_MCS = min(n_additional_MCS, 1e6); 75 | 76 | sample = mvnrnd(zeros(1,length(beta)), SIGMA, n_additional_MCS); 77 | label = sum(sample < beta,2) ~= length(beta); 78 | 79 | n_fail = n_fail + sum(label); 80 | n_total = n_total + n_additional_MCS; 81 | n_rare_event = min(n_fail, n_total - n_fail); 82 | end 83 | p = (n_total - n_fail)/n_total; 84 | end 85 | end -------------------------------------------------------------------------------- /model1/model1.m: -------------------------------------------------------------------------------- 1 | function model1() 2 | rng('shuffle'); 3 | 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% problem definition %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | problem.performanceFunc = @SteelBeam; 6 | problem.Ts = 0; 7 | problem.Te = 30; 8 | problem.variable_table = { 9 | % distribution mean std autocorrelationCoef 10 | % w0, h0, sigma 11 | 'lognormal', 0.20, 0.01, []; 12 | 'lognormal', 0.04, 4e-3, []; 13 | 'lognormal', 2.4e8, 2.4e7, []; 14 | % F(t) 15 | 'stationary', 3500, 700, @(t1, t2) exp(-(t1-t2).^2); 16 | }; 17 | 18 | solve(problem); 19 | analyzeResults(); 20 | end 21 | 22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% solve the problem %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 23 | 24 | function solve(problem) 25 | % MCS 26 | MCS_par.n_MCS = 2e6; 27 | MCS_par.n_time_instant = 500; 28 | result.MCS = MCS(problem, MCS_par); 29 | 30 | % ADMPT 31 | option.discretization_node_num = 70; 32 | result.AMPPT = AMPPT( problem, option ); 33 | 34 | % TDRA 35 | option.time_node_num = 30; result.TDRA30 = TDTRA( problem, option ); 36 | option.time_node_num = 40; result.TDRA40 = TDTRA( problem, option ); 37 | option.time_node_num = 50; result.TDRA50 = TDTRA( problem, option ); 38 | save('result.mat', 'result'); 39 | end 40 | 41 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% analyze the results %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 42 | function analyzeResults() 43 | result = []; 44 | load('result.mat'); 45 | 46 | accuracy = [result.MCS.pf; 47 | result.TDTRA30.pf; 48 | result.TDTRA40.pf; 49 | result.TDTRA50.pf; 50 | result.AMPPT.pf;]; 51 | accuracy(:,2) = abs(accuracy(:,1) - result.MCS.pf) ./ result.MCS.pf; 52 | 53 | efficiency(:,1) = [result.MCS.funccount; 54 | result.TDTRA30.funccount; 55 | result.TDTRA40.funccount; 56 | result.TDTRA50.funccount; 57 | result.AMPPT.funccount;]; 58 | efficiency(:,2) = [nan; 30; 40; 50; 5;]; 59 | efficiency(:,3) = efficiency(:,1) ./ efficiency(:,2); 60 | table = [accuracy efficiency]; % statistics table 61 | 62 | 63 | % plot Pf curves 64 | COLOR_MCS = [0, 114, 189] / 255.0; 65 | COLOR_ADMPT = [217, 83, 25] / 255.0; 66 | COLOR_1 = [237, 177, 32] / 255.0; 67 | COLOR_2 = [126, 47, 142] / 255.0; 68 | COLOR_3 = [119, 172, 48] / 255.0; 69 | 70 | clf; 71 | plotLine(result.MCS.pf_history, COLOR_MCS, '-'); 72 | plotLine(result.TDTRA30.pf_history, COLOR_1, ':v'); 73 | plotLine(result.TDTRA40.pf_history, COLOR_2, ':s'); 74 | plotLine(result.TDTRA50.pf_history, COLOR_3, ':d'); 75 | plotLine(result.AMPPT.pf_history, COLOR_ADMPT,'-o'); 76 | 77 | scale.figure_width = 8.6; 78 | scale.figure_height = 6.6; 79 | scale.left = 0.14; 80 | scale.bottom = 0.17; 81 | scale.top = 0.08; 82 | scale.right = 0.03; 83 | text.legend_title = {'MCS', 'TDTRA-30', 'TDTRA-40', 'TDTRA-50', 'AMPPT'}; 84 | text.x_label = 'Time (year)'; 85 | text.y_label = 'Probability of failure'; 86 | changeFigureSettings(scale, text); 87 | print('-dtiff','-r300','pf.tif'); 88 | end 89 | 90 | function changeFigureSettings(scale, text) 91 | set(gca,'fontsize',11, 'fontname','Times New Roman'); 92 | set(gcf,'windowstyle','normal'); 93 | set(gcf,'unit','centimeters','position',[0 0 scale.figure_width scale.figure_height]); 94 | set(gca,'Position',... 95 | [scale.left, scale.bottom, ... 96 | 1-scale.left-scale.right, 1-scale.bottom-scale.top]); 97 | h = legend(text.legend_title); 98 | set(h,'FontName','Times New Roman','FontSize',12,'Location','best'); 99 | xlabel(text.x_label,'Fontname', 'Times New Roman','FontSize',12); 100 | ylabel(text.y_label,'Fontname', 'Times New Roman','FontSize',12); 101 | box on; 102 | end 103 | 104 | function plotLine(data, color, style) 105 | LINE_WIDTH = 1.5; 106 | MARKER_SIZE = 4.0; 107 | hold on; 108 | plot(data(1,:), data(2,:), ... 109 | style,'LineWidth',LINE_WIDTH, 'MarkerSize', MARKER_SIZE, ... 110 | 'MarkerEdgeColor', color, 'MarkerFaceColor', color, 'Color', color,... 111 | 'MarkerIndices',round(linspace(1,size(data, 2), 10))); 112 | end -------------------------------------------------------------------------------- /methods/MCS.m: -------------------------------------------------------------------------------- 1 | function result = MCS( problem, option ) 2 | % Monto Carlo Simulation 3 | % for time-variant reliability analysis 4 | % 5 | % Structure of the arguments 6 | % problem: 7 | % problem.variable_table; 8 | % problem.Ts; 9 | % problem.Te; 10 | % problem.performanceFunc; 11 | % 12 | % option: 13 | % option.n_MCS 14 | % option.n_time_instant 15 | % 16 | % auther: zyw (ywzhang@nwpu.edu.cn) 17 | 18 | % parameter settings 19 | if nargin == 3 20 | n_MCS = 1e6; 21 | n_time_instant = 400; 22 | else 23 | n_MCS = option.n_MCS; 24 | n_time_instant = option.n_time_instant; 25 | end 26 | variable_table = problem.variable_table; 27 | performanceFunc = problem.performanceFunc; 28 | 29 | % identify the number of static and dynamic RVs 30 | n_RV = size(variable_table,1); 31 | n_static_RV = n_RV; 32 | for rv_id = 1:n_RV 33 | if ~isempty(variable_table{rv_id,end}) 34 | n_static_RV = rv_id - 1; 35 | break; 36 | end 37 | end 38 | n_dynamic_RV = n_RV - n_static_RV; 39 | time_series = linspace(problem.Ts, problem.Te, n_time_instant); 40 | 41 | % run simulation 42 | first_failure_list = inf*ones(n_MCS,1); 43 | batch_size = 5e5; 44 | batch_num = floor(n_MCS/batch_size); 45 | for batch_id = 1:batch_num 46 | start_id = (batch_id-1) * batch_size + 1; 47 | stop_id = batch_id * batch_size; 48 | first_failure_list(start_id:stop_id) = batch(batch_size); 49 | 50 | disp([datestr(clock) ' ' num2str(stop_id/n_MCS*100) '%']); 51 | end 52 | left_num = n_MCS - batch_size*batch_num; 53 | if left_num > 0 54 | start_id = batch_num * batch_size + 1; 55 | first_failure_list(start_id:end) = batch(left_num); 56 | disp([datestr(clock) ' 100%']); 57 | end 58 | 59 | % calculate the evolution of pf 60 | pf_history = zeros(1,n_time_instant); 61 | for time_point_id = 1:n_time_instant 62 | failure_num = sum(first_failure_list <= time_point_id); 63 | pf_history(time_point_id) = failure_num/n_MCS; 64 | end 65 | 66 | result.pf = pf_history(end); 67 | result.pf_history = [time_series; pf_history]; 68 | result.funccount = n_MCS*n_time_instant; 69 | return; 70 | 71 | function first_failure_list = batch(n_MCS) 72 | % realization of the static RVs 73 | static_RVs = zeros(n_MCS, n_static_RV); 74 | for rv_id = 1:n_static_RV 75 | static_RVs(:,rv_id) = ... 76 | GenerateRV( ... 77 | variable_table{rv_id,1}, ... 78 | variable_table{rv_id,2}, ... 79 | variable_table{rv_id,3}, ... 80 | n_MCS); 81 | end 82 | 83 | % realization of the dynamic RVs 84 | dynamic_RVs = cell(1, n_dynamic_RV); 85 | for dynamic_rv_id = 1 : n_dynamic_RV 86 | dynamic_RVs{dynamic_rv_id} = ... 87 | GenerateGP( ... 88 | variable_table{n_static_RV + dynamic_rv_id,1}, ... 89 | variable_table{n_static_RV + dynamic_rv_id,2}, ... 90 | variable_table{n_static_RV + dynamic_rv_id,3}, ... 91 | variable_table{n_static_RV + dynamic_rv_id,4}, ... 92 | time_series, n_MCS); 93 | end 94 | 95 | % run simulation 96 | first_failure_list = inf*ones(n_MCS,1); 97 | for simulation_id = 1:n_MCS 98 | static_part = static_RVs(simulation_id, :); 99 | dynamic_part = zeros(n_dynamic_RV, n_time_instant); 100 | for dynamic_rv_id = 1 : n_dynamic_RV 101 | dynamic_part(dynamic_rv_id,:) = dynamic_RVs{dynamic_rv_id}(simulation_id, :); 102 | end 103 | 104 | G = performanceFunc(time_series, static_part, dynamic_part); 105 | first_failure_list(simulation_id) = calFirstFailure(G); 106 | end 107 | end 108 | 109 | function first_failure = calFirstFailure(G) 110 | label = G >= 0; 111 | first_failure = find(label,1); 112 | if isempty(first_failure) 113 | first_failure = inf; 114 | end 115 | end 116 | 117 | end 118 | 119 | -------------------------------------------------------------------------------- /model2/model2.m: -------------------------------------------------------------------------------- 1 | function model2() 2 | 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% problem definition %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | problem.performanceFunc = @CantileverBeam; 5 | problem.Ts = 0; 6 | problem.Te = 5; 7 | problem.variable_table = { 8 | % distribution mean std autocorrelationCoef 9 | 10 | % d, h, R0, F2, P 11 | 'normal', 0.042, 0.042*0.0119, []; 12 | 'normal', 0.005, 0.005*0.02, []; 13 | 'normal', 560e6, 560e5, []; 14 | 'normal', 1.8e3, 1.8e2, []; 15 | 'gumbel', 1.0e3, 1.0e2, []; 16 | 17 | % F1 T(t) 18 | 'stationary', 1.8e3, 1.8e2, @(t1,t2) exp(-abs(t1-t2)/4); 19 | 'stationary', 1.9e3, 1.9e2, @(t1,t2) exp(-4*(t1-t2).^2); 20 | }; 21 | 22 | solve(problem); 23 | analyzeResults(); 24 | end 25 | 26 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% solve the problem %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 27 | 28 | function solve(problem) 29 | % MCS 30 | MCS_par.n_MCS = 1e6; 31 | MCS_par.n_time_instant = 300; 32 | result.MCS = MCS(problem, MCS_par); 33 | 34 | % ADMPT 35 | option.discretization_node_num = 100; 36 | result.AMPPT = AMPPT( problem, option ); 37 | 38 | % TDTRA 39 | option.time_node_num = 10; result.TDTRA10 = TDTRA( problem, option ); 40 | option.time_node_num = 20; result.TDTRA20 = TDTRA( problem, option ); 41 | option.time_node_num = 30; result.TDTRA30 = TDTRA( problem, option ); 42 | save('result.mat', 'result'); 43 | end 44 | 45 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% analyze the results %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 46 | function analyzeResults() 47 | result = []; 48 | load('result.mat'); 49 | 50 | accuracy = [result.MCS.pf; 51 | result.TDTRA10.pf; 52 | result.TDTRA20.pf; 53 | result.TDTRA30.pf; 54 | result.AMPPT.pf;]; 55 | accuracy(:,2) = abs(accuracy(:,1) - result.MCS.pf) ./ result.MCS.pf; 56 | 57 | efficiency(:,1) = [result.MCS.funccount; 58 | result.TDTRA10.funccount; 59 | result.TDTRA20.funccount; 60 | result.TDTRA30.funccount; 61 | result.AMPPT.funccount;]; 62 | efficiency(:,2) = [nan; 63 | 10; 20; 30; 64 | 5;]; 65 | efficiency(:,3) = efficiency(:,1) ./ efficiency(:,2); 66 | table = [accuracy efficiency]; % statistics table 67 | 68 | % plot Pf curves 69 | COLOR_MCS = [0, 114, 189] / 255.0; 70 | COLOR_ADMPT = [217, 83, 25] / 255.0; 71 | COLOR_1 = [237, 177, 32] / 255.0; 72 | COLOR_2 = [126, 47, 142] / 255.0; 73 | COLOR_3 = [119, 172, 48] / 255.0; 74 | 75 | clf; 76 | plotLine(result.MCS.pf_history, COLOR_MCS, '-'); 77 | plotLine(result.TDTRA10.pf_history, COLOR_1, ':v'); 78 | plotLine(result.TDTRA20.pf_history, COLOR_2, ':s'); 79 | plotLine(result.TDTRA30.pf_history, COLOR_3, ':d'); 80 | plotLine(result.AMPPT.pf_history, COLOR_ADMPT,'-o'); 81 | 82 | scale.figure_width = 8.6; 83 | scale.figure_height = 6.6; 84 | scale.left = 0.18; 85 | scale.bottom = 0.17; 86 | scale.margin = 0.02; 87 | text.legend_title = {'MCS', 'TDTRA-10', 'TDTRA-20', 'TDTRA-30', 'AMPPT'}; 88 | text.x_label = 'Time (year)'; 89 | text.y_label = 'Probability of failure'; 90 | changeFigureSettings(scale, text); 91 | 92 | print('-dtiff','-r300','pf.tif'); 93 | end 94 | 95 | function changeFigureSettings(scale, text) 96 | set(gca,'fontsize',11, 'fontname','Times New Roman'); 97 | set(gcf,'windowstyle','normal'); 98 | set(gcf,'unit','centimeters','position',[0 0 scale.figure_width scale.figure_height]); 99 | set(gca,'Position',... 100 | [scale.left, scale.bottom, ... 101 | 1-scale.left-scale.margin, 1-scale.bottom-scale.margin]); 102 | 103 | h = legend(text.legend_title); 104 | set(h,'FontName','Times New Roman','FontSize',12,'Location','best'); 105 | 106 | xlabel(text.x_label,'Fontname', 'Times New Roman','FontSize',12); 107 | ylabel(text.y_label,'Fontname', 'Times New Roman','FontSize',12); 108 | box on; 109 | end 110 | 111 | function plotLine(data, color, style) 112 | LINE_WIDTH = 1.5; 113 | MARKER_SIZE = 4.0; 114 | 115 | hold on; 116 | plot(data(1,:), data(2,:), ... 117 | style,'LineWidth',LINE_WIDTH, 'MarkerSize', MARKER_SIZE, ... 118 | 'MarkerEdgeColor', color, 'MarkerFaceColor', color, 'Color', color,... 119 | 'MarkerIndices',round(linspace(1,size(data, 2), 10))); 120 | end 121 | -------------------------------------------------------------------------------- /methods/TDTRA.m: -------------------------------------------------------------------------------- 1 | function result = TDTRA( problem, option ) 2 | % Time-discritization based time-variant 3 | % reliability analysis (TDTRA) 4 | % 5 | % Structure of the arguments 6 | % problem: 7 | % problem.variable_table; 8 | % problem.Ts; 9 | % problem.Te; 10 | % problem.performanceFunc; 11 | % 12 | % option: 13 | % option.inverse 14 | % option.time_node_num 15 | % 16 | % auther: zyw (ywzhang@nwpu.edu.cn) 17 | 18 | if ~isfield(option, 'inverse') 19 | option.inverse = 0; 20 | end 21 | 22 | % pf_history 23 | [pf_history, statistics] = analyze(problem); 24 | 25 | for ii=1:size(pf_history,2) 26 | pf_history(2,ii) = max(pf_history(2,1:ii)); 27 | end 28 | 29 | result.pf = pf_history(2,end); 30 | result.funccount = sum(statistics(:,2)); 31 | result.pf_history = pf_history; 32 | result.statistics = statistics; 33 | 34 | 35 | function [pf_history, statistics] = analyze(problem) 36 | 37 | % parameters 38 | variable_table = problem.variable_table; 39 | performanceFunc = problem.performanceFunc; 40 | n_var = size(variable_table,1); 41 | n_static_RV = n_var; 42 | for rv_id = 1:n_var 43 | if ~isempty(variable_table{rv_id,end}) 44 | n_static_RV = rv_id - 1; 45 | break; 46 | end 47 | end 48 | 49 | % start point of MPP search in the original space 50 | u0 = zeros(1, n_var); 51 | 52 | fprintf('%4s%16s%16s%16s%16s\n', ... 53 | 'id', 'time', 'RI', 'funccount', 'total funccount'); 54 | 55 | % step 1: time discretization and sampling 56 | time_series = linspace(problem.Ts, problem.Te, option.time_node_num); 57 | mpp_list = zeros(option.time_node_num, size(variable_table,1)); 58 | funccout_list = zeros(option.time_node_num,1); 59 | for id = 1:option.time_node_num 60 | variable_table_copy = copy_table(variable_table, time_series(id)); 61 | [mpp_list(id,:), funccout_list(id)] = SearchMPP( ... 62 | @(x) performanceFunc(time_series(id), x(1:n_static_RV), x(n_static_RV+1:end)'), ... 63 | variable_table_copy, ... 64 | u0); 65 | fprintf('%4g%16g%16g%16g%16g\n', ... 66 | id, time_series(id), norm(mpp_list(id,:)), funccout_list(id), sum(funccout_list)); 67 | end 68 | 69 | % step 2: calculate the probability of failure through series expansion of 70 | % the stochastic process 71 | n_var = size(problem.variable_table,1); 72 | ACF = cell(n_var, 1); 73 | for var_id = 1:n_var 74 | ACF{var_id} = problem.variable_table{var_id, 4}; 75 | end 76 | 77 | fprintf('%8s%16s%16s\n', 'id', 'time', 'pf'); 78 | 79 | n_time_point_export = min(40, option.time_node_num); % 10 80 | pf_history = zeros(2, n_time_point_export); 81 | time_points = round(linspace(1, option.time_node_num, n_time_point_export)); 82 | for jj = 1:n_time_point_export 83 | time_point_id = time_points(jj); 84 | 85 | pf_history(1, jj) = time_series(time_point_id); 86 | pf_history(2, jj) = CalculatePf( ... 87 | mpp_list(1:time_point_id,:), ... 88 | time_series(1:time_point_id), ... 89 | ACF, ... 90 | option.inverse); 91 | fprintf('%8d%16f%16f\n', jj, pf_history(1, jj), pf_history(2, jj)); 92 | end 93 | 94 | statistics = [time_series' funccout_list mpp_list]; 95 | end 96 | 97 | function variable_table_copy = copy_table(vt, t) 98 | variable_table_copy = vt; 99 | for rv_id = 1:size(vt,1) 100 | if isa(variable_table_copy{rv_id,2},'function_handle') 101 | variable_table_copy{rv_id,2} = variable_table_copy{rv_id,2}(t); 102 | end 103 | if isa(variable_table_copy{rv_id,3},'function_handle') 104 | variable_table_copy{rv_id,3} = variable_table_copy{rv_id,3}(t); 105 | end 106 | if ~isempty(variable_table_copy{rv_id,4}) 107 | variable_table_copy{rv_id,1} = 'normal'; 108 | end 109 | end 110 | end 111 | end -------------------------------------------------------------------------------- /tools/dace/dsmerge.m: -------------------------------------------------------------------------------- 1 | function [mS, mY] = dsmerge(S, Y, ds, nms, wtds, wtdy) 2 | %DSMERGE Merge data for multiple design sites. 3 | % 4 | % Call 5 | % [mS, mY] = dsmerge(S, Y) 6 | % [mS, mY] = dsmerge(S, Y, ds) 7 | % [mS, mY] = dsmerge(S, Y, ds, nms) 8 | % [mS, mY] = dsmerge(S, Y, ds, nms, wtds) 9 | % [mS, mY] = dsmerge(S, Y, ds, nms, wtds, wtdy) 10 | % 11 | % Input 12 | % S, Y : Data points (S(i,:), Y(i,:)), i = 1,...,m 13 | % ds : Threshold for equal, normalized sites. Default is 1e-14. 14 | % nms : Norm, in which the distance is measured. 15 | % nms = 1 : 1-norm (sum of absolute coordinate differences) 16 | % 2 : 2-norm (Euclidean distance) (default) 17 | % otherwise: infinity norm (max coordinate difference) 18 | % wtds : What to do with the S-values in case of multiple points. 19 | % wtds = 1 : return the mean value (default) 20 | % 2 : return the median value 21 | % 3 : return the 'cluster center' 22 | % wtdy : What to do with the Y-values in case of multiple points. 23 | % wtdy = 1 : return the mean value (default) 24 | % 2 : return the median value 25 | % 3 : return the 'cluster center' value 26 | % 4 : return the minimum value 27 | % 5 : return the maximum value 28 | % 29 | % Output 30 | % mS : Compressed design sites, with multiple points merged 31 | % according to wtds 32 | % mY : Responses, compressed according to wtdy 33 | 34 | % hbn@imm.dtu.dk 35 | % Last update July 3, 2002 36 | 37 | % Check design points 38 | [m n] = size(S); % number of design sites and their dimension 39 | sY = size(Y); 40 | if min(sY) == 1, Y = Y(:); lY = max(sY); sY = size(Y); 41 | else, lY = sY(1); end 42 | if m ~= lY 43 | error('S and Y must have the same number of rows'), end 44 | 45 | % Threshold 46 | if nargin < 3 47 | ds = 1e-14; 48 | elseif (ds < 0) | (ds > .5) 49 | error('ds must be in the range [0, 0.5]'), end 50 | 51 | % Which measure 52 | if nargin < 4 53 | nms = 2; 54 | elseif (nms ~= 1) & (nms ~= 2) 55 | nms = Inf; 56 | end 57 | 58 | % What to do 59 | if nargin < 5 60 | wtds = 1; 61 | else 62 | wtds = round(wtds); 63 | if (wtds < 1) | (wtds > 3) 64 | error('wtds must be in the range [1, 3]'), end 65 | end 66 | if nargin < 6 67 | wtdy = 1; 68 | else 69 | wtdy = round(wtdy); 70 | if (wtdy < 1) | (wtdy > 5) 71 | error('wtdy must be in the range [1, 5]'), end 72 | end 73 | 74 | % Process data 75 | more = 1; 76 | ladr = zeros(1,ceil(m/2)); 77 | while more 78 | m = size(S,1); 79 | D = zeros(m,m); 80 | 81 | % Normalize sites 82 | mS = mean(S); sS = std(S); 83 | scS = (S - repmat(mS,m,1)) ./ repmat(sS,m,1); 84 | 85 | % Calculate distances D (upper triangle of the symetric matrix) 86 | for k = 1 : m-1 87 | kk = k+1 : m; 88 | dk = abs(repmat(scS(k,:), m-k, 1) - scS(kk,:)); 89 | if nms == 1, D(kk,k) = sum(dk,2); 90 | elseif nms == 2, D(kk,k) = sqrt(sum(dk.^2,2)); 91 | else, D(kk,k) = max(dk,[],2); end 92 | end 93 | D = D + D'; % make D symetric 94 | 95 | % Check distances 96 | mult = zeros(1,m); 97 | for j = 1 : m 98 | % Find the number of multiple sites in each column of D 99 | mult(j) = length(find(D(:,j) < ds)); 100 | end 101 | % Find the first column with the maximum number of multiple sites 102 | [mmult jj] = max(mult); 103 | 104 | if mmult == 1, more = 0; 105 | else 106 | nm = 0; 107 | while mmult > 1 108 | nm = nm + 1; % no. of points to merge 109 | ladr(nm) = jj; 110 | 111 | % Merge point no jj and its neighbours, note that jj is the center 112 | % of the cluster, as it has the most neighbors (among the multiple sites) 113 | ngb = find(D(:,jj) < ds); 114 | 115 | switch wtds 116 | case 1, S(jj,:) = mean(S(ngb,:)); 117 | case 2, S(jj,:) = median(S(ngb,:)); 118 | case 3, S(jj,:) = S(jj,:); 119 | end 120 | 121 | switch wtdy 122 | case 1, Y(jj,:) = mean(Y(ngb,:)); 123 | case 2, Y(jj,:) = median(Y(ngb,:)); 124 | case 3, Y(jj,:) = Y(jj,:); 125 | case 4, Y(jj,:) = min(Y(ngb,:)); 126 | case 5, Y(jj,:) = max(Y(ngb,:)); 127 | end 128 | 129 | % Delete from list 130 | mult(ngb) = 0; 131 | [mmult jj] = max(mult); 132 | end 133 | 134 | % Reduced data set 135 | act = [find(mult > 0) ladr(1:nm)]; 136 | S = S(act,:); Y = Y(act,:); 137 | end % multiple 138 | end % loop 139 | 140 | % Return reduced set 141 | mS = S; mY = Y; -------------------------------------------------------------------------------- /model4/model4.m: -------------------------------------------------------------------------------- 1 | function model4() 2 | 3 | rng('shuffle'); 4 | 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% problem definition %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | % The weight coefficients of the response surface of P(t) 8 | w=[]; 9 | load('w.mat'); 10 | 11 | problem.performanceFunc = @performanceFunc; 12 | problem.Ts = 7; 13 | problem.Te = 10; 14 | problem.variable_table = { 15 | % distribution mean std autocorrelationCoef 16 | % C_star, rho, Dt 17 | 'normal', 1575, 1575*0.02, []; 18 | 'normal', 1.69*10^3, 1.69*10^3*0.02, []; 19 | 'normal', 64e-3, 64e-3*0.02, []; 20 | % Pa0 21 | 'normal', 9.2e6, 9.2e6*0.01, []; 22 | % k 23 | 'stationary', 1, 0.05, @(t1, t2) exp(-((t1-t2)/0.1).^2); 24 | }; 25 | function g = performanceFunc(t, rv, sp) 26 | p = engine(t, rv(:,1), rv(:,2), rv(:,3),w); 27 | k = sp; 28 | p_allowable = rv(:,end) * (1 - 0.002*t); 29 | g = k.*p - p_allowable; 30 | end 31 | 32 | solve(problem); 33 | analyzeResults(); 34 | end 35 | 36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% solve the problem %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37 | function solve(problem) 38 | % MCS 39 | MCS_par.n_MCS = 1e6; 40 | MCS_par.n_time_instant = 300; 41 | result.MCS = MCS(problem, MCS_par); 42 | 43 | % ADMPT 44 | option.discretization_node_num = 50; 45 | result.AMPPT = AMPPT( problem, option ); 46 | 47 | % TDRA 48 | % option.time_node_num = 10; result.TDTRA10 = TDTRA( problem, option ); 49 | option.time_node_num = 20; result.TDTRA20 = TDTRA( problem, option ); 50 | option.time_node_num = 30; result.TDTRA30 = TDTRA( problem, option ); 51 | option.time_node_num = 40; result.TDTRA40 = TDTRA( problem, option ); 52 | save('result.mat', 'result'); 53 | end 54 | 55 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% analyze the results %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 56 | function analyzeResults() 57 | result = []; 58 | load('result2.mat'); 59 | plot(result.MCS.pf_history(1,:),result.MCS.pf_history(2,:)); hold on; 60 | 61 | accuracy = [result.MCS.pf; 62 | result.TDTRA20.pf; 63 | result.TDTRA30.pf; 64 | result.TDTRA40.pf; 65 | result.AMPPT.pf;]; 66 | accuracy(:,2) = abs(accuracy(:,1) - result.MCS.pf) ./ result.MCS.pf; 67 | 68 | efficiency(:,1) = [result.MCS.funccount; 69 | result.TDTRA20.funccount; 70 | result.TDTRA30.funccount; 71 | result.TDTRA40.funccount; 72 | result.AMPPT.funccount;]; 73 | efficiency(:,2) = [nan; 20; 30; 40; 5;]; 74 | efficiency(:,3) = efficiency(:,1) ./ efficiency(:,2); 75 | 76 | table = [accuracy efficiency]; % statistics table 77 | 78 | 79 | % plot Pf curves 80 | COLOR_MCS = [0, 114, 189] / 255.0; 81 | COLOR_ADMPT = [217, 83, 25] / 255.0; 82 | COLOR_1 = [237, 177, 32] / 255.0; 83 | COLOR_2 = [126, 47, 142] / 255.0; 84 | COLOR_3 = [119, 172, 48] / 255.0; 85 | 86 | clf; 87 | plotLine(result.MCS.pf_history, COLOR_MCS, '-'); 88 | plotLine(result.TDTRA20.pf_history, COLOR_1, ':v'); 89 | plotLine(result.TDTRA30.pf_history, COLOR_2, ':s'); 90 | plotLine(result.TDTRA40.pf_history, COLOR_3, ':d'); 91 | plotLine(result.AMPPT.pf_history, COLOR_ADMPT,'-o'); 92 | 93 | scale.figure_width = 8.6; 94 | scale.figure_height = 6.6; 95 | scale.left = 0.10; 96 | scale.bottom = 0.17; 97 | scale.top = 0.08; 98 | scale.right = 0.03; 99 | text.legend_title = {'MCS', 'TDTRA-20', 'TDTRA-30', 'TDTRA-40', 'AMPPT'}; 100 | text.x_label = 'Time (s)'; 101 | text.y_label = 'Probability of failure'; 102 | changeFigureSettings(scale, text); 103 | print('-dtiff','-r300','pf.tif'); 104 | end 105 | 106 | function changeFigureSettings(scale, text) 107 | set(gca,'fontsize',11, 'fontname','Times New Roman'); 108 | set(gcf,'windowstyle','normal'); 109 | set(gcf,'unit','centimeters','position',[0 0 scale.figure_width scale.figure_height]); 110 | set(gca,'Position',... 111 | [scale.left, scale.bottom, ... 112 | 1-scale.left-scale.right, 1-scale.bottom-scale.top]); 113 | 114 | h = legend(text.legend_title); 115 | set(h,'FontName','Times New Roman','FontSize',12,'Location','best'); 116 | 117 | xlabel(text.x_label,'Fontname', 'Times New Roman','FontSize',12); 118 | ylabel(text.y_label,'Fontname', 'Times New Roman','FontSize',12); 119 | box on; 120 | ylim([0,4.5e-3]); 121 | end 122 | 123 | function plotLine(data, color, style) 124 | LINE_WIDTH = 1.5; 125 | MARKER_SIZE = 4.0; 126 | 127 | hold on; 128 | plot(data(1,:), data(2,:), ... 129 | style,'LineWidth',LINE_WIDTH, 'MarkerSize', MARKER_SIZE, ... 130 | 'MarkerEdgeColor', color, 'MarkerFaceColor', color, 'Color', color,... 131 | 'MarkerIndices',round(linspace(1,size(data, 2), 10))); 132 | end 133 | -------------------------------------------------------------------------------- /model3/model3.m: -------------------------------------------------------------------------------- 1 | function model3() 2 | 3 | rng('shuffle'); 4 | 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% problem definition %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | problem.performanceFunc = @blade; 7 | problem.Ts = 0; 8 | problem.Te = 12; 9 | problem.variable_table = { 10 | % distribution mean std autocorrelationCoef 11 | % l1, t1, t2, e_allowable 12 | 'normal', 0.22, 0.0022, []; 13 | 'normal', 0.025, 0.00025, []; 14 | 'normal', 0.019, 0.00019, []; 15 | 'normal', 0.025, 0.00025, []; 16 | % v(t) 17 | 'nonstationary', @meanFunc, @stdFunc, @autoCoefFunc; 18 | }; 19 | 20 | function m = meanFunc(t) 21 | a_m = [3.815, 2.528, 1.176, -0.07856]; 22 | b_m = [0.2895, 0.5887, 0.7619, 2.183]; 23 | c_m = [-0.2668, 0.9651, 3.116, -3.161]; 24 | temp = a_m .* sin(b_m .* t + c_m); 25 | m = sum(temp); 26 | end 27 | 28 | function s = stdFunc(t) 29 | t = t'; 30 | a_s = [0.7382, 1.013, 1.875, 1.283]; 31 | b_s = [6.456, 4.075, 9.913, 1.035]; 32 | c_s = [0.9193, 1.561, 6.959, 2.237]; 33 | temp = a_s .* exp(-((t-b_s)./c_s).^2); 34 | s = sum(temp,2)'; 35 | end 36 | function rho = autoCoefFunc(t1, t2) 37 | rho = cos(2*pi*(t2-t1)); 38 | end 39 | 40 | solve(problem); 41 | analyzeResults(); 42 | end 43 | 44 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% solve the problem %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 45 | 46 | function solve(problem) 47 | % MCS 48 | MCS_par.n_MCS = 1e6; 49 | MCS_par.n_time_instant = 300; 50 | result.MCS = MCS(problem, MCS_par); 51 | 52 | % ADMPT 53 | option.discretization_node_num = 200; 54 | result.AMPPT = AMPPT( problem, option ); 55 | 56 | % TDTRA 57 | option.time_node_num = 100; result.TDTRA100 = TDTRA( problem, option ); 58 | option.time_node_num = 150; result.TDTRA150 = TDTRA( problem, option ); 59 | option.time_node_num = 200; result.TDTRA200 = TDTRA( problem, option ); 60 | save('result.mat', 'result'); 61 | end 62 | 63 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% analyze the results %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 64 | function analyzeResults() 65 | result = []; 66 | load('result.mat'); 67 | 68 | accuracy = [result.MCS.pf; 69 | result.TDTRA100.pf; 70 | result.TDTRA150.pf; 71 | result.TDTRA200.pf; 72 | result.AMPPT.pf;]; 73 | accuracy(:,2) = abs(accuracy(:,1) - result.MCS.pf) ./ result.MCS.pf; 74 | 75 | efficiency(:,1) = [result.MCS.funccount; 76 | result.TDTRA100.funccount; 77 | result.TDTRA150.funccount; 78 | result.TDTRA200.funccount; 79 | result.AMPPT.funccount;]; 80 | efficiency(:,2) = [nan; 81 | 100; 150; 200; 82 | size(result.AMPPT.statistics,1);]; 83 | efficiency(:,3) = efficiency(:,1) ./ efficiency(:,2); 84 | table = [accuracy efficiency]; % statistics table 85 | 86 | 87 | % plot Pf curves 88 | COLOR_MCS = [0, 114, 189] / 255.0; 89 | COLOR_ADMPT = [217, 83, 25] / 255.0; 90 | COLOR_1 = [237, 177, 32] / 255.0; 91 | COLOR_2 = [126, 47, 142] / 255.0; 92 | COLOR_3 = [119, 172, 48] / 255.0; 93 | 94 | clf; 95 | plotLine(result.MCS.pf_history, COLOR_MCS, '-'); 96 | plotLine(result.TDTRA100.pf_history, COLOR_1, ':v'); 97 | plotLine(result.TDTRA150.pf_history, COLOR_2, ':s'); 98 | plotLine(result.TDTRA200.pf_history, COLOR_3, ':d'); 99 | plotLine(result.AMPPT.pf_history, COLOR_ADMPT,'-o'); 100 | 101 | scale.figure_width = 8.6; 102 | scale.figure_height = 6.6; 103 | scale.left = 0.14; 104 | scale.bottom = 0.17; 105 | scale.top = 0.08; 106 | scale.right = 0.03; 107 | text.legend_title = {'MCS', 'TDTRA-100', 'TDTRA-150', 'TDTRA-200', 'AMPPT'}; 108 | text.x_label = 'Time (month)'; 109 | text.y_label = 'Probability of failure'; 110 | changeFigureSettings(scale, text); 111 | print('-dtiff','-r300','pf.tif'); 112 | end 113 | 114 | function changeFigureSettings(scale, text) 115 | set(gca,'fontsize',11, 'fontname','Times New Roman'); 116 | set(gcf,'windowstyle','normal'); 117 | set(gcf,'unit','centimeters','position',[0 0 scale.figure_width scale.figure_height]); 118 | set(gca,'Position',... 119 | [scale.left, scale.bottom, ... 120 | 1-scale.left-scale.right, 1-scale.bottom-scale.top]); 121 | h = legend(text.legend_title); 122 | set(h,'FontName','Times New Roman','FontSize',11,'Location','best'); 123 | xlabel(text.x_label,'Fontname', 'Times New Roman','FontSize',12); 124 | ylabel(text.y_label,'Fontname', 'Times New Roman','FontSize',12); 125 | box on; 126 | end 127 | 128 | function plotLine(data, color, style) 129 | LINE_WIDTH = 1.5; 130 | MARKER_SIZE = 4.0; 131 | hold on; 132 | plot(data(1,:), data(2,:), ... 133 | style,'LineWidth',LINE_WIDTH, 'MarkerSize', MARKER_SIZE, ... 134 | 'MarkerEdgeColor', color, 'MarkerFaceColor', color, 'Color', color,... 135 | 'MarkerIndices',round(linspace(1,size(data, 2), 10))); 136 | end -------------------------------------------------------------------------------- /tools/dace/changelog: -------------------------------------------------------------------------------- 1 | 2 | c : comment 3 | * : bug fixed 4 | + : new feature/function 5 | x : changed functionality 6 | 7 | -------------------------------------------------------------------- 8 | Version 2.5, September 4, 2002 9 | 10 | * REGPOLY2 did not work properly for dimension greater than 2 11 | Bug fixed. 12 | 13 | -------------------------------------------------------------------- 14 | Version 2.4, September 3, 2002 15 | 16 | x DACEFIT gives an error return in case of a rank deficient matrix F. 17 | May arise with a poor combination of choice of regression model 18 | and distribution of design sites. 19 | 20 | -------------------------------------------------------------------- 21 | Version 2.3, August 30, 2002 22 | 23 | x DACEFIT gives an error return in case of zero columns in matrix F. 24 | May arise with a poor combination of choice of regression model 25 | and distribution of design sites. 26 | 27 | -------------------------------------------------------------------- 28 | Version 2.2, August 27, 2002 29 | 30 | x DACEFIT allows design data with standard deviation zero 31 | in one or more directions. 32 | 33 | -------------------------------------------------------------------- 34 | Version 2.1, August 26, 2002 35 | 36 | * PREDICTOR returned erroneous mse-values in case of single 37 | response, multiple entry. This bug is fixed. 38 | 39 | -------------------------------------------------------------------- 40 | Version 2.0, August 5, 2002 41 | 42 | x The element dmodel.regress is renamed to dmodel.regr 43 | in DACEFIT, lines 19, 106 44 | in PREDICTOR, lines 58, 90, 107 45 | 46 | c Documentation is adapted to the new version. A separate report 47 | documenting the algorithm and other special parts of the toolbox 48 | is available. 49 | 50 | -------------------------------------------------------------------- 51 | Version 1.3, July 3, 2002 52 | 53 | * A developer debug statement in PREDICTOR line 52: 54 | 55 | save NX x 56 | 57 | is removed. 58 | 59 | + DSMERGE is a new function for merging data sets with multiple 60 | design sites (i.e., sites sampled more than one time). 61 | See 'help dsmerge' for more information. 62 | 63 | + PREDICTOR now return Jacobian matrices for model and mean 64 | squared error also for cases with multiple response functions. 65 | 66 | c We would like to acknowledge the comments and suggestions from 67 | Thierry Dalon, from Siemens VDO Automotive AG, which is a great 68 | help in improving this software. 69 | 70 | -------------------------------------------------------------------- 71 | Version 1.2, June 25, 2002 72 | 73 | + DACEFIT now has a second output parameter 74 | 75 | [dmodel, perf] = dacefit(S, Y, regr, corr, theta0) 76 | 77 | or 78 | 79 | [dmodel, perf] = dacefit(S, Y, regr, corr, theta0, lob, upb) 80 | 81 | The second output parameter gives the convergence history of the 82 | optimization - see 'help dacefit' for more information. 83 | 84 | + DACEFIT now allows the second input argument to be an m*q matrix, 85 | i.e., allows q response functions to be modelled, the elements of 86 | dmodel: beta, gamma, sigma2, Ysc are changed accordingly. 87 | 88 | c The optimization method in DACEFIT is changed. A separate report 89 | documenting the algorithm and other special parts of the toolbox 90 | will be available in August 2002. 91 | 92 | + PREDICTOR is adapted to the changes in DACEFIT, though in case 93 | of multiple response functions it does not yet return the 94 | Jacobian matrices for the predicted models and their respective 95 | mean squared errors. 96 | 97 | + CORRCUBIC is the new name of the function named CORRSPLINE 98 | in version 1.1. See 'help corrcubic' for more information. 99 | 100 | x CORRSPLINE gives a correlation function based on a cubic 101 | spline. See 'help corrspline' for more information. 102 | The above mentioned report will also discuss this new 103 | correlation model. 104 | 105 | x The parameter vector q in GRIDSAMP is changed so that now it 106 | is the number of equidistant points in each coordinate direction. 107 | This is in accordance with the similar parameter in LHSAMP 108 | and LINSPACE. 109 | 110 | -------------------------------------------------------------------- 111 | Version 1.1, June 7, 2002 112 | 113 | * A sign error in the gradient calculation in CORRGAUSS is 114 | corrected: line 33 in the file is changed from 115 | 116 | dr = repmat(-2*theta(:).',m,1) .* d .* repmat(r,1,n); 117 | 118 | to 119 | 120 | dr = -2*repmat(-theta(:).',m,1) .* d .* repmat(r,1,n); 121 | 122 | -------------------------------------------------------------------- 123 | Version 1.0, April 16, 2002 124 | 125 | c First version released 126 | -------------------------------------------------------------------------------- /tools/dace/predictor.m: -------------------------------------------------------------------------------- 1 | function [y, or1, or2, dmse] = predictor(x, dmodel) 2 | %PREDICTOR Predictor for y(x) using the given DACE model. 3 | % 4 | % Call: y = predictor(x, dmodel) 5 | % [y, or] = predictor(x, dmodel) 6 | % [y, dy, mse] = predictor(x, dmodel) 7 | % [y, dy, mse, dmse] = predictor(x, dmodel) 8 | % 9 | % Input 10 | % x : trial design sites with n dimensions. 11 | % For mx trial sites x: 12 | % If mx = 1, then both a row and a column vector is accepted, 13 | % otherwise, x must be an mx*n matrix with the sites stored 14 | % rowwise. 15 | % dmodel : Struct with DACE model; see DACEFIT 16 | % 17 | % Output 18 | % y : predicted response at x. 19 | % or : If mx = 1, then or = gradient vector/Jacobian matrix of predictor 20 | % otherwise, or is an vector with mx rows containing the estimated 21 | % mean squared error of the predictor 22 | % Three or four results are allowed only when mx = 1, 23 | % dy : Gradient of predictor; column vector with n elements 24 | % mse : Estimated mean squared error of the predictor; 25 | % dmse : Gradient vector/Jacobian matrix of mse 26 | 27 | % hbn@imm.dtu.dk 28 | % Last update August 26, 2002 29 | 30 | or1 = NaN; or2 = NaN; dmse = NaN; % Default return values 31 | if isnan(dmodel.beta) 32 | y = NaN; 33 | error('DMODEL has not been found') 34 | end 35 | 36 | [m n] = size(dmodel.S); % number of design sites and number of dimensions 37 | sx = size(x); % number of trial sites and their dimension 38 | if min(sx) == 1 & n > 1 % Single trial point 39 | nx = max(sx); 40 | if nx == n 41 | mx = 1; x = x(:).'; 42 | end 43 | else 44 | mx = sx(1); nx = sx(2); 45 | end 46 | if nx ~= n 47 | error(sprintf('Dimension of trial sites should be %d',n)) 48 | end 49 | 50 | % Normalize trial sites 51 | x = (x - repmat(dmodel.Ssc(1,:),mx,1)) ./ repmat(dmodel.Ssc(2,:),mx,1); 52 | q = size(dmodel.Ysc,2); % number of response functions 53 | y = zeros(mx,q); % initialize result 54 | 55 | if mx == 1 % one site only 56 | dx = repmat(x,m,1) - dmodel.S; % distances to design sites 57 | if nargout > 1 % gradient/Jacobian wanted 58 | [f df] = feval(dmodel.regr, x); 59 | [r dr] = feval(dmodel.corr, dmodel.theta, dx); 60 | % Scaled Jacobian 61 | dy = (df * dmodel.beta).' + dmodel.gamma * dr; 62 | % Unscaled Jacobian 63 | or1 = dy .* repmat(dmodel.Ysc(2, :)', 1, nx) ./ repmat(dmodel.Ssc(2,:), q, 1); 64 | if q == 1 65 | % Gradient as a column vector 66 | or1 = or1'; 67 | end 68 | if nargout > 2 % MSE wanted 69 | 70 | rt = dmodel.C \ r; 71 | u = dmodel.Ft.' * rt - f.'; 72 | v = dmodel.G \ u; 73 | or2 = repmat(dmodel.sigma2,mx,1) .* repmat((1 + sum(v.^2) - sum(rt.^2))',1,q); 74 | 75 | if nargout > 3 % gradient/Jacobian of MSE wanted 76 | % Scaled gradient as a row vector 77 | Gv = dmodel.G' \ v; 78 | g = (dmodel.Ft * Gv - rt)' * (dmodel.C \ dr) - (df * Gv)'; 79 | % Unscaled Jacobian 80 | dmse = repmat(2 * dmodel.sigma2',1,nx) .* repmat(g ./ dmodel.Ssc(2,:),q,1); 81 | if q == 1 82 | % Gradient as a column vector 83 | dmse = dmse'; 84 | end 85 | end 86 | 87 | end 88 | 89 | else % predictor only 90 | f = feval(dmodel.regr, x); 91 | r = feval(dmodel.corr, dmodel.theta, dx); 92 | end 93 | 94 | % Scaled predictor 95 | sy = f * dmodel.beta + (dmodel.gamma*r).'; 96 | % Predictor 97 | y = (dmodel.Ysc(1,:) + dmodel.Ysc(2,:) .* sy)'; 98 | 99 | else % several trial sites 100 | % Get distances to design sites 101 | dx = zeros(mx*m,n); kk = 1:m; 102 | for k = 1 : mx 103 | dx(kk,:) = repmat(x(k,:),m,1) - dmodel.S; 104 | kk = kk + m; 105 | end 106 | % Get regression function and correlation 107 | f = feval(dmodel.regr, x); 108 | r = feval(dmodel.corr, dmodel.theta, dx); 109 | r = reshape(r, m, mx); 110 | 111 | % Scaled predictor 112 | sy = f * dmodel.beta + (dmodel.gamma * r).'; 113 | % Predictor 114 | y = repmat(dmodel.Ysc(1,:),mx,1) + repmat(dmodel.Ysc(2,:),mx,1) .* sy; 115 | 116 | if nargout > 1 % MSE wanted 117 | rt = dmodel.C \ r; 118 | u = dmodel.G \ (dmodel.Ft.' * rt - f.'); 119 | or1 = repmat(dmodel.sigma2,mx,1) .* repmat((1 + colsum(u.^2) - colsum(rt.^2))',1,q); 120 | if nargout > 2 121 | disp('WARNING from PREDICTOR. Only y and or1=mse are computed') 122 | end 123 | end 124 | 125 | end % of several sites 126 | 127 | % >>>>>>>>>>>>>>>> Auxiliary function ==================== 128 | 129 | function s = colsum(x) 130 | % Columnwise sum of elements in x 131 | if size(x,1) == 1, s = x; 132 | else, s = sum(x); end -------------------------------------------------------------------------------- /tools/DE_Canonical.m: -------------------------------------------------------------------------------- 1 | function [best, result] = DE_Canonical(problem) 2 | % the canonical DE algorithm 3 | % the parameter "problem" must have the following members: 4 | % problem.solver.obj 5 | % problem.solver.con 6 | % problem.bound 7 | % problem.popSize 8 | % problem.maxEvaluation 9 | 10 | F = 0.9; 11 | Cr = 0.4; 12 | MAX_STALLED_ITERATIONS = 40; 13 | 14 | x_dim = size(problem.bound,1); 15 | 16 | pop = []; 17 | fitness = []; 18 | constraint = []; 19 | 20 | best.best_point = NaN; 21 | best.best_fitness = NaN; 22 | best.best_constraint = NaN; 23 | 24 | funccount = 0; 25 | stall_iterations = 0; 26 | is_continue = 1; 27 | 28 | % tic(); 29 | while is_continue == 1 30 | globalSearch(); 31 | if funccount >= problem.maxEvaluation 32 | is_continue = -1; 33 | end 34 | if stall_iterations >= MAX_STALLED_ITERATIONS 35 | is_continue = -2; 36 | end 37 | end 38 | % result.elapsed_time = toc(); 39 | result.funccount = funccount; 40 | if is_continue == -1 41 | result.msg = ['The user-specified maxEvaluation(' num2str(problem.maxEvaluation) ') is reached.']; 42 | elseif is_continue == -2 43 | result.msg = ['MAX_STALLED_ITERATIONS(' num2str(MAX_STALLED_ITERATIONS) ') is reached.']; 44 | end 45 | 46 | 47 | %% subfunctions for global search 48 | function globalSearch() 49 | if isempty(pop) 50 | % initialization 51 | pop = DOE_latin( problem.bound, problem.popSize ); 52 | res = problem.solver(pop); 53 | fitness = res(:,1); 54 | constraint = res(:,2:end); 55 | else 56 | % obtain the next population 57 | newpop = move(pop, problem.bound); 58 | 59 | res = problem.solver(newpop); 60 | newfitness = res(:,1); 61 | newContraint = res(:,2:end); 62 | 63 | for i = 1:problem.popSize 64 | if isempty(constraint) 65 | superior = comparePoints(fitness(i), [], newfitness(i), []); 66 | else 67 | superior = comparePoints(fitness(i), constraint(i,:), newfitness(i), newContraint(i,:)); 68 | end 69 | if superior == 1 70 | pop(i,:) = newpop(i,:); 71 | fitness(i) = newfitness(i); 72 | if ~isempty(constraint) 73 | constraint(i,:) = newContraint(i,:); 74 | end 75 | end 76 | end 77 | end 78 | 79 | funccount = funccount + problem.popSize; 80 | 81 | % archive 82 | best_id = findBestIndividual(fitness, constraint); % findBestFeasibleIndividual 83 | if isnan(best.best_fitness) || comparePoints(best.best_fitness, best.best_constraint, ... 84 | fitness(best_id,:), constraint(best_id,:)) == 1 85 | best.best_point = pop(best_id,:); 86 | best.best_fitness = fitness(best_id,:); 87 | best.best_constraint = constraint(best_id,:); 88 | stall_iterations = 0; 89 | else 90 | stall_iterations = stall_iterations + 1; 91 | end 92 | end 93 | 94 | function U = move(X, bound) 95 | F = 0.8; Cr = 0.4; 96 | popSize = problem.popSize; 97 | V = X; 98 | for ii = 1:popSize 99 | squence = 1:popSize; 100 | squence(ii) = []; 101 | r = randperm(popSize-1,3); 102 | r1 = squence(r(1)); 103 | r2 = squence(r(2)); 104 | r3 = squence(r(3)); 105 | V(ii, :) = X(r1,:) + F * (X(r2,:) - X(r3,:)); 106 | end 107 | indexCross = logical(rand(popSize, x_dim) <= Cr | repmat(1 : x_dim, popSize, 1) == repmat(randi(x_dim, [popSize, 1]), 1, x_dim)); 108 | U = V .* indexCross + X .* (1 - indexCross); 109 | U = box(U, bound); 110 | 111 | function pop = box(pop, bound) 112 | for popIndex = 1 : popSize 113 | for dimIndex = 1:x_dim 114 | if pop(popIndex,dimIndex) < bound(dimIndex, 1) 115 | pop(popIndex,dimIndex) = bound(dimIndex, 1); 116 | end 117 | if pop(popIndex,dimIndex) > bound(dimIndex, 2) 118 | pop(popIndex,dimIndex) = bound(dimIndex, 2); 119 | end 120 | end 121 | end 122 | end 123 | end 124 | 125 | function best_id = findBestIndividual(fitness, constraint) 126 | best_id = 1; 127 | for i = 2 : problem.popSize 128 | superior = comparePoints(fitness(best_id,:), constraint(best_id,:),fitness(i,:), constraint(i,:)); 129 | if superior == 1 130 | best_id = i; 131 | end 132 | end 133 | end 134 | 135 | function is_feasible = isFeasible(constraint) 136 | constraint_num = size(constraint,2); 137 | if constraint_num == 0 || sum(constraint <= 0) == constraint_num 138 | is_feasible = 1; 139 | else 140 | is_feasible = 0; 141 | end 142 | end 143 | 144 | function [ x ] = DOE_latin( bound, n ) 145 | % Latin Hypercube Sampling 146 | % for generating the initial population 147 | 148 | dim = size(bound, 1); % dimension 149 | x = lhsdesign(n, dim, 'criterion','maximin'); 150 | for i = 1 : dim 151 | down = bound(i, 1); 152 | up = bound(i, 2); 153 | x(:, i) = x(:, i) .* (up - down) + down; 154 | end 155 | end 156 | 157 | function moveon = comparePoints(fitness1, contraint1, fitness2, contraint2) 158 | % superior == 0: the first point is better 159 | % superior == 1: the second point is better 160 | 161 | v1 = calV(contraint1); 162 | v2 = calV(contraint2); 163 | 164 | if v1 == 0 && v2 == 0 165 | moveon = compareFitness(fitness1, fitness2); 166 | return; 167 | end 168 | moveon = compareFitness(v1, v2); 169 | return; 170 | 171 | function v = calV(contraint) 172 | contraint(1,contraint<=0) = 0; 173 | v = sum(contraint); 174 | end 175 | 176 | function moveon = compareFitness(f1, f2) 177 | if f1 > f2 178 | moveon = 1; 179 | else 180 | moveon = 0; 181 | end 182 | end 183 | 184 | end 185 | end -------------------------------------------------------------------------------- /methods/AMPPT.m: -------------------------------------------------------------------------------- 1 | function result = AMPPT( problem, option ) 2 | % AMPPT 3 | % Efficient Time-variant Reliability Analysis 4 | % through Approximating the MPP trajectory 5 | % 6 | % Structure of the arguments 7 | % problem: 8 | % problem.variable_table; 9 | % problem.Ts; 10 | % problem.Te; 11 | % problem.performanceFunc; 12 | % 13 | % option: 14 | % option.approximation_initial_point_num 15 | % option.approximation_tolerance 16 | % option.discretization_node_num 17 | % 18 | % auther: zyw (ywzhang@nwpu.edu.cn) 19 | 20 | 21 | if ~isfield(option, 'inverse') 22 | option.inverse = 0; 23 | end 24 | if ~isfield(option, 'approximation_initial_point_num') 25 | option.approximation_initial_point_num = 3; 26 | end 27 | if ~isfield(option, 'approximation_tolerance') 28 | option.approximation_tolerance = 1e-4; 29 | end 30 | 31 | [MPPT_model, statistics] = createMPTModel(); 32 | pf_history = calReliability(MPPT_model); 33 | for k = 1:size(pf_history,2) 34 | pf_history(2,k) = max(pf_history(2,1:k)); 35 | end 36 | 37 | result.pf = pf_history(2,end); 38 | result.pf_history = pf_history; 39 | result.funccount = sum(statistics(:,2)); 40 | result.statistics = statistics; 41 | return; 42 | 43 | function model = train(time_series, mpp_list) 44 | [mpp_list_n,settings] = mapminmax(mpp_list'); 45 | mpp_list_n = mpp_list_n'; 46 | 47 | n_y_dim = size(mpp_list,2); 48 | total_model = cell(1,n_y_dim); 49 | theta = 1; lob = 0.2; upb = 2; 50 | for ii = 1:n_y_dim 51 | total_model{ii} = dacefit( ... 52 | time_series, mpp_list_n(:,ii), @regpoly0, @corrgauss, theta, lob, upb); 53 | end 54 | model = @predict; 55 | 56 | function [y,mse] = predict(x) 57 | for jj = 1:n_y_dim 58 | [y(:,jj), mse(:,jj)] = predictor(x, total_model{jj}); 59 | end 60 | y = mapminmax.reverse(y',settings)'; 61 | end 62 | end 63 | 64 | function [MPPT_model, statistics] = createMPTModel() 65 | % parameters 66 | variable_table = problem.variable_table; 67 | performanceFunc = problem.performanceFunc; 68 | n_var = size(variable_table,1); 69 | n_static_RV = n_var; 70 | for rv_id = 1:n_var 71 | if ~isempty(variable_table{rv_id,end}) 72 | n_static_RV = rv_id - 1; 73 | break; 74 | end 75 | end 76 | 77 | % start point of MPP search in the original space 78 | u0 = zeros(1, n_var); 79 | 80 | fprintf('%8s%16s%16s%16s%16s\n', ... 81 | 'mpp_num', 'funccount', 'total funccount', 't_next', 'max_mse'); 82 | 83 | % step 1: initial sampling: generate equally spaced samples 84 | time_series = linspace(problem.Ts, problem.Te, option.approximation_initial_point_num); 85 | mpp_list = zeros(option.approximation_initial_point_num, size(variable_table,1)); 86 | funccout_WS = zeros(option.approximation_initial_point_num,1); 87 | funccount_NWS = zeros(option.approximation_initial_point_num,1); 88 | error = zeros(option.approximation_initial_point_num,1)*NaN; 89 | for id = 1:option.approximation_initial_point_num 90 | start_point_u = u0; 91 | if id ~= 1 92 | start_point_u = mpp_list(id-1,:); 93 | end 94 | 95 | variable_table_copy = copy_table(variable_table, time_series(id)); 96 | 97 | [mpp_list(id,:), funccout_WS(id)] = SearchMPP( ... 98 | @(x) performanceFunc(time_series(id), x(1:n_static_RV), x(n_static_RV+1:end)'), ... 99 | variable_table_copy, ... 100 | start_point_u); 101 | 102 | if id < option.approximation_initial_point_num 103 | fprintf('%8g%16g%16g\n', id, funccout_WS(id), sum(funccout_WS)); 104 | end 105 | end 106 | 107 | % step 2: adaptive sampling to approximate the Most Probable Curve (MPC) 108 | while 1 109 | % update the Kriging model 110 | MPPT_model = train(time_series', mpp_list); 111 | 112 | % adaptive sampling 113 | subproblem.solver = @(x) solver(x, MPPT_model); 114 | subproblem.bound = [problem.Ts, problem.Te]; 115 | subproblem.popSize = 100; 116 | subproblem.maxEvaluation = 1e8; 117 | [optimum, ~] = DE_Canonical(subproblem); 118 | t_next = optimum.best_point; 119 | max_mse = -optimum.best_fitness; 120 | error(id) = max_mse; 121 | 122 | fprintf('%8g%16g%16g%16g%16g\n', ... 123 | size(mpp_list,1), funccout_WS(id), sum(funccout_WS), t_next, max_mse); 124 | 125 | if ~all(time_series - t_next) 126 | break; 127 | end 128 | 129 | if max_mse <= option.approximation_tolerance 130 | break; 131 | end 132 | 133 | % run MPP search at the new generated time point 134 | id = id + 1; 135 | time_series(id) = t_next; 136 | variable_table_copy = copy_table(variable_table, t_next); 137 | 138 | % warm-start: predict the MPP at t_next 139 | start_point_u = MPPT_model(t_next); 140 | 141 | [mpp_list(id,:), funccout_WS(id)] = SearchMPP( ... 142 | @(x) performanceFunc(t_next, x(1:n_static_RV), x(n_static_RV+1:end)'), ... 143 | variable_table_copy, ... 144 | start_point_u); 145 | end 146 | 147 | % statistics = [time_series' funccout_WS funccount_NWS mpp_list error]; 148 | statistics = [time_series' funccout_WS mpp_list error]; 149 | 150 | function result = solver(x, MPPT_model) 151 | [~, mse] = MPPT_model(x); 152 | result = zeros(size(x,1),1); 153 | for individual_id = 1:size(x,1) 154 | result(individual_id) = -mean(mse(individual_id,:)); 155 | end 156 | end 157 | end 158 | 159 | function pf_history = calReliability(MPPT_model) 160 | % step 3: discretization of the approximated MPPT 161 | time_series = linspace(problem.Ts, problem.Te, option.discretization_node_num); 162 | mpp_list = MPPT_model(time_series'); 163 | 164 | % step 4: calculate the probability of failure through 165 | % spectral decomposition and MCS 166 | n_var = size(problem.variable_table,1); 167 | ACF = cell(n_var, 1); 168 | for var_id = 1:n_var 169 | ACF{var_id} = problem.variable_table{var_id, 4}; 170 | end 171 | 172 | fprintf('%8s%16s%16s\n', 'id', 'time', 'pf'); 173 | 174 | n_time_point_export = min(40, option.discretization_node_num); 175 | time_points = round(linspace(1, option.discretization_node_num, n_time_point_export)); 176 | pf_history = zeros(2, n_time_point_export); 177 | for jj = 1:n_time_point_export 178 | time_point_id = time_points(jj); 179 | pf_history(1, jj) = time_series(time_point_id); 180 | pf_history(2, jj) = CalculatePf(mpp_list(1:time_point_id,:), ... 181 | time_series(1:time_point_id),ACF,option.inverse); 182 | 183 | fprintf('%8d%16f%16f\n', jj, pf_history(1, jj), pf_history(2, jj)); 184 | end 185 | end 186 | 187 | function variable_table_copy = copy_table(vt, t) 188 | variable_table_copy = vt; 189 | for rv_id = 1:size(vt,1) 190 | if isa(variable_table_copy{rv_id,2},'function_handle') 191 | variable_table_copy{rv_id,2} = variable_table_copy{rv_id,2}(t); 192 | end 193 | if isa(variable_table_copy{rv_id,3},'function_handle') 194 | variable_table_copy{rv_id,3} = variable_table_copy{rv_id,3}(t); 195 | end 196 | if ~isempty(variable_table_copy{rv_id,4}) 197 | variable_table_copy{rv_id,1} = 'normal'; 198 | end 199 | end 200 | end 201 | end 202 | -------------------------------------------------------------------------------- /tools/dace/dacefit.m: -------------------------------------------------------------------------------- 1 | function [dmodel, perf] = dacefit(S, Y, regr, corr, theta0, lob, upb) 2 | %DACEFIT Constrained non-linear least-squares fit of a given correlation 3 | % model to the provided data set and regression model 4 | % 5 | % Call 6 | % [dmodel, perf] = dacefit(S, Y, regr, corr, theta0) 7 | % [dmodel, perf] = dacefit(S, Y, regr, corr, theta0, lob, upb) 8 | % 9 | % Input 10 | % S, Y : Data points (S(i,:), Y(i,:)), i = 1,...,m 11 | % regr : Function handle to a regression model 12 | % corr : Function handle to a correlation function 13 | % theta0 : Initial guess on theta, the correlation function parameters 14 | % lob,upb : If present, then lower and upper bounds on theta 15 | % Otherwise, theta0 is used for theta 16 | % 17 | % Output 18 | % dmodel : DACE model: a struct with the elements 19 | % regr : function handle to the regression model 20 | % corr : function handle to the correlation function 21 | % theta : correlation function parameters 22 | % beta : generalized least squares estimate 23 | % gamma : correlation factors 24 | % sigma2 : maximum likelihood estimate of the process variance 25 | % S : scaled design sites 26 | % Ssc : scaling factors for design arguments 27 | % Ysc : scaling factors for design ordinates 28 | % C : Cholesky factor of correlation matrix 29 | % Ft : Decorrelated regression matrix 30 | % G : From QR factorization: Ft = Q*G' . 31 | % perf : struct with performance information. Elements 32 | % nv : Number of evaluations of objective function 33 | % perf : (q+2)*nv array, where q is the number of elements 34 | % in theta, and the columns hold current values of 35 | % [theta; psi(theta); type] 36 | % |type| = 1, 2 or 3, indicate 'start', 'explore' or 'move' 37 | % A negative value for type indicates an uphill step 38 | 39 | % hbn@imm.dtu.dk 40 | % Last update September 3, 2002 41 | 42 | % Check design points 43 | [m n] = size(S); % number of design sites and their dimension 44 | sY = size(Y); 45 | if min(sY) == 1, Y = Y(:); lY = max(sY); sY = size(Y); 46 | else, lY = sY(1); end 47 | if m ~= lY 48 | error('S and Y must have the same number of rows'), end 49 | 50 | % Check correlation parameters 51 | lth = length(theta0); 52 | if nargin > 5 % optimization case 53 | if length(lob) ~= lth | length(upb) ~= lth 54 | error('theta0, lob and upb must have the same length'), end 55 | if any(lob <= 0) | any(upb < lob) 56 | error('The bounds must satisfy 0 < lob <= upb'), end 57 | else % given theta 58 | if any(theta0 <= 0) 59 | error('theta0 must be strictly positive'), end 60 | end 61 | 62 | % Normalize data 63 | mS = mean(S); sS = std(S); 64 | mY = mean(Y); sY = std(Y); 65 | % 02.08.27: Check for 'missing dimension' 66 | j = find(sS == 0); 67 | if ~isempty(j), sS(j) = 1; end 68 | j = find(sY == 0); 69 | if ~isempty(j), sY(j) = 1; end 70 | S = (S - repmat(mS,m,1)) ./ repmat(sS,m,1); 71 | Y = (Y - repmat(mY,m,1)) ./ repmat(sY,m,1); 72 | 73 | % Calculate distances D between points 74 | mzmax = m*(m-1) / 2; % number of non-zero distances 75 | ij = zeros(mzmax, 2); % initialize matrix with indices 76 | D = zeros(mzmax, n); % initialize matrix with distances 77 | ll = 0; 78 | for k = 1 : m-1 79 | ll = ll(end) + (1 : m-k); 80 | ij(ll,:) = [repmat(k, m-k, 1) (k+1 : m)']; % indices for sparse matrix 81 | D(ll,:) = repmat(S(k,:), m-k, 1) - S(k+1:m,:); % differences between points 82 | end 83 | if min(sum(abs(D),2) ) == 0 84 | error('Multiple design sites are not allowed'), end 85 | 86 | % Regression matrix 87 | F = feval(regr, S); [mF p] = size(F); 88 | if mF ~= m, error('number of rows in F and S do not match'), end 89 | if p > mF, error('least squares problem is underdetermined'), end 90 | 91 | % parameters for objective function 92 | par = struct('corr',corr, 'regr',regr, 'y',Y, 'F',F, ... 93 | 'D', D, 'ij',ij, 'scS',sS); 94 | 95 | % Determine theta 96 | if nargin > 5 97 | % Bound constrained non-linear optimization 98 | [theta f fit perf] = boxmin(theta0, lob, upb, par); 99 | if isinf(f) 100 | error('Bad parameter region. Try increasing upb'), end 101 | else 102 | % Given theta 103 | theta = theta0(:); 104 | [f fit] = objfunc(theta, par); 105 | perf = struct('perf',[theta; f; 1], 'nv',1); 106 | if isinf(f) 107 | error('Bad point. Try increasing theta0'), end 108 | end 109 | 110 | % Return values 111 | dmodel = struct('regr',regr, 'corr',corr, 'theta',theta.', ... 112 | 'beta',fit.beta, 'gamma',fit.gamma, 'sigma2',sY.^2.*fit.sigma2, ... 113 | 'S',S, 'Ssc',[mS; sS], 'Ysc',[mY; sY], ... 114 | 'C',fit.C, 'Ft',fit.Ft, 'G',fit.G); 115 | 116 | % >>>>>>>>>>>>>>>> Auxiliary functions ==================== 117 | 118 | function [obj, fit] = objfunc(theta, par) 119 | % Initialize 120 | obj = inf; 121 | fit = struct('sigma2',NaN, 'beta',NaN, 'gamma',NaN, ... 122 | 'C',NaN, 'Ft',NaN, 'G',NaN); 123 | m = size(par.F,1); 124 | % Set up R 125 | r = feval(par.corr, theta, par.D); 126 | idx = find(r > 0); o = (1 : m)'; 127 | mu = (10+m)*eps; 128 | R = sparse([par.ij(idx,1); o], [par.ij(idx,2); o], ... 129 | [r(idx); ones(m,1)+mu]); 130 | % Cholesky factorization with check for pos. def. 131 | [C rd] = chol(R); 132 | if rd, return, end % not positive definite 133 | 134 | % Get least squares solution 135 | C = C'; Ft = C \ par.F; 136 | [Q G] = qr(Ft,0); 137 | if rcond(G) < 1e-10 138 | % Check F 139 | if cond(par.F) > 1e15 140 | T = sprintf('F is too ill conditioned\nPoor combination of regression model and design sites'); 141 | error(T) 142 | else % Matrix Ft is too ill conditioned 143 | return 144 | end 145 | end 146 | Yt = C \ par.y; beta = G \ (Q'*Yt); 147 | rho = Yt - Ft*beta; sigma2 = sum(rho.^2)/m; 148 | detR = prod( full(diag(C)) .^ (2/m) ); 149 | obj = sum(sigma2) * detR; 150 | if nargout > 1 151 | fit = struct('sigma2',sigma2, 'beta',beta, 'gamma',rho' / C, ... 152 | 'C',C, 'Ft',Ft, 'G',G'); 153 | end 154 | 155 | % -------------------------------------------------------- 156 | 157 | function [t, f, fit, perf] = boxmin(t0, lo, up, par) 158 | %BOXMIN Minimize with positive box constraints 159 | 160 | % Initialize 161 | [t, f, fit, itpar] = start(t0, lo, up, par); 162 | if ~isinf(f) 163 | % Iterate 164 | p = length(t); 165 | if p <= 2, kmax = 2; else, kmax = min(p,4); end 166 | for k = 1 : kmax 167 | th = t; 168 | [t, f, fit, itpar] = explore(t, f, fit, itpar, par); 169 | [t, f, fit, itpar] = move(th, t, f, fit, itpar, par); 170 | end 171 | end 172 | perf = struct('nv',itpar.nv, 'perf',itpar.perf(:,1:itpar.nv)); 173 | 174 | % -------------------------------------------------------- 175 | 176 | function [t, f, fit, itpar] = start(t0, lo, up, par) 177 | % Get starting point and iteration parameters 178 | 179 | % Initialize 180 | t = t0(:); lo = lo(:); up = up(:); p = length(t); 181 | D = 2 .^ ([1:p]'/(p+2)); 182 | ee = find(up == lo); % Equality constraints 183 | if ~isempty(ee) 184 | D(ee) = ones(length(ee),1); t(ee) = up(ee); 185 | end 186 | ng = find(t < lo | up < t); % Free starting values 187 | if ~isempty(ng) 188 | t(ng) = (lo(ng) .* up(ng).^7).^(1/8); % Starting point 189 | end 190 | ne = find(D ~= 1); 191 | 192 | % Check starting point and initialize performance info 193 | [f fit] = objfunc(t,par); nv = 1; 194 | itpar = struct('D',D, 'ne',ne, 'lo',lo, 'up',up, ... 195 | 'perf',zeros(p+2,200*p), 'nv',1); 196 | itpar.perf(:,1) = [t; f; 1]; 197 | if isinf(f) % Bad parameter region 198 | return 199 | end 200 | 201 | if length(ng) > 1 % Try to improve starting guess 202 | d0 = 16; d1 = 2; q = length(ng); 203 | th = t; fh = f; jdom = ng(1); 204 | for k = 1 : q 205 | j = ng(k); fk = fh; tk = th; 206 | DD = ones(p,1); DD(ng) = repmat(1/d1,q,1); DD(j) = 1/d0; 207 | alpha = min(log(lo(ng) ./ th(ng)) ./ log(DD(ng))) / 5; 208 | v = DD .^ alpha; tk = th; 209 | for rept = 1 : 4 210 | tt = tk .* v; 211 | [ff fitt] = objfunc(tt,par); nv = nv+1; 212 | itpar.perf(:,nv) = [tt; ff; 1]; 213 | if ff <= fk 214 | tk = tt; fk = ff; 215 | if ff <= f 216 | t = tt; f = ff; fit = fitt; jdom = j; 217 | end 218 | else 219 | itpar.perf(end,nv) = -1; break 220 | end 221 | end 222 | end % improve 223 | 224 | % Update Delta 225 | if jdom > 1 226 | D([1 jdom]) = D([jdom 1]); 227 | itpar.D = D; 228 | end 229 | end % free variables 230 | 231 | itpar.nv = nv; 232 | 233 | % -------------------------------------------------------- 234 | 235 | function [t, f, fit, itpar] = explore(t, f, fit, itpar, par) 236 | % Explore step 237 | 238 | nv = itpar.nv; ne = itpar.ne; 239 | for k = 1 : length(ne) 240 | j = ne(k); tt = t; DD = itpar.D(j); 241 | if t(j) == itpar.up(j) 242 | atbd = 1; tt(j) = t(j) / sqrt(DD); 243 | elseif t(j) == itpar.lo(j) 244 | atbd = 1; tt(j) = t(j) * sqrt(DD); 245 | else 246 | atbd = 0; tt(j) = min(itpar.up(j), t(j)*DD); 247 | end 248 | [ff fitt] = objfunc(tt,par); nv = nv+1; 249 | itpar.perf(:,nv) = [tt; ff; 2]; 250 | if ff < f 251 | t = tt; f = ff; fit = fitt; 252 | else 253 | itpar.perf(end,nv) = -2; 254 | if ~atbd % try decrease 255 | tt(j) = max(itpar.lo(j), t(j)/DD); 256 | [ff fitt] = objfunc(tt,par); nv = nv+1; 257 | itpar.perf(:,nv) = [tt; ff; 2]; 258 | if ff < f 259 | t = tt; f = ff; fit = fitt; 260 | else 261 | itpar.perf(end,nv) = -2; 262 | end 263 | end 264 | end 265 | end % k 266 | 267 | itpar.nv = nv; 268 | 269 | % -------------------------------------------------------- 270 | 271 | function [t, f, fit, itpar] = move(th, t, f, fit, itpar, par) 272 | % Pattern move 273 | 274 | nv = itpar.nv; ne = itpar.ne; p = length(t); 275 | v = t ./ th; 276 | if all(v == 1) 277 | itpar.D = itpar.D([2:p 1]).^.2; 278 | return 279 | end 280 | 281 | % Proper move 282 | rept = 1; 283 | while rept 284 | tt = min(itpar.up, max(itpar.lo, t .* v)); 285 | [ff fitt] = objfunc(tt,par); nv = nv+1; 286 | itpar.perf(:,nv) = [tt; ff; 3]; 287 | if ff < f 288 | t = tt; f = ff; fit = fitt; 289 | v = v .^ 2; 290 | else 291 | itpar.perf(end,nv) = -3; 292 | rept = 0; 293 | end 294 | if any(tt == itpar.lo | tt == itpar.up), rept = 0; end 295 | end 296 | 297 | itpar.nv = nv; 298 | itpar.D = itpar.D([2:p 1]).^.25; 299 | --------------------------------------------------------------------------------