ostore.oil
Class Screen

java.lang.Object
  |
  +--ostore.oil.Screen
All Implemented Interfaces:
Model, QuickSerializable

public class Screen
extends Object
implements Model

A model that filters a stream of QuickSerializable objects. The Screen counts the number of times each of a specified set of keys occurs in the stream.

Internally HashMaps are used to store the set of interesting keys. It is therefore not advised to apply this class to objects whose hashCode or equals methods are expensive to compute.

This class is synchronized.

Version:
$Id: Screen.java,v 1.10 2002/07/20 18:44:40 srhea Exp $
Author:
Dennis Geels
See Also:
Model

Nested Class Summary
 
Nested classes inherited from class ostore.oil.Model
Model.Delta, Model.Prediction
 
Constructor Summary
Screen()
          Construct a new Screen.
Screen(boolean remember)
          Construct a new Screen.
Screen(InputBuffer buffer)
          Constructs a Screen from its serialized form.
 
Method Summary
 void add_delta(Model.Delta d)
          Incorporate the information from a Delta into this Model.
 void clear()
          Forget all observations recorded since the last call to clear or recalculate.
 void clear(int num)
          Forget the least-recent recorded observations.
 int get_all_counts()
          Returns the current sum of all counts.
 int get_count(QuickSerializable key)
          Returns the current count for the specified key.
 double loglikelihood()
          Calculates the log-likelihood of all recorded observations.
 QuickSerializable[] outliers()
          Returns the recent observations which the model assigns the lowest likelihood.
 Model.Prediction predict(int horizon)
          Make a prediction based on current model parameters and observations.
 Model.Delta recalculate()
          Processes the recent event stream.
 void record(QuickSerializable observation)
          Records an object from the event stream (does not process).
 void record(QuickSerializable[] observations)
          Processes a group of objects from the event stream.
 void remove_all()
          Removes all keys from the screened set.
 void remove(QuickSerializable key)
          Removes a key from the screened set.
 void serialize(OutputBuffer buffer)
          Add the object to the buffer.
 int total()
          Returns the current total count.
 void watch(QuickSerializable key)
          Adds a key to screened.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Screen

public Screen()
Construct a new Screen.


Screen

public Screen(InputBuffer buffer)
       throws QSException
Constructs a Screen from its serialized form.


Screen

public Screen(boolean remember)
Construct a new Screen.

Parameters:
remember - true iff the Screen should remember the counts for keys that are removed.
Method Detail

watch

public void watch(QuickSerializable key)
Adds a key to screened. If this Screen remembers a previous count for the specified key, that count shall be restored.

Parameters:
key - The object to look for in the stream.

remove

public void remove(QuickSerializable key)
Removes a key from the screened set. If this Screen has been told to remember old keys, the key and its current count will be stored for later salvaging.

Parameters:
key - The object to stop looking for.

remove_all

public void remove_all()
Removes all keys from the screened set. If this Screen has been told to remember old keys, the keys and their current counts will be stored for later salvaging.


get_count

public int get_count(QuickSerializable key)
Returns the current count for the specified key.

Parameters:
key - The key whose count to return.
Returns:
the number of times key has been processed. If the key was never watched, or has since been forgotten, returns 0.

get_all_counts

public int get_all_counts()
Returns the current sum of all counts.

Returns:
the number of times any currently watched key has been matched.

total

public int total()
Returns the current total count.

Returns:
the total number of observations processed.

record

public void record(QuickSerializable observation)
Records an object from the event stream (does not process).

Specified by:
record in interface Model
Parameters:
observation - The object to record

record

public void record(QuickSerializable[] observations)
Processes a group of objects from the event stream. If an object matches any key in the watched set, increments the proper counters.

Specified by:
record in interface Model
Parameters:
observations - The objects to record

clear

public void clear(int num)
Description copied from interface: Model
Forget the least-recent recorded observations.

Specified by:
clear in interface Model

clear

public void clear()
Description copied from interface: Model
Forget all observations recorded since the last call to clear or recalculate.

Specified by:
clear in interface Model

loglikelihood

public double loglikelihood()
Description copied from interface: Model
Calculates the log-likelihood of all recorded observations. Only observations recorded since the last call to clear or recalculate are considered.

Specified by:
loglikelihood in interface Model
Returns:
a non-positive number equal to the logarithm of the probability of the observations (D) given the current model (M); log(p(D|M)). If no observations exist, it returns Double.NaN.

recalculate

public Model.Delta recalculate()
Processes the recent event stream. If an object matches any key in the watched set, this method increments the proper counters.

Specified by:
recalculate in interface Model
Returns:
A Delta storing the difference between the new model parameters and the old.

predict

public Model.Prediction predict(int horizon)
Description copied from interface: Model
Make a prediction based on current model parameters and observations.

Specified by:
predict in interface Model
Returns:
A Prediction, whose semantics depends on the particular subclass of Model.

outliers

public QuickSerializable[] outliers()
Description copied from interface: Model
Returns the recent observations which the model assigns the lowest likelihood. This method is useful both for standard outlier detections as well as for swapping in model segments using reverse lookup.

Specified by:
outliers in interface Model
Returns:
an array containing recent observations which the model did not expect.

add_delta

public void add_delta(Model.Delta d)
Description copied from interface: Model
Incorporate the information from a Delta into this Model. The resulting Model should be equivalent to that which produced the Delta, given that they began in the same state. Subclasses of Model employ specific subclasses of Delta.

Specified by:
add_delta in interface Model

serialize

public void serialize(OutputBuffer buffer)
Description copied from interface: QuickSerializable
Add the object to the buffer.

Specified by:
serialize in interface QuickSerializable
Parameters:
buffer - the output buffer to add the object to