KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Utils Class Reference

Collection of generally useful functions. More...

Detailed Description

Collection of generally useful functions.

Author
Daniel Wirtz
Date
11.10.2010
Change in 0.6:
(Daniel Wirtz, 2012-06-08) Bugfix: Now the logarithmic norms are computed correctly. ARGH that took a while to detect..
New in 0.6:
(Daniel Wirtz, 2012-04-13) New method "getTube" that allows to draw random vectors from spaces of arbitrary dimension but restricted to a specified tube.
Change in 0.6:
(Daniel Wirtz, 2011-11-17) Moved the getObjectConfig to a separate file.
Change in 0.6:
(Daniel Wirtz, 2011-11-16) Using mex CalcMD5 now to compute hash values for vectors. Source downloaded from http://www.mathworks.com/matlabcentral/fileexchange/25921. Also updated the KerMor.setup script to automatically compile the CalcMD5 mex file.
Change in 0.5:
(Daniel Wirtz, 2011-09-15)
  • saveAxes and saveFigure now store the last save location in the preferences and reuse them.
  • removeMargin now properly works, together with saveFigure or saveAxes.
New in 0.5:
(Daniel Wirtz, 2011-07-05) Added the Utils.implode function.
New in 0.3:
(Daniel Wirtz, 2011-04-20) Added a new function Utils.getHelpShort to extract the first line(s) of a help text in matlab style (text until first emtpy line = short)
New in 0.3:
(Daniel Wirtz, 2011-04-18) Added the saveFigure and saveAxes methods from SegMedix.
Change in 0.3:
(Daniel Wirtz, 2011-04-04) Moved the Utils.getObjectConfig method here from models.BaseModel
New in 0.3:
(Daniel Wirtz, 2011-04-01)

This class is part of the framework

KerMor - Model Order Reduction using Kernels

Definition at line 17 of file Utils.m.

Static Public Member Functions

static function char
short = 
getHelpShort (char txt)
 Extracts the help short subtext from a given text. More...
 
static function [
double
bmin , double
bmax ] = 
getBoundingBox (double vectors)
 Gets the bounding box for a matrix containing column vectors. More...
 
static function comb = createCombinations (ranges, varargin)
 Creates the cartesian product of the vectors passed as a matrix containing elements of each vector per row. More...
 
static function struct
target = 
copyStructFields (struct source,struct target)
 Recursively copies struct fields from one struct to another. More...
 
static function str = getLatexStr (value, digits)
 
static function char str = implode (char|rowvec data,char glue,char format)
 Implodes the elements of data using glue. More...
 
static function idx = findVecInMatrix (A, b)
 Finds column vectors inside a matrix. More...
 
static function y = preparePlainPlot (y)
 Memory-saving plotting for plain result plots. More...
 
static function  saveFigure (fig, filename, ext)
 Opens a matlab save dialog and saves the given figure to the file selected. More...
 
static function  saveAxes (handle ax, varargin)
 Convenience function. Allows to save a custom axes instead of a whole figure which allows to drop any unwanted uiobjects contained on the source figure. More...
 
static function  removeMargin (f)
 Requires the axes and figure units to be the same. More...
 
static function h = getHash (vec)
 Returns a hash code for the given vector. More...
 
static function [
matrix
< double > x , colvec< double > farend ] = 
getTube (integer dim,integer num,double length,double spread,integer seed)
 Computes \(n=\)num random vectors inside a tube of length \(l=\)length inside a \(d=\)dim dimensional space. The tube starts at zero and ends at a random point \(x_e\in\R^d\) of length \(l\). The spread \(s=\)spread determines the maximum distance \(ls\) by which the random vectors might be away from the tube center \(\{x\in\R^d~|~ x = \alpha x_e,\alpha\in[0,1]\}\). More...
 
static function [
double ln ,
colvec
< double > v ] = 
logNorm (matrix< double > A,matrix< double > G,colvec< double > v0)
 Computes the logarithmic norm of a matrix \(\vA\), optionally using a positive definite symmetric matrix \(\vG\) inducing the matrix norm to use. More...
 
static function S = sprand (integer n,integer m,double dens,RandStream rs)
 Creates a random sparse matrix with given density (approximately). More...
 
static function  closeAllFigures ()
 
static function folder = getDir (caption, initial_path)
 Prompts the user to select a directory. More...
 
static function logical success = ensureDir (char dir)
 Ensures that a directory exists. More...
 
