SG++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
python.tools Namespace Reference

Classes

class  Matrix
 Class Matrix that incorporates settings and actions for applying the matrix C and computing the RHS b. More...
 

Functions

def appendToDict
 A value pair is added to a dictionary's value entry. More...
 
def checkData
 Validates Dataset. More...
 
def gzOpen
 Opens a file. More...
 
def isARFFFile
 Checks whether a file given by a filename is an ARFF-file. More...
 
def makedir
 (Recursively) creates a directory if not yet existant. More...
 
def normalize
 Normalize values of input vectors on the segment [0,1]. More...
 
def normalizeClasses
 Divides the class values in two categories. More...
 
def readAlpha
 Opens and reads the onedimensional data of an ARFF (or plain whitespace-separated data) file. More...
 
def readAlphaARFF
 Reads in onedimensional data from an ARFF file. More...
 
def readAlphaTrivial
 Reads in onedimensional data from a delimiter separated data file. More...
 
def readCheckpoint
 read checkpoint More...
 
def readData
 Opens and read the (multidimensional) data of an ARFF (or plain whitespace-separated data) file. More...
 
def readDataARFF
 Reads in (multidimensional) data from an ARFF file. More...
 
def readDataTrivial
 Reads in (multidimensional) data from a delimiter separated data file. More...
 
def readGrid
 Unserialize a Grid from a file. More...
 
def readGridAlpha
 
def readNormfile
 Reads information that is needed for the normalization of data from a file. More...
 
def split_DataVector_by_proportion
 perform sequential split of a DataVector into two DataVectors More...
 
def split_DataVectors_by_proportion_stratified
 perform stratified split of a data set given by two DataVectors into two DataVectors each More...
 
def split_n_folds
 
def split_n_folds_sequential
 
def split_n_folds_stratified
 
def writeAlphaARFF
 Writes DataVector to arff file. More...
 
def writeCheckpoint
 Write whole checkpoint data to file. More...
 
def writeDataARFF
 write ARFF data More...
 
def writeDataMaple
 Writes a data object to a file, specified by data["filename"]+".maple". More...
 
def writeDataVectorMaple
 Writes a DataVector object to a file, specified by filename. More...
 
def writeGnuplot
 Evaluates function on a full grid in the domain, and writes evaluation points to a file. More...
 
def writeGnuplotFctn
 Evaluates function on a full grid in the domain, and writes evaluation points to a file. More...
 
def writeGnuplotGrid
 Writes coordinates of a grid into a file, suitable for gnuplot. More...
 
def writeGrid
 Serialize a Grid to a file. More...
 
def writeLockFile
 Writes a String txt to File filename, appends by default. More...
 
def writeNormfile
 Writes information that is needed for the normalization of data to a file. More...
 
def writeStats
 writes statistics More...
 
def writeStringToFile
 Writes String to File and checks if file existant. More...
 

Variables

int ARFF = 1
 
dictionary base_types
 base function types More...
 
dictionary CModes
 An array containing all modes and descriptions. More...
 
int NOTAFILE = -1
 
int SIMPLE = 0
 

Function Documentation

def python.tools.appendToDict (   dict,
  key,
  val 
)

A value pair is added to a dictionary's value entry.

Each entry of the dictionary is a list. If the dictionary has no entry for key, [value] is added. Otherwise value is appended to the list under key.

Parameters
dictthe dictionary
keythe key
valthe value
def python.tools.checkData (   data)

Validates Dataset.

Parameters
dataDataset
def python.tools.gzOpen (   filename,
  mode = "r" 
)

Opens a file.

If the file ends with ".gz", automatically gzip compression is used for the file.

Returns the filedescriptor

Parameters
filenamefile's filename
modedefault: "r" for read only
Returns
file descriptor

Referenced by python.tools.isARFFFile(), python.tools.readDataARFF(), python.tools.readDataTrivial(), python.tools.readGrid(), python.tools.readNormfile(), python.tools.writeAlphaARFF(), python.tools.writeDataARFF(), python.tools.writeGnuplot(), python.tools.writeGnuplotFctn(), python.tools.writeGrid(), python.tools.writeLockFile(), and python.tools.writeStringToFile().

