cz.cuni.jagrlib.piece
Class IntervalArray

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.piece.IntervalArray
All Implemented Interfaces:
Breakable, EntropyHistogram, Property, WheelOfFortune, Template

public class IntervalArray
extends Piece
implements EntropyHistogram

Entropy histogram implementation: map of cummulative frequency interval trees.

Since:
0.24
See Also:
IntervalArray.java

Nested Class Summary
protected  class IntervalArray.CFTree
          Cummulative frequency interval tree.
 
Field Summary
protected static java.lang.String CATEGORY
          Object category.
protected  IntMap<IntervalArray.CFTree> contexts
          All open contexts.
protected  IntervalArray.CFTree ctx
          The actual context.
protected  int ctxId
          Identifier of the actual context.
protected  boolean defaultNonZero
          Default non-zero flag.
protected  long defaultSumLimit
          Default frequency sum limit.
protected  int defaultSymbols
          Default number of symbols.
static RegPiece reg
          Static registration instance for this class.
protected static java.lang.String TEMPLATE_NAME
          Object template identifier.
 
Fields inherited from class cz.cuni.jagrlib.Piece
channels, info, pl, plugs, TEMPLATE_TYPE, userBreak
 
Fields inherited from interface cz.cuni.jagrlib.iface.Property
LOGGING, STATISTICS, TEXT_DESCRIPTION
 
Fields inherited from interface cz.cuni.jagrlib.Template
ALL_PLUGS, C_1D, C_2D, C_3D, C_ALPHA, C_BINARY, C_BREP, C_CAMERA, C_CIRCLE, C_CLIP, C_COMPRESSION, C_CURVE, C_DATA, C_DRAW, C_EDITOR, C_ELLIPSE, C_FILL, C_FILTER, C_FLOAT, C_FUNCTION, C_IMAGE, C_INTEGER, C_IO, C_LIGHT, C_LINE, C_METRIC, C_POLYGON, C_PROJECTION, C_RADIOSITY, C_RASTER, C_RENDER, C_SAMPLE, C_SCENE, C_SET, C_SOLID, C_TEXT, C_TRANSFORM, C_VECTOR, C_VIEWER, C_WORKER, CAT_EMPTY, EMPTY, IFACE, JAGRLIB, JAGRLIB2, MANIPULATOR_COMBO, MANIPULATOR_CUSTOM, MANIPULATOR_DEFAULT, MANIPULATOR_MULTILINE, PL_ALPHAMASK, PL_BITMASK, PL_CAUSTIC, PL_CODEC, PL_COLORMAP, PL_COMPARE, PL_DATA, PL_DIRECT, PL_EDITOR, PL_FILTER, PL_FUNCTION, PL_IMAGE, PL_IMPORT, PL_INPUT, PL_INTERSECTION, PL_LIGHTSOURCE, PL_ORDER, PL_OUTPUT, PL_PALETTE, PL_PHOTON, PL_PROPERTY, PL_QUANTIZER, PL_RASTER, PL_RENDER, PL_SHADOW, PL_STREAM, PL_TRANSFORM, PL_TRIGGER, PL_VOLUME, PL_WINDOW, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INTEGER, TYPE_LONG, TYPE_OBJECT, TYPE_STRING
 
Constructor Summary
IntervalArray()
           
 
Method Summary
 int convert(long cf)
          Converts a frequency sum to the corresponding symbol.
 void decimate()
          Divides each frequency in the current context by 2.
 long get(int s)
          Returns the frequency of the given symbol.
 java.lang.Object get(java.lang.String key)
          Gets the given property.
 int getContext()
          Returns the current context.
 boolean getNonZero()
          Read non-zero attribute for the current context
 long getSumLimit()
          Returns the frequency sum limit for the current context.
 int getSymbols()
          Returns the number of symbols in the current context.
 void inc(int s)
          Increments a single symbol's frequency by 1.
 void inc(int symbol, long _freq)
          Increments a single symbol's frequency.
 void inc(long[] f)
          Increments frequencies of all symbols in the current context.
 void init(int _defaultSymbols, long _defaultSumLimit, boolean _defaultNonZero, int _ctxId)
          Histogram (re-)initialization.
 long left(int s)
          Returns the start of the symbol's cummulative frequency interval (the frequency sum of all preceding symbols).
protected  void printStatistics()
           
 void set(int symbol, long _freq)
          Sets a single symbol's frequency.
 void set(long[] f)
          Sets frequencies of all symbols in the current context.
 void set(java.lang.String key, java.lang.Object value)
          Sets the given property.
 int setContext(int _ctxId)
          Sets the given context as current.
 void setDefaultNonZero(boolean b)
          Set non-zero attribute: keep frequencies non-zero at all times?
 void setDefaultSumLimit(long l)
          Sets the new default frequency sum limit for new contexts.
 void setDefaultSymbols(int i)
          Sets the new default number of symbols for new contexts.
 void setNonZero(boolean b)
          Set non-zero attribute for the current context: keep frequencies non-zero at all times?
 void setSumLimit(long l)
          Changes the frequency sum limit for the current context.
 void setSymbols(int i)
          Changes the number of symbols in the current context.
