protected class SamplingScoreBasedClassifier.DiffSMSamplingComponent extends Object implements SamplingComponent
SamplingComponent
that handles storing and loading sampled parameters values
to and from files.Constructor and Description |
---|
DiffSMSamplingComponent(String outfilePrefix)
Creates a new
SamplingScoreBasedClassifier.DiffSMSamplingComponent that uses temporary files
with name prefix outfilePrefix to store sampled parameters. |
Modifier and Type | Method and Description |
---|---|
void |
acceptParameters()
This methods accepts the drawn parameters.
|
protected void |
createFiles(StringBuffer contents)
Creates files out of file contents saved as XML.
|
void |
extendSampling(int sampling,
boolean append)
This method allows to extend a sampling.
|
int |
getNumberOfParameterSets(int sampling)
Returns the number of parameters set that can be retrieved from an internal file which has been creating while previous training.
|
void |
initForSampling(int starts)
This method initializes the instance for the sampling.
|
boolean |
isInSamplingMode()
This method returns
true if the object is currently used in
a sampling, otherwise false . |
boolean |
joinAndSetParameterFiles(boolean add,
File[] files)
Combines parameter files such that they are accepted as parameter files
of the calling
SamplingScoreBasedClassifier |
boolean |
parseNextParameterSet()
This method allows the user to parse the next set of parameters (from a
file).
|
boolean |
parseParameterSet(int sampling,
int n)
This method allows the user to parse the set of parameters with index
n of a certain sampling (from a file). |
void |
samplingStopped()
This method is the opposite of the method
SamplingComponent.extendSampling(int, boolean) . |
protected StringBuffer |
saveParameters()
Saves the parameter values of all parameter files to
a
StringBuffer representing these as XML. |
public DiffSMSamplingComponent(String outfilePrefix)
SamplingScoreBasedClassifier.DiffSMSamplingComponent
that uses temporary files
with name prefix outfilePrefix
to store sampled parameters.
These files are either stored in the default temp directory of the OS, or,
if specified, in the directory set by SamplingScoreBasedClassifier.setTempDir(File)
before
starting the sampling process.outfilePrefix
- the prefix of the parameter filespublic boolean joinAndSetParameterFiles(boolean add, File[] files) throws Exception
SamplingScoreBasedClassifier
add
- if true, parameter files are appended to the current ones, i.e., the number
of samplings is augmented by these filesfiles
- the parameter filestrue
if the parameters could be joinedException
- if the parameter files could not be loadedpublic int getNumberOfParameterSets(int sampling) throws IOException
sampling
- the index of the samplingIOException
- if some problem occur during the file handlingparseNextParameterSet()
,
parseParameterSet(int, int)
public boolean parseParameterSet(int sampling, int n) throws IOException
SamplingComponent
n
of a certain sampling
(from a file). The
internal numbering should start with 0. The parameter set with index 0 is
the initial (random) parameter set. It is recommended that a series of
parameter sets is accessed by the following lines:
for( sampling = 0; sampling < numSampling; sampling++ )
{
boolean b = parseParameterSet( sampling, n );
while( b )
{
//do something
b = parseNextParameterSet();
}
}
parseParameterSet
in interface SamplingComponent
sampling
- the index of the samplingn
- the index of the parameter settrue
if the parameter set could be parsedIOException
SamplingComponent.parseNextParameterSet()
public boolean parseNextParameterSet()
SamplingComponent
parseNextParameterSet
in interface SamplingComponent
true
if the parameters could be parsed, otherwise
false
SamplingComponent.parseParameterSet(int, int)
public void initForSampling(int starts) throws IOException
SamplingComponent
initForSampling
in interface SamplingComponent
starts
- the number of different sampling starts that will be doneIOException
- if something went wrongFile.createTempFile(String, String, java.io.File )
public void extendSampling(int sampling, boolean append) throws IOException
SamplingComponent
extendSampling
in interface SamplingComponent
sampling
- the index of the samplingappend
- whether to append the sampled parameters to an existing file
or to overwrite the fileIOException
- if the file could not be handled correctlypublic void samplingStopped() throws IOException
SamplingComponent
SamplingComponent.extendSampling(int, boolean)
. It can be
used for closing any streams of writer, ...samplingStopped
in interface SamplingComponent
IOException
- if something went wrongSamplingComponent.extendSampling(int, boolean)
public boolean isInSamplingMode()
SamplingComponent
true
if the object is currently used in
a sampling, otherwise false
.isInSamplingMode
in interface SamplingComponent
true
if the object is currently used in a sampling,
otherwise false
public void acceptParameters() throws IOException
SamplingComponent
acceptParameters
in interface SamplingComponent
IOException
- if the file could not be handled correctlyprotected StringBuffer saveParameters() throws IOException
StringBuffer
representing these as XML.StringBuffer
containing the parametersIOException
- if the files could not be readprotected void createFiles(StringBuffer contents) throws NonParsableException, IOException
contents
- the parameter values to be stored in the filesNonParsableException
- if the parameters could not be parsedIOException
- if the files could not be writtensaveParameters()