update distribution functions for Mmax bias
This commit is contained in:
		@@ -1,99 +1,99 @@
 | 
			
		||||
%   [x,z]=ExcProbGRT(opt,xd,xu,dx,y,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
%
 | 
			
		||||
%EVALUATES THE EXCEEDANCE PROBABILITY VALUES USING THE UPPER-BOUNDED G-R 
 | 
			
		||||
%   LED MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distriobution Mmax as well as the
 | 
			
		||||
% activity rate of M>=Mmin events are calculated at start-up of the 
 | 
			
		||||
% stationary hazard assessment services in the upper-bounded 
 | 
			
		||||
% Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The exceedance probability of magnitude M' in the time period of 
 | 
			
		||||
% length T' is the probability of an earthquake of magnitude M' or greater 
 | 
			
		||||
% to occur in T'. Depending on the value of the parameter opt the 
 | 
			
		||||
% exceedance probability values are calculated for a fixed time period T'
 | 
			
		||||
% and different magnitude values or for a fixed magnitude M' and different
 | 
			
		||||
% time period length values. In either case the independent variable vector
 | 
			
		||||
% starts from xd, up to xu with step dx. In either case the result is 
 | 
			
		||||
% returned in the vector z.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   x - vector of changeable independent variable: magnitudes if opt=0, 
 | 
			
		||||
%       time period lengths if opt=1, 
 | 
			
		||||
%       x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values of the same length as x
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=ExcProbGRT(opt,xd,xu,dx,y,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
if opt==0
 | 
			
		||||
    if xd<Mmin; xd=Mmin;end
 | 
			
		||||
    if xu>Mmax; xu=Mmax;end
 | 
			
		||||
end
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
if opt==0
 | 
			
		||||
    z=1-exp(-lamb*y.*(1-Cdfgr(x,beta,Mmin-eps/2,Mmax)));
 | 
			
		||||
else
 | 
			
		||||
    z=1-exp(-lamb*(1-Cdfgr(y,beta,Mmin-eps/2,Mmax)).*x);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [x,z]=ExcProbGRT(opt,xd,xu,dx,y,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
%
 | 
			
		||||
%EVALUATES THE EXCEEDANCE PROBABILITY VALUES USING THE UPPER-BOUNDED G-R 
 | 
			
		||||
%   LED MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distriobution Mmax as well as the
 | 
			
		||||
% activity rate of M>=Mmin events are calculated at start-up of the 
 | 
			
		||||
% stationary hazard assessment services in the upper-bounded 
 | 
			
		||||
% Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The exceedance probability of magnitude M' in the time period of 
 | 
			
		||||
% length T' is the probability of an earthquake of magnitude M' or greater 
 | 
			
		||||
% to occur in T'. Depending on the value of the parameter opt the 
 | 
			
		||||
% exceedance probability values are calculated for a fixed time period T'
 | 
			
		||||
% and different magnitude values or for a fixed magnitude M' and different
 | 
			
		||||
% time period length values. In either case the independent variable vector
 | 
			
		||||
% starts from xd, up to xu with step dx. In either case the result is 
 | 
			
		||||
% returned in the vector z.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   x - vector of changeable independent variable: magnitudes if opt=0, 
 | 
			
		||||
%       time period lengths if opt=1, 
 | 
			
		||||
%       x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values of the same length as x
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=ExcProbGRT(opt,xd,xu,dx,y,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
if opt==0
 | 
			
		||||
    if xd<Mmin; xd=Mmin;end
 | 
			
		||||
    if xu>Mmax; xu=Mmax;end
 | 
			
		||||
end
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
if opt==0
 | 
			
		||||
    z=1-exp(-lamb*y.*(1-Cdfgr(x,beta,Mmin-eps/2,Mmax)));
 | 
			
		||||
else
 | 
			
		||||
    z=1-exp(-lamb*(1-Cdfgr(y,beta,Mmin-eps/2,Mmax)).*x);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,78 +1,78 @@
 | 
			
		||||
%   [x,z]=ExcProbGRU(opt,xd,xu,dx,y,Mmin,lamb,eps,b)
 | 
			
		||||
%
 | 
			
		||||
%EVALUATES THE EXCEEDANCE PROBABILITY VALUES USING THE UNLIMITED G-R 
 | 
			
		||||
%   LED MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The exceedance probability of magnitude M' in the time period of 
 | 
			
		||||
% length T' is the probability of an earthquake of magnitude M' or greater 
 | 
			
		||||
% to occur in T'. Depending on the value of the parameter opt the 
 | 
			
		||||
% exceedance probability values are calculated for a fixed time period T'
 | 
			
		||||
% and different magnitude values or for a fixed magnitude M' and different
 | 
			
		||||
% time period length values. In either case the independent variable vector
 | 
			
		||||
% starts from xd, up to xu with step dx. In either case the result is 
 | 
			
		||||
% returned in the vector z.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%OUTPUT
 | 
			
		||||
%   x - vector of changeable independent variable: magnitudes if opt=0, 
 | 
			
		||||
%       time period lengths if opt=1, 
 | 
			
		||||
%       x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values of the same length as x
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=ExcProbGRU(opt,xd,xu,dx,y,Mmin,lamb,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    if xd<Mmin; xd=Mmin;end
 | 
			
		||||
 end
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
if opt==0
 | 
			
		||||
    z=1-exp(-lamb*y.*exp(-beta*(x-Mmin+eps/2)));
 | 
			
		||||
else
 | 
			
		||||
    z=1-exp(-lamb*exp(-beta*(y-Mmin+eps/2)).*x);
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [x,z]=ExcProbGRU(opt,xd,xu,dx,y,Mmin,lamb,eps,b)
 | 
			
		||||
%
 | 
			
		||||
%EVALUATES THE EXCEEDANCE PROBABILITY VALUES USING THE UNLIMITED G-R 
 | 
			
		||||
%   LED MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The exceedance probability of magnitude M' in the time period of 
 | 
			
		||||
% length T' is the probability of an earthquake of magnitude M' or greater 
 | 
			
		||||
% to occur in T'. Depending on the value of the parameter opt the 
 | 
			
		||||
% exceedance probability values are calculated for a fixed time period T'
 | 
			
		||||
% and different magnitude values or for a fixed magnitude M' and different
 | 
			
		||||
% time period length values. In either case the independent variable vector
 | 
			
		||||
% starts from xd, up to xu with step dx. In either case the result is 
 | 
			
		||||
% returned in the vector z.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%OUTPUT
 | 
			
		||||
%   x - vector of changeable independent variable: magnitudes if opt=0, 
 | 
			
		||||
%       time period lengths if opt=1, 
 | 
			
		||||
%       x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values of the same length as x
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=ExcProbGRU(opt,xd,xu,dx,y,Mmin,lamb,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    if xd<Mmin; xd=Mmin;end
 | 
			
		||||
 end
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
if opt==0
 | 
			
		||||
    z=1-exp(-lamb*y.*exp(-beta*(x-Mmin+eps/2)));
 | 
			
		||||
else
 | 
			
		||||
    z=1-exp(-lamb*exp(-beta*(y-Mmin+eps/2)).*x);
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,116 +1,116 @@
 | 
			
		||||
%   [x,z]=ExcProbNPT(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE  
 | 
			
		||||
%   EXCEEDANCE PROBABILITY VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The exceedance probability of magnitude M' in the time 
 | 
			
		||||
% period of length T' is the probability of an earthquake of magnitude M' 
 | 
			
		||||
% or greater to occur in T'. 
 | 
			
		||||
%
 | 
			
		||||
% Depending on the value of the parameter opt the exceedance probability 
 | 
			
		||||
% values are calculated for a fixed time period T' and different magnitude 
 | 
			
		||||
% values or for a fixed magnitude M' and different time period length 
 | 
			
		||||
% values. In either case the independent variable vector starts from  
 | 
			
		||||
% xd, up to xu with step dx. In either case the result is returned in the
 | 
			
		||||
% vector z.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
% Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
% Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
% Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   x - vector of changeable independent variable x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=...
 | 
			
		||||
    ExcProbNPT(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    if xd<Mmin; xd=Mmin;end
 | 
			
		||||
    if xu>Mmax; xu=Mmax;end
 | 
			
		||||
end
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
n=length(x);
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    for i=1:n
 | 
			
		||||
        CDF_NPT=2*(Dystr_npr(x(i),xx,ambd,h)...
 | 
			
		||||
            -Dystr_npr(Mmin-eps/2,xx,ambd,h))./mian;
 | 
			
		||||
        z(i)=1-exp(-lamb*y.*(1-CDF_NPT));
 | 
			
		||||
    end
 | 
			
		||||
else
 | 
			
		||||
    CDF_NPT=2*(Dystr_npr(y,xx,ambd,h)...
 | 
			
		||||
        -Dystr_npr(Mmin-eps/2,xx,ambd,h))./mian;
 | 
			
		||||
    z=1-exp(-lamb*(1-CDF_NPT).*x);
 | 
			
		||||
        if y>Mmax;z=zeros(size(x));end %K15DEC2015
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [x,z]=ExcProbNPT(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE  
 | 
			
		||||
%   EXCEEDANCE PROBABILITY VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The exceedance probability of magnitude M' in the time 
 | 
			
		||||
% period of length T' is the probability of an earthquake of magnitude M' 
 | 
			
		||||
% or greater to occur in T'. 
 | 
			
		||||
%
 | 
			
		||||
% Depending on the value of the parameter opt the exceedance probability 
 | 
			
		||||
% values are calculated for a fixed time period T' and different magnitude 
 | 
			
		||||
% values or for a fixed magnitude M' and different time period length 
 | 
			
		||||
% values. In either case the independent variable vector starts from  
 | 
			
		||||
% xd, up to xu with step dx. In either case the result is returned in the
 | 
			
		||||
% vector z.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
% Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
% Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
% Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   x - vector of changeable independent variable x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=...
 | 
			
		||||
    ExcProbNPT(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    if xd<Mmin; xd=Mmin;end
 | 
			
		||||
    if xu>Mmax; xu=Mmax;end
 | 
			
		||||
end
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
n=length(x);
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    for i=1:n
 | 
			
		||||
        CDF_NPT=2*(Dystr_npr(x(i),xx,ambd,h)...
 | 
			
		||||
            -Dystr_npr(Mmin-eps/2,xx,ambd,h))./mian;
 | 
			
		||||
        z(i)=1-exp(-lamb*y.*(1-CDF_NPT));
 | 
			
		||||
    end
 | 
			
		||||
else
 | 
			
		||||
    CDF_NPT=2*(Dystr_npr(y,xx,ambd,h)...
 | 
			
		||||
        -Dystr_npr(Mmin-eps/2,xx,ambd,h))./mian;
 | 
			
		||||
    z=1-exp(-lamb*(1-CDF_NPT).*x);
 | 
			
		||||
        if y>Mmax;z=zeros(size(x));end %K15DEC2015
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,105 +1,105 @@
 | 
			
		||||
%   [x,z]=ExcProbNPU(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE  
 | 
			
		||||
%   EXCEEDANCE PROBABILITY VALUES FOR THE UNBOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
% The exceedance probability of magnitude M' in the time period of length 
 | 
			
		||||
% T' is the probability of an earthquake of magnitude M' or greater to 
 | 
			
		||||
% occur in T'. 
 | 
			
		||||
% Depending on the value of the parameter opt the exceedance probability 
 | 
			
		||||
% values are calculated for a fixed time period T' and different magnitude 
 | 
			
		||||
% values or for a fixed magnitude M' and different time period length 
 | 
			
		||||
% values. In either case the independent variable vector starts from  
 | 
			
		||||
% xd, up to xu with step dx. In either case the result is returned in the
 | 
			
		||||
% vector z.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%       
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   x - vector of changeable independent variable: magnitudes if opt=0, 
 | 
			
		||||
%       time period lengths if opt=1, 
 | 
			
		||||
%       x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values of the same length as x
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=ExcProbNPU(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
n=length(x);
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    for i=1:n
 | 
			
		||||
        CDF_NPU=2*(Dystr_npr(x(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
        z(i)=1-exp(-lamb*y.*(1-CDF_NPU));
 | 
			
		||||
    end
 | 
			
		||||
else
 | 
			
		||||
    CDF_NPU=2*(Dystr_npr(y,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
    z=1-exp(-lamb*(1-CDF_NPU).*x);
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [x,z]=ExcProbNPU(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE  
 | 
			
		||||
%   EXCEEDANCE PROBABILITY VALUES FOR THE UNBOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
% The exceedance probability of magnitude M' in the time period of length 
 | 
			
		||||
% T' is the probability of an earthquake of magnitude M' or greater to 
 | 
			
		||||
% occur in T'. 
 | 
			
		||||
% Depending on the value of the parameter opt the exceedance probability 
 | 
			
		||||
% values are calculated for a fixed time period T' and different magnitude 
 | 
			
		||||
% values or for a fixed magnitude M' and different time period length 
 | 
			
		||||
% values. In either case the independent variable vector starts from  
 | 
			
		||||
% xd, up to xu with step dx. In either case the result is returned in the
 | 
			
		||||
% vector z.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%       
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   x - vector of changeable independent variable: magnitudes if opt=0, 
 | 
			
		||||
%       time period lengths if opt=1, 
 | 
			
		||||
%       x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values of the same length as x
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=ExcProbNPU(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
n=length(x);
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    for i=1:n
 | 
			
		||||
        CDF_NPU=2*(Dystr_npr(x(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
        z(i)=1-exp(-lamb*y.*(1-CDF_NPU));
 | 
			
		||||
    end
 | 
			
		||||
else
 | 
			
		||||
    CDF_NPU=2*(Dystr_npr(y,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
    z=1-exp(-lamb*(1-CDF_NPU).*x);
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,59 +1,59 @@
 | 
			
		||||
%   [T,m]=Max_credM_GRT(Td,Tu,dT,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
%EVALUATES THE MAXIMUM CREDIBLE MAGNITUDE VALUES USING THE UPPER-BOUNDED 
 | 
			
		||||
%   G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distriobution Mmax as well as the
 | 
			
		||||
% activity rate of M>=Mmin events are calculated at start-up of the 
 | 
			
		||||
% stationary hazard assessment services in the upper-bounded 
 | 
			
		||||
% Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_GRT(Td,Tu,dT,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin+eps/2)));
 | 
			
		||||
m=Mmin-eps/2-1/beta*log((1-(1-1./(lamb*T))*mian));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [T,m]=Max_credM_GRT(Td,Tu,dT,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
%EVALUATES THE MAXIMUM CREDIBLE MAGNITUDE VALUES USING THE UPPER-BOUNDED 
 | 
			
		||||
%   G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distriobution Mmax as well as the
 | 
			
		||||
% activity rate of M>=Mmin events are calculated at start-up of the 
 | 
			
		||||
% stationary hazard assessment services in the upper-bounded 
 | 
			
		||||
% Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_GRT(Td,Tu,dT,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin+eps/2)));
 | 
			
		||||
m=Mmin-eps/2-1/beta*log((1-(1-1./(lamb*T))*mian));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,63 +1,63 @@
 | 
			
		||||
%   [T,m]=Max_credM_GRU(Td,Tu,dT,Mmin,lamb,eps,b)
 | 
			
		||||
%
 | 
			
		||||
%EVALUATES THE MAXIMUM CREDIBLE MAGNITUDE VALUES USING THE UNLIMITED 
 | 
			
		||||
%   G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
% 
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_GRU(Td,Tu,dT,Mmin,lamb,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
m=Mmin-eps/2+1/beta.*log(lamb*T);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%   [T,m]=Max_credM_GRU(Td,Tu,dT,Mmin,lamb,eps,b)
 | 
			
		||||
%
 | 
			
		||||
%EVALUATES THE MAXIMUM CREDIBLE MAGNITUDE VALUES USING THE UNLIMITED 
 | 
			
		||||
%   G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
% 
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_GRU(Td,Tu,dT,Mmin,lamb,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
m=Mmin-eps/2+1/beta.*log(lamb*T);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,98 +1,98 @@
 | 
			
		||||
%   [T,m]=Max_credM_NPT(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)    
 | 
			
		||||
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE MAXIMUM 
 | 
			
		||||
%   CREDIBLE MAGNITUDE VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPT(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 Mmax-0.001];
 | 
			
		||||
for i=1:n
 | 
			
		||||
    m(i)=fzero(@F_maxmagn,interval,[],xx,h,ambd,Mmin-eps/2,Mmax,lamb,T(i));
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn(t,xx,h,ambd,xmin,Mmax,lamb,D)
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
CDF_NPT=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h))/mian;
 | 
			
		||||
y=CDF_NPT-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [T,m]=Max_credM_NPT(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)    
 | 
			
		||||
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE MAXIMUM 
 | 
			
		||||
%   CREDIBLE MAGNITUDE VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPT(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 Mmax-0.001];
 | 
			
		||||
for i=1:n
 | 
			
		||||
    m(i)=fzero(@F_maxmagn,interval,[],xx,h,ambd,Mmin-eps/2,Mmax,lamb,T(i));
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn(t,xx,h,ambd,xmin,Mmax,lamb,D)
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
CDF_NPT=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h))/mian;
 | 
			
		||||
y=CDF_NPT-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,98 +1,98 @@
 | 
			
		||||
%   [T,m]=Max_credM_NPT_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)  ---- (Octave Compatible Version)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE MAXIMUM 
 | 
			
		||||
%   CREDIBLE MAGNITUDE VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPT_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 Mmax-0.001];
 | 
			
		||||
for i=1:n
 | 
			
		||||
 m(i)=fzero(@(t) F_maxmagn(t,xx,h,ambd,Mmin-eps/2,Mmax,lamb,T(i)),interval);
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn(t,xx,h,ambd,xmin,Mmax,lamb,D)
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
CDF_NPT=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h))/mian;
 | 
			
		||||
y=CDF_NPT-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [T,m]=Max_credM_NPT_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)  ---- (Octave Compatible Version)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE MAXIMUM 
 | 
			
		||||
%   CREDIBLE MAGNITUDE VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPT_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 Mmax-0.001];
 | 
			
		||||
for i=1:n
 | 
			
		||||
 m(i)=fzero(@(t) F_maxmagn(t,xx,h,ambd,Mmin-eps/2,Mmax,lamb,T(i)),interval);
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn(t,xx,h,ambd,xmin,Mmax,lamb,D)
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
CDF_NPT=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h))/mian;
 | 
			
		||||
y=CDF_NPT-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,98 +1,98 @@
 | 
			
		||||
%   [T,m]=Max_credM_NPU(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES  
 | 
			
		||||
%   THE MAXIMUM CREDIBLE MAGNITUDE VALUES FOR THE UNBOUNDED 
 | 
			
		||||
%   NONPARAMETRIC DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPU(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 10.0];
 | 
			
		||||
for i=1:n
 | 
			
		||||
     m(i)=fzero(@F_maxmagn_NPU,interval,[],xx,h,ambd,Mmin-eps/2,lamb,T(i));
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn_NPU(t,xx,h,ambd,xmin,lamb,D)
 | 
			
		||||
CDF_NPU=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
y=CDF_NPU-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [T,m]=Max_credM_NPU(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES  
 | 
			
		||||
%   THE MAXIMUM CREDIBLE MAGNITUDE VALUES FOR THE UNBOUNDED 
 | 
			
		||||
%   NONPARAMETRIC DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPU(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 10.0];
 | 
			
		||||
for i=1:n
 | 
			
		||||
     m(i)=fzero(@F_maxmagn_NPU,interval,[],xx,h,ambd,Mmin-eps/2,lamb,T(i));
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn_NPU(t,xx,h,ambd,xmin,lamb,D)
 | 
			
		||||
CDF_NPU=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
y=CDF_NPU-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,99 +1,99 @@
 | 
			
		||||
%   [T,m]=Max_credM_NPU_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)  ---- (Octave  Comlatible Version)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES  
 | 
			
		||||
%   THE MAXIMUM CREDIBLE MAGNITUDE VALUES FOR THE UNBOUNDED 
 | 
			
		||||
%   NONPARAMETRIC DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPU_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 10.0];
 | 
			
		||||
for i=1:n
 | 
			
		||||
%     m(i)=fzero(@F_maxmagn_NPU,interval,[],xx,h,ambd,Mmin-eps/2,lamb,T(i));
 | 
			
		||||
     m(i)=fzero(@(t) F_maxmagn_NPU(t,xx,h,ambd,Mmin-eps/2,lamb,T(i)),interval);
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn_NPU(t,xx,h,ambd,xmin,lamb,D)
 | 
			
		||||
CDF_NPU=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
y=CDF_NPU-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [T,m]=Max_credM_NPU_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)  ---- (Octave  Comlatible Version)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES  
 | 
			
		||||
%   THE MAXIMUM CREDIBLE MAGNITUDE VALUES FOR THE UNBOUNDED 
 | 
			
		||||
%   NONPARAMETRIC DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPU_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 10.0];
 | 
			
		||||
for i=1:n
 | 
			
		||||
%     m(i)=fzero(@F_maxmagn_NPU,interval,[],xx,h,ambd,Mmin-eps/2,lamb,T(i));
 | 
			
		||||
     m(i)=fzero(@(t) F_maxmagn_NPU(t,xx,h,ambd,Mmin-eps/2,lamb,T(i)),interval);
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn_NPU(t,xx,h,ambd,xmin,lamb,D)
 | 
			
		||||
CDF_NPU=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
y=CDF_NPU-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,259 +1,259 @@
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=Nonpar(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx AND CALCULATES THE WEIGHTING FACTORS - ambd 
 | 
			
		||||
% FOR A USE OF THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE 
 | 
			
		||||
% DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UNBOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx. 
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (the zero of the h functional 
 | 
			
		||||
%   has been found, ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=...
 | 
			
		||||
            Nonpar(t,M,iop,Mmin)
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
    
 | 
			
		||||
if iop==0
 | 
			
		||||
    lamb_all=n/round(t(n)-t(1));
 | 
			
		||||
    lamb=nn/round(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
lamb_all=30*n/(t(n)-t(1));      % K20OCT2014
 | 
			
		||||
lamb=30*nn/(t2-t1);               % K20OCT2014
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
lamb_all=365*n/(t(n)-t(1));       % K20OCT2014
 | 
			
		||||
lamb=365*nn/(t2-t1);                % K20OCT2014
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
   [hh(1),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
            [hh(jj),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=Nonpar(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx AND CALCULATES THE WEIGHTING FACTORS - ambd 
 | 
			
		||||
% FOR A USE OF THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE 
 | 
			
		||||
% DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UNBOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx. 
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (the zero of the h functional 
 | 
			
		||||
%   has been found, ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=...
 | 
			
		||||
            Nonpar(t,M,iop,Mmin)
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
    
 | 
			
		||||
if iop==0
 | 
			
		||||
    lamb_all=n/round(t(n)-t(1));
 | 
			
		||||
    lamb=nn/round(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
lamb_all=30*n/(t(n)-t(1));      % K20OCT2014
 | 
			
		||||
lamb=30*nn/(t2-t1);               % K20OCT2014
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
lamb_all=365*n/(t(n)-t(1));       % K20OCT2014
 | 
			
		||||
lamb=365*nn/(t2-t1);                % K20OCT2014
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
   [hh(1),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
            [hh(jj),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
@@ -1,310 +1,310 @@
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=Nonpar(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx AND CALCULATES THE WEIGHTING FACTORS - ambd 
 | 
			
		||||
% FOR A USE OF THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE 
 | 
			
		||||
% DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UNBOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2 01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx. 
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (the zero of the h functional 
 | 
			
		||||
%   has been found, ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=...
 | 
			
		||||
            Nonpar_O(t,M,iop,Mmin)
 | 
			
		||||
if isempty(t) || numel(t)<3 isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
xx=NaN;
 | 
			
		||||
ambd=NaN;
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
%                                           enai=dlmread('para.txt'); %for fixed xx,ambd to test in different platforms
 | 
			
		||||
%                                           [ambd]=enai(:,1);
 | 
			
		||||
%                                           xx=enai(:,2)';               
 | 
			
		||||
%                                           [h,ierr]=hopt(xx);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)              % SL 03MAR2015 
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
 	fun = @(t) funct(t,x);                                       % FOR OCTAVE
 | 
			
		||||
	x0 =interval;                                                    % FOR OCTAVE
 | 
			
		||||
    [hh(1),fval,exitflag] = fzero(fun,x0);               % FOR OCTAVE
 | 
			
		||||
    
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
             fun = @(t) funct(t,x);                              % FOR OCTAVE
 | 
			
		||||
				x0 =interval;                                        % FOR OCTAVE
 | 
			
		||||
				[hh(jj),fval,exitflag] = fzero(fun,x0);    % FOR OCTAVE
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=Nonpar(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx AND CALCULATES THE WEIGHTING FACTORS - ambd 
 | 
			
		||||
% FOR A USE OF THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE 
 | 
			
		||||
% DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UNBOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2 01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx. 
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (the zero of the h functional 
 | 
			
		||||
%   has been found, ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=...
 | 
			
		||||
            Nonpar_O(t,M,iop,Mmin)
 | 
			
		||||
if isempty(t) || numel(t)<3 isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
xx=NaN;
 | 
			
		||||
ambd=NaN;
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
%                                           enai=dlmread('para.txt'); %for fixed xx,ambd to test in different platforms
 | 
			
		||||
%                                           [ambd]=enai(:,1);
 | 
			
		||||
%                                           xx=enai(:,2)';               
 | 
			
		||||
%                                           [h,ierr]=hopt(xx);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)              % SL 03MAR2015 
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
 	fun = @(t) funct(t,x);                                       % FOR OCTAVE
 | 
			
		||||
	x0 =interval;                                                    % FOR OCTAVE
 | 
			
		||||
    [hh(1),fval,exitflag] = fzero(fun,x0);               % FOR OCTAVE
 | 
			
		||||
    
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
             fun = @(t) funct(t,x);                              % FOR OCTAVE
 | 
			
		||||
				x0 =interval;                                        % FOR OCTAVE
 | 
			
		||||
				[hh(jj),fval,exitflag] = fzero(fun,x0);    % FOR OCTAVE
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
@@ -1,373 +1,373 @@
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err]=
 | 
			
		||||
%           Nonpar(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx, CALCULATES THE WEIGHTING FACTORS - amb, AND
 | 
			
		||||
% THE END-POINT OF MAGNITUDE DISTRIBUTION Mmax FOR A USE OF THE NONPARAMETRIC 
 | 
			
		||||
% ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE DISTRIBUTION UNDER THE 
 | 
			
		||||
% ASSUMPTION OF THE EXISTENCE OF THE UPPER LIMIT OF MAGNITUDE DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx.
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred.
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
%
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (a zero of the h functional 
 | 
			
		||||
%   has been found), ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err]=...
 | 
			
		||||
            Nonpar_tr(t,M,iop,Mmin)
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
    
 | 
			
		||||
if iop==0
 | 
			
		||||
    lamb_all=n/round(t(n)-t(1));
 | 
			
		||||
    lamb=nn/round(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
lamb_all=30*n/(t(n)-t(1));      % K20OCT2014
 | 
			
		||||
lamb=30*nn/(t2-t1);               % K20OCT2014
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
lamb_all=365*n/(t(n)-t(1));       % K20OCT2014
 | 
			
		||||
lamb=365*nn/(t2-t1);                % K20OCT2014
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
[Mmax,err]=Mmaxest(xx,h,Mmin-eps/2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
   [hh(1),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
            [hh(jj),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Mmax,ierr]=Mmaxest(x,h,Mmin)
 | 
			
		||||
 | 
			
		||||
% ESTIMATION OF UPPER BOUND USING NONPARAMETRIC DISTRIBUTION FUNCTIONS
 | 
			
		||||
% x - row vector of magnitudes (basic sample). 
 | 
			
		||||
% h - optimal smoothing factor
 | 
			
		||||
% Mmax - upper bound
 | 
			
		||||
% ierr=0 if basic procedure converges, ierr=1 when Robsen & Whitlock Mmas
 | 
			
		||||
% estimation
 | 
			
		||||
 | 
			
		||||
% Uses function 'dystryb'
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
ierr=1;
 | 
			
		||||
x=sort(x);
 | 
			
		||||
Mmax1=x(n);
 | 
			
		||||
for i=1:50,
 | 
			
		||||
d=normcdf((Mmin-x)./h);
 | 
			
		||||
mian=sum(normcdf((Mmax1-x)./h)-d);
 | 
			
		||||
Mmax=x(n)+moja_calka(@dystryb,x(1),Mmax1,0.00001,h,mian,x,d);
 | 
			
		||||
if abs(Mmax-Mmax1)<0.01 
 | 
			
		||||
   ierr=0;break;
 | 
			
		||||
end
 | 
			
		||||
Mmax1=Mmax;
 | 
			
		||||
end
 | 
			
		||||
if (ierr==1 || Mmax>9)
 | 
			
		||||
    Mmax=2*x(n)-x(n-1);
 | 
			
		||||
    ierr=1;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=dystryb(z,h,mian,x,d)
 | 
			
		||||
n=length(x);
 | 
			
		||||
m=length(z);
 | 
			
		||||
for i=1:m, 
 | 
			
		||||
t=(z(i)-x)./h;
 | 
			
		||||
t=normcdf(t);
 | 
			
		||||
yy=sum(t-d);
 | 
			
		||||
y(i)=(yy/mian)^n;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err]=
 | 
			
		||||
%           Nonpar(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx, CALCULATES THE WEIGHTING FACTORS - amb, AND
 | 
			
		||||
% THE END-POINT OF MAGNITUDE DISTRIBUTION Mmax FOR A USE OF THE NONPARAMETRIC 
 | 
			
		||||
% ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE DISTRIBUTION UNDER THE 
 | 
			
		||||
% ASSUMPTION OF THE EXISTENCE OF THE UPPER LIMIT OF MAGNITUDE DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx.
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred.
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
%
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (a zero of the h functional 
 | 
			
		||||
%   has been found), ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err]=...
 | 
			
		||||
            Nonpar_tr(t,M,iop,Mmin)
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
    
 | 
			
		||||
if iop==0
 | 
			
		||||
    lamb_all=n/round(t(n)-t(1));
 | 
			
		||||
    lamb=nn/round(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
lamb_all=30*n/(t(n)-t(1));      % K20OCT2014
 | 
			
		||||
lamb=30*nn/(t2-t1);               % K20OCT2014
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
lamb_all=365*n/(t(n)-t(1));       % K20OCT2014
 | 
			
		||||
lamb=365*nn/(t2-t1);                % K20OCT2014
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
[Mmax,err]=Mmaxest(xx,h,Mmin-eps/2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
   [hh(1),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
            [hh(jj),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Mmax,ierr]=Mmaxest(x,h,Mmin)
 | 
			
		||||
 | 
			
		||||
% ESTIMATION OF UPPER BOUND USING NONPARAMETRIC DISTRIBUTION FUNCTIONS
 | 
			
		||||
% x - row vector of magnitudes (basic sample). 
 | 
			
		||||
% h - optimal smoothing factor
 | 
			
		||||
% Mmax - upper bound
 | 
			
		||||
% ierr=0 if basic procedure converges, ierr=1 when Robsen & Whitlock Mmas
 | 
			
		||||
% estimation
 | 
			
		||||
 | 
			
		||||
% Uses function 'dystryb'
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
ierr=1;
 | 
			
		||||
x=sort(x);
 | 
			
		||||
Mmax1=x(n);
 | 
			
		||||
for i=1:50,
 | 
			
		||||
d=normcdf((Mmin-x)./h);
 | 
			
		||||
mian=sum(normcdf((Mmax1-x)./h)-d);
 | 
			
		||||
Mmax=x(n)+moja_calka(@dystryb,x(1),Mmax1,0.00001,h,mian,x,d);
 | 
			
		||||
if abs(Mmax-Mmax1)<0.01 
 | 
			
		||||
   ierr=0;break;
 | 
			
		||||
end
 | 
			
		||||
Mmax1=Mmax;
 | 
			
		||||
end
 | 
			
		||||
if (ierr==1 || Mmax>9)
 | 
			
		||||
    Mmax=2*x(n)-x(n-1);
 | 
			
		||||
    ierr=1;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=dystryb(z,h,mian,x,d)
 | 
			
		||||
n=length(x);
 | 
			
		||||
m=length(z);
 | 
			
		||||
for i=1:m, 
 | 
			
		||||
t=(z(i)-x)./h;
 | 
			
		||||
t=normcdf(t);
 | 
			
		||||
yy=sum(t-d);
 | 
			
		||||
y(i)=(yy/mian)^n;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,431 +1,506 @@
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err]=
 | 
			
		||||
%           Nonpar_tr(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx, CALCULATES THE WEIGHTING FACTORS - amb, AND
 | 
			
		||||
% THE END-POINT OF MAGNITUDE DISTRIBUTION Mmax FOR A USE OF THE NONPARAMETRIC 
 | 
			
		||||
% ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE DISTRIBUTION UNDER THE 
 | 
			
		||||
% ASSUMPTION OF THE EXISTENCE OF THE UPPER LIMIT OF MAGNITUDE DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2  01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx.
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred.
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
%
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (a zero of the h functional 
 | 
			
		||||
%   has been found), ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err]=...
 | 
			
		||||
            Nonpar_tr_O(t,M,iop,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
if isempty(t) || numel(t)<3 isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
xx=NaN;
 | 
			
		||||
ambd=NaN;
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
 | 
			
		||||
if isempty(Mmax)                         %K30AUG2019 - Allow for manually set Mmax
 | 
			
		||||
[Mmax,err]=Mmaxest(xx,h,Mmin-eps/2);
 | 
			
		||||
else                                     
 | 
			
		||||
err=0;                                   %K30AUG2019
 | 
			
		||||
end
 | 
			
		||||
%                                           enai=dlmread('paraT.txt'); %for fixed xx,ambd to test in different platforms
 | 
			
		||||
%                                           [ambd]=enai(:,1);
 | 
			
		||||
%                                           xx=enai(:,2)';               
 | 
			
		||||
%                                           [h,ierr]=hopt(xx);
 | 
			
		||||
%                                           [Mmax,err]=Mmaxest(xx,h,Mmin-eps/2);
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)              % SL 03MAR2015 ----------------------------------
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
   fun = @(t) funct(t,x);                                       % for octave  
 | 
			
		||||
	x0 =interval;                                                   % for octave
 | 
			
		||||
    [hh(1),fval,exitflag] = fzero(fun,x0);              % for octave
 | 
			
		||||
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
                fun = @(t) funct(t,x);                          % for octave
 | 
			
		||||
				x0 =interval;                                       % for octave
 | 
			
		||||
				[hh(jj),fval,exitflag] = fzero(fun,x0);   % for octave
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Mmax,ierr]=Mmaxest(x,h,Mmin)
 | 
			
		||||
 | 
			
		||||
% ESTIMATION OF UPPER BOUND USING NONPARAMETRIC DISTRIBUTION FUNCTIONS
 | 
			
		||||
% x - row vector of magnitudes (basic sample). 
 | 
			
		||||
% h - optimal smoothing factor
 | 
			
		||||
% Mmax - upper bound
 | 
			
		||||
% ierr=0 if basic procedure converges, ierr=1 when Robsen & Whitlock Mmas
 | 
			
		||||
% estimation
 | 
			
		||||
 | 
			
		||||
% Uses function 'dystryb'
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
ierr=1;
 | 
			
		||||
x=sort(x);
 | 
			
		||||
Mmax1=x(n);
 | 
			
		||||
for i=1:50,
 | 
			
		||||
d=normcdf((Mmin-x)./h);
 | 
			
		||||
mian=sum(normcdf((Mmax1-x)./h)-d);
 | 
			
		||||
Mmax=x(n)+moja_calka(@dystryb,x(1),Mmax1,0.00001,h,mian,x,d);
 | 
			
		||||
if abs(Mmax-Mmax1)<0.01 
 | 
			
		||||
   ierr=0;break;
 | 
			
		||||
end
 | 
			
		||||
Mmax1=Mmax;
 | 
			
		||||
end
 | 
			
		||||
if (ierr==1 || Mmax>9)
 | 
			
		||||
    Mmax=2*x(n)-x(n-1);
 | 
			
		||||
    ierr=1;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=dystryb(z,h,mian,x,d)
 | 
			
		||||
n=length(x);
 | 
			
		||||
m=length(z);
 | 
			
		||||
for i=1:m, 
 | 
			
		||||
t=(z(i)-x)./h;
 | 
			
		||||
t=normcdf(t);
 | 
			
		||||
yy=sum(t-d);
 | 
			
		||||
y(i)=(yy/mian)^n;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err,BIAS,SD]=
 | 
			
		||||
%           Nonpar_tr(t,M,iop,Mmin,Mmax,Nsynth)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx, CALCULATES THE WEIGHTING FACTORS - amb, AND
 | 
			
		||||
% THE END-POINT OF MAGNITUDE DISTRIBUTION Mmax FOR A USE OF THE NONPARAMETRIC 
 | 
			
		||||
% ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE DISTRIBUTION UNDER THE 
 | 
			
		||||
% ASSUMPTION OF THE EXISTENCE OF THE UPPER LIMIT OF MAGNITUDE DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2  01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx.
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred.
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
%
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   Mmax - upper limit of Magnitude Distribution. Can be set by user, or
 | 
			
		||||
%   estimate within the program - it then should be set as Mmax=[].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (a zero of the h functional 
 | 
			
		||||
%   has been found), ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%   BIAS - Mmax estimation Bias (Lasocki and Urban, 2011)
 | 
			
		||||
%   SD   - Mmax standard deviation (Lasocki ands Urban, 2011)
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err,BIAS,SD]=...
 | 
			
		||||
            Nonpar_tr_Ob(t,M,iop,Mmin,Mmax,Nsynth)
 | 
			
		||||
if nargin==5;Nsynth=[];end                                   % K08DEC2019
 | 
			
		||||
if isempty(t) || numel(t)<3 isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
xx=NaN;
 | 
			
		||||
ambd=NaN;
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    BIAS=NaN;SD=NaN;                                               %%%     K 08NOV2019  
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
 | 
			
		||||
if isempty(Mmax)                         %K30AUG2019 - Allow for manually set Mmax
 | 
			
		||||
err_Mmax=1;[Mmax,err]=Mmaxest(xx,h,Mmin-eps/2);      %  err_Mmax added 04DEC2019
 | 
			
		||||
else                                     
 | 
			
		||||
err_Mmax=0;err=0;                        %K30AUG2019
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
% Estimation of Mmax Bias                                               %%%   K 04DEC2019 
 | 
			
		||||
% (Lasocki and Urban, 2011, doi:10.2478/s11600-010-0049-y)
 | 
			
		||||
if isempty(Nsynth)==0  && err_Mmax==1              % set number of synthetic datasets, e.g. 10000
 | 
			
		||||
[BIAS,SD]=Mmax_Bias_GR(t,M,Mmin,Mmax,err,h,xx,ambd,Nsynth);
 | 
			
		||||
elseif isempty(Nsynth)==0 && err_Mmax==0;              
 | 
			
		||||
warning('Mmax must be empty for BIAS calculation');BIAS=[];SD=[];
 | 
			
		||||
else; BIAS=0;SD=0;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)              % SL 03MAR2015 ----------------------------------
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
   fun = @(t) funct(t,x);                                       % for octave  
 | 
			
		||||
	x0 =interval;                                                   % for octave
 | 
			
		||||
    [hh(1),fval,exitflag] = fzero(fun,x0);              % for octave
 | 
			
		||||
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
                fun = @(t) funct(t,x);                          % for octave
 | 
			
		||||
				x0 =interval;                                       % for octave
 | 
			
		||||
				[hh(jj),fval,exitflag] = fzero(fun,x0);   % for octave
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Mmax,ierr]=Mmaxest(x,h,Mmin)
 | 
			
		||||
 | 
			
		||||
% ESTIMATION OF UPPER BOUND USING NONPARAMETRIC DISTRIBUTION FUNCTIONS
 | 
			
		||||
% x - row vector of magnitudes (basic sample). 
 | 
			
		||||
% h - optimal smoothing factor
 | 
			
		||||
% Mmax - upper bound
 | 
			
		||||
% ierr=0 if basic procedure converges, ierr=1 when Robsen & Whitlock Mmas
 | 
			
		||||
% estimation
 | 
			
		||||
 | 
			
		||||
% Uses function 'dystryb'
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
ierr=1;
 | 
			
		||||
x=sort(x);
 | 
			
		||||
Mmax1=x(n);
 | 
			
		||||
for i=1:50,
 | 
			
		||||
d=normcdf((Mmin-x)./h);
 | 
			
		||||
mian=sum(normcdf((Mmax1-x)./h)-d);
 | 
			
		||||
Mmax=x(n)+moja_calka(@dystryb,x(1),Mmax1,0.00001,h,mian,x,d);
 | 
			
		||||
if abs(Mmax-Mmax1)<0.01 
 | 
			
		||||
   ierr=0;break;
 | 
			
		||||
end
 | 
			
		||||
Mmax1=Mmax;
 | 
			
		||||
end
 | 
			
		||||
if (ierr==1 || Mmax>9)
 | 
			
		||||
    Mmax=2*x(n)-x(n-1);
 | 
			
		||||
    ierr=1;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=dystryb(z,h,mian,x,d)
 | 
			
		||||
n=length(x);
 | 
			
		||||
m=length(z);
 | 
			
		||||
for i=1:m, 
 | 
			
		||||
t=(z(i)-x)./h;
 | 
			
		||||
t=normcdf(t);
 | 
			
		||||
yy=sum(t-d);
 | 
			
		||||
y(i)=(yy/mian)^n;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
% --------------------- Mmax BIAS estimation routine ----------------------  K 08NOV2019
 | 
			
		||||
 | 
			
		||||
function [BIAS,SD]=Mmax_Bias_GR(t,m,Mc,Mmax1,err,h,xx,ambd,synth)
 | 
			
		||||
 | 
			
		||||
s1=sort(unique(m));s2=s1(2:length(s1))-s1(1:length(s1)-1);EPS=min(s2);
 | 
			
		||||
 | 
			
		||||
if err~=0
 | 
			
		||||
warning('process did not converge!!')   
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
MAXm=max(m);N=numel(m(m>=Mc));DeltaM=MAXm-Mc;    %beta=b*log(10);
 | 
			
		||||
[mag,PDF_NPT,CDF_NPT]=dist_NPT(Mc-EPS,Mmax1+EPS,0.01,Mc,EPS,h,xx,ambd,Mmax1);
 | 
			
		||||
 | 
			
		||||
for j=1:synth         %set number of synthetic datasets, default is 10000 
 | 
			
		||||
% % CDF:
 | 
			
		||||
 
 | 
			
		||||
                                                                                     % j  
 | 
			
		||||
 | 
			
		||||
% linear interpolation to assign magnitude values from a uniform distribution sample
 | 
			
		||||
 iM=rand(1,N);M1=interp1q(CDF_NPT,mag,iM');
 | 
			
		||||
 br(j)=1/(log(10)*(mean(M1)-min(M1)+EPS/2));DM=range(M1);
 | 
			
		||||
 Mmax=max(M1);
 | 
			
		||||
 | 
			
		||||
 % Iteration Process to estimate b and Mmax
 | 
			
		||||
b1=10;best=[1.0 10.0];i=1; 
 | 
			
		||||
while min(abs(diff(best)))>0.00001
 | 
			
		||||
w=exp(b1*(Mmax-Mc));E1=expint(N/(w-1));E2=expint(N*w/(w-1));
 | 
			
		||||
%E=expint(w);
 | 
			
		||||
Mme=Mmax+(E1-E2)/(b1*exp(-N/(w-1)))+(Mc)*exp(-N);    %Mme=round(Mme/EPS)*EPS;            
 | 
			
		||||
 | 
			
		||||
if isnan(Mme)
 | 
			
		||||
KM=sort(unique(M1),'descend');
 | 
			
		||||
Mme=2*KM(1)-KM(2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
fun=@(bb) 1/bb+(Mme-Mc)/(1-exp(bb*(Mme-Mc)))-mean(M1)+Mc-EPS/2;  %consider th5 last 0.05 term
 | 
			
		||||
b1=fzero(fun,1);best(i)=b1;i=i+1;
 | 
			
		||||
 | 
			
		||||
if i==50
 | 
			
		||||
   warning('process did not converge!!');break 
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
be(j)=b1/log(10);
 | 
			
		||||
Me(j)=Mme;dm(j)=DM;Mm(j)=Mmax;
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
BIAS=mean(MAXm-Me);
 | 
			
		||||
SD=std(MAXm-Me);
 | 
			
		||||
 | 
			
		||||
%b-mean(be)    %check b-value difference
 | 
			
		||||
%histogram(be)
 | 
			
		||||
 | 
			
		||||
% MAXm: maximum magnitude in the real catalog 
 | 
			
		||||
% Mmax: maximum magnitudes observed in the synthetic catalogs (rounded)
 | 
			
		||||
% Me: maximum magnitude estimates for the synthetic catalogs 
 | 
			
		||||
% Mmax1: maximum magnitude estimated by GRT
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,83 +1,83 @@
 | 
			
		||||
%   [m,T]=Ret_periodGRT(Md,Mu,dM,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE MEAN RETURN PERIOD VALUES USING THE UPPER-BOUNDED G-R LED 
 | 
			
		||||
%   MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distriobution Mmax as well as the
 | 
			
		||||
% activity rate of M>=Mmin events are calculated at start-up of the 
 | 
			
		||||
% stationary hazard assessment services in the upper-bounded 
 | 
			
		||||
% Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The mean return period of magnitude M is the average elapsed time between
 | 
			
		||||
% the consecutive earthquakes of magnitude M.   
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodGRT(Md,Mu,dM,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
if Mu>Mmax; Mu=Mmax;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
T=1/lamb./(1-Cdfgr(m,beta,Mmin-eps/2,Mmax));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%   [m,T]=Ret_periodGRT(Md,Mu,dM,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE MEAN RETURN PERIOD VALUES USING THE UPPER-BOUNDED G-R LED 
 | 
			
		||||
%   MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distriobution Mmax as well as the
 | 
			
		||||
% activity rate of M>=Mmin events are calculated at start-up of the 
 | 
			
		||||
% stationary hazard assessment services in the upper-bounded 
 | 
			
		||||
% Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The mean return period of magnitude M is the average elapsed time between
 | 
			
		||||
% the consecutive earthquakes of magnitude M.   
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodGRT(Md,Mu,dM,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
if Mu>Mmax; Mu=Mmax;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
T=1/lamb./(1-Cdfgr(m,beta,Mmin-eps/2,Mmax));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,59 +1,59 @@
 | 
			
		||||
%   [m,T]=Ret_periodGRU(Md,Mu,dM,Mmin,lamb,eps,b)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE MEAN RETURN PERIOD VALUES USING THE UNLIMITED G-R LED 
 | 
			
		||||
%   MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The mean return period of magnitude M is the average elapsed time between
 | 
			
		||||
% the consecutive earthquakes of magnitude M.   
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
% 
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodGRU(Md,Mu,dM,Mmin,lamb,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
T=1/lamb./exp(-beta*(m-Mmin+eps/2));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%   [m,T]=Ret_periodGRU(Md,Mu,dM,Mmin,lamb,eps,b)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE MEAN RETURN PERIOD VALUES USING THE UNLIMITED G-R LED 
 | 
			
		||||
%   MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The mean return period of magnitude M is the average elapsed time between
 | 
			
		||||
% the consecutive earthquakes of magnitude M.   
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
% 
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodGRU(Md,Mu,dM,Mmin,lamb,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
T=1/lamb./exp(-beta*(m-Mmin+eps/2));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,94 +1,94 @@
 | 
			
		||||
%   [m,T]=Ret_periodNPT(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE MEAN 
 | 
			
		||||
%   RETURN PERIOD VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
% 
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodNPT(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
if Mu>Mmax; Mu=Mmax;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
n=length(m);
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
for i=1:n
 | 
			
		||||
    CDF_NPT=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h))/mian;
 | 
			
		||||
    T(i)=1/lamb./(1-CDF_NPT);
 | 
			
		||||
end
 | 
			
		||||
T=T';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%   [m,T]=Ret_periodNPT(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE MEAN 
 | 
			
		||||
%   RETURN PERIOD VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
% 
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodNPT(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
if Mu>Mmax; Mu=Mmax;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
n=length(m);
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
for i=1:n
 | 
			
		||||
    CDF_NPT=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h))/mian;
 | 
			
		||||
    T(i)=1/lamb./(1-CDF_NPT);
 | 
			
		||||
end
 | 
			
		||||
T=T';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,91 +1,91 @@
 | 
			
		||||
%   [m,T]=Ret_periodNPU(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES 
 | 
			
		||||
%   THE MEAN RETURN PERIOD VALUES FOR THE UNBOUNDED 
 | 
			
		||||
%   NONPARAMETRIC DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The mean return period of magnitude M is the average 
 | 
			
		||||
%   elapsed time between the consecutive earthquakes of magnitude M.   
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodNPU(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
n=length(m);
 | 
			
		||||
 | 
			
		||||
for i=1:n
 | 
			
		||||
    CDF_NPU=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
    T(i)=1/lamb./(1-CDF_NPU);
 | 
			
		||||
end
 | 
			
		||||
T=T';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [m,T]=Ret_periodNPU(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES 
 | 
			
		||||
%   THE MEAN RETURN PERIOD VALUES FOR THE UNBOUNDED 
 | 
			
		||||
%   NONPARAMETRIC DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The mean return period of magnitude M is the average 
 | 
			
		||||
%   elapsed time between the consecutive earthquakes of magnitude M.   
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodNPU(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
n=length(m);
 | 
			
		||||
 | 
			
		||||
for i=1:n
 | 
			
		||||
    CDF_NPU=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
    T(i)=1/lamb./(1-CDF_NPU);
 | 
			
		||||
end
 | 
			
		||||
T=T';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,250 +1,250 @@
 | 
			
		||||
%
 | 
			
		||||
%   [lamb_all,lamb,lmab_err,unit,eps,b,Mmax,err]=TruncGR(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% ESTIMATES THE MEAN ACTIVITY RATE WITHIN THE WHOLE SAMPLE AND WITHIN THE 
 | 
			
		||||
% COMPLETE PART OF THE SAMPLE, THE ROUND-OFF ERROR OF MAGNITUDE, 
 | 
			
		||||
% THE GUTENBERG-RICHTER B-VALUE AND THE UPPER BOUND OF MAGNITUDE
 | 
			
		||||
% DISTRIBUTION USING THE UPPER-BOUNDED G-R LED MAGNITUDE DISTRIBUTION MODEL
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       GUTENBERG-RICHETR HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution and consequently the G-R
 | 
			
		||||
% b-value is estimated by maximum likelihood method (Aki-Utsu procedure).   
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred. Upon the value of the input 
 | 
			
		||||
% parameter, iop, the used unit of time can be either day ot month or year.    
 | 
			
		||||
% The round-off interval length - eps is the least non-zero difference 
 | 
			
		||||
% between sample data or 0.1 if the least difference is greater than 0.1.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of magnitudes from a user selected catalog
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - catalog completeness level. Must be determined externally.
 | 
			
		||||
%   Can take any value from [min(M), max(M)].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 15 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,b,Mmax,err]=TruncGR(t,M,iop,Mmin)
 | 
			
		||||
n=length(M);
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
    
 | 
			
		||||
if iop==0
 | 
			
		||||
    lamb_all=n/round(t(n)-t(1));
 | 
			
		||||
    lamb=nn/round(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
lamb_all=30*n/(t(n)-t(1));      % K20OCT2014
 | 
			
		||||
lamb=30*nn/(t2-t1);               % K20OCT2014
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
lamb_all=365*n/(t(n)-t(1));       % K20OCT2014
 | 
			
		||||
lamb=365*nn/(t2-t1);                % K20OCT2014
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if nn<15
 | 
			
		||||
    eps=0;b=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
xx=M(M>=Mmin); %K21OCT2014
 | 
			
		||||
% x=sort(M,'descend'); 
 | 
			
		||||
% for i=1:n
 | 
			
		||||
%     if x(i)<Mmin; break; end
 | 
			
		||||
%     xx(i)=x(i);                                                       %
 | 
			
		||||
% end
 | 
			
		||||
 | 
			
		||||
clear x;
 | 
			
		||||
nn=length(xx);
 | 
			
		||||
    
 | 
			
		||||
Max_obs=max(xx);
 | 
			
		||||
beta0=0;
 | 
			
		||||
Mmax1=Max_obs;
 | 
			
		||||
for i=1:50,
 | 
			
		||||
    beta=fzero(@bet_est,[0.05,4.0],[],mean(xx),Mmin-eps/2,Mmax1);
 | 
			
		||||
  	Mmax=Max_obs+moja_calka('f_podc',Mmin,Max_obs,1e-5,nn,beta,Mmin-eps/2,Mmax1);
 | 
			
		||||
    if ((abs(Mmax-Mmax1)<0.01)&&(abs(beta-beta0)<0.0001))
 | 
			
		||||
        err=0;
 | 
			
		||||
        break;
 | 
			
		||||
    end
 | 
			
		||||
    Mmax1=Mmax;
 | 
			
		||||
    beta0=beta;
 | 
			
		||||
end
 | 
			
		||||
if i==50; 
 | 
			
		||||
    err=1.0;
 | 
			
		||||
    Mmax=2*xx(1)-xx(2);
 | 
			
		||||
    beta=fzero(@bet_est,1.0,[],mean(xx),Mmin-eps/2,Mmax);
 | 
			
		||||
end
 | 
			
		||||
b=beta/log(10);
 | 
			
		||||
clear xx
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [zero]=bet_est(b,ms,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%First derivative of the log likelihood function of the upper-bounded 
 | 
			
		||||
% exponential distribution (truncated GR model)
 | 
			
		||||
% b - parameter of the distribution 'beta'
 | 
			
		||||
% ms - mean of the observed magnitudes
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
M_max_min=Mmax-Mmin;
 | 
			
		||||
e_m=exp(-b*M_max_min);
 | 
			
		||||
zero=1/b-ms+Mmin-M_max_min*e_m/(1-e_m);
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=f_podc(z,n,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
% Integrated function for Mmax estimation. Truncated GR model
 | 
			
		||||
% z - column vector of independent variable
 | 
			
		||||
% n - the size of 'z'
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% Mmin - the catalog completeness level
 | 
			
		||||
% Mmax - the upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
y=Cdfgr(z,beta,Mmin,Mmax).^n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
%
 | 
			
		||||
%   [lamb_all,lamb,lmab_err,unit,eps,b,Mmax,err]=TruncGR(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% ESTIMATES THE MEAN ACTIVITY RATE WITHIN THE WHOLE SAMPLE AND WITHIN THE 
 | 
			
		||||
% COMPLETE PART OF THE SAMPLE, THE ROUND-OFF ERROR OF MAGNITUDE, 
 | 
			
		||||
% THE GUTENBERG-RICHTER B-VALUE AND THE UPPER BOUND OF MAGNITUDE
 | 
			
		||||
% DISTRIBUTION USING THE UPPER-BOUNDED G-R LED MAGNITUDE DISTRIBUTION MODEL
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       GUTENBERG-RICHETR HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution and consequently the G-R
 | 
			
		||||
% b-value is estimated by maximum likelihood method (Aki-Utsu procedure).   
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred. Upon the value of the input 
 | 
			
		||||
% parameter, iop, the used unit of time can be either day ot month or year.    
 | 
			
		||||
% The round-off interval length - eps is the least non-zero difference 
 | 
			
		||||
% between sample data or 0.1 if the least difference is greater than 0.1.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of magnitudes from a user selected catalog
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - catalog completeness level. Must be determined externally.
 | 
			
		||||
%   Can take any value from [min(M), max(M)].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 15 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,b,Mmax,err]=TruncGR(t,M,iop,Mmin)
 | 
			
		||||
n=length(M);
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
    
 | 
			
		||||
if iop==0
 | 
			
		||||
    lamb_all=n/round(t(n)-t(1));
 | 
			
		||||
    lamb=nn/round(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
lamb_all=30*n/(t(n)-t(1));      % K20OCT2014
 | 
			
		||||
lamb=30*nn/(t2-t1);               % K20OCT2014
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
lamb_all=365*n/(t(n)-t(1));       % K20OCT2014
 | 
			
		||||
lamb=365*nn/(t2-t1);                % K20OCT2014
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if nn<15
 | 
			
		||||
    eps=0;b=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
xx=M(M>=Mmin); %K21OCT2014
 | 
			
		||||
% x=sort(M,'descend'); 
 | 
			
		||||
% for i=1:n
 | 
			
		||||
%     if x(i)<Mmin; break; end
 | 
			
		||||
%     xx(i)=x(i);                                                       %
 | 
			
		||||
% end
 | 
			
		||||
 | 
			
		||||
clear x;
 | 
			
		||||
nn=length(xx);
 | 
			
		||||
    
 | 
			
		||||
Max_obs=max(xx);
 | 
			
		||||
beta0=0;
 | 
			
		||||
Mmax1=Max_obs;
 | 
			
		||||
for i=1:50,
 | 
			
		||||
    beta=fzero(@bet_est,[0.05,4.0],[],mean(xx),Mmin-eps/2,Mmax1);
 | 
			
		||||
  	Mmax=Max_obs+moja_calka('f_podc',Mmin,Max_obs,1e-5,nn,beta,Mmin-eps/2,Mmax1);
 | 
			
		||||
    if ((abs(Mmax-Mmax1)<0.01)&&(abs(beta-beta0)<0.0001))
 | 
			
		||||
        err=0;
 | 
			
		||||
        break;
 | 
			
		||||
    end
 | 
			
		||||
    Mmax1=Mmax;
 | 
			
		||||
    beta0=beta;
 | 
			
		||||
end
 | 
			
		||||
if i==50; 
 | 
			
		||||
    err=1.0;
 | 
			
		||||
    Mmax=2*xx(1)-xx(2);
 | 
			
		||||
    beta=fzero(@bet_est,1.0,[],mean(xx),Mmin-eps/2,Mmax);
 | 
			
		||||
end
 | 
			
		||||
b=beta/log(10);
 | 
			
		||||
clear xx
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [zero]=bet_est(b,ms,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%First derivative of the log likelihood function of the upper-bounded 
 | 
			
		||||
% exponential distribution (truncated GR model)
 | 
			
		||||
% b - parameter of the distribution 'beta'
 | 
			
		||||
% ms - mean of the observed magnitudes
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
M_max_min=Mmax-Mmin;
 | 
			
		||||
e_m=exp(-b*M_max_min);
 | 
			
		||||
zero=1/b-ms+Mmin-M_max_min*e_m/(1-e_m);
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=f_podc(z,n,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
% Integrated function for Mmax estimation. Truncated GR model
 | 
			
		||||
% z - column vector of independent variable
 | 
			
		||||
% n - the size of 'z'
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% Mmin - the catalog completeness level
 | 
			
		||||
% Mmax - the upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
y=Cdfgr(z,beta,Mmin,Mmax).^n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -1,305 +1,387 @@
 | 
			
		||||
%
 | 
			
		||||
%   [lamb_all,lamb,lmab_err,unit,eps,b,Mmax,err]=TruncGR(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% ESTIMATES THE MEAN ACTIVITY RATE WITHIN THE WHOLE SAMPLE AND WITHIN THE 
 | 
			
		||||
% COMPLETE PART OF THE SAMPLE, THE ROUND-OFF ERROR OF MAGNITUDE, 
 | 
			
		||||
% THE GUTENBERG-RICHTER B-VALUE AND THE UPPER BOUND OF MAGNITUDE
 | 
			
		||||
% DISTRIBUTION USING THE UPPER-BOUNDED G-R LED MAGNITUDE DISTRIBUTION MODEL
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       GUTENBERG-RICHETR HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2 01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution and consequently the G-R
 | 
			
		||||
% b-value is estimated by maximum likelihood method (Aki-Utsu procedure).   
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred. Upon the value of the input 
 | 
			
		||||
% parameter, iop, the used unit of time can be either day ot month or year.    
 | 
			
		||||
% The round-off interval length - eps is the least non-zero difference 
 | 
			
		||||
% between sample data or 0.1 if the least difference is greater than 0.1.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of magnitudes from a user selected catalog
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - catalog completeness level. Must be determined externally.
 | 
			
		||||
%   Can take any value from [min(M), max(M)].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 15 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,b,Mmax,err]=TruncGR_O(t,M,iop,Mmin,Mmax)
 | 
			
		||||
if isempty(t) || numel(t)<3 || isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
n=length(M);
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
 | 
			
		||||
if nn<15
 | 
			
		||||
    eps=0;b=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
xx=M(M>=Mmin); %K21OCT2014
 | 
			
		||||
% x=sort(M,'descend');
 | 
			
		||||
% for i=1:n
 | 
			
		||||
%      if x(i)<Mmin; break; end
 | 
			
		||||
%      xx(i)=x(i);                                                      %
 | 
			
		||||
% end
 | 
			
		||||
 | 
			
		||||
clear x;
 | 
			
		||||
nn=length(xx);
 | 
			
		||||
    
 | 
			
		||||
Max_obs=max(xx);
 | 
			
		||||
beta0=0;
 | 
			
		||||
Mmax1=Max_obs; 
 | 
			
		||||
            if isempty(Mmax)==0                            %%%   K 28JUL2015
 | 
			
		||||
                	fun = @(b) bet_est(b,mean(xx),Mmin-eps/2,Mmax);    %%%   K 28JUL2015
 | 
			
		||||
                	x0 = 1;              %[0.05,4.0];           %%%   K 28JUL2015 - See exception line 153
 | 
			
		||||
                    beta = fzero(fun,x0);                     %%%   K 28JUL2015
 | 
			
		||||
                    err=0;                                             %%%   K 28JUL2015
 | 
			
		||||
            else                                                         %%%   K 28JUL2015  -  line 148
 | 
			
		||||
for i=1:50,                                                           
 | 
			
		||||
	fun = @(b) bet_est(b,mean(xx),Mmin-eps/2,Mmax1);
 | 
			
		||||
	x0 =1;           %[0.05,4.0];                               %%%   K29JUL2015 - See exception line 153
 | 
			
		||||
    beta = fzero(fun,x0);
 | 
			
		||||
  	Mmax=Max_obs+moja_calka('f_podc',Mmin,Max_obs,1e-5,nn,beta,Mmin-eps/2,Mmax1);
 | 
			
		||||
    if ((abs(Mmax-Mmax1)<0.01)&&(abs(beta-beta0)<0.0001))
 | 
			
		||||
        err=0;
 | 
			
		||||
        break;
 | 
			
		||||
    end
 | 
			
		||||
    Mmax1=Mmax;
 | 
			
		||||
    beta0=beta;
 | 
			
		||||
end
 | 
			
		||||
if i==50; 
 | 
			
		||||
    err=1.0;
 | 
			
		||||
    Mmax=2*xx(1)-xx(2);
 | 
			
		||||
fun = @(b) bet_est(b,mean(xx),Mmin-eps/2,Mmax);
 | 
			
		||||
	x0 =1;
 | 
			
		||||
    beta = fzero(fun,x0);
 | 
			
		||||
end
 | 
			
		||||
            end                                                         %%%   K 28JUL2015
 | 
			
		||||
b=beta/log(10);
 | 
			
		||||
clear xx
 | 
			
		||||
 | 
			
		||||
% Exception for v-value
 | 
			
		||||
if b<0.05 || b>6.0; error('Unacceptable b-value, abort and select different dataset');end
 | 
			
		||||
beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)               % SL 03MAR2015 
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [zero]=bet_est(b,ms,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%First derivative of the log likelihood function of the upper-bounded 
 | 
			
		||||
% exponential distribution (truncated GR model)
 | 
			
		||||
% b - parameter of the distribution 'beta'
 | 
			
		||||
% ms - mean of the observed magnitudes
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
M_max_min=Mmax-Mmin;
 | 
			
		||||
e_m=exp(-b*M_max_min);
 | 
			
		||||
zero=1/b-ms+Mmin-M_max_min*e_m/(1-e_m);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=f_podc(z,n,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
% Integrated function for Mmax estimation. Truncated GR model
 | 
			
		||||
% z - column vector of independent variable
 | 
			
		||||
% n - the size of 'z'
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% Mmin - the catalog completeness level
 | 
			
		||||
% Mmax - the upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
y=Cdfgr(z,beta,Mmin,Mmax).^n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
%
 | 
			
		||||
%[lamb_all,lamb,lamb_err,unit,eps,b,Mmax,err,BIAS,SD]=TruncGR_Ob(t,M,iop,Mmin,Mmax,Nsynth)
 | 
			
		||||
%
 | 
			
		||||
% ESTIMATES THE MEAN ACTIVITY RATE WITHIN THE WHOLE SAMPLE AND WITHIN THE 
 | 
			
		||||
% COMPLETE PART OF THE SAMPLE, THE ROUND-OFF ERROR OF MAGNITUDE, 
 | 
			
		||||
% THE GUTENBERG-RICHTER B-VALUE AND THE UPPER BOUND OF MAGNITUDE
 | 
			
		||||
% DISTRIBUTION USING THE UPPER-BOUNDED G-R LED MAGNITUDE DISTRIBUTION MODEL
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       GUTENBERG-RICHETR HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2 01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution and consequently the G-R
 | 
			
		||||
% b-value is estimated by maximum likelihood method (Aki-Utsu procedure).   
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred. Upon the value of the input 
 | 
			
		||||
% parameter, iop, the used unit of time can be either day ot month or year.    
 | 
			
		||||
% The round-off interval length - eps is the least non-zero difference 
 | 
			
		||||
% between sample data or 0.1 if the least difference is greater than 0.1.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of magnitudes from a user selected catalog
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - catalog completeness level. Must be determined externally.
 | 
			
		||||
%   Can take any value from [min(M), max(M)].
 | 
			
		||||
%   Mmax - upper limit of Magnitude Distribution. Can be set by user, or
 | 
			
		||||
%   estimate within the program - it then should be set as Mmax=[].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 15 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%   BIAS - Mmax estimation Bias (Lasocki and Urban, 2011)
 | 
			
		||||
%   SD   - Mmax standard deviation (Lasocki ands Urban, 2011)
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,b,Mmax,err,BIAS,SD]=TruncGR_Ob(t,M,iop,Mmin,Mmax,Nsynth)
 | 
			
		||||
if nargin==5;Nsynth=[];end                                   % K08DEC2019
 | 
			
		||||
if isempty(t) || numel(t)<3 || isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
n=length(M);
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
 | 
			
		||||
if nn<15
 | 
			
		||||
    eps=0;b=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    BIAS=NaN;SD=NaN;                                               %%%     K 08NOV2019  
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
xx=M(M>=Mmin); %K21OCT2014
 | 
			
		||||
% x=sort(M,'descend');
 | 
			
		||||
% for i=1:n
 | 
			
		||||
%      if x(i)<Mmin; break; end
 | 
			
		||||
%      xx(i)=x(i);                                                      %
 | 
			
		||||
% end
 | 
			
		||||
 | 
			
		||||
clear x;
 | 
			
		||||
nn=length(xx);
 | 
			
		||||
    
 | 
			
		||||
Max_obs=max(xx);
 | 
			
		||||
beta0=0;
 | 
			
		||||
Mmax1=Max_obs; 
 | 
			
		||||
            if isempty(Mmax)==0                                      %%%   K 28JUL2015
 | 
			
		||||
                	err_Mmax=0;                                      %%%   K 04DEC2019 
 | 
			
		||||
                    fun = @(b) bet_est(b,mean(xx),Mmin-eps/2,Mmax);  %%%   K 28JUL2015
 | 
			
		||||
                	x0 = 1;              %[0.05,4.0];                %%%   K 28JUL2015 - See exception line 155
 | 
			
		||||
                    beta = fzero(fun,x0);                            %%%   K 28JUL2015
 | 
			
		||||
                    err=0;                                           %%%   K 28JUL2015
 | 
			
		||||
            else                                                     %%%   K 28JUL2015  -  line 150
 | 
			
		||||
                    err_Mmax=1;                                      %%%   K 04DEC2019 
 | 
			
		||||
for i=1:50,                                                           
 | 
			
		||||
	fun = @(b) bet_est(b,mean(xx),Mmin-eps/2,Mmax1);
 | 
			
		||||
	x0 =1;           %[0.05,4.0];                               %%%   K29JUL2015 - See exception line 155
 | 
			
		||||
    beta = fzero(fun,x0);
 | 
			
		||||
  	Mmax=Max_obs+moja_calka('f_podc',Mmin,Max_obs,1e-5,nn,beta,Mmin-eps/2,Mmax1);
 | 
			
		||||
    if ((abs(Mmax-Mmax1)<0.01)&&(abs(beta-beta0)<0.0001))
 | 
			
		||||
        err=0;
 | 
			
		||||
        break;
 | 
			
		||||
    end
 | 
			
		||||
    Mmax1=Mmax;
 | 
			
		||||
    beta0=beta;
 | 
			
		||||
end
 | 
			
		||||
if i==50; 
 | 
			
		||||
    err=1.0;
 | 
			
		||||
    Mmax=2*xx(1)-xx(2);
 | 
			
		||||
fun = @(b) bet_est(b,mean(xx),Mmin-eps/2,Mmax);
 | 
			
		||||
	x0 =1;
 | 
			
		||||
    beta = fzero(fun,x0);
 | 
			
		||||
end
 | 
			
		||||
            end                                                         %%%   K 28JUL2015
 | 
			
		||||
b=beta/log(10);
 | 
			
		||||
clear xx
 | 
			
		||||
 | 
			
		||||
% Exception for v-value
 | 
			
		||||
if b<0.05 || b>6.0; error('Unacceptable b-value, abort and select different dataset');end
 | 
			
		||||
beta;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
% Estimation of Mmax Bias                                               %%%   K 04DEC2019 
 | 
			
		||||
% (Lasocki and Urban, 2011, doi:10.2478/s11600-010-0049-y)
 | 
			
		||||
if isempty(Nsynth)==0 && err_Mmax==1              % set number of synthetic datasets, e.g. 10000
 | 
			
		||||
[BIAS,SD]=Mmax_Bias_GR(t,M,Mmin,Mmax,b,err,Nsynth);
 | 
			
		||||
elseif isempty(Nsynth)==0 && err_Mmax==0;              
 | 
			
		||||
warning('Mmax must be empty for BIAS calculation');BIAS=[];SD=[];
 | 
			
		||||
else; BIAS=0;SD=0;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)               % SL 03MAR2015 
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [zero]=bet_est(b,ms,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%First derivative of the log likelihood function of the upper-bounded 
 | 
			
		||||
% exponential distribution (truncated GR model)
 | 
			
		||||
% b - parameter of the distribution 'beta'
 | 
			
		||||
% ms - mean of the observed magnitudes
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
M_max_min=Mmax-Mmin;
 | 
			
		||||
e_m=exp(-b*M_max_min);
 | 
			
		||||
zero=1/b-ms+Mmin-M_max_min*e_m/(1-e_m);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=f_podc(z,n,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
% Integrated function for Mmax estimation. Truncated GR model
 | 
			
		||||
% z - column vector of independent variable
 | 
			
		||||
% n - the size of 'z'
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% Mmin - the catalog completeness level
 | 
			
		||||
% Mmax - the upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
y=Cdfgr(z,beta,Mmin,Mmax).^n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
% --------------------- Mmax BIAS estimation routine ----------------------  K 08NOV2019
 | 
			
		||||
 | 
			
		||||
function [BIAS,SD]=Mmax_Bias_GR(t,m,Mc,Mmax1,b,err,synth)
 | 
			
		||||
 | 
			
		||||
if err~=0
 | 
			
		||||
warning('process did not converge!!'),pause   
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
MAXm=max(m);beta=b*log(10);N=numel(m(m>=Mc));DeltaM=MAXm-Mc;
 | 
			
		||||
 | 
			
		||||
for j=1:synth         %set number of synthetic datasets, default is 10000 
 | 
			
		||||
% % CDF:
 | 
			
		||||
 M=Mc:0.0001:MAXm;upt=1-exp(-beta*(M-Mc));
 | 
			
		||||
 dwt=1-exp(-beta*(MAXm-Mc));F=upt./dwt;                                             % j
 | 
			
		||||
% linear interpolation to assign magnitude values from a uniform distribution sample
 | 
			
		||||
 iM=rand(1,N);M1=interp1q(F',M',iM');
 | 
			
		||||
 br(j)=1/(log(10)*(mean(M1)-min(M1)));DM=range(M1);
 | 
			
		||||
 Mmax=max(M1);
 | 
			
		||||
 | 
			
		||||
 % Iteration Process to estimate b and Mmax
 | 
			
		||||
b1=1;best=[1.0 10.0];i=1; 
 | 
			
		||||
while min(abs(diff(best)))>0.00001
 | 
			
		||||
w=exp(b1*(Mmax-Mc));E1=expint(N/(w-1));E2=expint(N*w/(w-1));
 | 
			
		||||
%E=expint(w);
 | 
			
		||||
Mme=Mmax+(E1-E2)/(b1*exp(-N/(w-1)))+(Mc)*exp(-N);    %Mme=round(Mme/EPS)*EPS;            
 | 
			
		||||
 | 
			
		||||
if isnan(Mme)
 | 
			
		||||
KM=sort(unique(M1),'descend');
 | 
			
		||||
Mme=2*KM(1)-KM(2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
fun=@(bb) 1/bb+(Mme-Mc)/(1-exp(bb*(Mme-Mc)))-mean(M1)+Mc;  %consider th5 last 0.05 term
 | 
			
		||||
b1=fzero(fun,1);best(i)=b1;i=i+1;
 | 
			
		||||
 | 
			
		||||
if i==50
 | 
			
		||||
   warning('process did not converge!!');break 
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
be(j)=b1/log(10);
 | 
			
		||||
Me(j)=Mme;dm(j)=DM;Mm(j)=Mmax;
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
BIAS=mean(MAXm-Me)
 | 
			
		||||
SD=std(MAXm-Me);
 | 
			
		||||
 | 
			
		||||
%b-mean(be)    %check b-value difference
 | 
			
		||||
%histogram(be)
 | 
			
		||||
 | 
			
		||||
% MAXm: maximum magnitude in the real catalog 
 | 
			
		||||
% Mmax: maximum magnitudes observed in the synthetic catalogs (rounded)
 | 
			
		||||
% Me: maximum magnitude estimates for the synthetic catalogs 
 | 
			
		||||
% Mmax1: maximum magnitude estimated by GRT
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,162 +1,162 @@
 | 
			
		||||
%   [lamb_all,lamb,lmab_err,unit,eps,b]=UnlimitGR(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% ESTIMATES THE MEAN ACTIVITY RATE WITHIN THE WHOLE SAMPLE AND WITHIN THE 
 | 
			
		||||
% COMPLETE PART OF THE SAMPLE, THE ROUND-OFF ERROR OF MAGNITUDE AND THE 
 | 
			
		||||
% GUTENBERG-RICHTER B-VALUE USING THE UNLIMITED G-R LED MAGNITUDE 
 | 
			
		||||
% DISTRIBUTION MODEL 
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UNBOUNDED 
 | 
			
		||||
%       GUTENBERG-RICHETR HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2 01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value is estimated by 
 | 
			
		||||
% maximum likelihood method (Aki-Utsu procedure).  
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred. Upon the value of the input 
 | 
			
		||||
% parameter, iop, the used unit of time can be either day ot month or year.    
 | 
			
		||||
% The round-off interval length - eps if the least non-zero difference 
 | 
			
		||||
% between sample data or 0.1 is the least difference is greater than 0.1. 
 | 
			
		||||
% 
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of magnitudes from a user selected catalog
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - catalog completeness level. Must be determined externally.
 | 
			
		||||
%   can take any value from [min(M), max(M)].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 7 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
%     You should have received a copy of the GNU General Public License
 | 
			
		||||
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
%
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,b]=UnlimitGR(t,M,iop,Mmin)
 | 
			
		||||
if isempty(t) || numel(t)<3 || isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
 | 
			
		||||
if nn<7
 | 
			
		||||
    eps=0;b=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
xx=M(M>=Mmin); %K21OCT2014
 | 
			
		||||
% x=sort(M,'descend');
 | 
			
		||||
% for i=1:n
 | 
			
		||||
%      if x(i)<Mmin; break; end
 | 
			
		||||
%      xx(i)=x(i);                                                      %
 | 
			
		||||
% end
 | 
			
		||||
clear x;
 | 
			
		||||
beta=1/(mean(xx)-Mmin+eps/2);
 | 
			
		||||
b=beta/log(10);
 | 
			
		||||
clear xx
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)              % SL 03MAR2015
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
%   [lamb_all,lamb,lmab_err,unit,eps,b]=UnlimitGR(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% ESTIMATES THE MEAN ACTIVITY RATE WITHIN THE WHOLE SAMPLE AND WITHIN THE 
 | 
			
		||||
% COMPLETE PART OF THE SAMPLE, THE ROUND-OFF ERROR OF MAGNITUDE AND THE 
 | 
			
		||||
% GUTENBERG-RICHTER B-VALUE USING THE UNLIMITED G-R LED MAGNITUDE 
 | 
			
		||||
% DISTRIBUTION MODEL 
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UNBOUNDED 
 | 
			
		||||
%       GUTENBERG-RICHETR HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2 01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value is estimated by 
 | 
			
		||||
% maximum likelihood method (Aki-Utsu procedure).  
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred. Upon the value of the input 
 | 
			
		||||
% parameter, iop, the used unit of time can be either day ot month or year.    
 | 
			
		||||
% The round-off interval length - eps if the least non-zero difference 
 | 
			
		||||
% between sample data or 0.1 is the least difference is greater than 0.1. 
 | 
			
		||||
% 
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of magnitudes from a user selected catalog
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - catalog completeness level. Must be determined externally.
 | 
			
		||||
%   can take any value from [min(M), max(M)].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 7 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
%     You should have received a copy of the GNU General Public License
 | 
			
		||||
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
%
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,b]=UnlimitGR(t,M,iop,Mmin)
 | 
			
		||||
if isempty(t) || numel(t)<3 || isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
 | 
			
		||||
if nn<7
 | 
			
		||||
    eps=0;b=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
xx=M(M>=Mmin); %K21OCT2014
 | 
			
		||||
% x=sort(M,'descend');
 | 
			
		||||
% for i=1:n
 | 
			
		||||
%      if x(i)<Mmin; break; end
 | 
			
		||||
%      xx(i)=x(i);                                                      %
 | 
			
		||||
% end
 | 
			
		||||
clear x;
 | 
			
		||||
beta=1/(mean(xx)-Mmin+eps/2);
 | 
			
		||||
b=beta/log(10);
 | 
			
		||||
clear xx
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)              % SL 03MAR2015
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -1,64 +1,64 @@
 | 
			
		||||
%   [m, PDF_GRT, CDF_GRT]=dist_GRT(Md,Mu,dM,Mmin,eps,b,Mmax)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE DENSITY AND CUMULATIVE DISTRIBUTION FUNCTIONS OF MAGNITUDE
 | 
			
		||||
%   UNDER THE UPPER-BOUNDED G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distribution Mmax are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% upper-bounded Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The distribution function values are calculated for magnitude starting 
 | 
			
		||||
% from Md up to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of the independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   PDF_GRT - PDF vector of the same length as m
 | 
			
		||||
%   CDF_GRT - CDF vector of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [m, PDF_GRT, CDF_GRT]=dist_GRT(Md,Mu,dM,Mmin,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin+eps/2))); 
 | 
			
		||||
PDF_GRT=beta*exp(-beta*(m-Mmin+eps/2))/mian;
 | 
			
		||||
CDF_GRT=(1-exp(-beta*(m-Mmin+eps/2)))/mian;
 | 
			
		||||
idx=find(CDF_GRT<0);
 | 
			
		||||
PDF_GRT(idx)=zeros(size(idx));CDF_GRT(idx)=zeros(size(idx));
 | 
			
		||||
idx=find(CDF_GRT>1);
 | 
			
		||||
PDF_GRT(idx)=zeros(size(idx));CDF_GRT(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [m, PDF_GRT, CDF_GRT]=dist_GRT(Md,Mu,dM,Mmin,eps,b,Mmax)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE DENSITY AND CUMULATIVE DISTRIBUTION FUNCTIONS OF MAGNITUDE
 | 
			
		||||
%   UNDER THE UPPER-BOUNDED G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distribution Mmax are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% upper-bounded Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The distribution function values are calculated for magnitude starting 
 | 
			
		||||
% from Md up to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of the independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   PDF_GRT - PDF vector of the same length as m
 | 
			
		||||
%   CDF_GRT - CDF vector of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [m, PDF_GRT, CDF_GRT]=dist_GRT(Md,Mu,dM,Mmin,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin+eps/2))); 
 | 
			
		||||
PDF_GRT=beta*exp(-beta*(m-Mmin+eps/2))/mian;
 | 
			
		||||
CDF_GRT=(1-exp(-beta*(m-Mmin+eps/2)))/mian;
 | 
			
		||||
idx=find(CDF_GRT<0);
 | 
			
		||||
PDF_GRT(idx)=zeros(size(idx));CDF_GRT(idx)=zeros(size(idx));
 | 
			
		||||
idx=find(CDF_GRT>1);
 | 
			
		||||
PDF_GRT(idx)=zeros(size(idx));CDF_GRT(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,61 +1,61 @@
 | 
			
		||||
%   [m, PDF_GRU, CDF_GRU]=dist_GRU(Md,Mu,dM,Mmin,eps,b)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE DENSITY AND CUMULATIVE DISTRIBUTION FUNCTIONS OF MAGNITUDE 
 | 
			
		||||
%   UNDER THE UNLIMITED G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The distribution function values are calculated for magnitude starting 
 | 
			
		||||
% from Md up to Mu with step dM.
 | 
			
		||||
% 
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of the independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   PDF_GRT - PDF vector of the same length as m
 | 
			
		||||
%   CDF_GRT - CDF vector of the same length as m
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m, PDF_GRU, CDF_GRU]=dist_GRU(Md,Mu,dM,Mmin,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
PDF_GRU=beta*exp(-beta*(m-Mmin+eps/2));
 | 
			
		||||
CDF_GRU=1-exp(-beta*(m-Mmin+eps/2));
 | 
			
		||||
idx=find(CDF_GRU<0);
 | 
			
		||||
PDF_GRU(idx)=zeros(size(idx));CDF_GRU(idx)=zeros(size(idx));
 | 
			
		||||
idx=find(CDF_GRU>1);
 | 
			
		||||
PDF_GRU(idx)=zeros(size(idx));CDF_GRU(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [m, PDF_GRU, CDF_GRU]=dist_GRU(Md,Mu,dM,Mmin,eps,b)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE DENSITY AND CUMULATIVE DISTRIBUTION FUNCTIONS OF MAGNITUDE 
 | 
			
		||||
%   UNDER THE UNLIMITED G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The distribution function values are calculated for magnitude starting 
 | 
			
		||||
% from Md up to Mu with step dM.
 | 
			
		||||
% 
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of the independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   PDF_GRT - PDF vector of the same length as m
 | 
			
		||||
%   CDF_GRT - CDF vector of the same length as m
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m, PDF_GRU, CDF_GRU]=dist_GRU(Md,Mu,dM,Mmin,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
PDF_GRU=beta*exp(-beta*(m-Mmin+eps/2));
 | 
			
		||||
CDF_GRU=1-exp(-beta*(m-Mmin+eps/2));
 | 
			
		||||
idx=find(CDF_GRU<0);
 | 
			
		||||
PDF_GRU(idx)=zeros(size(idx));CDF_GRU(idx)=zeros(size(idx));
 | 
			
		||||
idx=find(CDF_GRU>1);
 | 
			
		||||
PDF_GRU(idx)=zeros(size(idx));CDF_GRU(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,116 +1,116 @@
 | 
			
		||||
%   [m,PDF_NPT,CDF_NPT]=dist_NPT(Md,Mu,dM,Mmin,eps,h,xx,ambd,Mmax)
 | 
			
		||||
%
 | 
			
		||||
% USING THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS EVALUATES THE DENSITY 
 | 
			
		||||
%   AND CUMULATIVE DISTRIBUTION FUNCTIONS FOR THE UPPER-BOUNDED MAGNITUDE 
 | 
			
		||||
%   DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   m - vector of the independent variable (magnitude)
 | 
			
		||||
%   PDF_NPT - PDF vector
 | 
			
		||||
%   CDF_NPT - CDF vector
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,PDF_NPT,CDF_NPT]=dist_NPT(Md,Mu,dM,Mmin,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
nn=length(m);
 | 
			
		||||
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
for i=1:nn
 | 
			
		||||
    if m(i)<Mmin-eps/2
 | 
			
		||||
        PDF_NPT(i)=0;CDF_NPT(i)=0;
 | 
			
		||||
    elseif m(i)>Mmax
 | 
			
		||||
        PDF_NPT(i)=0;CDF_NPT(i)=1;
 | 
			
		||||
    else
 | 
			
		||||
    PDF_NPT(i)=dens_npr1(m(i),xx,ambd,h,Mmin-eps/2)/mian;
 | 
			
		||||
    CDF_NPT(i)=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h))/mian;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
PDF_NPT=PDF_NPT';CDF_NPT=CDF_NPT';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [gau]=dens_npr1(y,x,ambd,h,x1)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive density for a variable from the interval [x1,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data doubled and sorted in the ascending order. Use 
 | 
			
		||||
%   "podwajanie.m" first to accmoplish that.
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
if y<x1
 | 
			
		||||
    gau=0;
 | 
			
		||||
else
 | 
			
		||||
    gau=2*sum(exp(-0.5*(((y-x)./ambd')./h).^2)./ambd')/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [m,PDF_NPT,CDF_NPT]=dist_NPT(Md,Mu,dM,Mmin,eps,h,xx,ambd,Mmax)
 | 
			
		||||
%
 | 
			
		||||
% USING THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS EVALUATES THE DENSITY 
 | 
			
		||||
%   AND CUMULATIVE DISTRIBUTION FUNCTIONS FOR THE UPPER-BOUNDED MAGNITUDE 
 | 
			
		||||
%   DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   m - vector of the independent variable (magnitude)
 | 
			
		||||
%   PDF_NPT - PDF vector
 | 
			
		||||
%   CDF_NPT - CDF vector
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,PDF_NPT,CDF_NPT]=dist_NPT(Md,Mu,dM,Mmin,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
nn=length(m);
 | 
			
		||||
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
for i=1:nn
 | 
			
		||||
    if m(i)<Mmin-eps/2
 | 
			
		||||
        PDF_NPT(i)=0;CDF_NPT(i)=0;
 | 
			
		||||
    elseif m(i)>Mmax
 | 
			
		||||
        PDF_NPT(i)=0;CDF_NPT(i)=1;
 | 
			
		||||
    else
 | 
			
		||||
    PDF_NPT(i)=dens_npr1(m(i),xx,ambd,h,Mmin-eps/2)/mian;
 | 
			
		||||
    CDF_NPT(i)=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h))/mian;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
PDF_NPT=PDF_NPT';CDF_NPT=CDF_NPT';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [gau]=dens_npr1(y,x,ambd,h,x1)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive density for a variable from the interval [x1,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data doubled and sorted in the ascending order. Use 
 | 
			
		||||
%   "podwajanie.m" first to accmoplish that.
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
if y<x1
 | 
			
		||||
    gau=0;
 | 
			
		||||
else
 | 
			
		||||
    gau=2*sum(exp(-0.5*(((y-x)./ambd')./h).^2)./ambd')/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,114 +1,114 @@
 | 
			
		||||
%   [m, PDF_NPU, CDF_NPU]=dist_NPU(Md,Mu,dM,Mmin,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
% USING THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS EVALUATES THE DENSITY 
 | 
			
		||||
%   AND CUMULATIVE DISTRIBUTION FUNCTIONS FOR THE UNLIMITED MAGNITUDE 
 | 
			
		||||
%   DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2 
 | 
			
		||||
% 
 | 
			
		||||
% The distribution function values are calculated for magnitude starting 
 | 
			
		||||
% from Md up to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT
 | 
			
		||||
% m - vector of the independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   PDF_NPU - PDF vector of the same length as m
 | 
			
		||||
%   CDF_NPU - CDF vector of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m, PDF_NPU, CDF_NPU]=dist_NPU(Md,Mu,dM,Mmin,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
nn=length(m);
 | 
			
		||||
 | 
			
		||||
for i=1:nn
 | 
			
		||||
    if m(i)>=Mmin-eps/2
 | 
			
		||||
        PDF_NPU(i)=dens_npr1(m(i),xx,ambd,h,Mmin-eps/2);
 | 
			
		||||
        CDF_NPU(i)=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
    else
 | 
			
		||||
        PDF_NPU(i)=0;
 | 
			
		||||
        CDF_NPU(i)=0;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
PDF_NPU=PDF_NPU';CDF_NPU=CDF_NPU';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [gau]=dens_npr1(y,x,ambd,h,x1)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive density for a variable from the interval [x1,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data doubled and sorted in the ascending order. Use 
 | 
			
		||||
%   "podwajanie.m" first to accmoplish that.
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
if y<x1
 | 
			
		||||
    gau=0;
 | 
			
		||||
else
 | 
			
		||||
    gau=2*sum(exp(-0.5*(((y-x)./ambd')./h).^2)./ambd')/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [m, PDF_NPU, CDF_NPU]=dist_NPU(Md,Mu,dM,Mmin,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
% USING THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS EVALUATES THE DENSITY 
 | 
			
		||||
%   AND CUMULATIVE DISTRIBUTION FUNCTIONS FOR THE UNLIMITED MAGNITUDE 
 | 
			
		||||
%   DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2 
 | 
			
		||||
% 
 | 
			
		||||
% The distribution function values are calculated for magnitude starting 
 | 
			
		||||
% from Md up to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT
 | 
			
		||||
% m - vector of the independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   PDF_NPU - PDF vector of the same length as m
 | 
			
		||||
%   CDF_NPU - CDF vector of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m, PDF_NPU, CDF_NPU]=dist_NPU(Md,Mu,dM,Mmin,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
nn=length(m);
 | 
			
		||||
 | 
			
		||||
for i=1:nn
 | 
			
		||||
    if m(i)>=Mmin-eps/2
 | 
			
		||||
        PDF_NPU(i)=dens_npr1(m(i),xx,ambd,h,Mmin-eps/2);
 | 
			
		||||
        CDF_NPU(i)=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
    else
 | 
			
		||||
        PDF_NPU(i)=0;
 | 
			
		||||
        CDF_NPU(i)=0;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
PDF_NPU=PDF_NPU';CDF_NPU=CDF_NPU';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [gau]=dens_npr1(y,x,ambd,h,x1)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive density for a variable from the interval [x1,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data doubled and sorted in the ascending order. Use 
 | 
			
		||||
%   "podwajanie.m" first to accmoplish that.
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
if y<x1
 | 
			
		||||
    gau=0;
 | 
			
		||||
else
 | 
			
		||||
    gau=2*sum(exp(-0.5*(((y-x)./ambd')./h).^2)./ambd')/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,99 +1,99 @@
 | 
			
		||||
%   [x,z]=ExcProbGRT(opt,xd,xu,dx,y,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
%
 | 
			
		||||
%EVALUATES THE EXCEEDANCE PROBABILITY VALUES USING THE UPPER-BOUNDED G-R 
 | 
			
		||||
%   LED MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distriobution Mmax as well as the
 | 
			
		||||
% activity rate of M>=Mmin events are calculated at start-up of the 
 | 
			
		||||
% stationary hazard assessment services in the upper-bounded 
 | 
			
		||||
% Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The exceedance probability of magnitude M' in the time period of 
 | 
			
		||||
% length T' is the probability of an earthquake of magnitude M' or greater 
 | 
			
		||||
% to occur in T'. Depending on the value of the parameter opt the 
 | 
			
		||||
% exceedance probability values are calculated for a fixed time period T'
 | 
			
		||||
% and different magnitude values or for a fixed magnitude M' and different
 | 
			
		||||
% time period length values. In either case the independent variable vector
 | 
			
		||||
% starts from xd, up to xu with step dx. In either case the result is 
 | 
			
		||||
% returned in the vector z.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   x - vector of changeable independent variable: magnitudes if opt=0, 
 | 
			
		||||
%       time period lengths if opt=1, 
 | 
			
		||||
%       x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values of the same length as x
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=ExcProbGRT(opt,xd,xu,dx,y,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
if opt==0
 | 
			
		||||
    if xd<Mmin; xd=Mmin;end
 | 
			
		||||
    if xu>Mmax; xu=Mmax;end
 | 
			
		||||
end
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
if opt==0
 | 
			
		||||
    z=1-exp(-lamb*y.*(1-Cdfgr(x,beta,Mmin-eps/2,Mmax)));
 | 
			
		||||
else
 | 
			
		||||
    z=1-exp(-lamb*(1-Cdfgr(y,beta,Mmin-eps/2,Mmax)).*x);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [x,z]=ExcProbGRT(opt,xd,xu,dx,y,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
%
 | 
			
		||||
%EVALUATES THE EXCEEDANCE PROBABILITY VALUES USING THE UPPER-BOUNDED G-R 
 | 
			
		||||
%   LED MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distriobution Mmax as well as the
 | 
			
		||||
% activity rate of M>=Mmin events are calculated at start-up of the 
 | 
			
		||||
% stationary hazard assessment services in the upper-bounded 
 | 
			
		||||
% Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The exceedance probability of magnitude M' in the time period of 
 | 
			
		||||
% length T' is the probability of an earthquake of magnitude M' or greater 
 | 
			
		||||
% to occur in T'. Depending on the value of the parameter opt the 
 | 
			
		||||
% exceedance probability values are calculated for a fixed time period T'
 | 
			
		||||
% and different magnitude values or for a fixed magnitude M' and different
 | 
			
		||||
% time period length values. In either case the independent variable vector
 | 
			
		||||
% starts from xd, up to xu with step dx. In either case the result is 
 | 
			
		||||
% returned in the vector z.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   x - vector of changeable independent variable: magnitudes if opt=0, 
 | 
			
		||||
%       time period lengths if opt=1, 
 | 
			
		||||
%       x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values of the same length as x
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=ExcProbGRT(opt,xd,xu,dx,y,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
if opt==0
 | 
			
		||||
    if xd<Mmin; xd=Mmin;end
 | 
			
		||||
    if xu>Mmax; xu=Mmax;end
 | 
			
		||||
end
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
if opt==0
 | 
			
		||||
    z=1-exp(-lamb*y.*(1-Cdfgr(x,beta,Mmin-eps/2,Mmax)));
 | 
			
		||||
else
 | 
			
		||||
    z=1-exp(-lamb*(1-Cdfgr(y,beta,Mmin-eps/2,Mmax)).*x);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,78 +1,78 @@
 | 
			
		||||
%   [x,z]=ExcProbGRU(opt,xd,xu,dx,y,Mmin,lamb,eps,b)
 | 
			
		||||
%
 | 
			
		||||
%EVALUATES THE EXCEEDANCE PROBABILITY VALUES USING THE UNLIMITED G-R 
 | 
			
		||||
%   LED MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The exceedance probability of magnitude M' in the time period of 
 | 
			
		||||
% length T' is the probability of an earthquake of magnitude M' or greater 
 | 
			
		||||
% to occur in T'. Depending on the value of the parameter opt the 
 | 
			
		||||
% exceedance probability values are calculated for a fixed time period T'
 | 
			
		||||
% and different magnitude values or for a fixed magnitude M' and different
 | 
			
		||||
% time period length values. In either case the independent variable vector
 | 
			
		||||
% starts from xd, up to xu with step dx. In either case the result is 
 | 
			
		||||
% returned in the vector z.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%OUTPUT
 | 
			
		||||
%   x - vector of changeable independent variable: magnitudes if opt=0, 
 | 
			
		||||
%       time period lengths if opt=1, 
 | 
			
		||||
%       x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values of the same length as x
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=ExcProbGRU(opt,xd,xu,dx,y,Mmin,lamb,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    if xd<Mmin; xd=Mmin;end
 | 
			
		||||
 end
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
if opt==0
 | 
			
		||||
    z=1-exp(-lamb*y.*exp(-beta*(x-Mmin+eps/2)));
 | 
			
		||||
else
 | 
			
		||||
    z=1-exp(-lamb*exp(-beta*(y-Mmin+eps/2)).*x);
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [x,z]=ExcProbGRU(opt,xd,xu,dx,y,Mmin,lamb,eps,b)
 | 
			
		||||
%
 | 
			
		||||
%EVALUATES THE EXCEEDANCE PROBABILITY VALUES USING THE UNLIMITED G-R 
 | 
			
		||||
%   LED MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The exceedance probability of magnitude M' in the time period of 
 | 
			
		||||
% length T' is the probability of an earthquake of magnitude M' or greater 
 | 
			
		||||
% to occur in T'. Depending on the value of the parameter opt the 
 | 
			
		||||
% exceedance probability values are calculated for a fixed time period T'
 | 
			
		||||
% and different magnitude values or for a fixed magnitude M' and different
 | 
			
		||||
% time period length values. In either case the independent variable vector
 | 
			
		||||
% starts from xd, up to xu with step dx. In either case the result is 
 | 
			
		||||
% returned in the vector z.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%OUTPUT
 | 
			
		||||
%   x - vector of changeable independent variable: magnitudes if opt=0, 
 | 
			
		||||
%       time period lengths if opt=1, 
 | 
			
		||||
%       x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values of the same length as x
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=ExcProbGRU(opt,xd,xu,dx,y,Mmin,lamb,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    if xd<Mmin; xd=Mmin;end
 | 
			
		||||
 end
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
if opt==0
 | 
			
		||||
    z=1-exp(-lamb*y.*exp(-beta*(x-Mmin+eps/2)));
 | 
			
		||||
else
 | 
			
		||||
    z=1-exp(-lamb*exp(-beta*(y-Mmin+eps/2)).*x);
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,116 +1,116 @@
 | 
			
		||||
%   [x,z]=ExcProbNPT(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE  
 | 
			
		||||
%   EXCEEDANCE PROBABILITY VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The exceedance probability of magnitude M' in the time 
 | 
			
		||||
% period of length T' is the probability of an earthquake of magnitude M' 
 | 
			
		||||
% or greater to occur in T'. 
 | 
			
		||||
%
 | 
			
		||||
% Depending on the value of the parameter opt the exceedance probability 
 | 
			
		||||
% values are calculated for a fixed time period T' and different magnitude 
 | 
			
		||||
% values or for a fixed magnitude M' and different time period length 
 | 
			
		||||
% values. In either case the independent variable vector starts from  
 | 
			
		||||
% xd, up to xu with step dx. In either case the result is returned in the
 | 
			
		||||
% vector z.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
% Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
% Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
% Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   x - vector of changeable independent variable x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=...
 | 
			
		||||
    ExcProbNPT(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    if xd<Mmin; xd=Mmin;end
 | 
			
		||||
    if xu>Mmax; xu=Mmax;end
 | 
			
		||||
end
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
n=length(x);
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    for i=1:n
 | 
			
		||||
        CDF_NPT=2*(Dystr_npr(x(i),xx,ambd,h)...
 | 
			
		||||
            -Dystr_npr(Mmin-eps/2,xx,ambd,h))./mian;
 | 
			
		||||
        z(i)=1-exp(-lamb*y.*(1-CDF_NPT));
 | 
			
		||||
    end
 | 
			
		||||
else
 | 
			
		||||
    CDF_NPT=2*(Dystr_npr(y,xx,ambd,h)...
 | 
			
		||||
        -Dystr_npr(Mmin-eps/2,xx,ambd,h))./mian;
 | 
			
		||||
    z=1-exp(-lamb*(1-CDF_NPT).*x);
 | 
			
		||||
        if y>Mmax;z=zeros(size(x));end %K15DEC2015
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [x,z]=ExcProbNPT(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE  
 | 
			
		||||
%   EXCEEDANCE PROBABILITY VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The exceedance probability of magnitude M' in the time 
 | 
			
		||||
% period of length T' is the probability of an earthquake of magnitude M' 
 | 
			
		||||
% or greater to occur in T'. 
 | 
			
		||||
%
 | 
			
		||||
% Depending on the value of the parameter opt the exceedance probability 
 | 
			
		||||
% values are calculated for a fixed time period T' and different magnitude 
 | 
			
		||||
% values or for a fixed magnitude M' and different time period length 
 | 
			
		||||
% values. In either case the independent variable vector starts from  
 | 
			
		||||
% xd, up to xu with step dx. In either case the result is returned in the
 | 
			
		||||
% vector z.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
% Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
% Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
% Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   x - vector of changeable independent variable x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=...
 | 
			
		||||
    ExcProbNPT(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    if xd<Mmin; xd=Mmin;end
 | 
			
		||||
    if xu>Mmax; xu=Mmax;end
 | 
			
		||||
end
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
n=length(x);
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    for i=1:n
 | 
			
		||||
        CDF_NPT=2*(Dystr_npr(x(i),xx,ambd,h)...
 | 
			
		||||
            -Dystr_npr(Mmin-eps/2,xx,ambd,h))./mian;
 | 
			
		||||
        z(i)=1-exp(-lamb*y.*(1-CDF_NPT));
 | 
			
		||||
    end
 | 
			
		||||
else
 | 
			
		||||
    CDF_NPT=2*(Dystr_npr(y,xx,ambd,h)...
 | 
			
		||||
        -Dystr_npr(Mmin-eps/2,xx,ambd,h))./mian;
 | 
			
		||||
    z=1-exp(-lamb*(1-CDF_NPT).*x);
 | 
			
		||||
        if y>Mmax;z=zeros(size(x));end %K15DEC2015
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,105 +1,105 @@
 | 
			
		||||
%   [x,z]=ExcProbNPU(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE  
 | 
			
		||||
%   EXCEEDANCE PROBABILITY VALUES FOR THE UNBOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
% The exceedance probability of magnitude M' in the time period of length 
 | 
			
		||||
% T' is the probability of an earthquake of magnitude M' or greater to 
 | 
			
		||||
% occur in T'. 
 | 
			
		||||
% Depending on the value of the parameter opt the exceedance probability 
 | 
			
		||||
% values are calculated for a fixed time period T' and different magnitude 
 | 
			
		||||
% values or for a fixed magnitude M' and different time period length 
 | 
			
		||||
% values. In either case the independent variable vector starts from  
 | 
			
		||||
% xd, up to xu with step dx. In either case the result is returned in the
 | 
			
		||||
% vector z.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%       
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   x - vector of changeable independent variable: magnitudes if opt=0, 
 | 
			
		||||
%       time period lengths if opt=1, 
 | 
			
		||||
%       x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values of the same length as x
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=ExcProbNPU(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
n=length(x);
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    for i=1:n
 | 
			
		||||
        CDF_NPU=2*(Dystr_npr(x(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
        z(i)=1-exp(-lamb*y.*(1-CDF_NPU));
 | 
			
		||||
    end
 | 
			
		||||
else
 | 
			
		||||
    CDF_NPU=2*(Dystr_npr(y,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
    z=1-exp(-lamb*(1-CDF_NPU).*x);
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [x,z]=ExcProbNPU(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE  
 | 
			
		||||
%   EXCEEDANCE PROBABILITY VALUES FOR THE UNBOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
% The exceedance probability of magnitude M' in the time period of length 
 | 
			
		||||
% T' is the probability of an earthquake of magnitude M' or greater to 
 | 
			
		||||
% occur in T'. 
 | 
			
		||||
% Depending on the value of the parameter opt the exceedance probability 
 | 
			
		||||
% values are calculated for a fixed time period T' and different magnitude 
 | 
			
		||||
% values or for a fixed magnitude M' and different time period length 
 | 
			
		||||
% values. In either case the independent variable vector starts from  
 | 
			
		||||
% xd, up to xu with step dx. In either case the result is returned in the
 | 
			
		||||
% vector z.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%       
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   x - vector of changeable independent variable: magnitudes if opt=0, 
 | 
			
		||||
%       time period lengths if opt=1, 
 | 
			
		||||
%       x=(xd:dx:xu)
 | 
			
		||||
%   z - vector of exceedance probability values of the same length as x
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [x,z]=ExcProbNPU(opt,xd,xu,dx,y,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dx<=0;error('Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
x=(xd:dx:xu)';
 | 
			
		||||
n=length(x);
 | 
			
		||||
 | 
			
		||||
if opt==0
 | 
			
		||||
    for i=1:n
 | 
			
		||||
        CDF_NPU=2*(Dystr_npr(x(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
        z(i)=1-exp(-lamb*y.*(1-CDF_NPU));
 | 
			
		||||
    end
 | 
			
		||||
else
 | 
			
		||||
    CDF_NPU=2*(Dystr_npr(y,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
    z=1-exp(-lamb*(1-CDF_NPU).*x);
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,59 +1,59 @@
 | 
			
		||||
%   [T,m]=Max_credM_GRT(Td,Tu,dT,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
%EVALUATES THE MAXIMUM CREDIBLE MAGNITUDE VALUES USING THE UPPER-BOUNDED 
 | 
			
		||||
%   G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distriobution Mmax as well as the
 | 
			
		||||
% activity rate of M>=Mmin events are calculated at start-up of the 
 | 
			
		||||
% stationary hazard assessment services in the upper-bounded 
 | 
			
		||||
% Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_GRT(Td,Tu,dT,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin+eps/2)));
 | 
			
		||||
m=Mmin-eps/2-1/beta*log((1-(1-1./(lamb*T))*mian));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [T,m]=Max_credM_GRT(Td,Tu,dT,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
%EVALUATES THE MAXIMUM CREDIBLE MAGNITUDE VALUES USING THE UPPER-BOUNDED 
 | 
			
		||||
%   G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distriobution Mmax as well as the
 | 
			
		||||
% activity rate of M>=Mmin events are calculated at start-up of the 
 | 
			
		||||
% stationary hazard assessment services in the upper-bounded 
 | 
			
		||||
% Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_GRT(Td,Tu,dT,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin+eps/2)));
 | 
			
		||||
m=Mmin-eps/2-1/beta*log((1-(1-1./(lamb*T))*mian));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,63 +1,63 @@
 | 
			
		||||
%   [T,m]=Max_credM_GRU(Td,Tu,dT,Mmin,lamb,eps,b)
 | 
			
		||||
%
 | 
			
		||||
%EVALUATES THE MAXIMUM CREDIBLE MAGNITUDE VALUES USING THE UNLIMITED 
 | 
			
		||||
%   G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
% 
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_GRU(Td,Tu,dT,Mmin,lamb,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
m=Mmin-eps/2+1/beta.*log(lamb*T);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%   [T,m]=Max_credM_GRU(Td,Tu,dT,Mmin,lamb,eps,b)
 | 
			
		||||
%
 | 
			
		||||
%EVALUATES THE MAXIMUM CREDIBLE MAGNITUDE VALUES USING THE UNLIMITED 
 | 
			
		||||
%   G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
% 
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_GRU(Td,Tu,dT,Mmin,lamb,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
m=Mmin-eps/2+1/beta.*log(lamb*T);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,98 +1,98 @@
 | 
			
		||||
%   [T,m]=Max_credM_NPT(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)    
 | 
			
		||||
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE MAXIMUM 
 | 
			
		||||
%   CREDIBLE MAGNITUDE VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPT(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 Mmax-0.001];
 | 
			
		||||
for i=1:n
 | 
			
		||||
    m(i)=fzero(@F_maxmagn,interval,[],xx,h,ambd,Mmin-eps/2,Mmax,lamb,T(i));
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn(t,xx,h,ambd,xmin,Mmax,lamb,D)
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
CDF_NPT=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h))/mian;
 | 
			
		||||
y=CDF_NPT-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [T,m]=Max_credM_NPT(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)    
 | 
			
		||||
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE MAXIMUM 
 | 
			
		||||
%   CREDIBLE MAGNITUDE VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPT(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 Mmax-0.001];
 | 
			
		||||
for i=1:n
 | 
			
		||||
    m(i)=fzero(@F_maxmagn,interval,[],xx,h,ambd,Mmin-eps/2,Mmax,lamb,T(i));
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn(t,xx,h,ambd,xmin,Mmax,lamb,D)
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
CDF_NPT=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h))/mian;
 | 
			
		||||
y=CDF_NPT-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,98 +1,98 @@
 | 
			
		||||
%   [T,m]=Max_credM_NPT_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)  ---- (Octave Compatible Version)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE MAXIMUM 
 | 
			
		||||
%   CREDIBLE MAGNITUDE VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPT_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 Mmax-0.001];
 | 
			
		||||
for i=1:n
 | 
			
		||||
 m(i)=fzero(@(t) F_maxmagn(t,xx,h,ambd,Mmin-eps/2,Mmax,lamb,T(i)),interval);
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn(t,xx,h,ambd,xmin,Mmax,lamb,D)
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
CDF_NPT=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h))/mian;
 | 
			
		||||
y=CDF_NPT-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [T,m]=Max_credM_NPT_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)  ---- (Octave Compatible Version)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE MAXIMUM 
 | 
			
		||||
%   CREDIBLE MAGNITUDE VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Td - starting period length for maximum credible magnitude calculations
 | 
			
		||||
%   Tu - ending period length for maximum credible magnitude calculations
 | 
			
		||||
%   dT - period length step for maximum credible magnitude calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPT_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 Mmax-0.001];
 | 
			
		||||
for i=1:n
 | 
			
		||||
 m(i)=fzero(@(t) F_maxmagn(t,xx,h,ambd,Mmin-eps/2,Mmax,lamb,T(i)),interval);
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn(t,xx,h,ambd,xmin,Mmax,lamb,D)
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
CDF_NPT=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h))/mian;
 | 
			
		||||
y=CDF_NPT-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,98 +1,98 @@
 | 
			
		||||
%   [T,m]=Max_credM_NPU(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES  
 | 
			
		||||
%   THE MAXIMUM CREDIBLE MAGNITUDE VALUES FOR THE UNBOUNDED 
 | 
			
		||||
%   NONPARAMETRIC DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPU(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 10.0];
 | 
			
		||||
for i=1:n
 | 
			
		||||
     m(i)=fzero(@F_maxmagn_NPU,interval,[],xx,h,ambd,Mmin-eps/2,lamb,T(i));
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn_NPU(t,xx,h,ambd,xmin,lamb,D)
 | 
			
		||||
CDF_NPU=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
y=CDF_NPU-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [T,m]=Max_credM_NPU(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES  
 | 
			
		||||
%   THE MAXIMUM CREDIBLE MAGNITUDE VALUES FOR THE UNBOUNDED 
 | 
			
		||||
%   NONPARAMETRIC DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPU(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 10.0];
 | 
			
		||||
for i=1:n
 | 
			
		||||
     m(i)=fzero(@F_maxmagn_NPU,interval,[],xx,h,ambd,Mmin-eps/2,lamb,T(i));
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn_NPU(t,xx,h,ambd,xmin,lamb,D)
 | 
			
		||||
CDF_NPU=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
y=CDF_NPU-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,99 +1,99 @@
 | 
			
		||||
%   [T,m]=Max_credM_NPU_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)  ---- (Octave  Comlatible Version)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES  
 | 
			
		||||
%   THE MAXIMUM CREDIBLE MAGNITUDE VALUES FOR THE UNBOUNDED 
 | 
			
		||||
%   NONPARAMETRIC DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPU_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 10.0];
 | 
			
		||||
for i=1:n
 | 
			
		||||
%     m(i)=fzero(@F_maxmagn_NPU,interval,[],xx,h,ambd,Mmin-eps/2,lamb,T(i));
 | 
			
		||||
     m(i)=fzero(@(t) F_maxmagn_NPU(t,xx,h,ambd,Mmin-eps/2,lamb,T(i)),interval);
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn_NPU(t,xx,h,ambd,xmin,lamb,D)
 | 
			
		||||
CDF_NPU=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
y=CDF_NPU-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [T,m]=Max_credM_NPU_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)  ---- (Octave  Comlatible Version)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES  
 | 
			
		||||
%   THE MAXIMUM CREDIBLE MAGNITUDE VALUES FOR THE UNBOUNDED 
 | 
			
		||||
%   NONPARAMETRIC DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The maximum credible magnitude for the period of length T
 | 
			
		||||
% is the magnitude value whose mean return period is T. 
 | 
			
		||||
% The maximum credible magnitude values are calculated for periods of 
 | 
			
		||||
% length starting from Td up to Tu with step dT.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   opt - determines the mode of calculations. opt=0 - fixed time period
 | 
			
		||||
%       length (y), different magnitude values (x), opt=1 - fixed magnitude 
 | 
			
		||||
%       (y), different time period lengths (x)
 | 
			
		||||
%   xd - starting value of the changeable independent variable 
 | 
			
		||||
%   xu - ending value of the changeable independent variable
 | 
			
		||||
%   dx - step change of the changeable independent variable
 | 
			
		||||
%   y - fixed independent variable value: time period length T' if opt=0, 
 | 
			
		||||
%        magnitude M' if opt=1
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
 | 
			
		||||
%   m - vector of maximum credible magnitudes of the same length as T
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [T,m]=Max_credM_NPU_O(Td,Tu,dT,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dT<=0;error('Time Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
T=(Td:dT:Tu)';
 | 
			
		||||
n=length(T);
 | 
			
		||||
interval=[Mmin-eps/2 10.0];
 | 
			
		||||
for i=1:n
 | 
			
		||||
%     m(i)=fzero(@F_maxmagn_NPU,interval,[],xx,h,ambd,Mmin-eps/2,lamb,T(i));
 | 
			
		||||
     m(i)=fzero(@(t) F_maxmagn_NPU(t,xx,h,ambd,Mmin-eps/2,lamb,T(i)),interval);
 | 
			
		||||
end
 | 
			
		||||
m=m';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=F_maxmagn_NPU(t,xx,h,ambd,xmin,lamb,D)
 | 
			
		||||
CDF_NPU=2*(Dystr_npr(t,xx,ambd,h)-Dystr_npr(xmin,xx,ambd,h));
 | 
			
		||||
y=CDF_NPU-1+1/(lamb*D);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,259 +1,259 @@
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=Nonpar(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx AND CALCULATES THE WEIGHTING FACTORS - ambd 
 | 
			
		||||
% FOR A USE OF THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE 
 | 
			
		||||
% DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UNBOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx. 
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (the zero of the h functional 
 | 
			
		||||
%   has been found, ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=...
 | 
			
		||||
            Nonpar(t,M,iop,Mmin)
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
    
 | 
			
		||||
if iop==0
 | 
			
		||||
    lamb_all=n/round(t(n)-t(1));
 | 
			
		||||
    lamb=nn/round(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
lamb_all=30*n/(t(n)-t(1));      % K20OCT2014
 | 
			
		||||
lamb=30*nn/(t2-t1);               % K20OCT2014
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
lamb_all=365*n/(t(n)-t(1));       % K20OCT2014
 | 
			
		||||
lamb=365*nn/(t2-t1);                % K20OCT2014
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
   [hh(1),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
            [hh(jj),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=Nonpar(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx AND CALCULATES THE WEIGHTING FACTORS - ambd 
 | 
			
		||||
% FOR A USE OF THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE 
 | 
			
		||||
% DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UNBOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx. 
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (the zero of the h functional 
 | 
			
		||||
%   has been found, ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=...
 | 
			
		||||
            Nonpar(t,M,iop,Mmin)
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
    
 | 
			
		||||
if iop==0
 | 
			
		||||
    lamb_all=n/round(t(n)-t(1));
 | 
			
		||||
    lamb=nn/round(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
lamb_all=30*n/(t(n)-t(1));      % K20OCT2014
 | 
			
		||||
lamb=30*nn/(t2-t1);               % K20OCT2014
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
lamb_all=365*n/(t(n)-t(1));       % K20OCT2014
 | 
			
		||||
lamb=365*nn/(t2-t1);                % K20OCT2014
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
   [hh(1),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
            [hh(jj),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
@@ -1,310 +1,310 @@
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=Nonpar(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx AND CALCULATES THE WEIGHTING FACTORS - ambd 
 | 
			
		||||
% FOR A USE OF THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE 
 | 
			
		||||
% DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UNBOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2 01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx. 
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (the zero of the h functional 
 | 
			
		||||
%   has been found, ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=...
 | 
			
		||||
            Nonpar_O(t,M,iop,Mmin)
 | 
			
		||||
if isempty(t) || numel(t)<3 isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
xx=NaN;
 | 
			
		||||
ambd=NaN;
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
%                                           enai=dlmread('para.txt'); %for fixed xx,ambd to test in different platforms
 | 
			
		||||
%                                           [ambd]=enai(:,1);
 | 
			
		||||
%                                           xx=enai(:,2)';               
 | 
			
		||||
%                                           [h,ierr]=hopt(xx);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)              % SL 03MAR2015 
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
 	fun = @(t) funct(t,x);                                       % FOR OCTAVE
 | 
			
		||||
	x0 =interval;                                                    % FOR OCTAVE
 | 
			
		||||
    [hh(1),fval,exitflag] = fzero(fun,x0);               % FOR OCTAVE
 | 
			
		||||
    
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
             fun = @(t) funct(t,x);                              % FOR OCTAVE
 | 
			
		||||
				x0 =interval;                                        % FOR OCTAVE
 | 
			
		||||
				[hh(jj),fval,exitflag] = fzero(fun,x0);    % FOR OCTAVE
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=Nonpar(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx AND CALCULATES THE WEIGHTING FACTORS - ambd 
 | 
			
		||||
% FOR A USE OF THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE 
 | 
			
		||||
% DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UNBOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2 01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx. 
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (the zero of the h functional 
 | 
			
		||||
%   has been found, ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd]=...
 | 
			
		||||
            Nonpar_O(t,M,iop,Mmin)
 | 
			
		||||
if isempty(t) || numel(t)<3 isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
xx=NaN;
 | 
			
		||||
ambd=NaN;
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
%                                           enai=dlmread('para.txt'); %for fixed xx,ambd to test in different platforms
 | 
			
		||||
%                                           [ambd]=enai(:,1);
 | 
			
		||||
%                                           xx=enai(:,2)';               
 | 
			
		||||
%                                           [h,ierr]=hopt(xx);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)              % SL 03MAR2015 
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
 	fun = @(t) funct(t,x);                                       % FOR OCTAVE
 | 
			
		||||
	x0 =interval;                                                    % FOR OCTAVE
 | 
			
		||||
    [hh(1),fval,exitflag] = fzero(fun,x0);               % FOR OCTAVE
 | 
			
		||||
    
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
             fun = @(t) funct(t,x);                              % FOR OCTAVE
 | 
			
		||||
				x0 =interval;                                        % FOR OCTAVE
 | 
			
		||||
				[hh(jj),fval,exitflag] = fzero(fun,x0);    % FOR OCTAVE
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
@@ -1,373 +1,373 @@
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err]=
 | 
			
		||||
%           Nonpar(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx, CALCULATES THE WEIGHTING FACTORS - amb, AND
 | 
			
		||||
% THE END-POINT OF MAGNITUDE DISTRIBUTION Mmax FOR A USE OF THE NONPARAMETRIC 
 | 
			
		||||
% ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE DISTRIBUTION UNDER THE 
 | 
			
		||||
% ASSUMPTION OF THE EXISTENCE OF THE UPPER LIMIT OF MAGNITUDE DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx.
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred.
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
%
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (a zero of the h functional 
 | 
			
		||||
%   has been found), ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err]=...
 | 
			
		||||
            Nonpar_tr(t,M,iop,Mmin)
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
    
 | 
			
		||||
if iop==0
 | 
			
		||||
    lamb_all=n/round(t(n)-t(1));
 | 
			
		||||
    lamb=nn/round(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
lamb_all=30*n/(t(n)-t(1));      % K20OCT2014
 | 
			
		||||
lamb=30*nn/(t2-t1);               % K20OCT2014
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
lamb_all=365*n/(t(n)-t(1));       % K20OCT2014
 | 
			
		||||
lamb=365*nn/(t2-t1);                % K20OCT2014
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
[Mmax,err]=Mmaxest(xx,h,Mmin-eps/2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
   [hh(1),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
            [hh(jj),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Mmax,ierr]=Mmaxest(x,h,Mmin)
 | 
			
		||||
 | 
			
		||||
% ESTIMATION OF UPPER BOUND USING NONPARAMETRIC DISTRIBUTION FUNCTIONS
 | 
			
		||||
% x - row vector of magnitudes (basic sample). 
 | 
			
		||||
% h - optimal smoothing factor
 | 
			
		||||
% Mmax - upper bound
 | 
			
		||||
% ierr=0 if basic procedure converges, ierr=1 when Robsen & Whitlock Mmas
 | 
			
		||||
% estimation
 | 
			
		||||
 | 
			
		||||
% Uses function 'dystryb'
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
ierr=1;
 | 
			
		||||
x=sort(x);
 | 
			
		||||
Mmax1=x(n);
 | 
			
		||||
for i=1:50,
 | 
			
		||||
d=normcdf((Mmin-x)./h);
 | 
			
		||||
mian=sum(normcdf((Mmax1-x)./h)-d);
 | 
			
		||||
Mmax=x(n)+moja_calka(@dystryb,x(1),Mmax1,0.00001,h,mian,x,d);
 | 
			
		||||
if abs(Mmax-Mmax1)<0.01 
 | 
			
		||||
   ierr=0;break;
 | 
			
		||||
end
 | 
			
		||||
Mmax1=Mmax;
 | 
			
		||||
end
 | 
			
		||||
if (ierr==1 || Mmax>9)
 | 
			
		||||
    Mmax=2*x(n)-x(n-1);
 | 
			
		||||
    ierr=1;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=dystryb(z,h,mian,x,d)
 | 
			
		||||
n=length(x);
 | 
			
		||||
m=length(z);
 | 
			
		||||
for i=1:m, 
 | 
			
		||||
t=(z(i)-x)./h;
 | 
			
		||||
t=normcdf(t);
 | 
			
		||||
yy=sum(t-d);
 | 
			
		||||
y(i)=(yy/mian)^n;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err]=
 | 
			
		||||
%           Nonpar(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx, CALCULATES THE WEIGHTING FACTORS - amb, AND
 | 
			
		||||
% THE END-POINT OF MAGNITUDE DISTRIBUTION Mmax FOR A USE OF THE NONPARAMETRIC 
 | 
			
		||||
% ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE DISTRIBUTION UNDER THE 
 | 
			
		||||
% ASSUMPTION OF THE EXISTENCE OF THE UPPER LIMIT OF MAGNITUDE DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx.
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred.
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
%
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (a zero of the h functional 
 | 
			
		||||
%   has been found), ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err]=...
 | 
			
		||||
            Nonpar_tr(t,M,iop,Mmin)
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
    
 | 
			
		||||
if iop==0
 | 
			
		||||
    lamb_all=n/round(t(n)-t(1));
 | 
			
		||||
    lamb=nn/round(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
lamb_all=30*n/(t(n)-t(1));      % K20OCT2014
 | 
			
		||||
lamb=30*nn/(t2-t1);               % K20OCT2014
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
lamb_all=365*n/(t(n)-t(1));       % K20OCT2014
 | 
			
		||||
lamb=365*nn/(t2-t1);                % K20OCT2014
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
[Mmax,err]=Mmaxest(xx,h,Mmin-eps/2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
   [hh(1),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
            [hh(jj),fval,exitflag]=fzero(@funct,interval,[],x);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Mmax,ierr]=Mmaxest(x,h,Mmin)
 | 
			
		||||
 | 
			
		||||
% ESTIMATION OF UPPER BOUND USING NONPARAMETRIC DISTRIBUTION FUNCTIONS
 | 
			
		||||
% x - row vector of magnitudes (basic sample). 
 | 
			
		||||
% h - optimal smoothing factor
 | 
			
		||||
% Mmax - upper bound
 | 
			
		||||
% ierr=0 if basic procedure converges, ierr=1 when Robsen & Whitlock Mmas
 | 
			
		||||
% estimation
 | 
			
		||||
 | 
			
		||||
% Uses function 'dystryb'
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
ierr=1;
 | 
			
		||||
x=sort(x);
 | 
			
		||||
Mmax1=x(n);
 | 
			
		||||
for i=1:50,
 | 
			
		||||
d=normcdf((Mmin-x)./h);
 | 
			
		||||
mian=sum(normcdf((Mmax1-x)./h)-d);
 | 
			
		||||
Mmax=x(n)+moja_calka(@dystryb,x(1),Mmax1,0.00001,h,mian,x,d);
 | 
			
		||||
if abs(Mmax-Mmax1)<0.01 
 | 
			
		||||
   ierr=0;break;
 | 
			
		||||
end
 | 
			
		||||
Mmax1=Mmax;
 | 
			
		||||
end
 | 
			
		||||
if (ierr==1 || Mmax>9)
 | 
			
		||||
    Mmax=2*x(n)-x(n-1);
 | 
			
		||||
    ierr=1;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=dystryb(z,h,mian,x,d)
 | 
			
		||||
n=length(x);
 | 
			
		||||
m=length(z);
 | 
			
		||||
for i=1:m, 
 | 
			
		||||
t=(z(i)-x)./h;
 | 
			
		||||
t=normcdf(t);
 | 
			
		||||
yy=sum(t-d);
 | 
			
		||||
y(i)=(yy/mian)^n;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,431 +1,506 @@
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err]=
 | 
			
		||||
%           Nonpar_tr(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx, CALCULATES THE WEIGHTING FACTORS - amb, AND
 | 
			
		||||
% THE END-POINT OF MAGNITUDE DISTRIBUTION Mmax FOR A USE OF THE NONPARAMETRIC 
 | 
			
		||||
% ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE DISTRIBUTION UNDER THE 
 | 
			
		||||
% ASSUMPTION OF THE EXISTENCE OF THE UPPER LIMIT OF MAGNITUDE DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2  01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx.
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred.
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
%
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (a zero of the h functional 
 | 
			
		||||
%   has been found), ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err]=...
 | 
			
		||||
            Nonpar_tr_O(t,M,iop,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
if isempty(t) || numel(t)<3 isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
xx=NaN;
 | 
			
		||||
ambd=NaN;
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
 | 
			
		||||
if isempty(Mmax)                         %K30AUG2019 - Allow for manually set Mmax
 | 
			
		||||
[Mmax,err]=Mmaxest(xx,h,Mmin-eps/2);
 | 
			
		||||
else                                     
 | 
			
		||||
err=0;                                   %K30AUG2019
 | 
			
		||||
end
 | 
			
		||||
%                                           enai=dlmread('paraT.txt'); %for fixed xx,ambd to test in different platforms
 | 
			
		||||
%                                           [ambd]=enai(:,1);
 | 
			
		||||
%                                           xx=enai(:,2)';               
 | 
			
		||||
%                                           [h,ierr]=hopt(xx);
 | 
			
		||||
%                                           [Mmax,err]=Mmaxest(xx,h,Mmin-eps/2);
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)              % SL 03MAR2015 ----------------------------------
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
   fun = @(t) funct(t,x);                                       % for octave  
 | 
			
		||||
	x0 =interval;                                                   % for octave
 | 
			
		||||
    [hh(1),fval,exitflag] = fzero(fun,x0);              % for octave
 | 
			
		||||
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
                fun = @(t) funct(t,x);                          % for octave
 | 
			
		||||
				x0 =interval;                                       % for octave
 | 
			
		||||
				[hh(jj),fval,exitflag] = fzero(fun,x0);   % for octave
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Mmax,ierr]=Mmaxest(x,h,Mmin)
 | 
			
		||||
 | 
			
		||||
% ESTIMATION OF UPPER BOUND USING NONPARAMETRIC DISTRIBUTION FUNCTIONS
 | 
			
		||||
% x - row vector of magnitudes (basic sample). 
 | 
			
		||||
% h - optimal smoothing factor
 | 
			
		||||
% Mmax - upper bound
 | 
			
		||||
% ierr=0 if basic procedure converges, ierr=1 when Robsen & Whitlock Mmas
 | 
			
		||||
% estimation
 | 
			
		||||
 | 
			
		||||
% Uses function 'dystryb'
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
ierr=1;
 | 
			
		||||
x=sort(x);
 | 
			
		||||
Mmax1=x(n);
 | 
			
		||||
for i=1:50,
 | 
			
		||||
d=normcdf((Mmin-x)./h);
 | 
			
		||||
mian=sum(normcdf((Mmax1-x)./h)-d);
 | 
			
		||||
Mmax=x(n)+moja_calka(@dystryb,x(1),Mmax1,0.00001,h,mian,x,d);
 | 
			
		||||
if abs(Mmax-Mmax1)<0.01 
 | 
			
		||||
   ierr=0;break;
 | 
			
		||||
end
 | 
			
		||||
Mmax1=Mmax;
 | 
			
		||||
end
 | 
			
		||||
if (ierr==1 || Mmax>9)
 | 
			
		||||
    Mmax=2*x(n)-x(n-1);
 | 
			
		||||
    ierr=1;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=dystryb(z,h,mian,x,d)
 | 
			
		||||
n=length(x);
 | 
			
		||||
m=length(z);
 | 
			
		||||
for i=1:m, 
 | 
			
		||||
t=(z(i)-x)./h;
 | 
			
		||||
t=normcdf(t);
 | 
			
		||||
yy=sum(t-d);
 | 
			
		||||
y(i)=(yy/mian)^n;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err,BIAS,SD]=
 | 
			
		||||
%           Nonpar_tr(t,M,iop,Mmin,Mmax,Nsynth)
 | 
			
		||||
%
 | 
			
		||||
% BASED ON MAGNITUDE SAMPLE DATA M DETERMINES THE ROUND-OFF INTERVAL LENGTH
 | 
			
		||||
% OF THE MAGNITUDE DATA - eps, THE SMOOTHING FACTOR - h, CONSTRUCTS 
 | 
			
		||||
% THE BACKGROUND SAMPLE - xx, CALCULATES THE WEIGHTING FACTORS - amb, AND
 | 
			
		||||
% THE END-POINT OF MAGNITUDE DISTRIBUTION Mmax FOR A USE OF THE NONPARAMETRIC 
 | 
			
		||||
% ADAPTATIVE KERNEL ESTIMATORS OF MAGNITUDE DISTRIBUTION UNDER THE 
 | 
			
		||||
% ASSUMPTION OF THE EXISTENCE OF THE UPPER LIMIT OF MAGNITUDE DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       NON-PARAMETRIC HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2  01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. The smoothing factor 
 | 
			
		||||
% h, is estimated using the least-squares cross-validation for the Gaussian
 | 
			
		||||
% kernel function. The final form of the kernel is the adaptive kernel.
 | 
			
		||||
% In order to avoid repetitions, which cannot appear in a sample when the
 | 
			
		||||
% kernel estimators are used, the magnitude sample data are randomized
 | 
			
		||||
% within the magnitude round-off interval. The round-off interval length -
 | 
			
		||||
% eps is the least non-zero difference between sample data or 0.1 is the
 | 
			
		||||
% least difference if greater than 0.1. The randomization is done
 | 
			
		||||
% assuming exponential distribution of m in [m0-eps/2, m0+eps/2], where m0
 | 
			
		||||
% is the sample data point and eps is the length of roud-off inteval. The 
 | 
			
		||||
% shape parameter of the exponential distribution is estimated from the whole
 | 
			
		||||
% data sample assuming the exponential distribution. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of magnitude doubled symmetrically 
 | 
			
		||||
% with respect to the value Mmin-eps/2: length(xx)=2*length(M). Weigthing 
 | 
			
		||||
% factors row vector for the adaptive kernel is of the same size as xx.
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred.
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
%
 | 
			
		||||
% See: the references below for a more comprehensive description.
 | 
			
		||||
% 
 | 
			
		||||
% This is a beta version of the program. Further developments are foreseen.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes (sample data)
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   Mmax - upper limit of Magnitude Distribution. Can be set by user, or
 | 
			
		||||
%   estimate within the program - it then should be set as Mmax=[].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 50 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   ierr - h-convergence indicator. ierr=0 if the estimation procedure of 
 | 
			
		||||
%   the optimal smoothing factor has converged (a zero of the h functional 
 | 
			
		||||
%   has been found), ierr=1 when multiple zeros of h functional were 
 | 
			
		||||
%   encountered - the largest h is accepted, ierr = 2 when h functional did  
 | 
			
		||||
%   not zeroe - the approximate h value is taken.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample for the nonparametric estimators of magnitude 
 | 
			
		||||
%   distribution
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%   BIAS - Mmax estimation Bias (Lasocki and Urban, 2011)
 | 
			
		||||
%   SD   - Mmax standard deviation (Lasocki ands Urban, 2011)
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,ierr,h,xx,ambd,Mmax,err,BIAS,SD]=...
 | 
			
		||||
            Nonpar_tr_Ob(t,M,iop,Mmin,Mmax,Nsynth)
 | 
			
		||||
if nargin==5;Nsynth=[];end                                   % K08DEC2019
 | 
			
		||||
if isempty(t) || numel(t)<3 isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
xx=NaN;
 | 
			
		||||
ambd=NaN;
 | 
			
		||||
%%% %%%%%%%%%%%%%MICHAL
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
if nn<50
 | 
			
		||||
    eps=0;ierr=0;h=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    BIAS=NaN;SD=NaN;                                               %%%     K 08NOV2019  
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
n=0;
 | 
			
		||||
for i=1:length(M)
 | 
			
		||||
    if M(i)>=Mmin;
 | 
			
		||||
        n=n+1;
 | 
			
		||||
        x(n)=M(i);
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
x=sort(x)';
 | 
			
		||||
beta=1/(mean(x)-Mmin+eps/2);
 | 
			
		||||
[xx]=korekta(x,Mmin,eps,beta);
 | 
			
		||||
xx=sort(xx);
 | 
			
		||||
clear x;
 | 
			
		||||
xx = podwajanie(xx,Mmin-eps/2);
 | 
			
		||||
[h,ierr]=hopt(xx);
 | 
			
		||||
[ambd]=scaling(xx,h);
 | 
			
		||||
 | 
			
		||||
if isempty(Mmax)                         %K30AUG2019 - Allow for manually set Mmax
 | 
			
		||||
err_Mmax=1;[Mmax,err]=Mmaxest(xx,h,Mmin-eps/2);      %  err_Mmax added 04DEC2019
 | 
			
		||||
else                                     
 | 
			
		||||
err_Mmax=0;err=0;                        %K30AUG2019
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
% Estimation of Mmax Bias                                               %%%   K 04DEC2019 
 | 
			
		||||
% (Lasocki and Urban, 2011, doi:10.2478/s11600-010-0049-y)
 | 
			
		||||
if isempty(Nsynth)==0  && err_Mmax==1              % set number of synthetic datasets, e.g. 10000
 | 
			
		||||
[BIAS,SD]=Mmax_Bias_GR(t,M,Mmin,Mmax,err,h,xx,ambd,Nsynth);
 | 
			
		||||
elseif isempty(Nsynth)==0 && err_Mmax==0;              
 | 
			
		||||
warning('Mmax must be empty for BIAS calculation');BIAS=[];SD=[];
 | 
			
		||||
else; BIAS=0;SD=0;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)              % SL 03MAR2015 ----------------------------------
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [m_corr]=korekta(m,Mmin,eps,beta)
 | 
			
		||||
 | 
			
		||||
% RANDOMIZATION OF MAGNITUDE WITHIN THE ACCURACY INTERVAL
 | 
			
		||||
%
 | 
			
		||||
% m - input vector of magnitudes 
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% eps - accuracy of magnitude
 | 
			
		||||
% beta - the parameter of the unbounded exponential distribution
 | 
			
		||||
%
 | 
			
		||||
% m_corr - vector of randomized magnitudes
 | 
			
		||||
%
 | 
			
		||||
F1=1-exp(-beta*(m-Mmin-0.5*eps));
 | 
			
		||||
F2=1-exp(-beta*(m-Mmin+0.5*eps));
 | 
			
		||||
u=rand(size(m));
 | 
			
		||||
w=u.*(F2-F1)+F1;
 | 
			
		||||
m_corr=Mmin-log(1-w)./beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function x2 = podwajanie(x,x0)
 | 
			
		||||
 | 
			
		||||
% DOUBLES THE SAMPLE
 | 
			
		||||
 | 
			
		||||
% If the sample x(i) is is truncated from the left hand side and belongs 
 | 
			
		||||
% to the interval [x0,inf) or it is truncated from the right hand side and
 | 
			
		||||
% belongs to the interval (-inf,x0]
 | 
			
		||||
%   then the doubled sample is [-x(i)+2x0,x(i)]
 | 
			
		||||
% x - is the column data vector
 | 
			
		||||
% x2 - is the column vector of data doubled and sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
 | 
			
		||||
x2=[-x+2*x0
 | 
			
		||||
    x];
 | 
			
		||||
x2=sort(x2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [h,ierr]=hopt(x)
 | 
			
		||||
 | 
			
		||||
%Estimation of the optimal smoothing factor by means of the least squares
 | 
			
		||||
%method
 | 
			
		||||
% x - column data vector
 | 
			
		||||
% The result is an optimal smoothing factor
 | 
			
		||||
% ierr=0 - convergence, ierr=1 - multiple h, ierr=2 - approximate h is used 
 | 
			
		||||
% The function calls the procedure FZERO for the function 'funct'
 | 
			
		||||
% NEW VERSION 2 - without a square matrix. Also equipped with extra zeros
 | 
			
		||||
% search
 | 
			
		||||
 | 
			
		||||
% MODIFIED JUNE 2014
 | 
			
		||||
 | 
			
		||||
ierr=0;
 | 
			
		||||
n=length(x);
 | 
			
		||||
x=sort(x);
 | 
			
		||||
interval=[0.000001 2*std(x)/n^0.2];
 | 
			
		||||
x1=funct(interval(1),x);
 | 
			
		||||
x2=funct(interval(2),x);
 | 
			
		||||
if x1*x2<0
 | 
			
		||||
   fun = @(t) funct(t,x);                                       % for octave  
 | 
			
		||||
	x0 =interval;                                                   % for octave
 | 
			
		||||
    [hh(1),fval,exitflag] = fzero(fun,x0);              % for octave
 | 
			
		||||
 | 
			
		||||
% Extra zeros search
 | 
			
		||||
    jj=1;
 | 
			
		||||
    for kk=2:7
 | 
			
		||||
        interval(1)=1.1*hh(jj);
 | 
			
		||||
        interval(2)=interval(1)+(kk-1)*hh(jj);
 | 
			
		||||
        x1=funct(interval(1),x);
 | 
			
		||||
        x2=funct(interval(2),x);
 | 
			
		||||
        if x1*x2<0
 | 
			
		||||
            jj=jj+1;
 | 
			
		||||
                fun = @(t) funct(t,x);                          % for octave
 | 
			
		||||
				x0 =interval;                                       % for octave
 | 
			
		||||
				[hh(jj),fval,exitflag] = fzero(fun,x0);   % for octave
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    if jj>1;ierr=1;end
 | 
			
		||||
    h=max(hh);
 | 
			
		||||
 | 
			
		||||
   if exitflag==1;return;end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
h=0.891836*(mean(x)-x(1))/(n^0.2);
 | 
			
		||||
ierr=2;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [fct]=funct(t,x)
 | 
			
		||||
p2=1.41421356;
 | 
			
		||||
n=length(x);
 | 
			
		||||
yy=zeros(size(x));
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   xij=(x-x(i)).^2/t^2;
 | 
			
		||||
   y=exp(-xij/4).*((xij/2-1)/p2)-2*exp(-xij/2).*(xij-1);
 | 
			
		||||
   yy(i)=sum(y);
 | 
			
		||||
end;
 | 
			
		||||
fct=sum(yy)-2*n;
 | 
			
		||||
clear xij y yy;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [ambd]=scaling(x,h)
 | 
			
		||||
 | 
			
		||||
% EVALUATES A VECTOR OF SCALING FACTORS FOR THE NONPARAMETRIC ADAPTATIVE
 | 
			
		||||
% ESTIMATION
 | 
			
		||||
 | 
			
		||||
% x - the n dimensional column vector of data values sorted in the ascending
 | 
			
		||||
% order
 | 
			
		||||
% h - the optimal smoothing factor
 | 
			
		||||
% ambd - the resultant n dimensional row vector of local scaling factors 
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
gau=zeros(1,n);
 | 
			
		||||
for i=1:n,
 | 
			
		||||
   gau(i)=sum(exp(-0.5*((x(i)-x)/h).^2))/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
g=exp(mean(log(gau)));
 | 
			
		||||
ambd=sqrt(g./gau);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Mmax,ierr]=Mmaxest(x,h,Mmin)
 | 
			
		||||
 | 
			
		||||
% ESTIMATION OF UPPER BOUND USING NONPARAMETRIC DISTRIBUTION FUNCTIONS
 | 
			
		||||
% x - row vector of magnitudes (basic sample). 
 | 
			
		||||
% h - optimal smoothing factor
 | 
			
		||||
% Mmax - upper bound
 | 
			
		||||
% ierr=0 if basic procedure converges, ierr=1 when Robsen & Whitlock Mmas
 | 
			
		||||
% estimation
 | 
			
		||||
 | 
			
		||||
% Uses function 'dystryb'
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
ierr=1;
 | 
			
		||||
x=sort(x);
 | 
			
		||||
Mmax1=x(n);
 | 
			
		||||
for i=1:50,
 | 
			
		||||
d=normcdf((Mmin-x)./h);
 | 
			
		||||
mian=sum(normcdf((Mmax1-x)./h)-d);
 | 
			
		||||
Mmax=x(n)+moja_calka(@dystryb,x(1),Mmax1,0.00001,h,mian,x,d);
 | 
			
		||||
if abs(Mmax-Mmax1)<0.01 
 | 
			
		||||
   ierr=0;break;
 | 
			
		||||
end
 | 
			
		||||
Mmax1=Mmax;
 | 
			
		||||
end
 | 
			
		||||
if (ierr==1 || Mmax>9)
 | 
			
		||||
    Mmax=2*x(n)-x(n-1);
 | 
			
		||||
    ierr=1;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=dystryb(z,h,mian,x,d)
 | 
			
		||||
n=length(x);
 | 
			
		||||
m=length(z);
 | 
			
		||||
for i=1:m, 
 | 
			
		||||
t=(z(i)-x)./h;
 | 
			
		||||
t=normcdf(t);
 | 
			
		||||
yy=sum(t-d);
 | 
			
		||||
y(i)=(yy/mian)^n;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
% --------------------- Mmax BIAS estimation routine ----------------------  K 08NOV2019
 | 
			
		||||
 | 
			
		||||
function [BIAS,SD]=Mmax_Bias_GR(t,m,Mc,Mmax1,err,h,xx,ambd,synth)
 | 
			
		||||
 | 
			
		||||
s1=sort(unique(m));s2=s1(2:length(s1))-s1(1:length(s1)-1);EPS=min(s2);
 | 
			
		||||
 | 
			
		||||
if err~=0
 | 
			
		||||
warning('process did not converge!!')   
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
MAXm=max(m);N=numel(m(m>=Mc));DeltaM=MAXm-Mc;    %beta=b*log(10);
 | 
			
		||||
[mag,PDF_NPT,CDF_NPT]=dist_NPT(Mc-EPS,Mmax1+EPS,0.01,Mc,EPS,h,xx,ambd,Mmax1);
 | 
			
		||||
 | 
			
		||||
for j=1:synth         %set number of synthetic datasets, default is 10000 
 | 
			
		||||
% % CDF:
 | 
			
		||||
 
 | 
			
		||||
                                                                                     % j  
 | 
			
		||||
 | 
			
		||||
% linear interpolation to assign magnitude values from a uniform distribution sample
 | 
			
		||||
 iM=rand(1,N);M1=interp1q(CDF_NPT,mag,iM');
 | 
			
		||||
 br(j)=1/(log(10)*(mean(M1)-min(M1)+EPS/2));DM=range(M1);
 | 
			
		||||
 Mmax=max(M1);
 | 
			
		||||
 | 
			
		||||
 % Iteration Process to estimate b and Mmax
 | 
			
		||||
b1=10;best=[1.0 10.0];i=1; 
 | 
			
		||||
while min(abs(diff(best)))>0.00001
 | 
			
		||||
w=exp(b1*(Mmax-Mc));E1=expint(N/(w-1));E2=expint(N*w/(w-1));
 | 
			
		||||
%E=expint(w);
 | 
			
		||||
Mme=Mmax+(E1-E2)/(b1*exp(-N/(w-1)))+(Mc)*exp(-N);    %Mme=round(Mme/EPS)*EPS;            
 | 
			
		||||
 | 
			
		||||
if isnan(Mme)
 | 
			
		||||
KM=sort(unique(M1),'descend');
 | 
			
		||||
Mme=2*KM(1)-KM(2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
fun=@(bb) 1/bb+(Mme-Mc)/(1-exp(bb*(Mme-Mc)))-mean(M1)+Mc-EPS/2;  %consider th5 last 0.05 term
 | 
			
		||||
b1=fzero(fun,1);best(i)=b1;i=i+1;
 | 
			
		||||
 | 
			
		||||
if i==50
 | 
			
		||||
   warning('process did not converge!!');break 
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
be(j)=b1/log(10);
 | 
			
		||||
Me(j)=Mme;dm(j)=DM;Mm(j)=Mmax;
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
BIAS=mean(MAXm-Me);
 | 
			
		||||
SD=std(MAXm-Me);
 | 
			
		||||
 | 
			
		||||
%b-mean(be)    %check b-value difference
 | 
			
		||||
%histogram(be)
 | 
			
		||||
 | 
			
		||||
% MAXm: maximum magnitude in the real catalog 
 | 
			
		||||
% Mmax: maximum magnitudes observed in the synthetic catalogs (rounded)
 | 
			
		||||
% Me: maximum magnitude estimates for the synthetic catalogs 
 | 
			
		||||
% Mmax1: maximum magnitude estimated by GRT
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,83 +1,83 @@
 | 
			
		||||
%   [m,T]=Ret_periodGRT(Md,Mu,dM,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE MEAN RETURN PERIOD VALUES USING THE UPPER-BOUNDED G-R LED 
 | 
			
		||||
%   MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distriobution Mmax as well as the
 | 
			
		||||
% activity rate of M>=Mmin events are calculated at start-up of the 
 | 
			
		||||
% stationary hazard assessment services in the upper-bounded 
 | 
			
		||||
% Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The mean return period of magnitude M is the average elapsed time between
 | 
			
		||||
% the consecutive earthquakes of magnitude M.   
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodGRT(Md,Mu,dM,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
if Mu>Mmax; Mu=Mmax;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
T=1/lamb./(1-Cdfgr(m,beta,Mmin-eps/2,Mmax));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%   [m,T]=Ret_periodGRT(Md,Mu,dM,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE MEAN RETURN PERIOD VALUES USING THE UPPER-BOUNDED G-R LED 
 | 
			
		||||
%   MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distriobution Mmax as well as the
 | 
			
		||||
% activity rate of M>=Mmin events are calculated at start-up of the 
 | 
			
		||||
% stationary hazard assessment services in the upper-bounded 
 | 
			
		||||
% Gutenberg-Richter estimation mode.
 | 
			
		||||
% 
 | 
			
		||||
% The mean return period of magnitude M is the average elapsed time between
 | 
			
		||||
% the consecutive earthquakes of magnitude M.   
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of earthquake magnitudes
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodGRT(Md,Mu,dM,Mmin,lamb,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
if Mu>Mmax; Mu=Mmax;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
T=1/lamb./(1-Cdfgr(m,beta,Mmin-eps/2,Mmax));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,59 +1,59 @@
 | 
			
		||||
%   [m,T]=Ret_periodGRU(Md,Mu,dM,Mmin,lamb,eps,b)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE MEAN RETURN PERIOD VALUES USING THE UNLIMITED G-R LED 
 | 
			
		||||
%   MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The mean return period of magnitude M is the average elapsed time between
 | 
			
		||||
% the consecutive earthquakes of magnitude M.   
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
% 
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodGRU(Md,Mu,dM,Mmin,lamb,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
T=1/lamb./exp(-beta*(m-Mmin+eps/2));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%   [m,T]=Ret_periodGRU(Md,Mu,dM,Mmin,lamb,eps,b)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE MEAN RETURN PERIOD VALUES USING THE UNLIMITED G-R LED 
 | 
			
		||||
%   MAGNITUDE DISTRIBUTION MODEL.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The mean return period of magnitude M is the average elapsed time between
 | 
			
		||||
% the consecutive earthquakes of magnitude M.   
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
% 
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodGRU(Md,Mu,dM,Mmin,lamb,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
T=1/lamb./exp(-beta*(m-Mmin+eps/2));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,94 +1,94 @@
 | 
			
		||||
%   [m,T]=Ret_periodNPT(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE MEAN 
 | 
			
		||||
%   RETURN PERIOD VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
% 
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodNPT(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
if Mu>Mmax; Mu=Mmax;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
n=length(m);
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
for i=1:n
 | 
			
		||||
    CDF_NPT=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h))/mian;
 | 
			
		||||
    T(i)=1/lamb./(1-CDF_NPT);
 | 
			
		||||
end
 | 
			
		||||
T=T';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%   [m,T]=Ret_periodNPT(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES THE MEAN 
 | 
			
		||||
%   RETURN PERIOD VALUES FOR THE UPPER-BOUNDED NONPARAMETRIC 
 | 
			
		||||
%   DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
% 
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodNPT(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
if Mu>Mmax; Mu=Mmax;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
n=length(m);
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
for i=1:n
 | 
			
		||||
    CDF_NPT=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h))/mian;
 | 
			
		||||
    T(i)=1/lamb./(1-CDF_NPT);
 | 
			
		||||
end
 | 
			
		||||
T=T';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,91 +1,91 @@
 | 
			
		||||
%   [m,T]=Ret_periodNPU(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES 
 | 
			
		||||
%   THE MEAN RETURN PERIOD VALUES FOR THE UNBOUNDED 
 | 
			
		||||
%   NONPARAMETRIC DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The mean return period of magnitude M is the average 
 | 
			
		||||
%   elapsed time between the consecutive earthquakes of magnitude M.   
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodNPU(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
n=length(m);
 | 
			
		||||
 | 
			
		||||
for i=1:n
 | 
			
		||||
    CDF_NPU=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
    T(i)=1/lamb./(1-CDF_NPU);
 | 
			
		||||
end
 | 
			
		||||
T=T';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [m,T]=Ret_periodNPU(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
%USING THE NONPARAMETRIC ADAPTATIVE KERNEL APPROACH EVALUATES 
 | 
			
		||||
%   THE MEAN RETURN PERIOD VALUES FOR THE UNBOUNDED 
 | 
			
		||||
%   NONPARAMETRIC DISTRIBUTION FOR MAGNITUDE. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% The mean return period of magnitude M is the average 
 | 
			
		||||
%   elapsed time between the consecutive earthquakes of magnitude M.   
 | 
			
		||||
% The mean return periods are calculated for magnitude starting from Md up
 | 
			
		||||
% to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   Md - starting magnitude for return period calculations
 | 
			
		||||
%   Mu - ending magnitude for return period calculations
 | 
			
		||||
%   dM - magnitude step for return period calculations 
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   lamb - mean activity rate for events M>=Mmin
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   T - vector od mean return periods of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,T]=Ret_periodNPU(Md,Mu,dM,Mmin,lamb,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if Md<Mmin; Md=Mmin;end
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
n=length(m);
 | 
			
		||||
 | 
			
		||||
for i=1:n
 | 
			
		||||
    CDF_NPU=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
    T(i)=1/lamb./(1-CDF_NPU);
 | 
			
		||||
end
 | 
			
		||||
T=T';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,250 +1,250 @@
 | 
			
		||||
%
 | 
			
		||||
%   [lamb_all,lamb,lmab_err,unit,eps,b,Mmax,err]=TruncGR(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% ESTIMATES THE MEAN ACTIVITY RATE WITHIN THE WHOLE SAMPLE AND WITHIN THE 
 | 
			
		||||
% COMPLETE PART OF THE SAMPLE, THE ROUND-OFF ERROR OF MAGNITUDE, 
 | 
			
		||||
% THE GUTENBERG-RICHTER B-VALUE AND THE UPPER BOUND OF MAGNITUDE
 | 
			
		||||
% DISTRIBUTION USING THE UPPER-BOUNDED G-R LED MAGNITUDE DISTRIBUTION MODEL
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       GUTENBERG-RICHETR HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution and consequently the G-R
 | 
			
		||||
% b-value is estimated by maximum likelihood method (Aki-Utsu procedure).   
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred. Upon the value of the input 
 | 
			
		||||
% parameter, iop, the used unit of time can be either day ot month or year.    
 | 
			
		||||
% The round-off interval length - eps is the least non-zero difference 
 | 
			
		||||
% between sample data or 0.1 if the least difference is greater than 0.1.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of magnitudes from a user selected catalog
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - catalog completeness level. Must be determined externally.
 | 
			
		||||
%   Can take any value from [min(M), max(M)].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 15 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,b,Mmax,err]=TruncGR(t,M,iop,Mmin)
 | 
			
		||||
n=length(M);
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
    
 | 
			
		||||
if iop==0
 | 
			
		||||
    lamb_all=n/round(t(n)-t(1));
 | 
			
		||||
    lamb=nn/round(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
lamb_all=30*n/(t(n)-t(1));      % K20OCT2014
 | 
			
		||||
lamb=30*nn/(t2-t1);               % K20OCT2014
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
lamb_all=365*n/(t(n)-t(1));       % K20OCT2014
 | 
			
		||||
lamb=365*nn/(t2-t1);                % K20OCT2014
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if nn<15
 | 
			
		||||
    eps=0;b=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
xx=M(M>=Mmin); %K21OCT2014
 | 
			
		||||
% x=sort(M,'descend'); 
 | 
			
		||||
% for i=1:n
 | 
			
		||||
%     if x(i)<Mmin; break; end
 | 
			
		||||
%     xx(i)=x(i);                                                       %
 | 
			
		||||
% end
 | 
			
		||||
 | 
			
		||||
clear x;
 | 
			
		||||
nn=length(xx);
 | 
			
		||||
    
 | 
			
		||||
Max_obs=max(xx);
 | 
			
		||||
beta0=0;
 | 
			
		||||
Mmax1=Max_obs;
 | 
			
		||||
for i=1:50,
 | 
			
		||||
    beta=fzero(@bet_est,[0.05,4.0],[],mean(xx),Mmin-eps/2,Mmax1);
 | 
			
		||||
  	Mmax=Max_obs+moja_calka('f_podc',Mmin,Max_obs,1e-5,nn,beta,Mmin-eps/2,Mmax1);
 | 
			
		||||
    if ((abs(Mmax-Mmax1)<0.01)&&(abs(beta-beta0)<0.0001))
 | 
			
		||||
        err=0;
 | 
			
		||||
        break;
 | 
			
		||||
    end
 | 
			
		||||
    Mmax1=Mmax;
 | 
			
		||||
    beta0=beta;
 | 
			
		||||
end
 | 
			
		||||
if i==50; 
 | 
			
		||||
    err=1.0;
 | 
			
		||||
    Mmax=2*xx(1)-xx(2);
 | 
			
		||||
    beta=fzero(@bet_est,1.0,[],mean(xx),Mmin-eps/2,Mmax);
 | 
			
		||||
end
 | 
			
		||||
b=beta/log(10);
 | 
			
		||||
clear xx
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [zero]=bet_est(b,ms,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%First derivative of the log likelihood function of the upper-bounded 
 | 
			
		||||
% exponential distribution (truncated GR model)
 | 
			
		||||
% b - parameter of the distribution 'beta'
 | 
			
		||||
% ms - mean of the observed magnitudes
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
M_max_min=Mmax-Mmin;
 | 
			
		||||
e_m=exp(-b*M_max_min);
 | 
			
		||||
zero=1/b-ms+Mmin-M_max_min*e_m/(1-e_m);
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=f_podc(z,n,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
% Integrated function for Mmax estimation. Truncated GR model
 | 
			
		||||
% z - column vector of independent variable
 | 
			
		||||
% n - the size of 'z'
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% Mmin - the catalog completeness level
 | 
			
		||||
% Mmax - the upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
y=Cdfgr(z,beta,Mmin,Mmax).^n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
%
 | 
			
		||||
%   [lamb_all,lamb,lmab_err,unit,eps,b,Mmax,err]=TruncGR(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% ESTIMATES THE MEAN ACTIVITY RATE WITHIN THE WHOLE SAMPLE AND WITHIN THE 
 | 
			
		||||
% COMPLETE PART OF THE SAMPLE, THE ROUND-OFF ERROR OF MAGNITUDE, 
 | 
			
		||||
% THE GUTENBERG-RICHTER B-VALUE AND THE UPPER BOUND OF MAGNITUDE
 | 
			
		||||
% DISTRIBUTION USING THE UPPER-BOUNDED G-R LED MAGNITUDE DISTRIBUTION MODEL
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       GUTENBERG-RICHETR HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution and consequently the G-R
 | 
			
		||||
% b-value is estimated by maximum likelihood method (Aki-Utsu procedure).   
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred. Upon the value of the input 
 | 
			
		||||
% parameter, iop, the used unit of time can be either day ot month or year.    
 | 
			
		||||
% The round-off interval length - eps is the least non-zero difference 
 | 
			
		||||
% between sample data or 0.1 if the least difference is greater than 0.1.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of magnitudes from a user selected catalog
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - catalog completeness level. Must be determined externally.
 | 
			
		||||
%   Can take any value from [min(M), max(M)].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 15 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,b,Mmax,err]=TruncGR(t,M,iop,Mmin)
 | 
			
		||||
n=length(M);
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
    
 | 
			
		||||
if iop==0
 | 
			
		||||
    lamb_all=n/round(t(n)-t(1));
 | 
			
		||||
    lamb=nn/round(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
lamb_all=30*n/(t(n)-t(1));      % K20OCT2014
 | 
			
		||||
lamb=30*nn/(t2-t1);               % K20OCT2014
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
lamb_all=365*n/(t(n)-t(1));       % K20OCT2014
 | 
			
		||||
lamb=365*nn/(t2-t1);                % K20OCT2014
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if nn<15
 | 
			
		||||
    eps=0;b=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
xx=M(M>=Mmin); %K21OCT2014
 | 
			
		||||
% x=sort(M,'descend'); 
 | 
			
		||||
% for i=1:n
 | 
			
		||||
%     if x(i)<Mmin; break; end
 | 
			
		||||
%     xx(i)=x(i);                                                       %
 | 
			
		||||
% end
 | 
			
		||||
 | 
			
		||||
clear x;
 | 
			
		||||
nn=length(xx);
 | 
			
		||||
    
 | 
			
		||||
Max_obs=max(xx);
 | 
			
		||||
beta0=0;
 | 
			
		||||
Mmax1=Max_obs;
 | 
			
		||||
for i=1:50,
 | 
			
		||||
    beta=fzero(@bet_est,[0.05,4.0],[],mean(xx),Mmin-eps/2,Mmax1);
 | 
			
		||||
  	Mmax=Max_obs+moja_calka('f_podc',Mmin,Max_obs,1e-5,nn,beta,Mmin-eps/2,Mmax1);
 | 
			
		||||
    if ((abs(Mmax-Mmax1)<0.01)&&(abs(beta-beta0)<0.0001))
 | 
			
		||||
        err=0;
 | 
			
		||||
        break;
 | 
			
		||||
    end
 | 
			
		||||
    Mmax1=Mmax;
 | 
			
		||||
    beta0=beta;
 | 
			
		||||
end
 | 
			
		||||
if i==50; 
 | 
			
		||||
    err=1.0;
 | 
			
		||||
    Mmax=2*xx(1)-xx(2);
 | 
			
		||||
    beta=fzero(@bet_est,1.0,[],mean(xx),Mmin-eps/2,Mmax);
 | 
			
		||||
end
 | 
			
		||||
b=beta/log(10);
 | 
			
		||||
clear xx
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [zero]=bet_est(b,ms,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%First derivative of the log likelihood function of the upper-bounded 
 | 
			
		||||
% exponential distribution (truncated GR model)
 | 
			
		||||
% b - parameter of the distribution 'beta'
 | 
			
		||||
% ms - mean of the observed magnitudes
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
M_max_min=Mmax-Mmin;
 | 
			
		||||
e_m=exp(-b*M_max_min);
 | 
			
		||||
zero=1/b-ms+Mmin-M_max_min*e_m/(1-e_m);
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=f_podc(z,n,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
% Integrated function for Mmax estimation. Truncated GR model
 | 
			
		||||
% z - column vector of independent variable
 | 
			
		||||
% n - the size of 'z'
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% Mmin - the catalog completeness level
 | 
			
		||||
% Mmax - the upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
y=Cdfgr(z,beta,Mmin,Mmax).^n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -1,305 +1,387 @@
 | 
			
		||||
%
 | 
			
		||||
%   [lamb_all,lamb,lmab_err,unit,eps,b,Mmax,err]=TruncGR(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% ESTIMATES THE MEAN ACTIVITY RATE WITHIN THE WHOLE SAMPLE AND WITHIN THE 
 | 
			
		||||
% COMPLETE PART OF THE SAMPLE, THE ROUND-OFF ERROR OF MAGNITUDE, 
 | 
			
		||||
% THE GUTENBERG-RICHTER B-VALUE AND THE UPPER BOUND OF MAGNITUDE
 | 
			
		||||
% DISTRIBUTION USING THE UPPER-BOUNDED G-R LED MAGNITUDE DISTRIBUTION MODEL
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       GUTENBERG-RICHETR HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2 01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution and consequently the G-R
 | 
			
		||||
% b-value is estimated by maximum likelihood method (Aki-Utsu procedure).   
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred. Upon the value of the input 
 | 
			
		||||
% parameter, iop, the used unit of time can be either day ot month or year.    
 | 
			
		||||
% The round-off interval length - eps is the least non-zero difference 
 | 
			
		||||
% between sample data or 0.1 if the least difference is greater than 0.1.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of magnitudes from a user selected catalog
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - catalog completeness level. Must be determined externally.
 | 
			
		||||
%   Can take any value from [min(M), max(M)].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 15 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,b,Mmax,err]=TruncGR_O(t,M,iop,Mmin,Mmax)
 | 
			
		||||
if isempty(t) || numel(t)<3 || isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
n=length(M);
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
 | 
			
		||||
if nn<15
 | 
			
		||||
    eps=0;b=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
xx=M(M>=Mmin); %K21OCT2014
 | 
			
		||||
% x=sort(M,'descend');
 | 
			
		||||
% for i=1:n
 | 
			
		||||
%      if x(i)<Mmin; break; end
 | 
			
		||||
%      xx(i)=x(i);                                                      %
 | 
			
		||||
% end
 | 
			
		||||
 | 
			
		||||
clear x;
 | 
			
		||||
nn=length(xx);
 | 
			
		||||
    
 | 
			
		||||
Max_obs=max(xx);
 | 
			
		||||
beta0=0;
 | 
			
		||||
Mmax1=Max_obs; 
 | 
			
		||||
            if isempty(Mmax)==0                            %%%   K 28JUL2015
 | 
			
		||||
                	fun = @(b) bet_est(b,mean(xx),Mmin-eps/2,Mmax);    %%%   K 28JUL2015
 | 
			
		||||
                	x0 = 1;              %[0.05,4.0];           %%%   K 28JUL2015 - See exception line 153
 | 
			
		||||
                    beta = fzero(fun,x0);                     %%%   K 28JUL2015
 | 
			
		||||
                    err=0;                                             %%%   K 28JUL2015
 | 
			
		||||
            else                                                         %%%   K 28JUL2015  -  line 148
 | 
			
		||||
for i=1:50,                                                           
 | 
			
		||||
	fun = @(b) bet_est(b,mean(xx),Mmin-eps/2,Mmax1);
 | 
			
		||||
	x0 =1;           %[0.05,4.0];                               %%%   K29JUL2015 - See exception line 153
 | 
			
		||||
    beta = fzero(fun,x0);
 | 
			
		||||
  	Mmax=Max_obs+moja_calka('f_podc',Mmin,Max_obs,1e-5,nn,beta,Mmin-eps/2,Mmax1);
 | 
			
		||||
    if ((abs(Mmax-Mmax1)<0.01)&&(abs(beta-beta0)<0.0001))
 | 
			
		||||
        err=0;
 | 
			
		||||
        break;
 | 
			
		||||
    end
 | 
			
		||||
    Mmax1=Mmax;
 | 
			
		||||
    beta0=beta;
 | 
			
		||||
end
 | 
			
		||||
if i==50; 
 | 
			
		||||
    err=1.0;
 | 
			
		||||
    Mmax=2*xx(1)-xx(2);
 | 
			
		||||
fun = @(b) bet_est(b,mean(xx),Mmin-eps/2,Mmax);
 | 
			
		||||
	x0 =1;
 | 
			
		||||
    beta = fzero(fun,x0);
 | 
			
		||||
end
 | 
			
		||||
            end                                                         %%%   K 28JUL2015
 | 
			
		||||
b=beta/log(10);
 | 
			
		||||
clear xx
 | 
			
		||||
 | 
			
		||||
% Exception for v-value
 | 
			
		||||
if b<0.05 || b>6.0; error('Unacceptable b-value, abort and select different dataset');end
 | 
			
		||||
beta;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)               % SL 03MAR2015 
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [zero]=bet_est(b,ms,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%First derivative of the log likelihood function of the upper-bounded 
 | 
			
		||||
% exponential distribution (truncated GR model)
 | 
			
		||||
% b - parameter of the distribution 'beta'
 | 
			
		||||
% ms - mean of the observed magnitudes
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
M_max_min=Mmax-Mmin;
 | 
			
		||||
e_m=exp(-b*M_max_min);
 | 
			
		||||
zero=1/b-ms+Mmin-M_max_min*e_m/(1-e_m);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=f_podc(z,n,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
% Integrated function for Mmax estimation. Truncated GR model
 | 
			
		||||
% z - column vector of independent variable
 | 
			
		||||
% n - the size of 'z'
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% Mmin - the catalog completeness level
 | 
			
		||||
% Mmax - the upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
y=Cdfgr(z,beta,Mmin,Mmax).^n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
%
 | 
			
		||||
%[lamb_all,lamb,lamb_err,unit,eps,b,Mmax,err,BIAS,SD]=TruncGR_Ob(t,M,iop,Mmin,Mmax,Nsynth)
 | 
			
		||||
%
 | 
			
		||||
% ESTIMATES THE MEAN ACTIVITY RATE WITHIN THE WHOLE SAMPLE AND WITHIN THE 
 | 
			
		||||
% COMPLETE PART OF THE SAMPLE, THE ROUND-OFF ERROR OF MAGNITUDE, 
 | 
			
		||||
% THE GUTENBERG-RICHTER B-VALUE AND THE UPPER BOUND OF MAGNITUDE
 | 
			
		||||
% DISTRIBUTION USING THE UPPER-BOUNDED G-R LED MAGNITUDE DISTRIBUTION MODEL
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UPPER-BOUNDED 
 | 
			
		||||
%       GUTENBERG-RICHETR HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2 01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution and consequently the G-R
 | 
			
		||||
% b-value is estimated by maximum likelihood method (Aki-Utsu procedure).   
 | 
			
		||||
% The upper limit of the distribution Mmax is evaluated using 
 | 
			
		||||
% the Kijko-Sellevol generic formula. If convergence is not reached the
 | 
			
		||||
% Whitlock @ Robson simplified formula is used: 
 | 
			
		||||
% Mmaxest= 2(max obs M) - (second max obs M)).
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred. Upon the value of the input 
 | 
			
		||||
% parameter, iop, the used unit of time can be either day ot month or year.    
 | 
			
		||||
% The round-off interval length - eps is the least non-zero difference 
 | 
			
		||||
% between sample data or 0.1 if the least difference is greater than 0.1.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Kijko, A., and M.A. Sellevoll (1989) Bull. Seismol. Soc. Am. 79, 3,645-654 
 | 
			
		||||
%Lasocki, S., Urban, P. (2011) Acta Geophys 59, 659-673, 
 | 
			
		||||
% doi: 10.2478/s11600-010-0049-y
 | 
			
		||||
%
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of magnitudes from a user selected catalog
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - catalog completeness level. Must be determined externally.
 | 
			
		||||
%   Can take any value from [min(M), max(M)].
 | 
			
		||||
%   Mmax - upper limit of Magnitude Distribution. Can be set by user, or
 | 
			
		||||
%   estimate within the program - it then should be set as Mmax=[].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 15 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%   err - error parameter on Mmax estimation, err=0 - convergence, err=1 - 
 | 
			
		||||
%   no converegence of Kijko-Sellevol estimator, Robinson @ Whitlock
 | 
			
		||||
%   method used.
 | 
			
		||||
%   BIAS - Mmax estimation Bias (Lasocki and Urban, 2011)
 | 
			
		||||
%   SD   - Mmax standard deviation (Lasocki ands Urban, 2011)
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,b,Mmax,err,BIAS,SD]=TruncGR_Ob(t,M,iop,Mmin,Mmax,Nsynth)
 | 
			
		||||
if nargin==5;Nsynth=[];end                                   % K08DEC2019
 | 
			
		||||
if isempty(t) || numel(t)<3 || isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
n=length(M);
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
 | 
			
		||||
if nn<15
 | 
			
		||||
    eps=0;b=0;Mmax=0;err=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    BIAS=NaN;SD=NaN;                                               %%%     K 08NOV2019  
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
xx=M(M>=Mmin); %K21OCT2014
 | 
			
		||||
% x=sort(M,'descend');
 | 
			
		||||
% for i=1:n
 | 
			
		||||
%      if x(i)<Mmin; break; end
 | 
			
		||||
%      xx(i)=x(i);                                                      %
 | 
			
		||||
% end
 | 
			
		||||
 | 
			
		||||
clear x;
 | 
			
		||||
nn=length(xx);
 | 
			
		||||
    
 | 
			
		||||
Max_obs=max(xx);
 | 
			
		||||
beta0=0;
 | 
			
		||||
Mmax1=Max_obs; 
 | 
			
		||||
            if isempty(Mmax)==0                                      %%%   K 28JUL2015
 | 
			
		||||
                	err_Mmax=0;                                      %%%   K 04DEC2019 
 | 
			
		||||
                    fun = @(b) bet_est(b,mean(xx),Mmin-eps/2,Mmax);  %%%   K 28JUL2015
 | 
			
		||||
                	x0 = 1;              %[0.05,4.0];                %%%   K 28JUL2015 - See exception line 155
 | 
			
		||||
                    beta = fzero(fun,x0);                            %%%   K 28JUL2015
 | 
			
		||||
                    err=0;                                           %%%   K 28JUL2015
 | 
			
		||||
            else                                                     %%%   K 28JUL2015  -  line 150
 | 
			
		||||
                    err_Mmax=1;                                      %%%   K 04DEC2019 
 | 
			
		||||
for i=1:50,                                                           
 | 
			
		||||
	fun = @(b) bet_est(b,mean(xx),Mmin-eps/2,Mmax1);
 | 
			
		||||
	x0 =1;           %[0.05,4.0];                               %%%   K29JUL2015 - See exception line 155
 | 
			
		||||
    beta = fzero(fun,x0);
 | 
			
		||||
  	Mmax=Max_obs+moja_calka('f_podc',Mmin,Max_obs,1e-5,nn,beta,Mmin-eps/2,Mmax1);
 | 
			
		||||
    if ((abs(Mmax-Mmax1)<0.01)&&(abs(beta-beta0)<0.0001))
 | 
			
		||||
        err=0;
 | 
			
		||||
        break;
 | 
			
		||||
    end
 | 
			
		||||
    Mmax1=Mmax;
 | 
			
		||||
    beta0=beta;
 | 
			
		||||
end
 | 
			
		||||
if i==50; 
 | 
			
		||||
    err=1.0;
 | 
			
		||||
    Mmax=2*xx(1)-xx(2);
 | 
			
		||||
fun = @(b) bet_est(b,mean(xx),Mmin-eps/2,Mmax);
 | 
			
		||||
	x0 =1;
 | 
			
		||||
    beta = fzero(fun,x0);
 | 
			
		||||
end
 | 
			
		||||
            end                                                         %%%   K 28JUL2015
 | 
			
		||||
b=beta/log(10);
 | 
			
		||||
clear xx
 | 
			
		||||
 | 
			
		||||
% Exception for v-value
 | 
			
		||||
if b<0.05 || b>6.0; error('Unacceptable b-value, abort and select different dataset');end
 | 
			
		||||
beta;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
% Estimation of Mmax Bias                                               %%%   K 04DEC2019 
 | 
			
		||||
% (Lasocki and Urban, 2011, doi:10.2478/s11600-010-0049-y)
 | 
			
		||||
if isempty(Nsynth)==0 && err_Mmax==1              % set number of synthetic datasets, e.g. 10000
 | 
			
		||||
[BIAS,SD]=Mmax_Bias_GR(t,M,Mmin,Mmax,b,err,Nsynth);
 | 
			
		||||
elseif isempty(Nsynth)==0 && err_Mmax==0;              
 | 
			
		||||
warning('Mmax must be empty for BIAS calculation');BIAS=[];SD=[];
 | 
			
		||||
else; BIAS=0;SD=0;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)               % SL 03MAR2015 
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [zero]=bet_est(b,ms,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%First derivative of the log likelihood function of the upper-bounded 
 | 
			
		||||
% exponential distribution (truncated GR model)
 | 
			
		||||
% b - parameter of the distribution 'beta'
 | 
			
		||||
% ms - mean of the observed magnitudes
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
M_max_min=Mmax-Mmin;
 | 
			
		||||
e_m=exp(-b*M_max_min);
 | 
			
		||||
zero=1/b-ms+Mmin-M_max_min*e_m/(1-e_m);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [calka,ier]=moja_calka(funfc,a,b,eps,varargin)
 | 
			
		||||
 | 
			
		||||
% Integration by means of 16th poit Gauss method. Adopted from CERNLIBRARY
 | 
			
		||||
 | 
			
		||||
% funfc - string with the name of function to be integrated
 | 
			
		||||
% a,b - integration limits
 | 
			
		||||
% eps - accurracy
 | 
			
		||||
% varargin - other parameters of function to be integrated
 | 
			
		||||
% calka - integral
 | 
			
		||||
% ier=0 - convergence, ier=1 - no conbergence
 | 
			
		||||
 | 
			
		||||
persistent W X CONST
 | 
			
		||||
W=[0.101228536290376 0.222381034453374 0.313706645877887 ...
 | 
			
		||||
0.362683783378362 0.027152459411754 0.062253523938648 ...
 | 
			
		||||
0.095158511682493 0.124628971255534 0.149595988816577 ...
 | 
			
		||||
0.169156519395003 0.182603415044924 0.189450610455069];
 | 
			
		||||
X=[0.960289856497536 0.796666477413627 0.525532409916329 ...
 | 
			
		||||
0.183434642495650 0.989400934991650 0.944575023073233 ...
 | 
			
		||||
0.865631202387832 0.755404408355003 0.617876244402644 ...
 | 
			
		||||
0.458016777657227 0.281603550779259 0.095012509837637];
 | 
			
		||||
CONST=1E-12;
 | 
			
		||||
delta=CONST*abs(a-b);
 | 
			
		||||
calka=0.;
 | 
			
		||||
aa=a;
 | 
			
		||||
y=b-aa;
 | 
			
		||||
ier=0;
 | 
			
		||||
while abs(y)>delta,
 | 
			
		||||
   bb=aa+y;
 | 
			
		||||
   c1=0.5*(aa+bb);
 | 
			
		||||
   c2=c1-aa;
 | 
			
		||||
   s8=0.;
 | 
			
		||||
   s16=0.;
 | 
			
		||||
   for i=1:4,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s8=s8+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   for i=5:12,
 | 
			
		||||
      u=X(i)*c2;
 | 
			
		||||
      s16=s16+W(i)*(feval(funfc,c1+u,varargin{:})+feval(funfc,c1-u,varargin{:}));
 | 
			
		||||
   end
 | 
			
		||||
   s8=s8*c2;
 | 
			
		||||
   s16=s16*c2;
 | 
			
		||||
   if abs(s16-s8)>eps*(1+abs(s16))
 | 
			
		||||
      y=0.5*y;
 | 
			
		||||
      calka=0.;
 | 
			
		||||
      ier=1;
 | 
			
		||||
   else
 | 
			
		||||
      calka=calka+s16;
 | 
			
		||||
      aa=bb;
 | 
			
		||||
      y=b-aa;
 | 
			
		||||
      ier=0;
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=f_podc(z,n,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
% Integrated function for Mmax estimation. Truncated GR model
 | 
			
		||||
% z - column vector of independent variable
 | 
			
		||||
% n - the size of 'z'
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% Mmin - the catalog completeness level
 | 
			
		||||
% Mmax - the upper limit of the distribution
 | 
			
		||||
 | 
			
		||||
y=Cdfgr(z,beta,Mmin,Mmax).^n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [y]=Cdfgr(t,beta,Mmin,Mmax)
 | 
			
		||||
 | 
			
		||||
%CDF of the truncated upper-bounded exponential distribution (truncated G-R
 | 
			
		||||
% model
 | 
			
		||||
% Mmin - catalog completeness level
 | 
			
		||||
% Mmax - upper limit of the distribution
 | 
			
		||||
% beta - the distribution parameter
 | 
			
		||||
% t - vector of magnitudes (independent variable)
 | 
			
		||||
% y - CDF vector
 | 
			
		||||
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin)));
 | 
			
		||||
y=(1-exp(-beta*(t-Mmin)))/mian;
 | 
			
		||||
idx=find(y>1);
 | 
			
		||||
y(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
% --------------------- Mmax BIAS estimation routine ----------------------  K 08NOV2019
 | 
			
		||||
 | 
			
		||||
function [BIAS,SD]=Mmax_Bias_GR(t,m,Mc,Mmax1,b,err,synth)
 | 
			
		||||
 | 
			
		||||
if err~=0
 | 
			
		||||
warning('process did not converge!!'),pause   
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
MAXm=max(m);beta=b*log(10);N=numel(m(m>=Mc));DeltaM=MAXm-Mc;
 | 
			
		||||
 | 
			
		||||
for j=1:synth         %set number of synthetic datasets, default is 10000 
 | 
			
		||||
% % CDF:
 | 
			
		||||
 M=Mc:0.0001:MAXm;upt=1-exp(-beta*(M-Mc));
 | 
			
		||||
 dwt=1-exp(-beta*(MAXm-Mc));F=upt./dwt;                                             % j
 | 
			
		||||
% linear interpolation to assign magnitude values from a uniform distribution sample
 | 
			
		||||
 iM=rand(1,N);M1=interp1q(F',M',iM');
 | 
			
		||||
 br(j)=1/(log(10)*(mean(M1)-min(M1)));DM=range(M1);
 | 
			
		||||
 Mmax=max(M1);
 | 
			
		||||
 | 
			
		||||
 % Iteration Process to estimate b and Mmax
 | 
			
		||||
b1=1;best=[1.0 10.0];i=1; 
 | 
			
		||||
while min(abs(diff(best)))>0.00001
 | 
			
		||||
w=exp(b1*(Mmax-Mc));E1=expint(N/(w-1));E2=expint(N*w/(w-1));
 | 
			
		||||
%E=expint(w);
 | 
			
		||||
Mme=Mmax+(E1-E2)/(b1*exp(-N/(w-1)))+(Mc)*exp(-N);    %Mme=round(Mme/EPS)*EPS;            
 | 
			
		||||
 | 
			
		||||
if isnan(Mme)
 | 
			
		||||
KM=sort(unique(M1),'descend');
 | 
			
		||||
Mme=2*KM(1)-KM(2);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
fun=@(bb) 1/bb+(Mme-Mc)/(1-exp(bb*(Mme-Mc)))-mean(M1)+Mc;  %consider th5 last 0.05 term
 | 
			
		||||
b1=fzero(fun,1);best(i)=b1;i=i+1;
 | 
			
		||||
 | 
			
		||||
if i==50
 | 
			
		||||
   warning('process did not converge!!');break 
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
be(j)=b1/log(10);
 | 
			
		||||
Me(j)=Mme;dm(j)=DM;Mm(j)=Mmax;
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
BIAS=mean(MAXm-Me)
 | 
			
		||||
SD=std(MAXm-Me);
 | 
			
		||||
 | 
			
		||||
%b-mean(be)    %check b-value difference
 | 
			
		||||
%histogram(be)
 | 
			
		||||
 | 
			
		||||
% MAXm: maximum magnitude in the real catalog 
 | 
			
		||||
% Mmax: maximum magnitudes observed in the synthetic catalogs (rounded)
 | 
			
		||||
% Me: maximum magnitude estimates for the synthetic catalogs 
 | 
			
		||||
% Mmax1: maximum magnitude estimated by GRT
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,162 +1,162 @@
 | 
			
		||||
%   [lamb_all,lamb,lmab_err,unit,eps,b]=UnlimitGR(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% ESTIMATES THE MEAN ACTIVITY RATE WITHIN THE WHOLE SAMPLE AND WITHIN THE 
 | 
			
		||||
% COMPLETE PART OF THE SAMPLE, THE ROUND-OFF ERROR OF MAGNITUDE AND THE 
 | 
			
		||||
% GUTENBERG-RICHTER B-VALUE USING THE UNLIMITED G-R LED MAGNITUDE 
 | 
			
		||||
% DISTRIBUTION MODEL 
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UNBOUNDED 
 | 
			
		||||
%       GUTENBERG-RICHETR HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2 01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value is estimated by 
 | 
			
		||||
% maximum likelihood method (Aki-Utsu procedure).  
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred. Upon the value of the input 
 | 
			
		||||
% parameter, iop, the used unit of time can be either day ot month or year.    
 | 
			
		||||
% The round-off interval length - eps if the least non-zero difference 
 | 
			
		||||
% between sample data or 0.1 is the least difference is greater than 0.1. 
 | 
			
		||||
% 
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of magnitudes from a user selected catalog
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - catalog completeness level. Must be determined externally.
 | 
			
		||||
%   can take any value from [min(M), max(M)].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 7 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
%     You should have received a copy of the GNU General Public License
 | 
			
		||||
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
%
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,b]=UnlimitGR(t,M,iop,Mmin)
 | 
			
		||||
if isempty(t) || numel(t)<3 || isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
 | 
			
		||||
if nn<7
 | 
			
		||||
    eps=0;b=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
xx=M(M>=Mmin); %K21OCT2014
 | 
			
		||||
% x=sort(M,'descend');
 | 
			
		||||
% for i=1:n
 | 
			
		||||
%      if x(i)<Mmin; break; end
 | 
			
		||||
%      xx(i)=x(i);                                                      %
 | 
			
		||||
% end
 | 
			
		||||
clear x;
 | 
			
		||||
beta=1/(mean(xx)-Mmin+eps/2);
 | 
			
		||||
b=beta/log(10);
 | 
			
		||||
clear xx
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)              % SL 03MAR2015
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
%   [lamb_all,lamb,lmab_err,unit,eps,b]=UnlimitGR(t,M,iop,Mmin)
 | 
			
		||||
%
 | 
			
		||||
% ESTIMATES THE MEAN ACTIVITY RATE WITHIN THE WHOLE SAMPLE AND WITHIN THE 
 | 
			
		||||
% COMPLETE PART OF THE SAMPLE, THE ROUND-OFF ERROR OF MAGNITUDE AND THE 
 | 
			
		||||
% GUTENBERG-RICHTER B-VALUE USING THE UNLIMITED G-R LED MAGNITUDE 
 | 
			
		||||
% DISTRIBUTION MODEL 
 | 
			
		||||
%
 | 
			
		||||
% !! THIS FUNCTION MUST BE EXECUTED AT START-UP OF THE UNBOUNDED 
 | 
			
		||||
%       GUTENBERG-RICHETR HAZARD ESTIMATION MODE !!
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki ver 2 01/2015 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value is estimated by 
 | 
			
		||||
% maximum likelihood method (Aki-Utsu procedure).  
 | 
			
		||||
% The mean activity rate, lamb, is the number of events >=Mmin into the
 | 
			
		||||
% length of the period in which they occurred. Upon the value of the input 
 | 
			
		||||
% parameter, iop, the used unit of time can be either day ot month or year.    
 | 
			
		||||
% The round-off interval length - eps if the least non-zero difference 
 | 
			
		||||
% between sample data or 0.1 is the least difference is greater than 0.1. 
 | 
			
		||||
% 
 | 
			
		||||
% INPUT:
 | 
			
		||||
%   t - vector of earthquake occurrence times
 | 
			
		||||
%   M - vector of magnitudes from a user selected catalog
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%   Mmin - catalog completeness level. Must be determined externally.
 | 
			
		||||
%   can take any value from [min(M), max(M)].
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   lamb_all - mean activity rate for all events
 | 
			
		||||
%   lamb - mean activity rate for events >= Mmin
 | 
			
		||||
%   lamb_err - error paramter on the number of events >=Mmin. lamb_err=0
 | 
			
		||||
%       for 7 or more events >=Mmin and the parameter estimation is
 | 
			
		||||
%       continued, lamb_err=1 otherwise, all output paramters except 
 | 
			
		||||
%       lamb_all and lamb are set to zero and the function execution is 
 | 
			
		||||
%       terminated.  
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
%     You should have received a copy of the GNU General Public License
 | 
			
		||||
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
%
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [lamb_all,lamb,lamb_err,unit,eps,b]=UnlimitGR(t,M,iop,Mmin)
 | 
			
		||||
if isempty(t) || numel(t)<3 || isempty(M(M>=Mmin)) %K03OCT
 | 
			
		||||
    t=[1 2];M=[1 2];   end   %K30SEP
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
lamb_err=0;
 | 
			
		||||
n=length(M);
 | 
			
		||||
t1=t(1);
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t1=t(i+1);
 | 
			
		||||
end
 | 
			
		||||
    t2=t(n);
 | 
			
		||||
for i=n:1
 | 
			
		||||
    if M(i)>=Mmin; break; end
 | 
			
		||||
    t2=t(i-1);
 | 
			
		||||
end
 | 
			
		||||
nn=0;
 | 
			
		||||
for i=1:n
 | 
			
		||||
    if M(i)>=Mmin
 | 
			
		||||
        nn=nn+1;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
[NM,unit]=time_diff(t(1),t(n),iop);    
 | 
			
		||||
lamb_all=n/NM;
 | 
			
		||||
[NM,unit]=time_diff(t1,t2,iop);        
 | 
			
		||||
lamb=nn/NM;
 | 
			
		||||
% SL 03MAR2015 ----------------------------------
 | 
			
		||||
 | 
			
		||||
if nn<7
 | 
			
		||||
    eps=0;b=0;
 | 
			
		||||
    lamb_err=1;
 | 
			
		||||
    return;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
eps=magn_accur(M);
 | 
			
		||||
xx=M(M>=Mmin); %K21OCT2014
 | 
			
		||||
% x=sort(M,'descend');
 | 
			
		||||
% for i=1:n
 | 
			
		||||
%      if x(i)<Mmin; break; end
 | 
			
		||||
%      xx(i)=x(i);                                                      %
 | 
			
		||||
% end
 | 
			
		||||
clear x;
 | 
			
		||||
beta=1/(mean(xx)-Mmin+eps/2);
 | 
			
		||||
b=beta/log(10);
 | 
			
		||||
clear xx
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [NM,unit]=time_diff(t1,t2,iop)              % SL 03MAR2015
 | 
			
		||||
 | 
			
		||||
% TIME DIFFERENCE BETWEEEN t1,t2 EXPRESSED IN DAY, MONTH OR YEAR UNIT
 | 
			
		||||
%
 | 
			
		||||
% t1 - start time (in MATLAB numerical format)
 | 
			
		||||
% t2 - end time (in MATLAB numerical format)  t2>=t1
 | 
			
		||||
%   iop - determines the used unit of time. iop=0 - 'day', iop=1 - 'month', 
 | 
			
		||||
%       iop=2 - 'year'
 | 
			
		||||
%
 | 
			
		||||
%   NM - number of time units from t1 to t2
 | 
			
		||||
%   unit - string with name of time unit used ('year' or 'month' or 'day').
 | 
			
		||||
 | 
			
		||||
if iop==0
 | 
			
		||||
    NM=(t2-t1);
 | 
			
		||||
    unit='day';
 | 
			
		||||
elseif iop==1
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM=V2(3)/eomday(V2(1),V2(2))+V2(2)+12-V1(2)-V1(3)/eomday(V1(1),V1(2))...
 | 
			
		||||
        +(V2(1)-V1(1)-1)*12;
 | 
			
		||||
    unit='month';
 | 
			
		||||
else
 | 
			
		||||
    V1=datevec(t1);
 | 
			
		||||
    V2=datevec(t2);
 | 
			
		||||
    NM2=V2(3);
 | 
			
		||||
    if V2(2)>1
 | 
			
		||||
        for k=1:V2(2)-1
 | 
			
		||||
            NM2=NM2+eomday(V2(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day2=365; if eomday(V2(1),2)==29; day2=366; end;
 | 
			
		||||
    NM2=NM2/day2;
 | 
			
		||||
    NM1=V1(3);
 | 
			
		||||
    if V1(2)>1
 | 
			
		||||
        for k=1:V1(2)-1
 | 
			
		||||
            NM1=NM1+eomday(V1(1),k);
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    day1=365; if eomday(V1(1),2)==29; day1=366; end;
 | 
			
		||||
    NM1=(day1-NM1)/day1;
 | 
			
		||||
    NM=NM2+NM1+V2(1)-V1(1)-1;
 | 
			
		||||
    unit='year';
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [eps]=magn_accur(M)
 | 
			
		||||
x=sort(M);
 | 
			
		||||
d=x(2:length(x))-x(1:length(x)-1);
 | 
			
		||||
eps=min(d(d>0));
 | 
			
		||||
if eps>0.1; eps=0.1;end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -1,64 +1,64 @@
 | 
			
		||||
%   [m, PDF_GRT, CDF_GRT]=dist_GRT(Md,Mu,dM,Mmin,eps,b,Mmax)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE DENSITY AND CUMULATIVE DISTRIBUTION FUNCTIONS OF MAGNITUDE
 | 
			
		||||
%   UNDER THE UPPER-BOUNDED G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distribution Mmax are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% upper-bounded Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The distribution function values are calculated for magnitude starting 
 | 
			
		||||
% from Md up to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of the independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   PDF_GRT - PDF vector of the same length as m
 | 
			
		||||
%   CDF_GRT - CDF vector of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [m, PDF_GRT, CDF_GRT]=dist_GRT(Md,Mu,dM,Mmin,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin+eps/2))); 
 | 
			
		||||
PDF_GRT=beta*exp(-beta*(m-Mmin+eps/2))/mian;
 | 
			
		||||
CDF_GRT=(1-exp(-beta*(m-Mmin+eps/2)))/mian;
 | 
			
		||||
idx=find(CDF_GRT<0);
 | 
			
		||||
PDF_GRT(idx)=zeros(size(idx));CDF_GRT(idx)=zeros(size(idx));
 | 
			
		||||
idx=find(CDF_GRT>1);
 | 
			
		||||
PDF_GRT(idx)=zeros(size(idx));CDF_GRT(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [m, PDF_GRT, CDF_GRT]=dist_GRT(Md,Mu,dM,Mmin,eps,b,Mmax)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE DENSITY AND CUMULATIVE DISTRIBUTION FUNCTIONS OF MAGNITUDE
 | 
			
		||||
%   UNDER THE UPPER-BOUNDED G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
 | 
			
		||||
% relation leads to the upper truncated exponential distribution to model 
 | 
			
		||||
% magnitude distribution from and above the catalog completness level 
 | 
			
		||||
% Mmin. The shape parameter of this distribution, consequently the G-R
 | 
			
		||||
% b-value and the end-point of the distribution Mmax are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% upper-bounded Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The distribution function values are calculated for magnitude starting 
 | 
			
		||||
% from Md up to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of the independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   PDF_GRT - PDF vector of the same length as m
 | 
			
		||||
%   CDF_GRT - CDF vector of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [m, PDF_GRT, CDF_GRT]=dist_GRT(Md,Mu,dM,Mmin,eps,b,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
mian=(1-exp(-beta*(Mmax-Mmin+eps/2))); 
 | 
			
		||||
PDF_GRT=beta*exp(-beta*(m-Mmin+eps/2))/mian;
 | 
			
		||||
CDF_GRT=(1-exp(-beta*(m-Mmin+eps/2)))/mian;
 | 
			
		||||
idx=find(CDF_GRT<0);
 | 
			
		||||
PDF_GRT(idx)=zeros(size(idx));CDF_GRT(idx)=zeros(size(idx));
 | 
			
		||||
idx=find(CDF_GRT>1);
 | 
			
		||||
PDF_GRT(idx)=zeros(size(idx));CDF_GRT(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,61 +1,61 @@
 | 
			
		||||
%   [m, PDF_GRU, CDF_GRU]=dist_GRU(Md,Mu,dM,Mmin,eps,b)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE DENSITY AND CUMULATIVE DISTRIBUTION FUNCTIONS OF MAGNITUDE 
 | 
			
		||||
%   UNDER THE UNLIMITED G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The distribution function values are calculated for magnitude starting 
 | 
			
		||||
% from Md up to Mu with step dM.
 | 
			
		||||
% 
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of the independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   PDF_GRT - PDF vector of the same length as m
 | 
			
		||||
%   CDF_GRT - CDF vector of the same length as m
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m, PDF_GRU, CDF_GRU]=dist_GRU(Md,Mu,dM,Mmin,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
PDF_GRU=beta*exp(-beta*(m-Mmin+eps/2));
 | 
			
		||||
CDF_GRU=1-exp(-beta*(m-Mmin+eps/2));
 | 
			
		||||
idx=find(CDF_GRU<0);
 | 
			
		||||
PDF_GRU(idx)=zeros(size(idx));CDF_GRU(idx)=zeros(size(idx));
 | 
			
		||||
idx=find(CDF_GRU>1);
 | 
			
		||||
PDF_GRU(idx)=zeros(size(idx));CDF_GRU(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [m, PDF_GRU, CDF_GRU]=dist_GRU(Md,Mu,dM,Mmin,eps,b)
 | 
			
		||||
%
 | 
			
		||||
% EVALUATES THE DENSITY AND CUMULATIVE DISTRIBUTION FUNCTIONS OF MAGNITUDE 
 | 
			
		||||
%   UNDER THE UNLIMITED G-R LED MAGNITUDE DISTRIBUTION MODEL. 
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The assumption on the unlimited Gutenberg-Richter relation 
 | 
			
		||||
% leads to the exponential distribution model of magnitude distribution 
 | 
			
		||||
% from and above the catalog completness level Mmin. The shape parameter of 
 | 
			
		||||
% this distribution and consequently the G-R b-value are calculated at 
 | 
			
		||||
% start-up of the stationary hazard assessment services in the
 | 
			
		||||
% unlimited Gutenberg-Richter estimation mode.
 | 
			
		||||
%
 | 
			
		||||
% The distribution function values are calculated for magnitude starting 
 | 
			
		||||
% from Md up to Mu with step dM.
 | 
			
		||||
% 
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of the round-off interval of magnitudes.
 | 
			
		||||
%   b - Gutenberg-Richter b-value
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT:
 | 
			
		||||
%   m - vector of the independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   PDF_GRT - PDF vector of the same length as m
 | 
			
		||||
%   CDF_GRT - CDF vector of the same length as m
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m, PDF_GRU, CDF_GRU]=dist_GRU(Md,Mu,dM,Mmin,eps,b)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
beta=b*log(10);
 | 
			
		||||
PDF_GRU=beta*exp(-beta*(m-Mmin+eps/2));
 | 
			
		||||
CDF_GRU=1-exp(-beta*(m-Mmin+eps/2));
 | 
			
		||||
idx=find(CDF_GRU<0);
 | 
			
		||||
PDF_GRU(idx)=zeros(size(idx));CDF_GRU(idx)=zeros(size(idx));
 | 
			
		||||
idx=find(CDF_GRU>1);
 | 
			
		||||
PDF_GRU(idx)=zeros(size(idx));CDF_GRU(idx)=ones(size(idx));
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,116 +1,116 @@
 | 
			
		||||
%   [m,PDF_NPT,CDF_NPT]=dist_NPT(Md,Mu,dM,Mmin,eps,h,xx,ambd,Mmax)
 | 
			
		||||
%
 | 
			
		||||
% USING THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS EVALUATES THE DENSITY 
 | 
			
		||||
%   AND CUMULATIVE DISTRIBUTION FUNCTIONS FOR THE UPPER-BOUNDED MAGNITUDE 
 | 
			
		||||
%   DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   m - vector of the independent variable (magnitude)
 | 
			
		||||
%   PDF_NPT - PDF vector
 | 
			
		||||
%   CDF_NPT - CDF vector
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,PDF_NPT,CDF_NPT]=dist_NPT(Md,Mu,dM,Mmin,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
nn=length(m);
 | 
			
		||||
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
for i=1:nn
 | 
			
		||||
    if m(i)<Mmin-eps/2
 | 
			
		||||
        PDF_NPT(i)=0;CDF_NPT(i)=0;
 | 
			
		||||
    elseif m(i)>Mmax
 | 
			
		||||
        PDF_NPT(i)=0;CDF_NPT(i)=1;
 | 
			
		||||
    else
 | 
			
		||||
    PDF_NPT(i)=dens_npr1(m(i),xx,ambd,h,Mmin-eps/2)/mian;
 | 
			
		||||
    CDF_NPT(i)=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h))/mian;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
PDF_NPT=PDF_NPT';CDF_NPT=CDF_NPT';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [gau]=dens_npr1(y,x,ambd,h,x1)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive density for a variable from the interval [x1,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data doubled and sorted in the ascending order. Use 
 | 
			
		||||
%   "podwajanie.m" first to accmoplish that.
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
if y<x1
 | 
			
		||||
    gau=0;
 | 
			
		||||
else
 | 
			
		||||
    gau=2*sum(exp(-0.5*(((y-x)./ambd')./h).^2)./ambd')/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [m,PDF_NPT,CDF_NPT]=dist_NPT(Md,Mu,dM,Mmin,eps,h,xx,ambd,Mmax)
 | 
			
		||||
%
 | 
			
		||||
% USING THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS EVALUATES THE DENSITY 
 | 
			
		||||
%   AND CUMULATIVE DISTRIBUTION FUNCTIONS FOR THE UPPER-BOUNDED MAGNITUDE 
 | 
			
		||||
%   DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution has a hard end point Mmax from the right hand  
 | 
			
		||||
% side.The estimation makes use of the previously estimated parameters 
 | 
			
		||||
% namely the mean activity rate lamb, the length of magnitude round-off 
 | 
			
		||||
% interval, eps, the smoothing factor, h, the background sample, xx, the 
 | 
			
		||||
% scaling factors for the background sample, ambd, and the end-point of 
 | 
			
		||||
% magnitude distribution Mmax. The background sample,xx, comprises the 
 | 
			
		||||
% randomized values of observed magnitude doubled symmetrically with 
 | 
			
		||||
% respect to the value Mmin-eps/2.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%  Silverman B.W. (1986) Density Estimation for Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%  Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%  Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%   Mmax - upper limit of magnitude distribution
 | 
			
		||||
%
 | 
			
		||||
% OUTPUT:
 | 
			
		||||
%   m - vector of the independent variable (magnitude)
 | 
			
		||||
%   PDF_NPT - PDF vector
 | 
			
		||||
%   CDF_NPT - CDF vector
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m,PDF_NPT,CDF_NPT]=dist_NPT(Md,Mu,dM,Mmin,eps,h,xx,ambd,Mmax)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
nn=length(m);
 | 
			
		||||
 | 
			
		||||
mian=2*(Dystr_npr(Mmax,xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
for i=1:nn
 | 
			
		||||
    if m(i)<Mmin-eps/2
 | 
			
		||||
        PDF_NPT(i)=0;CDF_NPT(i)=0;
 | 
			
		||||
    elseif m(i)>Mmax
 | 
			
		||||
        PDF_NPT(i)=0;CDF_NPT(i)=1;
 | 
			
		||||
    else
 | 
			
		||||
    PDF_NPT(i)=dens_npr1(m(i),xx,ambd,h,Mmin-eps/2)/mian;
 | 
			
		||||
    CDF_NPT(i)=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h))/mian;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
PDF_NPT=PDF_NPT';CDF_NPT=CDF_NPT';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [gau]=dens_npr1(y,x,ambd,h,x1)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive density for a variable from the interval [x1,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data doubled and sorted in the ascending order. Use 
 | 
			
		||||
%   "podwajanie.m" first to accmoplish that.
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
if y<x1
 | 
			
		||||
    gau=0;
 | 
			
		||||
else
 | 
			
		||||
    gau=2*sum(exp(-0.5*(((y-x)./ambd')./h).^2)./ambd')/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,114 +1,114 @@
 | 
			
		||||
%   [m, PDF_NPU, CDF_NPU]=dist_NPU(Md,Mu,dM,Mmin,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
% USING THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS EVALUATES THE DENSITY 
 | 
			
		||||
%   AND CUMULATIVE DISTRIBUTION FUNCTIONS FOR THE UNLIMITED MAGNITUDE 
 | 
			
		||||
%   DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2 
 | 
			
		||||
% 
 | 
			
		||||
% The distribution function values are calculated for magnitude starting 
 | 
			
		||||
% from Md up to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT
 | 
			
		||||
% m - vector of the independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   PDF_NPU - PDF vector of the same length as m
 | 
			
		||||
%   CDF_NPU - CDF vector of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m, PDF_NPU, CDF_NPU]=dist_NPU(Md,Mu,dM,Mmin,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
nn=length(m);
 | 
			
		||||
 | 
			
		||||
for i=1:nn
 | 
			
		||||
    if m(i)>=Mmin-eps/2
 | 
			
		||||
        PDF_NPU(i)=dens_npr1(m(i),xx,ambd,h,Mmin-eps/2);
 | 
			
		||||
        CDF_NPU(i)=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
    else
 | 
			
		||||
        PDF_NPU(i)=0;
 | 
			
		||||
        CDF_NPU(i)=0;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
PDF_NPU=PDF_NPU';CDF_NPU=CDF_NPU';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [gau]=dens_npr1(y,x,ambd,h,x1)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive density for a variable from the interval [x1,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data doubled and sorted in the ascending order. Use 
 | 
			
		||||
%   "podwajanie.m" first to accmoplish that.
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
if y<x1
 | 
			
		||||
    gau=0;
 | 
			
		||||
else
 | 
			
		||||
    gau=2*sum(exp(-0.5*(((y-x)./ambd')./h).^2)./ambd')/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
%   [m, PDF_NPU, CDF_NPU]=dist_NPU(Md,Mu,dM,Mmin,eps,h,xx,ambd)
 | 
			
		||||
%
 | 
			
		||||
% USING THE NONPARAMETRIC ADAPTATIVE KERNEL ESTIMATORS EVALUATES THE DENSITY 
 | 
			
		||||
%   AND CUMULATIVE DISTRIBUTION FUNCTIONS FOR THE UNLIMITED MAGNITUDE 
 | 
			
		||||
%   DISTRIBUTION.
 | 
			
		||||
%
 | 
			
		||||
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
 | 
			
		||||
%
 | 
			
		||||
% DESCRIPTION: The kernel estimator approach is a model-free alternative 
 | 
			
		||||
% to estimating the magnitude distribution functions. It is assumed that 
 | 
			
		||||
% the magnitude distribution is unlimited from the right hand side. 
 | 
			
		||||
% The estimation makes use of the previously estimated parameters of kernel 
 | 
			
		||||
% estimation, namely the smoothing factor, the background sample and the 
 | 
			
		||||
% scaling factors for the background sample. The background sample 
 | 
			
		||||
% - xx comprises the randomized values of observed magnitude doubled 
 | 
			
		||||
% symmetrically with respect to the value Mmin-eps/2 
 | 
			
		||||
% 
 | 
			
		||||
% The distribution function values are calculated for magnitude starting 
 | 
			
		||||
% from Md up to Mu with step dM.
 | 
			
		||||
%
 | 
			
		||||
% REFERENCES:
 | 
			
		||||
%Silverman B.W. (1986) Density Estimation fro Statistics and Data Analysis, 
 | 
			
		||||
%   Chapman and Hall, London 
 | 
			
		||||
%Kijko A., Lasocki S., Graham G. (2001) Pure appl. geophys. 158, 1655-1665
 | 
			
		||||
%Lasocki S., Orlecka-Sikora B. (2008) Tectonophysics 456, 28-37
 | 
			
		||||
%
 | 
			
		||||
%INPUT:
 | 
			
		||||
%   Md - starting magnitude for distribution functions calculations
 | 
			
		||||
%   Mu - ending magnitude for distribution functions calculations
 | 
			
		||||
%   dM - magnitude step for distribution functions calculations
 | 
			
		||||
%   Mmin - lower bound of the distribution - catalog completeness level
 | 
			
		||||
%   eps - length of round-off interval of magnitudes.  
 | 
			
		||||
%   h - kernel smoothing factor.
 | 
			
		||||
%   xx - the background sample
 | 
			
		||||
%   ambd - the weigthing factors for the adaptive kernel
 | 
			
		||||
%
 | 
			
		||||
%
 | 
			
		||||
%OUTPUT
 | 
			
		||||
% m - vector of the independent variable (magnitude) m=(Md:dM:Mu)
 | 
			
		||||
%   PDF_NPU - PDF vector of the same length as m
 | 
			
		||||
%   CDF_NPU - CDF vector of the same length as m
 | 
			
		||||
%
 | 
			
		||||
% LICENSE
 | 
			
		||||
%     This file is a part of the IS-EPOS e-PLATFORM.
 | 
			
		||||
%
 | 
			
		||||
%     This is free software: you can redistribute it and/or modify it under 
 | 
			
		||||
%     the terms of the GNU General Public License as published by the Free 
 | 
			
		||||
%     Software Foundation, either version 3 of the License, or 
 | 
			
		||||
%     (at your option) any later version.
 | 
			
		||||
% 
 | 
			
		||||
%     This program is distributed in the hope that it will be useful,
 | 
			
		||||
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
%     GNU General Public License for more details.
 | 
			
		||||
% 
 | 
			
		||||
 | 
			
		||||
function [m, PDF_NPU, CDF_NPU]=dist_NPU(Md,Mu,dM,Mmin,eps,h,xx,ambd)
 | 
			
		||||
 | 
			
		||||
% -------------- VALIDATION RULES -------------  K_21NOV2016
 | 
			
		||||
 if dM<=0;error('Magnitude Step must be greater than 0');end
 | 
			
		||||
%----------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
m=(Md:dM:Mu)';
 | 
			
		||||
nn=length(m);
 | 
			
		||||
 | 
			
		||||
for i=1:nn
 | 
			
		||||
    if m(i)>=Mmin-eps/2
 | 
			
		||||
        PDF_NPU(i)=dens_npr1(m(i),xx,ambd,h,Mmin-eps/2);
 | 
			
		||||
        CDF_NPU(i)=2*(Dystr_npr(m(i),xx,ambd,h)-Dystr_npr(Mmin-eps/2,xx,ambd,h));
 | 
			
		||||
    else
 | 
			
		||||
        PDF_NPU(i)=0;
 | 
			
		||||
        CDF_NPU(i)=0;
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
PDF_NPU=PDF_NPU';CDF_NPU=CDF_NPU';
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function [gau]=dens_npr1(y,x,ambd,h,x1)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive density for a variable from the interval [x1,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data doubled and sorted in the ascending order. Use 
 | 
			
		||||
%   "podwajanie.m" first to accmoplish that.
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
c=sqrt(2*pi);
 | 
			
		||||
if y<x1
 | 
			
		||||
    gau=0;
 | 
			
		||||
else
 | 
			
		||||
    gau=2*sum(exp(-0.5*(((y-x)./ambd')./h).^2)./ambd')/c/n/h;
 | 
			
		||||
end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function [Fgau]=Dystr_npr(y,x,ambd,h)
 | 
			
		||||
 | 
			
		||||
%Nonparametric adaptive cumulative distribution for a variable from the
 | 
			
		||||
%interval (-inf,inf)
 | 
			
		||||
 | 
			
		||||
% x - the sample data 
 | 
			
		||||
% ambd - the local scaling factors for the adaptive estimation 
 | 
			
		||||
% h - the optimal smoothing factor 
 | 
			
		||||
% y - the value of random variable X for which the density is calculated
 | 
			
		||||
% gau - the density value f(y)
 | 
			
		||||
 | 
			
		||||
n=length(x);
 | 
			
		||||
Fgau=sum(normcdf(((y-x)./ambd')./h))/n;
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user