Rank: 177 based on 512 downloads (last 30 days) and 14 files submitted
photo

Wolfgang Schwanghart

E-mail
Company/University
University of Postdam

Personal Profile:
Professional Interests:
GIS, Physical Geography, Hydrology

 

Watch this Author's files

 

Files Posted by Wolfgang View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
09 Jan 2013 Screenshot Experimental (Semi-) Variogram calculate the isotropic and anisotropic experimental (semi-) variogram Author: Wolfgang Schwanghart geostatistics, spatial modelling, variogram, dimensions, kriging, earth science 106 40
  • 4.93333
4.9 | 17 ratings
14 Oct 2010 Screenshot Ordinary Kriging 2D-interpolation using geostatistics Author: Wolfgang Schwanghart geostatistics, variogram, kriging 110 10
  • 3.875
3.9 | 8 ratings
14 Oct 2010 Screenshot variogramfit fits different theoretical variograms to an experimental variogram Author: Wolfgang Schwanghart variogram, geostatistics, spatial statistics, kriging, optimization, statistics 91 27
  • 5.0
5.0 | 8 ratings
13 Jul 2010 Screenshot Line Simplification Recursive Douglas-Peucker Polyline Simplification (Iterative Endpoint Fit) Author: Wolfgang Schwanghart approximation, interpolation, polyline, vertex reduction, mathematics, approximations 62 10
  • 5.0
5.0 | 3 ratings
21 Sep 2009 Screenshot cropmat crop arrays with axis-aligned minimum bounding box Author: Wolfgang Schwanghart matrix manipulation, matrix, image processing 14 0
  • 2.0
2.0 | 1 rating
Comments and Ratings by Wolfgang View all
Updated File Comments Rating
23 Oct 2014 variogramfit fits different theoretical variograms to an experimental variogram Author: Wolfgang Schwanghart

@steve: thanks for your comment. variofun is a subfunction that you'll find below the main function.

26 Apr 2014 Find Network Components Find network components, sizes, and lists of member nodes. Author: Daniel Larremore

Hi, you might also want to take a look at Tim Davis' function find_components: http://www.mathworks.com/matlabcentral/fileexchange/21366-find-components
find_components uses the builtin function dmperm to find connected components.

26 Feb 2014 variogramfit fits different theoretical variograms to an experimental variogram Author: Wolfgang Schwanghart

@Roque Santos: Hi, see here: http://blogs.mathworks.com/community/2010/12/13/citing-file-exchange-submissions/

06 Jan 2014 variogramfit fits different theoretical variograms to an experimental variogram Author: Wolfgang Schwanghart

@Roque Santos: thanks for your comment. Please check the documentation for varargin here: http://www.mathworks.de/de/help/matlab/ref/varargin.html

06 Dec 2013 Experimental (Semi-) Variogram calculate the isotropic and anisotropic experimental (semi-) variogram Author: Wolfgang Schwanghart

@JG: Yes, [x y] can also be a nx1 vector with n number of points in time. Use datenum to calculate a numeric vector from your dates. Variogram doesn't do the conversion for you.

Comments and Ratings on Wolfgang's Files View all
Updated File Comment by Comments Rating
23 Oct 2014 variogramfit fits different theoretical variograms to an experimental variogram Author: Wolfgang Schwanghart steve

function [a,c,n,S] = variogramfit(h,gammaexp,a0,c0,numobs,varargin)

h=[2.238; 2; 3; 5.657; 2.238; 1.414;3.606; 3.606; 4.472; 4.123];
gammaexp=[12.5; 12.5; 0; 112.5; 0; 12.5; 50; 12.5; 50; 112.5];
a0=[];
c0=[];
numobs=10;

% check input arguments

if ~exist('a0','var') || isempty(a0)
a0 = max(h)*2/3;
end
if ~exist('c0','var') || isempty(c0)
c0 = max(gammaexp);
end
if ~exist('numobs','var') || isempty(a0)
numobs = [];
end
% check input parameters
params.model = 'spherical';
params.nugget = [];
params.plotit = true;
params.stablealpha = 1.5;
params.solver ='fminsearch';
params.weightfun = 'cressie85';
params.nu = 1;

% check if fminsearchbnd is in the search path
switch lower(params.solver)
case 'fminsearchbnd'
if ~exist('fminsearchbnd.m','file')==2
params.solver = 'fminsearch';
warning('Variogramfit:fminsearchbnd',...
'fminsearchbnd was not found. fminsearch is used instead')
end
end

% check if h and gammaexp are vectors and have the same size
if ~isvector(h) || ~isvector(gammaexp)
error('Variogramfit:inputargs',...
'h and gammaexp must be vectors');
end
% check size of supplied vectors
if numel(h) ~= numel(gammaexp)
error('Variogramfit:inputargs',...
'h and gammaexp must have same size');
end
% remove nans;
nans = isnan(h) | isnan(gammaexp);
if any(nans);
h(nans) = [];
gammaexp(nans) = [];
if ~isempty(numobs)
numobs(nans) = [];
end
end
% check weight inputs
if isempty(numobs);
params.weightfun = 'none';
end
b(1)=a0;
b(2)=c0;
b0 = [a0 c0 params.nugget];

switch lower(params.model)
case 'spherical'
type = 'bounded';
func = @(b,h)b(2)*((3*h./(2*b(1)))-1/2*(h./b(1)).^3);

case 'exponential'
type = 'unbounded';
func = @(b,h)b(2)*(1-exp(-h./b(1)));
otherwise
error('unknown model')
end

% nugget variance
if isempty(params.nugget)
nugget = false;
funnugget = @(b) 0;
else
nugget = true;
funnugget = @(b) b(3);
end