static function  copyPrefGroup (char from,char to)
 Copies the preferences from one group to another. More...
 
static function
entries = 
getLegendFromVector (values, format_string)
 
static function res = test_Tube ()
 
static function res = test_createCombinations ()
 Tests the createCombinations function. More...
 
static function res = test_findVec ()
 Tests the findVecInMatrix function. More...
 

Member Function Documentation

static function Utils.closeAllFigures ( )
static

Definition at line 658 of file Utils.m.

function Utils.copyPrefGroup ( char  from,
char  to 
)
static

Copies the preferences from one group to another.

Parameters
fromThe preference group to copy from
toThe preference group to copy to

Definition at line 730 of file Utils.m.

References k.

function struct target = Utils.copyStructFields ( struct  source,
struct  target 
)
static

Recursively copies struct fields from one struct to another.

Effectively implements a struct.clone() method.

Author
Daniel Wirtz
Date
2010-11-03
Parameters
sourceThe source struct.
targetThe target struct.

Definition at line 159 of file Utils.m.

References copyStructFields().

Referenced by copyStructFields().

Here is the call graph for this function:

Here is the caller graph for this function:

function comb = Utils.createCombinations (   ranges,
  varargin 
)
static

Creates the cartesian product of the vectors passed as a matrix containing elements of each vector per row.

Author
Daniel Wirtz
Date
2010-10-11
Parameters
rangesCan either be a cell array of vectors or a vector.
vararginIf the first argument is a vector, an arbitrary number of additional vectors can be passed to build the cartesian product from.
Return values
combA matrix containing the combinations, each row corresponds to an input vector's range.

Definition at line 114 of file Utils.m.

Referenced by demos.Basics5_KernelsAndApprox(), models.motoneuron.experiments.FrequencyLearning(), models.BaseFullModel.off2_genTrainingData(), sampling.WeightedRandomSampler.performSampling(), sampling.GridSampler.performSampling(), test_createCombinations(), models.muscle.functions.MarkertLaw.test_FitToOriginal(), models.muscle.functions.MarkertLaw.test_Linarization(), and approx.algorithms.VKOGA.test_VKOGA2D1D().

Here is the caller graph for this function:

function logical success = Utils.ensureDir ( char  dir)
static

Ensures that a directory exists.

If no return argument is wanted, an exception is thrown when creation of a nonexistent directory fails.

Parameters
dirThe target directory
Return values
successTrue if the directory exists or has been created, false otherwise

Definition at line 700 of file Utils.m.

Referenced by kernels.KernelExpansion.exportToDirectory().

Here is the caller graph for this function:

function idx = Utils.findVecInMatrix (   A,
  b 
)
static

Finds column vectors inside a matrix.

For multiple occurences, the first found index is used.

See http://www.mathworks.com/matlabcentral/newsreader/view_thread/174277 and the test function testing.find_vec_in_matrix_speedtest for further information.

Change in 0.3:

(Daniel Wirtz, 2011-04-12) Added support for multi vector search.

(Daniel Wirtz, 2011-04-13) Fixed errors when multiple occurences appear.

Parameters
AA \(n\times m\) matrix of \(m\) column vectors
bA \(n\times p\) vector, where each column is regarded as one vector to search
Return values
idxA \(1 \times p\) vector containing the first found positions indices if a vector from b is contained in A, zero otherwise.

Definition at line 259 of file Utils.m.

References t.

Referenced by fem.geometry.BaseGeometry.getCommonNodesWith(), spacereduction.BaseSpaceReducer.getInitialSpace(), demos.ResponseSurfaceApprox.iterationPlots(), ApproxVisualizer>plotCurrent(), FunVis2D>updateCenterPoints(), fem.geometry.RegularHex8Grid(), test_findVec(), and fem.geometry.BaseGeometry.toCMGUI().

Here is the caller graph for this function:

function [ double bmin , double bmax ] = Utils.getBoundingBox ( double  vectors)
static

Gets the bounding box for a matrix containing column vectors.

Parameters
vectorsA \(n\times m\) matrix containing \(m\) column vectors
Return values
bminA \(n\times 1\) vector representing the minimum value corner of the bounding box
bmaxA \(n\times 1\) vector representing the maximum value corner of the bounding box

Definition at line 96 of file Utils.m.

Referenced by data.ApproxTrainData.ApproxTrainData(), data.MemoryTrajectoryData.getBoundingBox(), FunVis2D>FunVis2D_OpeningFcn(), FunVis2D>rangesFromATD(), error.IterationCompLemmaEstimator.offlineComputations(), and data.FileMatrix.test_FileMatrix().