def python.tools.isARFFFile (   filename)

Checks whether a file given by a filename is an ARFF-file.

Parameters
filenamethe file's name
Returns
ARFF, SIMPLE or NOTAFILE

References python.tools.gzOpen().

Referenced by python.tools.readAlpha(), and python.tools.readData().

def python.tools.makedir (   path,
  verbose = False 
)

(Recursively) creates a directory if not yet existant.

Parameters
pathPath of directory
verboseTell what is been done (optional)
def python.tools.normalize (   data,
  border = 0.0,
  filename = None,
  minvals = None,
  maxvals = None,
  verbose = False 
)

Normalize values of input vectors on the segment [0,1].

Parameters
dataDataset
borderSpecifies border of the dataset, will be added to the normalized value
filenameFilename of normfile (optional)
minvalsArray of normalization boundary min values (one per dimension) (optional)
maxvalsArray of normalization boundary max values (one per dimension) (optional)
verboseProvide additional output

References python.tools.writeNormfile().

def python.tools.normalizeClasses (   data,
  border = 0.0,
  minborder = -sys.maxint-1,
  verbose = False 
)

Divides the class values in two categories.

Parameters
dataDataset
borderClasses will be differentiated between greater and less then border
minborderAll classes under the minborder are processed as if they were over border
verboseProvide additional output
def python.tools.readAlpha (   filename)

Opens and reads the onedimensional data of an ARFF (or plain whitespace-separated data) file.

Parameters
filenamefilename of the file
Returns
the data stored in the file as a set of arrays, DataVector

References python.tools.isARFFFile(), python.tools.readAlphaARFF(), and python.tools.readAlphaTrivial().

Referenced by python.tools.readGridAlpha().

def python.tools.readAlphaARFF (   filename)

Reads in onedimensional data from an ARFF file.

Parameters
filenamethe file's filename that should be red
Returns
returns the DataVector

References python.tools.readDataARFF().

Referenced by python.tools.readAlpha(), and python.tools.readCheckpoint().

def python.tools.readAlphaTrivial (   filename,
  delim = None 
)

Reads in onedimensional data from a delimiter separated data file.

Parameters
filenamethe file's filename that should be red
delim(optional) separator between columns. Default: whitespaces
Returns
returns the DataVector

References python.tools.readDataTrivial().

Referenced by python.tools.readAlpha().

def python.tools.readCheckpoint (   filename)

read checkpoint

Parameters
filenamefilename

References python.tools.readAlphaARFF(), and python.tools.readGrid().

def python.tools.readData (   filename)

Opens and read the (multidimensional) data of an ARFF (or plain whitespace-separated data) file.

Assumes that class information is available. Format is {"data": DataMatrix, "classes": DataVector, "filename": filename} or

Parameters
filenamefilename of the file
Returns
the data stored in the file as a set of arrays

References python.tools.isARFFFile(), python.tools.readDataARFF(), and python.tools.readDataTrivial().

def python.tools.readDataARFF (   filename)

Reads in (multidimensional) data from an ARFF file.

The data is stored in a dictionary, thus either {"data": DataMatrix, "classes": DataVector, "filename": filename} or {"data": DataMatrix, "filename": filename}, depending whether one of the attributes is called "class[es]"

Parameters
filenamethe file's filename that should be red
Returns
returns the data

References python.tools.gzOpen().

Referenced by python.tools.readAlphaARFF(), and python.tools.readData().

def python.tools.readDataTrivial (   filename,
  delim = None,
  hasclass = True 
)

Reads in (multidimensional) data from a delimiter separated data file.

Last column is assumend to contain class values, if hasclass=True. The data is stored in a dictionary, thus either {"data": DataMatrix, "classes": DataVector, "filename": filename} or {"data": DataMatrix, "filename": filename}

Parameters
filenamethe file's filename that should be read
delim(optional) separator between columns. Default: whitespaces
hasclass(optional) sets, whether last column contains class attribute. Default: True
Returns
returns the data

References python.tools.gzOpen().

Referenced by python.tools.readAlphaTrivial(), and python.tools.readData().

def python.tools.readGrid (   filename)

Unserialize a Grid from a file.