% create weights (see Webster and Oliver)
switch lower(params.weightfun)
case 'cressie85'
weights = @(b,h) (numobs./variofun(b,h).^2)./sum(numobs./variofun(b,h).^2);
case 'mcbratney86'
weights = @(b,h) (numobs.*gammaexp./variofun(b,h).^3)/sum(numobs.*gammaexp./variofun(b,h).^3);
otherwise
weights = @(b,h) 1;
end

% create objective function: weighted least square
objectfun = @(b)sum(((variofun(b,h)-gammaexp).^2).*weights(b,h));
% call solver
switch lower(params.solver)
case 'fminsearch'
% call fminsearch
[b,fval,exitflag,output] = fminsearch(objectfun,b0);
case 'fminsearchbnd'
% call fminsearchbnd
[b,fval,exitflag,output] = fminsearchbnd(objectfun,b0,lb,ub);
otherwise
error('Variogramfit:Solver','unknown or unsupported solver')
end

% create vector with initial values
a = b(1); %range
c = b(2); %sill
b0 = [a0 c0 params.nugget];

if nugget;
n = b(3);%nugget
else
n = [];
end
% Create structure array with results
if nargout == 4;
S.model = lower(params.model); % model
S.func = func;
S.type = type;
switch S.model
case 'matern';
S.nu = params.nu;
case 'stable';
S.stablealpha = params.stablealpha;
end


S.range = a;
S.sill = c;
S.nugget = n;
S.h = h; % distance
S.gamma = gammaexp; % experimental values
S.gammahat = variofun(b,h); % estimated values
S.residuals = gammaexp-S.gammahat; % residuals
COVyhaty = cov(S.gammahat,gammaexp);
S.Rs = (COVyhaty(2).^2) ./...
(var(S.gammahat).*var(gammaexp)); % Rsquare
S.weights = weights(b,h); %weights
S.weightfun = params.weightfun;
S.exitflag = exitflag; % exitflag (see doc fminsearch)
S.algorithm = output.algorithm;
S.funcCount = output.funcCount;
S.iterations= output.iterations;
S.message = output.message;
end
% if you want to plot the results...
if params.plotit
switch lower(type)
case 'bounded'
plot(h,gammaexp,'rs','MarkerSize',10);
hold on
fplot(@(h) funnugget(b) + func(b,h),[0 b(1)])
fplot(@(h) funnugget(b) + b(2),[b(1) max(h)])

case 'unbounded'
plot(h,gammaexp,'rs','MarkerSize',10);
hold on
fplot(@(h) funnugget(b) + func(b,h),[0 max(h)])
end
axis([0 max(h) 0 max(gammaexp)])
xlabel('lag distance h')
ylabel('\gamma(h)')
hold off
end

% fitting functions for fminsearch/bnd
function gammahat = variofun(b,h)

switch type
% bounded model
case 'bounded'
I = h<=b(1);
gammahat = zeros(size(I));
gammahat(I) = funnugget(b) + func(b,h(I));
gammahat(~I) = funnugget(b) + b(2);
% unbounded model
case 'unbounded'
gammahat = funnugget(b) + func(b,h);
if flagzerodistances
gammahat(izero) = funnugget(b);
end
end
end

end

23 Oct 2014 variogramfit fits different theoretical variograms to an experimental variogram Author: Wolfgang Schwanghart steve

look at that code and please advice me accordingly. i am trying to come up with a variogram for modeling but i just cannot get through. thanks

23 Oct 2014 variogramfit fits different theoretical variograms to an experimental variogram Author: Wolfgang Schwanghart Schwanghart, Wolfgang

@steve: thanks for your comment. variofun is a subfunction that you'll find below the main function.

23 Oct 2014 variogramfit fits different theoretical variograms to an experimental variogram Author: Wolfgang Schwanghart steve

nice work there. what am wondering is what does variofun mean? since am trying to run that code am being told that it is an undefined variable. please help

09 Apr 2014 Experimental (Semi-) Variogram calculate the isotropic and anisotropic experimental (semi-) variogram Author: Wolfgang Schwanghart Carlos

Wolfgang,

Thanks for this awesome submission. It was very helpful. I however have a questions..

On line 165 you perform the following operation

edges(end) = inf;

Can you explain the logic behind it?

The reason that I ask it that when the data is uniformly distributed in space the number of data pairs separated by a lag (h) decreases as h increases.

However, as written line 165 then makes later lines (l78 and 179)

S.val = accumarray(ixedge,...
lam,[numel(edges) 1],fvar,nan);

S.num = accumarray(ixedge,ones(size(lam))...
,[numel(edges) 1],@sum,nan);

Calculate the gamma value and the number of pairs using the the rest of the data set. You then do a final modification of the arrays but that does eliminate the extra data poins used int he Variogram calculation..

Let me give you an example.

My edges vector before line 165

250 500 750 1000 1250 1500 1750 2000 2250 2500 2750 3000

My edges vector after line 165

250 500 750 1000 1250 1500 1750 2000 2250 2500 2750 Inf

Then on lines
178,179 and 186, 187

you produce the S.distance,S.num and S.val struct arrays

This is what the S.distance says:

625
875
1125
1375
1625
1875
2125
2375
2625
2875

Then this is what the S.num says:

41
40
39
38
37
36
35
34
33
32
31
59

You see That 59 should not be there there are no 59 number of data pairs with an average lag distance of 2875. In fact there are only 30.

If I comment line 165 then I get the expected result of monotonically decreasing number of pairs as lag distance increases.

Let me know what you think...

Carlos Soto

Contact us