Sautrela

edu.gtts.sautrela.vq
Class CodebookTrainer

java.lang.Object
  extended by edu.gtts.sautrela.engine.AbstractDataProcessor
      extended by edu.gtts.sautrela.vq.CodebookTrainer
All Implemented Interfaces:
DataProcessor, java.beans.BeanInfo, java.io.Serializable

public class CodebookTrainer
extends AbstractDataProcessor

A Dataprocessor that implements the LBG algorithm (and the eLBG variant). Due to the nature of the Vector Quantization, only DoubleData elements are processed (IntData and ShortData are discarted). The processor buffers the input data untill a DataClose is received. Then, the LBG/eLBG algorithm is applied and the resulting codebook is saved in a File (using a Sequence representation).

See Also:
Serialized Form

Field Summary
static boolean DEFAULT_BINCDBK
          Default flag for binary Codebook == false
static int DEFAULT_CBKSIZE
          Default size for final codebook == 256
static double DEFAULT_DELTA
          Default value for convergence factor == 1e-10
static boolean DEFAULT_ELBG
          Default flag for eLBG == true
static boolean DEFAULT_INCREMENTAL
          Default flag for incremental LBG == false
static int DEFAULT_MAXITER
          Default maximun number of iterations == 100
 
Fields inherited from interface java.beans.BeanInfo
ICON_COLOR_16x16, ICON_COLOR_32x32, ICON_MONO_16x16, ICON_MONO_32x32
 
Constructor Summary
CodebookTrainer()
          Creates a new CodebookTrainer
 
Method Summary
 void editBeanInfo(java.beans.BeanInfo info)
           
 int getCodebookSize()
          Gets the Codebook's final size
 double getDelta()
          Gets the convergence factor.
 java.io.File getFinalCodebook()
          Gets the final Codebook File
 java.net.URL getInitCodebook()
          Gets the initial Codebook's URL
 int getMaxIter()
          Gets the maximun number of iterations
 boolean isBinaryCodebook()
          Getter for property binaryCodebook.
 boolean isELBG()
          Return true if eLBG algorithm is used
 boolean isIncremental()
          Return true if codebook size is enlarged incrementally
static void main(java.lang.String[] args)
           
 void process(Buffer in, Buffer out)
          Meaningfull data (DoubleData) is stored untill a (CloseData) is received.
 void setBinaryCodebook(boolean binaryCodebook)
          Setter for property binaryCodebook.
 void setCodebookSize(int size)
          Sets the Codebook's final size
 void setDelta(double delta)
          Sets the convergence factor.
 void setELBG(boolean flag)
          Sets the flag for eLBG algorithm.
 void setFinalCodebook(java.io.File file)
          Sets the final Codebook File
 void setIncremental(boolean flag)
          Sets the flag for incremental codebook enlargement.
 void setInitCodebook(java.net.URL url)
          Sets the initial Codebook's URL.
 void setMaxIter(int n)
          Sets the maximun number of iterations
 
Methods inherited from class edu.gtts.sautrela.engine.AbstractDataProcessor
getAdditionalBeanInfo, getBeanDescriptor, getDefaultEventIndex, getDefaultPropertyIndex, getEventSetDescriptors, getIcon, getMethodDescriptors, getName, getPropertyDescriptors, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CBKSIZE

public static final int DEFAULT_CBKSIZE
Default size for final codebook == 256

See Also:
Constant Field Values

DEFAULT_DELTA

public static final double DEFAULT_DELTA
Default value for convergence factor == 1e-10

See Also:
Constant Field Values

DEFAULT_MAXITER

public static final int DEFAULT_MAXITER
Default maximun number of iterations == 100

See Also:
Constant Field Values

DEFAULT_ELBG

public static final boolean DEFAULT_ELBG
Default flag for eLBG == true

See Also:
Constant Field Values

DEFAULT_INCREMENTAL

public static final boolean DEFAULT_INCREMENTAL
Default flag for incremental LBG == false

See Also:
Constant Field Values

DEFAULT_BINCDBK

public static final boolean DEFAULT_BINCDBK
Default flag for binary Codebook == false

See Also:
Constant Field Values
Constructor Detail

CodebookTrainer

public CodebookTrainer()
Creates a new CodebookTrainer

See Also:
DataProcessor, ClusterSet
Method Detail

getInitCodebook

public java.net.URL getInitCodebook()
Gets the initial Codebook's URL

Returns:
The initial Codebook's URL

setInitCodebook

public void setInitCodebook(java.net.URL url)
Sets the initial Codebook's URL. If set to null, a random one is generated

Parameters:
url - The initial Codebook's URL

isBinaryCodebook

public boolean isBinaryCodebook()
Getter for property binaryCodebook.

Returns:
Value of property binaryCodebook.

setBinaryCodebook

public void setBinaryCodebook(boolean binaryCodebook)
Setter for property binaryCodebook.

Parameters:
binaryCodebook - New value of property binaryCodebook.

getFinalCodebook

public java.io.File getFinalCodebook()
Gets the final Codebook File

Returns:
The final Codebook File

setFinalCodebook

public void setFinalCodebook(java.io.File file)
Sets the final Codebook File

Parameters:
file - The final Codebook File

getCodebookSize

public int getCodebookSize()
Gets the Codebook's final size

Returns:
The Codebook's final size

setCodebookSize

public void setCodebookSize(int size)
Sets the Codebook's final size

Parameters:
size - The Codebook's final size

isIncremental

public boolean isIncremental()
Return true if codebook size is enlarged incrementally

Returns:
The incremental flag

setIncremental

public void setIncremental(boolean flag)
Sets the flag for incremental codebook enlargement. If set to true, the initial codebook size (1 if there is no initial codebook) is doubled until final size is reached, and if set to false, the final size is reached with initial random clusters.

Parameters:
flag - The incremental flag

getDelta

public double getDelta()
Gets the convergence factor.

Returns:
The convergence factor

setDelta

public void setDelta(double delta)
Sets the convergence factor. Convergence is reached when:
(dist_old-dist_new)/dist_new <= delta

Parameters:
delta - The the convergence factor

getMaxIter

public int getMaxIter()
Gets the maximun number of iterations

Returns:
The maximun number of iterations

setMaxIter

public void setMaxIter(int n)
Sets the maximun number of iterations

Parameters:
n - The maximun number of iterations

isELBG

public boolean isELBG()
Return true if eLBG algorithm is used

Returns:
The eLBG algorithm flag

setELBG

public void setELBG(boolean flag)
Sets the flag for eLBG algorithm. If set to true, the eLBG algorithm is used instead of LBG.

Parameters:
flag - The flag for eLBG algorithm

process

public void process(Buffer in,
                    Buffer out)
             throws DataProcessorException
Meaningfull data (DoubleData) is stored untill a (CloseData) is received. Then, the LBG algorithm is performed and the obtained codebook is written to a file as a sequence if a finalCodebook is given and saved in the cdbk variable if it is not null.

Parameters:
in - Input Buffer
out - Output Buffer
Throws:
DataProcessorException

editBeanInfo

public void editBeanInfo(java.beans.BeanInfo info)
Overrides:
editBeanInfo in class AbstractDataProcessor

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

Sautrela