Here is the caller graph for this function:

function folder = Utils.getDir (   caption,
  initial_path 
)
static

Prompts the user to select a directory.

If no screen is used, a text input prompt will be used to let the user enter the path manually.

Parameters
captionThe caption for the dialog/prompt
initial_pathThe path to start from (only for UI)

Definition at line 669 of file Utils.m.

References all().

Referenced by data.ModelData.relocate().

Here is the call graph for this function:

Here is the caller graph for this function:

function h = Utils.getHash (   vec)
static

Returns a hash code for the given vector.

Currently using the CalcMD5 routine from 3rdparty/calcmd5, which is included in KerMor as 3rd party code. Original source: http://www.mathworks.com/matlabcentral/fileexchange/25921

Definition at line 493 of file Utils.m.

References CalcMD5().

Referenced by data.FileDataCollection.addData(), data.MemoryTrajectoryData.addTrajectory(), data.FileDataCollection.getData(), data.MemoryTrajectoryData.getTrajectory(), and data.FileDataCollection.hasData().

Here is the call graph for this function:

Here is the caller graph for this function:

function char short = Utils.getHelpShort ( char  txt)
static

Extracts the help short subtext from a given text.

Gets the first block of a text that goes until the first blank line.

Parameters
txtThe text to use.
Return values
shortThe subtext.

Definition at line 68 of file Utils.m.

static function str = Utils.getLatexStr (   value,
  digits 
)
static

Definition at line 194 of file Utils.m.

Referenced by EstimatorAnalyzer.getResultTable().

Here is the caller graph for this function:

static function entries = Utils.getLegendFromVector (   values,
  format_string 
)
static

Definition at line 747 of file Utils.m.

function [ matrix< double > x , colvec< double > farend ] = Utils.getTube ( integer  dim,
integer  num,
double  length,
double  spread,
integer  seed 
)
static

Computes \(n=\)num random vectors inside a tube of length \(l=\)length inside a \(d=\)dim dimensional space. The tube starts at zero and ends at a random point \(x_e\in\R^d\) of length \(l\). The spread \(s=\)spread determines the maximum distance \(ls\) by which the random vectors might be away from the tube center \(\{x\in\R^d~|~ x = \alpha x_e,\alpha\in[0,1]\}\).

Parameters
dimThe dimension of the tube.
numThe number of desired random vectors.
lengthThe length \(l\) of the tube. Default: 1
spreadThe spread \(s\) of the tube vectors around the tube core. Default: 0.15
seedThe seed to use for the random number generator. Default: cputime*10
Return values
xAn \(d\times n\) matrix with random vectors from a random tube.
farendThe vector from the far end away from zero.

Definition at line 510 of file Utils.m.

References Norm.L2().

Referenced by test_Tube().

Here is the call graph for this function:

Here is the caller graph for this function:

function char str = Utils.implode ( char|rowvec  data,
char  glue,
char  format 
)
static

Implodes the elements of data using glue.

Either transforms a cell array of strings into one string or implodes a numeric vector using the specified format.

New in 0.6:
(Daniel Wirtz, 2011-11-17) Added the possibility to pass a numeric vector plus a format string.
Parameters
dataA cell array of strings/chars or a numeric vector
glueA string that is inserted between any element string representation Default: ,
formatThe sprintf format string if data is a vector Default: %2.3e
Return values
strThe concatented string of all data strings glued together with the string glue

Definition at line 208 of file Utils.m.

Referenced by IClassConfig.addRange(), ModelAnalyzer.compareRedFull(), Java.exportFunctions(), IClassConfig.getAxisLabels(), kernels.config.ParamTimeExpansionConfig.getConfiguredPropertiesString(), general.functions.FuncSum.getFunction(), general.functions.PiecewiseLinear.getFunction(), general.DEIM.getInterpolationPoints(), fem.AFEMConfig.getOptionStr(), models.pcd.PCDSystem1D.plot(), and MonomialIterator.test_MonomialIterator().

Here is the caller graph for this function:

function [ double ln , colvec< double > v ] = Utils.logNorm ( matrix< double A,
matrix< double G,
colvec< double v0 
)
static

Computes the logarithmic norm of a matrix \(\vA\), optionally using a positive definite symmetric matrix \(\vG\) inducing the matrix norm to use.