static int setTemplate(Template t, int ord)
          General-purpose registration routine.
 long total()
          Returns the frequency sum of all symbols in the current context.
 
Methods inherited from class cz.cuni.jagrlib.Piece
className, connect, findPlug, findPlug, getInfo, getInterface, getInterface, getPlug, getReg, init, isCompatible, isCompatible, isConnected, logError, logWarning, myInterface, newInputPlug, newOptOutputPlug, newOutputPlug, newPlug, noTemplates, propBegin, propBounds, propDefault, propEnd, propEnum, propManipulator, propManipulator, setProgressListener, setRegStrings, setTemplateDynamic, stop
 
Methods inherited from class cz.cuni.jagrlib.DefaultProperty
booleanProperty, booleanProperty, colorDoubleProperty, colorProperty, commit, doubleProperty, doubleProperty, doubleProperty, enumProperty, floatProperty, floatProperty, floatProperty, intProperty, intProperty, intProperty, longProperty, longProperty, longProperty, set, stringProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.jagrlib.iface.Property
commit
 

Field Detail

ctxId

protected int ctxId
Identifier of the actual context.


ctx

protected IntervalArray.CFTree ctx
The actual context.


contexts

protected IntMap<IntervalArray.CFTree> contexts
All open contexts.


defaultSymbols

protected int defaultSymbols
Default number of symbols.


defaultSumLimit

protected long defaultSumLimit
Default frequency sum limit.


defaultNonZero

protected boolean defaultNonZero
Default non-zero flag.


TEMPLATE_NAME

protected static final java.lang.String TEMPLATE_NAME
Object template identifier.

See Also:
Constant Field Values

CATEGORY

protected static final java.lang.String CATEGORY
Object category.

See Also:
Constant Field Values

reg

public static final RegPiece reg
Static registration instance for this class. Automatically initialized in class-loading time.

Constructor Detail

IntervalArray

public IntervalArray()
Method Detail

init

public void init(int _defaultSymbols,
                 long _defaultSumLimit,
                 boolean _defaultNonZero,
                 int _ctxId)
Histogram (re-)initialization. Destroys all previously collected statistics.

Specified by:
init in interface EntropyHistogram
Parameters:
_defaultSymbols - Default number of symbols for new contexts.
_defaultSumLimit - Default frequency sum limit for new contexts (0 for no bounds).
_defaultNonZero - Keeps frequencies non-zero at all times. Default frequencies are the lowest possible.
_ctxId - The initial context.
See Also:
setDefaultSymbols(int), setDefaultSumLimit(long), setDefaultNonZero(boolean), decimate()

setDefaultSymbols

public void setDefaultSymbols(int i)
Sets the new default number of symbols for new contexts.

Specified by:
setDefaultSymbols in interface EntropyHistogram
Parameters:
i - New default number of symbols.
See Also:
init(int, long, boolean, int), setSymbols(int), getSymbols()

setSymbols

public void setSymbols(int i)
Changes the number of symbols in the current context. Keeps previous frequencies (truncated or padded with the default value).

Specified by:
setSymbols in interface WheelOfFortune
Parameters:
i - New number of symbols.
See Also:
setDefaultSymbols(int), getSymbols(), decimate()

getSymbols

public int getSymbols()
Returns the number of symbols in the current context.

Specified by:
getSymbols in interface WheelOfFortune
Returns:
Number of symbols.
See Also:
setDefaultSymbols(int), setSymbols(int)

setDefaultSumLimit

public void setDefaultSumLimit(long l)
Sets the new default frequency sum limit for new contexts.

Specified by:
setDefaultSumLimit in interface EntropyHistogram
Parameters:
l - New default frequency sum limit (0 for no bounds).
See Also:
init(int, long, boolean, int), setSumLimit(long), getSumLimit(), total()

setSumLimit

public void setSumLimit(long l)
Changes the frequency sum limit for the current context.

Specified by:
setSumLimit in interface EntropyHistogram
Parameters:
l - New frequency sum limit (0 for no bounds).
See Also:
init(int, long, boolean, int), setDefaultSumLimit(long), getSumLimit(), decimate(), total()

getSumLimit

public long getSumLimit()
Returns the frequency sum limit for the current context.

Specified by:
getSumLimit in interface EntropyHistogram
Returns:
Frequency sum limit (0 for no bounds).
See Also:
init(int, long, boolean, int), setDefaultSumLimit(long), setSumLimit(long), total()

setDefaultNonZero

public void setDefaultNonZero(boolean b)
Set non-zero attribute: keep frequencies non-zero at all times? Value for new contexts.