Parameters
filenameFilename of file
Returns
Grid

References python.tools.gzOpen().

Referenced by python.tools.readCheckpoint(), and python.tools.readGridAlpha().

def python.tools.readGridAlpha (   fnamegrid,
  fnamealpha 
)
def python.tools.readNormfile (   filename)

Reads information that is needed for the normalization of data from a file.

Parameters
filenamea filename
Returns
(border, minvals, maxvals, deltavals)
border: offset for normalization
minvals: the minimum value of each attribute
maxvals: the maximum value of each attribute
deltavals: (max-min)/(1.0-2*border), provided for convenience

References python.tools.gzOpen().

def python.tools.split_DataVector_by_proportion (   data,
  proportion 
)

perform sequential split of a DataVector into two DataVectors

Parameters
dataDataVector to split
proportionsplit into proportion, (1-proportion)
Returns
(DataVector1, DataVector2)

References python.tools.split_DataVectors_by_proportion_stratified().

def python.tools.split_DataVectors_by_proportion_stratified (   data,
  classes,
  proportion 
)

perform stratified split of a data set given by two DataVectors into two DataVectors each

Parameters
dataDataVector with data points to split
classesDataVector with class values to split
proportionsplit into proportion, (1-proportion)
Returns
(data1, data2, classes1, classes2)

Referenced by python.tools.split_DataVector_by_proportion().

def python.tools.split_n_folds (   data,
  num_partitions,
  seed = None 
)
def python.tools.split_n_folds_sequential (   data,
  num_partitions 
)
def python.tools.split_n_folds_stratified (   data,
  num_partitions,
  seed = None 
)
def python.tools.writeAlphaARFF (   filename,
  alpha 
)

Writes DataVector to arff file.

If filename ends with ".gz", file is gzip-compressed.

Parameters
filenameFilename of new file
alphaThe DataVector

References python.tools.gzOpen().

Referenced by python.uq.dists.optimization.estimateDensitySGDE.estimateDensitySGDE(), python.uq.analysis.asgc.ASGCAnalysis.ASGCAnalysis.sampleGrids(), python.tools.writeCheckpoint(), and python.uq.analysis.asgc.ASGCAnalysis.ASGCAnalysis.writeCheckpoints().

def python.tools.writeCheckpoint (   filename,
  grid,
  alpha,
  adaption = None,
  fold = None 
)

Write whole checkpoint data to file.

This writes two files containing grid and coefficient (alpha) vector. Optionally, two additional parameters can be specified, influencing the filename. The filename has the following form: FILENAME[.aADAPTATION][.fFOLD].{alpha.arff.gz|grid.gz}

Parameters
filenameFilename prefix
gridGrid file
alphaCoefficient DataVector
adaption(optional) number of adaptive step for refinement
fold(optional) specifying which fold

References python.tools.writeAlphaARFF(), and python.tools.writeGrid().

def python.tools.writeDataMaple (   data,
  merge 
)

Writes a data object to a file, specified by data["filename"]+".maple".

Parameters
dataa data object
mergeset to True, iff data is a list of data objects and they should be joined

References python.uq.operations.general.join().

def python.tools.writeDataVectorMaple (   data,
  filename,
  format = "%s",
  maple_name = "X",
  check = True 
)

Writes a DataVector object to a file, specified by filename.

Output in the file is "X := Matrix([[...],[...],...,[...]]);"

Parameters
dataa DataVector object
filenamethe file's name
format(optional) format specifier, default: "%s"
maple_name(optional) name of variable in Maple, default: "X"
check(optional) if set to true, program will ask before overwriting files

References python.uq.operations.general.join(), and python.tools.writeStringToFile().

def python.tools.writeGnuplot (   filename,
  grid,
  alpha,
  resolution,
  mode = "w",
  data = None,
  fvals = None 
)

Evaluates function on a full grid in the domain, and writes evaluation points to a file.

The output is suitable for Gnuplot.

Parameters
filenameFilename to which data is written
gridGrid
alphaCorresponding coefficient DataVector
resolutionNumber of sampling points per dimension
mode{'w'|'a'} to write or append, default 'w' (optional)
datapoints to plot (optional)
fvalscorresponding function values (optional)