Change in 0.6:
(Daniel Wirtz, 2012-07-18) Added a re-try with 6 eigenvalues if no convergence for one eigenvalue takes place. Added an optional v0 parameter as start vector for eigs.
Parameters
AThe target matrix \(\vA\)
GThe positive definite, symmetric matrix \(\vG\) inducing the norm and hence matrix norm to use. Defaults to identity matrix (Euclidean/L2 norm) Default: \(\vI_d\)
v0An initial vector for eigs to start with. Default: []
Return values
lnThe logarithmic norm with respect to the given matrix norm induced by \(\vG\).
vThe eigenvector of the largest eigenvalue (=log norm) of the symmetric part of \(\vA\).

Definition at line 551 of file Utils.m.

References KerMor.App(), and t.

Referenced by testing.DEIM.compareDEIM_Full_Jacobian(), testing.LogNorm.compareSimTransDEIMJac_FullJac(), testing.LogNorm.compareSimTransJac_FullJac(), testing.LogNorm.getApproxLogNormsAtPos(), error.DEIMEstimator.getBeta(), and error.DEIMEstimator.offlineComputations().

Here is the call graph for this function:

Here is the caller graph for this function:

function y = Utils.preparePlainPlot (   y)
static

Memory-saving plotting for plain result plots.

Parameters
yA result matrix \(y\) with rows corresponding to single dimensions and columns corresponding to time-steps.
Return values
yIf there are more than 1000 dimensions, the subset with distinct (via unique) last values are extracted. If this still results in more than 4000 plots, the first 4000 dimensions are selected.

Definition at line 297 of file Utils.m.

Referenced by ModelAnalyzer.analyzeError(), models.BaseModel.plot(), and models.BaseModel.plotState().

Here is the caller graph for this function:

function Utils.removeMargin (   f)
static

Requires the axes and figure units to be the same.

Todo:
tailor this method so that subplots are also supported (so far only one axis!) and change saveFigure again.

Definition at line 465 of file Utils.m.

function Utils.saveAxes ( handle  ax,
  varargin 
)
static

Convenience function. Allows to save a custom axes instead of a whole figure which allows to drop any unwanted uiobjects contained on the source figure.

Parameters
axThe axes handle to save.
vararginAny additional parameters are passed to Utils.saveFigure

Definition at line 437 of file Utils.m.

References saveFigure().

Referenced by ApproxVisualizer>btnSave_Callback(), and FunVis2D>uipushtool2_ClickedCallback().

Here is the call graph for this function:

Here is the caller graph for this function:

function Utils.saveFigure (   fig,
  filename,
  ext 
)
static

Opens a matlab save dialog and saves the given figure to the file selected.

Supported formats: eps, jpg, fig

Change in 0.4:
(Daniel Wirtz, 2011-05-31) Improved the export capabilites and automatic removement of any figure margins is performed.

Definition at line 324 of file Utils.m.

References export_fig(), and KerMor.getPrefTag().

Referenced by models.ReducedModel.createImage(), models.mathmod2012.MathMODExperiment.CreatePlots(), models.iciam2011.ICIAMExperiment.CreatePlots(), models.wh10.WH10Experiment.Experiment2(), models.wh10.WH10Experiment.Experiment4(), and saveAxes().

Here is the call graph for this function:

Here is the caller graph for this function:

function S = Utils.sprand ( integer  n,
integer  m,
double  dens,
RandStream  rs 
)
static

Creates a random sparse matrix with given density (approximately).

Faster than sprand as no exact density is achieved.

Parameters
nThe number \(n\) of rows
mThe number \(m\) of columns
densThe desired density \(dens*n*m\)
rsA RandStream instance Default: mt19937ar(0)
Required fields of rs:

Definition at line 629 of file Utils.m.

Referenced by demos.Basics2_Parametrized().

Here is the caller graph for this function:

function res = Utils.test_createCombinations ( )
static

Tests the createCombinations function.

Author
Daniel Wirtz
Date
11.10.2010

Definition at line 771 of file Utils.m.

References createCombinations().

Here is the call graph for this function:

function res = Utils.test_findVec ( )
static

Tests the findVecInMatrix function.

Author
Daniel Wirtz
Date
2011-04-12

Definition at line 788 of file Utils.m.

References all(), and findVecInMatrix().

Here is the call graph for this function:

static function res = Utils.test_Tube ( )
static

Definition at line 757 of file Utils.m.

References all(), getTube(), and Norm.L2().

Here is the call graph for this function:


The documentation for this class was generated from the following file: