|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ostore.introspect.SemanticDistanceModel
Instrospective model that implements a semantic distance table (distance between events based on continuous time).
The table is structured as follows:
(type_1) => (type_a1,dist_a1) (type_b1,dist_b1) ... (type_n1, dist_n1) (type_2) => (type_a2,dist_a2) (type_b2,dist_b2) ... (type_m1, dist_m1) ... (type_k) => (type_ak,dist_ak) (type_bk,dist_bk) ... (type_lk, dist_lk)where each row contains the distances between
type_i
and
types type_Ai
. This implementation treats the distances
as a sorted list (priority queue) and bounds the number of distances
kept per row (see setMaxRelations(int)
).
Note that the distance values in the table are asymmetric.
This model supports the Model
and
SegmentedModel
interfaces and can export and import
Model.Delta
s and
SegmentedModel.Segment
s to incorporate into this
model or remote ones.
A SemanticDistanceModel
is parameterized by a
SemanticDistanceModel.Filter
. The filter determines how distance
values in the semantic distance table are updated when (i) new observations
are made and (ii) when we wish to incorporate a model Delta
or Segment
. Note that normal operation simply keeps an
access history of record()
calls until
recalculate()
is called. At that point, a Delta
containing a table of only the new observations is created and
incorporated into the model with add_delta()
.
IMPORTANT: Make sure the
QuickSerializable
objects used as observation keys
implement both equals
and hashCode
.
Time
,
Distance
Nested Class Summary | |
---|---|
static class |
SemanticDistanceModel.BoundedPrioQueue
Implementation of a priority queue of bound .
|
static class |
SemanticDistanceModel.Delta
Implements Model.Delta for this model type. |
static interface |
SemanticDistanceModel.Filter
A filter determines how to integrate new semantic distance values into the table. |
static class |
SemanticDistanceModel.Prediction
Implements Model.Prediction for this model type. |
static class |
SemanticDistanceModel.Segment
A Segment object contains the internal model state
associated with a single state. |
static class |
SemanticDistanceModel.Table
The actual semantic distance table. |
static class |
SemanticDistanceModel.TestType
|
static class |
SemanticDistanceModel.Tuple
A <QuickSerializable obs,Distance d, int num> tuple. |
Nested classes inherited from class ostore.oil.Model |
---|
|
Nested classes inherited from class ostore.oil.SegmentedModel |
---|
|
Field Summary | |
---|---|
static String |
class_tag
|
static boolean |
DEBUG
|
Constructor Summary | |
---|---|
SemanticDistanceModel(InputBuffer buffer)
|
|
SemanticDistanceModel(int maxrelations,
Time now,
SemanticDistanceModel.Filter filter)
Construct a new model. |
|
SemanticDistanceModel(Time now)
Construct a new model with default filter WeightedAvgFilter() . |
Method Summary | |
---|---|
void |
add_delta(Model.Delta d)
Incorporate a Delta from a foreign source into our
model. |
protected void |
add_delta(Model.Delta d,
boolean save_times)
Incorporate a Delta with the latest access times in
the table. |
void |
add_segment(SegmentedModel.Segment segment)
Incorporates the portion of the model contained in the specified Segment . |
void |
choose_segments(int num)
Selects the most-relevant num segments to retain,
discarding all others. |
void |
clear()
Forget all observations record ed since the last call to
clear or recalculate . |
void |
clear(int num)
Forget the least-recent record ed observations. |
SemanticDistanceModel.Segment |
get_segment(QuickSerializable id)
Obtain a segment that contains the distance information between id and other types. |
int |
getClients()
Get the number of clients represented by this model. |
SemanticDistanceModel.Table |
getTable()
Get the semantic distance table. |
double |
loglikelihood()
Calculates the log-likelihood of all record ed
observations. |
static void |
main(String[] args)
Self test. |
QuickSerializable[] |
outliers()
Returns the recent observations which the model assigns the lowest likelihood. |
int |
outstanding_observations()
Return the number of observations recorded but not yet incorporated into the model. |
Model.Prediction |
predict(int horizon)
Make a prediction based on current model parameters and observations. |
Model.Delta |
recalculate()
Process recently record ed observations. |
void |
record(QuickSerializable obs)
This method assumes the observation occurred at time now. |
void |
record(QuickSerializable[] obs)
This method assumes the observations occurred at time now. |
void |
record(QuickSerializable[] obs,
Time time)
Record the observations and mark that they occurred at a particular time. |
void |
record(QuickSerializable obs,
Time time)
Record the observation and mark that it occurred at a particular time. |
void |
serialize(OutputBuffer buffer)
Add the object to the buffer . |
void |
setClients(int clients)
Set the number of clients represented by this model |
void |
setMaxRelations(int num)
Set the maximum number of distances to keep for each observation type. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final boolean DEBUG
public static final String class_tag
Constructor Detail |
public SemanticDistanceModel(Time now)
WeightedAvgFilter()
.
public SemanticDistanceModel(int maxrelations, Time now, SemanticDistanceModel.Filter filter)
maxrelations
- the max number of relations per keynow
- the time this model was created
(can be dynamically altered later with setMaxRelations
)filter
- the filter used to recalculate semantic distance values.public SemanticDistanceModel(InputBuffer buffer) throws QSException
Method Detail |
public void serialize(OutputBuffer buffer)
QuickSerializable
buffer
.
serialize
in interface QuickSerializable
buffer
- the output buffer to add the object topublic void record(QuickSerializable obs, Time time)
ContinuousModel
record
in interface ContinuousModel
obs
- the observationtime
- the time it occurredpublic void record(QuickSerializable[] obs, Time time)
ContinuousModel
record
in interface ContinuousModel
obs
- the observationstime
- the time they occurredpublic void record(QuickSerializable obs)
ContinuousModel
record
in interface ContinuousModel
obs
- Any event, value, etc. that this
Model
understands.public void record(QuickSerializable[] obs)
ContinuousModel
record
in interface ContinuousModel
obs
- An array of events, values, etc., not
necessarily all the same type, that this
Model
understands.public int outstanding_observations()
public void clear(int num)
Model
record
ed observations.
clear
in interface Model
public void clear()
Model
record
ed since the last call to
clear
or recalculate
.
clear
in interface Model
public double loglikelihood()
Model
record
ed
observations. Only observations recorded since the last call to
clear
or recalculate
are considered.
loglikelihood
in interface Model
D
) given the current
model (M
); log(p(D|M))
. If no
observations exist, it returns Double.NaN
.public Model.Delta recalculate()
Model
record
ed observations. The internal
model parameters are updated to produce the model which maximizes
the likelihood of the observations. Observations are forgotten
after processing, as if clear
were called.
Different Model
s may provide different semantics for
how prior parameters are included in the resulting ones. For
instance, sufficient statistics may be added cumulatively,
parameters may have finite moments, etc.
recalculate
in interface Model
Delta
storing the difference between the new
model parameters and the old.public Model.Prediction predict(int horizon)
Model
predict
in interface Model
Prediction
, whose semantics depends on the
particular subclass of Model
.public QuickSerializable[] outliers()
Model
outliers
in interface Model
public void add_delta(Model.Delta d)
Delta
from a foreign source into our
model. Do not save the latest access times in the delta.
add_delta
in interface Model
d
- the deltaprotected void add_delta(Model.Delta d, boolean save_times)
Delta
with the latest access times in
the table. This should be used to incorporate deltas we create to our
own table.
d
- the deltasave_times
- save the latest access times in the delta in
the model table.public void add_segment(SegmentedModel.Segment segment)
SegmentedModel
Segment
.
add_segment
in interface SegmentedModel
segment
- The Segment
to add.SegmentedModel.choose_segments(int)
public void choose_segments(int num)
SegmentedModel
num
segments to retain,
discarding all others.
choose_segments
in interface SegmentedModel
num
- The number of Segment
s to keep.public SemanticDistanceModel.Segment get_segment(QuickSerializable id)
id
and other types. This segment can be swapped to
other SemanticDistanceModel
s.
id
- the type from
id
to
other types. null
if we don't know about id
public SemanticDistanceModel.Table getTable()
public void setClients(int clients)
public int getClients()
public void setMaxRelations(int num)
num
semantically
closest values for each observation type.
num
- the new max number of distances.public String toString()
toString
in class Object
public static void main(String[] args) throws Exception
Exception
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |