ezander / sglib

A Matlab/Octave toolbox for stochastic Galerkin methods
http://ezander.github.com/sglib
GNU General Public License v3.0
21 stars 14 forks source link

missing functions #16

Open asobouti opened 1 year ago

asobouti commented 1 year ago

Hi Elmar, I was going to use your marten_covariance function but I caught by two missed function check_boolean and scaled_distance. Can I find them here?

litvinen commented 1 year ago

Hi Alireza, I see these functions, they are there. Probably matlab just doesn't see them.

litvinen commented 1 year ago

function dist=scaled_distance(x1, x2, l, smooth, sqr) % SCALED_DISTANCE Computes the scaled distance between points. % DIST=SCALED_DISTANCE(X1, X2) computes the Euclidean distance between % points given in X1 and X2. % % DIST=SCALED_DISTANCE(X1, X2, L) computes the Euclidean distance between % X1 and X2 scaled by L where L can be scalar or a vector of the same % dimension as the points in X1 and X2. % % DIST=SCALED_DISTANCE(X1, X2, L, SMOOTH) computes the smoothed % Euclidean distance where the smoothing function is given by % D_SMOOTH=SQRT(D+SMOOTH^2)-SMOOTH. %
% DIST=SCALED_DISTANCE(X1, X2, L, SMOOTH, SQR) returns the square of the % Eudclidean smoothed, scaled distance. This saves computing the square % root if only the square is needed by the calling code anyway. % % Note: if an empty array is specified for a parameter the default value % is used. DIST=SCALED_DISTANCE(X1, X2, [], [], TRUE) computes the square % of the distance with parameters L and SMOOTH set to their defaults 1 % and 0. % % Example (run) % d=linspace(-1,1); % plot(d, scaled_distance(d, [], [], 0)); hold all; % plot(d, scaled_distance(d, [], [], 1)); % plot(d, scaled_distance(d, [], [], 2)); % plot(d, scaled_distance(d, [], 0.3, 0)); % plot(d, scaled_distance(d, [], 0.3, 1)); % plot(d, scaled_distance(d, [], 0.3, 2)); hold off; % axis equal; % See also

% Elmar Zander % Copyright 2010, Inst. of Scientific Computing, TU Braunschweig % % This program 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. % 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/.

if nargin<5 || isempty(sqr) sqr=false; end if nargin<4 || isempty(smooth) smooth=0; end if nargin<3 || isempty(l) l=1; end

if isempty(x2) dx=x1; else dx=x1-x2; end

d=size(dx,1); if isscalar(l) dx=dx/l; elseif length(l)==d invl=diag(1./l); dx=invldx; else error( 'statistics:scaled_distance', 'Size of cov_length vector doesn''t match dimension. Transposed?' ); end dist2=sum( dx.dx, 1);

if sqr if smooth>0 dist=sqrt(dist2+smooth^2)-smooth; dist=dist.*dist; else dist=dist2; end else if smooth>0 dist=sqrt(dist2+smooth^2)-smooth; else dist=sqrt(dist2); end end

litvinen commented 1 year ago

function ok=check_boolean( ok, message, filename, varargin ) % CHECK_BOOLEAN Check whether condition is true on input. % OK=CHECK_BOOLEAN( COND, MESSAGE, MFILENAME ) checks whether the given % condition is true. If not an error message is printed and the program % is aborted. % % Note: pass mfilename literally for the last argument (i.e. pass the % return value of the buildin function 'mfilename' which tells you the % name of the current script, and is thus exactly what you want.) % % Example (run) % function my_function( str ) % % check_boolean( strcmp(str,str(end:-1:1)), 'str must be a palindrome', mfilename ); % % See also CHECK_RANGE, CHECK_CONDITION, CHECK_UNSUPPORTED_OPTIONS

% Elmar Zander % Copyright 2007, Institute of Scientific Computing, TU Braunschweig. % % This program 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. % 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/.

% save some time by returning immediately if ok is true if ok return end

options=varargin2options( varargin ); [mode,options]=get_option( options, 'mode', 'debug' ); [depth,options]=get_option( options, 'depth', 1 ); check_unsupported_options( options, mfilename );

if isempty(filename) filename='util:check'; end

switch mode case 'error' stack=dbstack('-completenames'); err_struct.message=sprintf( '%s: %s', filename, message ); err_struct.identifier=[filename ':check_failed']; err_struct.stack=stack((1+depth):end); % using 'rethrow' instead of 'error' suppresses incorrect % reports of error position in 'check_condition' (the 'error' % function disregards the stack for display of the error % position) rethrow( err_struct ); case 'warning' if exist('dbstack') %#ok fprintf('Warning: %s: %s\n', filename, message ); stack=dbstack('-completenames'); for i=(1+depth):length(dbstack) %fprintf( ' In %s at line %d\n', stack(i).file, stack(i).name, stack(i).line ); fprintf( ' In %s at line %d\n', stack(i).file, stack(i).line, stack(i).name, stack(i).line ); end else warning([filename ':check_failed'], '%s: %s', filename, message ); end case 'print' if exist('dbstack') %#ok stack=dbstack('-completenames'); i=(1+depth); fprintf( 'Check failed in %s at line %d: %s\n', stack(i).file, stack(i).line, stack(i).name, stack(i).line, message ); else fprintf( 'Check failed in %s: %s\n', filename, message ); end case 'debug' fprintf( '\nCheck failed in: %s\n', filename); fprintf( 2, 'Reason: %s\n', message ); cmd=repmat( 'dbup;', 1, depth ); fprintf( 'Use the stack to get to the place the assertion failed to \n', cmd ); fprintf( 'investigate the error. Then press F5 to continue or stop debugging.\n' ) keyboard; end

if nargout==0 clear ok; end

ezander commented 1 year ago

Hi Alireza! Those functions are in statistics/private and util respectively. If you run startup or sglib_startup from the main directory the paths should be set correctly and the functions should then be found automatically. Hope that helps. Cheers Elmar

ezander commented 1 year ago

@litvinen Hi Alex! Thanks for helping out! :+1: