Home > 02-Probability > fig_2_9_and_16_11_simulate_hom_inhom_profiles_gaussian.m

fig_2_9_and_16_11_simulate_hom_inhom_profiles_gaussian

PURPOSE ^

% Fig. 2.9 page 51 and Fig 16.11 page 742

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% Fig. 2.9 page 51 and Fig 16.11 page 742 
 simulate homgeneous/inhomogeneous 1D gaussian process

 Wolfgang Förstner 2015
 last changes: Susanne Wenzel 09/16
 wfoerstn@uni-bonn.de, wenzel@igg.uni-bonn.de

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% Fig. 2.9 page 51 and Fig 16.11 page 742
0002 % simulate homgeneous/inhomogeneous 1D gaussian process
0003 %
0004 % Wolfgang Förstner 2015
0005 % last changes: Susanne Wenzel 09/16
0006 % wfoerstn@uni-bonn.de, wenzel@igg.uni-bonn.de
0007 
0008 close all
0009 
0010 addpath(genpath('../General_Functions/'));
0011 
0012 %% set your parameters ------------------------------------------
0013 NoSample = 3;       % number of smaples for the plot, <5
0014 N = 300;            % number of grid points
0015 
0016 % parameters for homogeneous  gaussian process
0017 d0 = 20;            % reference distance
0018 sigma = 1;          % standard deviation
0019 
0020 % parameters for inhomogeneous  gaussian process
0021 d0l = 10;               % left reference distance
0022 sigma_l = 0.5;          % left std
0023 d0r = 40;               % right reference distance
0024 sigma_r = 3;            % right standard deviation
0025 dc = 30;                % smearing constant
0026 
0027 %---------------------------------------------------------------
0028 
0029 %% prepare visualization
0030 % line spec
0031 col=['k','b','r','c','m'];
0032 lin=['-','-','-','-','-'];
0033 
0034 % get current screensize, for proper positioning of figures and set default
0035 % plot settings
0036 ss = plot_init;
0037   
0038 %% homogeneous GP
0039 
0040 % initiate covariance matrix
0041 Sigma=zeros(N);  
0042 % generate 300x300 covariance matrix
0043 for n = 1:N
0044     for m = 1:N
0045         d = (n-m)/d0;
0046         Sigma(n,m) = sigma^2*exp(-d^2/2);
0047     end
0048 end
0049 
0050 % generate three samples
0051 y = rand_gauss(zeros(N,1),Sigma,NoSample);
0052 
0053 % plot samples
0054 figure('name','homogeneous GP','color','w','Position',[0.1*ss(1),0.2*ss(2),0.35*ss(1),0.60*ss(2)]); hold on
0055 for s = 1:NoSample
0056     plot(1:N,y(:,s),strcat(lin(s),col(s)),'LineWidth',2);
0057 end
0058 plot(1:N, -3*sigma*ones(1,N),'--k')
0059 plot(1:N, +3*sigma*ones(1,N),'--k')
0060 xlim([-25,N+25])
0061 ylim([-4.5,+4.5]*sigma)
0062 xlabel('$t$');ylabel('$x$')
0063 title('Fig. 2.9: Samples of homogeneous Gaussian Process')
0064 
0065 
0066 %% inhomogeneous GP
0067 
0068 % initiate covariance matrix
0069 Sigma=zeros(N);  
0070 % generate left upper covariance matrix
0071 for n=1:N/2
0072     for m=1:N/2
0073         d=(n-m)/d0l;
0074         % smear sigma using sigmoid function
0075         sig = (sigma_r+(sigma_l-sigma_r)./(1+exp(-(n-N/2)./N.*dc)))*...
0076               (sigma_r+(sigma_l-sigma_r)./(1+exp(-(m-N/2)./N.*dc)));
0077         Sigma(n,m)=sig*exp(-d^2/2);
0078     end
0079 end
0080 % generate right lower covariance matrix
0081 for n=N/2+1:N
0082     for m=N/2+1:N
0083         d=(n-m)/d0r;
0084         % smear sigma using sigmoid function
0085         sig = (sigma_r+(sigma_l-sigma_r)./(1+exp(-(n-N/2)./N.*dc)))*...
0086               (sigma_r+(sigma_l-sigma_r)./(1+exp(-(m-N/2)./N.*dc)));
0087         Sigma(n,m)=sig*exp(-d^2/2);
0088     end
0089 end
0090 % generate  right upper covariance matrix
0091 for n=1:N/2
0092     for m=N/2+1:N
0093         % take mean distance
0094         d=abs(N/2+1/2-n)/d0l + abs(m-N/2-1/2)/d0r;
0095         % smear sigma using sigmoid function
0096         sig = (sigma_r+(sigma_l-sigma_r)./(1+exp(-(n-N/2)./N.*dc)))*...
0097               (sigma_r+(sigma_l-sigma_r)./(1+exp(-(m-N/2)./N.*dc)));
0098         Sigma(n,m) = sig*exp(-d^2/2);
0099         % fill symmetric part
0100         Sigma(m,n) = Sigma(n,m);
0101     end
0102 end
0103 
0104 % generate samples
0105 y = rand_gauss(zeros(N,1),Sigma,NoSample);
0106 
0107 % prepare plot
0108 rang = N:-1:1;
0109 figure('name','inhomogeneous GP','color','w','Position',[0.55*ss(1),0.2*ss(2),0.35*ss(1),0.60*ss(2)]);hold on
0110 % plot samples: y + 3*sigma(smeared)
0111 for s = 1:NoSample
0112     plot(1:N,y(rang,s)'+...
0113         3*(sigma_r+...
0114         (sigma_l-sigma_r)./(1+exp(-(rang-N/2)./N*dc))),...
0115         strcat(lin(s),col(s)),'LineWidth',3);
0116 end
0117 xlabel('$x$');ylabel('$z$')
0118 title('Fig. 16.11: Samples of inhomogeneous profiles')

Generated on Mon 08-Jan-2018 17:21:49 by m2html © 2005