Specified by:
setDefaultNonZero in interface EntropyHistogram
Parameters:
b - Non-zero attribute for new contexts.
See Also:
init(int, long, boolean, int), setNonZero(boolean), getNonZero()

setNonZero

public void setNonZero(boolean b)
Set non-zero attribute for the current context: keep frequencies non-zero at all times?

Specified by:
setNonZero in interface EntropyHistogram
Parameters:
b - Non-zero attribute for the current context.
See Also:
init(int, long, boolean, int), setDefaultNonZero(boolean), getNonZero(), decimate()

getNonZero

public boolean getNonZero()
Read non-zero attribute for the current context

Specified by:
getNonZero in interface EntropyHistogram
Returns:
Non-zero attribute of the current context.
See Also:
init(int, long, boolean, int), setDefaultNonZero(boolean), setNonZero(boolean)

setContext

public int setContext(int _ctxId)
Sets the given context as current. For unknown contexts initializes parameters to default values.

Specified by:
setContext in interface EntropyHistogram
Parameters:
_ctxId - Identifier of the new context.
Returns:
Identifier of the old context.
See Also:
init(int, long, boolean, int), setDefaultSymbols(int), setDefaultSumLimit(long), getContext()

getContext

public int getContext()
Returns the current context.

Specified by:
getContext in interface EntropyHistogram
Returns:
Id of the current context.
See Also:
setContext(int)

decimate

public void decimate()
Divides each frequency in the current context by 2. Called automatically when the total frequency sum exceeds the limit.

Specified by:
decimate in interface EntropyHistogram
See Also:
init(int, long, boolean, int), setDefaultSumLimit(long), setSumLimit(long), getSumLimit(), setDefaultNonZero(boolean), setNonZero(boolean), getNonZero(), total()

set

public void set(long[] f)
Sets frequencies of all symbols in the current context. Can be used for context re-initialization (null parameter).

Specified by:
set in interface WheelOfFortune
Parameters:
f - Array of new frequencies. Can be null for context re-initialization.
See Also:
set(int,long), decimate()

set

public void set(int symbol,
                long _freq)
Sets a single symbol's frequency.

Specified by:
set in interface WheelOfFortune
Parameters:
symbol - Symbol code.
_freq - New frequency of the symbol.
See Also:
set(long[]), decimate()

inc

public void inc(long[] f)
Increments frequencies of all symbols in the current context.

Specified by:
inc in interface EntropyHistogram
Parameters:
f - Array of frequency increments.
See Also:
inc(int,long), inc(int), decimate()

inc

public void inc(int symbol,
                long _freq)
Increments a single symbol's frequency.

Specified by:
inc in interface EntropyHistogram
Parameters:
symbol - Symbol code.
_freq - Frequency increment of the symbol.
See Also:
inc(long[]), inc(int), decimate()

inc

public void inc(int s)
Increments a single symbol's frequency by 1.

Specified by:
inc in interface EntropyHistogram
Parameters:
s - Symbol code.
See Also:
inc(int,long), inc(long[]), decimate()

total

public long total()
Returns the frequency sum of all symbols in the current context. Same as left( getSymbols() ), but might be more effective.

Specified by:
total in interface WheelOfFortune
Returns:
The total frequency sum.
See Also:
left(int), get(int), convert(long)

left

public long left(int s)
Returns the start of the symbol's cummulative frequency interval (the frequency sum of all preceding symbols).

Specified by:
left in interface WheelOfFortune
Parameters:
s - Symbol code.
Returns:
The sum of all preceding symbol frequencies.
See Also:
total(), get(int), convert(long)

get

public long get(int s)
Returns the frequency of the given symbol. Same as left( _symbol + 1 ) - left( _symbol ).

Specified by:
get in interface WheelOfFortune
Parameters:
s - Symbol code.
Returns:
The frequency of that symbol.
See Also:
total(), left(int), convert(long)

convert

public int convert(long cf)
Converts a frequency sum to the corresponding symbol.

Specified by:
convert in interface WheelOfFortune
Parameters:
cf - Frequency sum of the unknown symbol.
Returns:
The symbol which has _sum in it's cummulative frequency interval.
See Also:
total(), left(int), get(int)

printStatistics

protected void printStatistics()

set

public void set(java.lang.String key,
                java.lang.Object value)
Sets the given property.

Specified by:
set in interface Property
Overrides:
set in class DefaultProperty
Parameters:
key - Key string.
value - The new value.
See Also:
Property.commit()

get

public java.lang.Object get(java.lang.String key)
Gets the given property.

Specified by:
get in interface Property
Overrides:
get in class DefaultProperty
Parameters:
key - Key string.
Returns:
The actual value or null.

setTemplate

public static int setTemplate(Template t,
                              int ord)
General-purpose registration routine. Sets all plugs, strings, etc. to the given Template.