References sgpp::op_factory.createOperationEval(), and python.tools.gzOpen().

def python.tools.writeGnuplotFctn (   filename,
  dim,
  fctn,
  resolution,
  mode = "w" 
)

Evaluates function on a full grid in the domain, and writes evaluation points to a file.

The output is suitable for Gnuplot.

Parameters
filenameFilename to which data is written
dimdimension
fctnfunction
resolutionNumber of sampling points per dimension
mode{'w'|'a'} to write or append, default 'w' (optional)

References python.tools.gzOpen().

def python.tools.writeGnuplotGrid (   filename,
  grid 
)

Writes coordinates of a grid into a file, suitable for gnuplot.

Parameters
filenameFilename to which data is written
gridGrid
def python.tools.writeGrid (   filename,
  grid 
)

Serialize a Grid to a file.

If filename ends with ".gz", file is gzip-compressed.

Parameters
filenameFilename of new file
gridThe Grid

References python.tools.gzOpen().

Referenced by python.tools.writeCheckpoint(), and python.uq.analysis.asgc.ASGCAnalysis.ASGCAnalysis.writeCheckpoints().

def python.tools.writeLockFile (   filename,
  txt,
  mode = "a" 
)

Writes a String txt to File filename, appends by default.

Uses secure writing, i.e. locks file.

On Windows concurrent access raises an error wich is handled. On Linux/Unix it should block until lock released!! param: filename param: txt param: mode, default: "a"

References python.tools.gzOpen().

Referenced by python.tools.writeStats().

def python.tools.writeNormfile (   filename,
  border,
  minvals,
  maxvals 
)

Writes information that is needed for the normalization of data to a file.

Using this information one can then later on reverse the normalization or normalize further data.

Parameters
filenamea filename
borderoffset for normalization
minvalsthe (original) minimum value of each attribute
maxvalsthe (original) maximum value of each attribute

References python.uq.operations.general.join(), and python.tools.writeStringToFile().

Referenced by python.tools.normalize().

def python.tools.writeStats (   filename,
  txt,
  mode = "a" 
)

writes statistics

Parameters
filenamefilename
txttext to write to file
modewriting mode (default "a")

References python.tools.writeLockFile().

def python.tools.writeStringToFile (   s,
  filename,
  check = True 
)

Writes String to File and checks if file existant.

Parameters
ssome text
filenamefilename (including relative or absolute path)
check(optional) set to False to overwrite without checking for existance

References python.tools.gzOpen().

Referenced by python.tools.writeDataVectorMaple(), and python.tools.writeNormfile().

Variable Documentation

int python.tools.ARFF = 1
dictionary python.tools.base_types
Initial value:
1 = {
2 # "linear" : {"base" : SLinearBase, "b" : SGridOperationB, "t" : test_dataset_linear, "laplace" : SGridOperationLaplace},
3 # "modlinear" : {"base" : SLinearModifiedBase, "b" : SGridModOperationB, "t" : test_dataset_modlin},
4 # "poly" : {"base" : "SPolyBase", },
5  }

base function types

dictionary python.tools.CModes
Initial value:
1 = {
2  "laplace" : "Classical Laplacian. See OpLaplaceAdaptive",
3  "identity" : "Identity matrix, most efficient.",
4  "identity_no_level1" : "Identity matrix, most efficient. But do not penalize Level 1",
5  "anisotropicpenalty" : "Preferres quadratical supports. See OperationRegularizationDiagonal.",
6  "levelsum" : "Sum of the levels, scaled by the gridlevel (usually 2 for adaptive SGs).",
7  "isotropicpenalty" : "Energy-norm-like SGs. See OperationRegularizationDiagonal.",
8  "rowsum" : "Sum of the rows of classical Laplacian. See OpLaplaceAdaptive",
9  "hkmix": "H^k_mix norm; requires parameter Hk",
10  "h0hklaplace" : "Pseudo-Laplace with H^k in one, and 'H^0' in the remaining dimensions each; requires paramer Hk"}

An array containing all modes and descriptions.

int python.tools.NOTAFILE = -1
int python.tools.SIMPLE = 0