|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.ExhibitPropsComputableMutableVoteCache
public final class ExhibitPropsComputableMutableVoteCache
Class to cache vote computations and correlated values. In particular this aims to avoid repeated expensive recomputation of underlying vote values so as global correlations can be efficiently computed.
| Nested Class Summary | |
|---|---|
private static class |
ExhibitPropsComputableMutableVoteCache.Accum
The class in which we accumulate stats while recomputing correlations. |
static class |
ExhibitPropsComputableMutableVoteCache.CorrType
Correlation types. |
| Field Summary | |
|---|---|
private static int |
_computeMaxConcurrentUpdateThreads
Maximum number of threads to allow in update(); strictly positive. |
private java.util.concurrent.locks.ReentrantLock |
_uCoreLock
Private lock to prevent more than one thread at once expending effort in the core part of update(). |
private java.util.concurrent.Semaphore |
_uStartSem
Counting semaphore to limit update() first-phase concurrency; never null. |
private static boolean |
EAGER_VOTE_LOAD
If true then try to load/compute early the scores of voted-for-exhibits. |
private static char |
KEY_SEPARATOR_CHAR
Key-separator character; not a valid exhibit-name character. |
private static java.lang.String |
MARKER_KEY
Special marker key value to indicate when we last computed correlations. |
private static ExhibitPropsComputableMutable.Factor[] |
NO_CORRELATES
Immutable empty correlates list. |
private static long |
serialVersionUID
Unique Serialisation class ID generated by http://random.hd.org/. |
private static float |
SIGNIFICANCE_CONF_THRESHOLD
Significance confidence threshold; non-negative. |
private static int |
SIGNIFICANCE_COUNT_THRESHOLD
Significance count threshold for non-sparse correlations; non-negative. |
private int |
UPDATE_TIME_LIMIT_MS
Time limit for update() in ms; strictly positive. |
private static boolean |
USE_ALL_BUCKET
If true then try to use the "all" votes buckets rather than summing the other buckets. |
private java.util.Hashtable<java.lang.String,Tuple.Pair<java.lang.Long,ExhibitPropsComputableMutable.Factor>> |
voteCorrCacheMap
Map from vote/correlation key to compute Factor and period for which it was computed; never null after construction/deserialisation. |
| Fields inherited from interface org.hd.d.pg2k.svrCore.ExhibitPropsComputableMutableVoteCacheIF |
|---|
TRIVIAL |
| Constructor Summary | |
|---|---|
|
ExhibitPropsComputableMutableVoteCache()
Construct default empty cache. |
private |
ExhibitPropsComputableMutableVoteCache(java.util.Hashtable<java.lang.String,Tuple.Pair<java.lang.Long,ExhibitPropsComputableMutable.Factor>> map)
Reconstruct object, eg during deserialisation. |
| Method Summary | |
|---|---|
private static void |
_clearStaleState(java.util.Hashtable<java.lang.String,Tuple.Pair<java.lang.Long,ExhibitPropsComputableMutable.Factor>> map)
Remove stale state from the map passed in. |
private void |
_findCorrelates(ExhibitStaticAttr esa,
AllExhibitProperties aep,
long currentPeriod,
java.util.List<ExhibitPropsComputableMutable.Factor> result,
boolean force)
Append to the result List any factors we find for this exhibit. |
ExhibitPropsComputableMutable.Factor |
calcVoteFactor(java.lang.String exhibitName,
AllExhibitProperties aep,
BasicVarMgrInterface vars)
Compute the vote or retrieve from cache; never null. |
ExhibitPropsComputableMutable.Factor[] |
getCorrelates(ExhibitStaticAttr esa,
AllExhibitProperties aep,
BasicVarMgrInterface vars,
boolean force)
Get correlates for specified exhibit; never null but result may be empty. |
java.lang.Boolean |
isCategoryGood(java.lang.String categoryDir,
AllExhibitProperties aep,
BasicVarMgrInterface vars,
boolean force)
Find out if a category is rated "good"/popular or not. |
protected java.lang.Object |
readResolve()
Deserialise: use constructor for validation, defensive copying, etc. |
void |
update(AllExhibitProperties aep,
BasicVarMgrInterface vars,
boolean noTimeLimit)
Bring correlations data up to date. |
void |
validateObject()
Validates the object. |
protected java.lang.Object |
writeReplace()
Serialise: strip out stale information before serialising. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final char KEY_SEPARATOR_CHAR
private final java.util.Hashtable<java.lang.String,Tuple.Pair<java.lang.Long,ExhibitPropsComputableMutable.Factor>> voteCorrCacheMap
One valid key format is a full, valid exhibit name.
Other keys are of the form of a CorrType name followed by a colon followed by the rest of the key.
This state can be serialised; it is also recomputed on demand.
We use a Hashtable to be thread-safe.
private static final ExhibitPropsComputableMutable.Factor[] NO_CORRELATES
private static final float SIGNIFICANCE_CONF_THRESHOLD
A value between 0.001 (0.1%) and 0.1 (10%) is probably reasonable.
private static final int SIGNIFICANCE_COUNT_THRESHOLD
A value between 2 and 10 is probably reasonable; an odd value avoids recording a "neutral" score at minimum count.
private final int UPDATE_TIME_LIMIT_MS
This should still let us get a reasonable amount of work done so that we can rebuild the data incrementally if necessary.
private final java.util.concurrent.locks.ReentrantLock _uCoreLock
private static final int _computeMaxConcurrentUpdateThreads
private final java.util.concurrent.Semaphore _uStartSem
private static final boolean EAGER_VOTE_LOAD
An eager setup should be able to compute the correlations more quickly, but at increased risk of using part/all somewhat/very stale values, and thus generating a less good result.
private static final boolean USE_ALL_BUCKET
private static final java.lang.String MARKER_KEY
private static final long serialVersionUID
| Constructor Detail |
|---|
public ExhibitPropsComputableMutableVoteCache()
private ExhibitPropsComputableMutableVoteCache(java.util.Hashtable<java.lang.String,Tuple.Pair<java.lang.Long,ExhibitPropsComputableMutable.Factor>> map)
throws java.io.InvalidObjectException
We also take the opportunity to strip out any invalid/stale state.
We hold a lock on the map parameter while copying its state.
java.io.InvalidObjectException| Method Detail |
|---|
public final ExhibitPropsComputableMutable.Factor calcVoteFactor(java.lang.String exhibitName,
AllExhibitProperties aep,
BasicVarMgrInterface vars)
throws java.io.IOException
The returned factor's goodness can range from -1 to +1, and confidence from 0 to +1; any scaling required will have to be applied elsewhere.
calcVoteFactor in interface ExhibitPropsComputableMutableVoteCacheIFexhibitName - full, valid exhibit name; never nullaep - never nullvars - never null
java.io.IOException
public ExhibitPropsComputableMutable.Factor[] getCorrelates(ExhibitStaticAttr esa,
AllExhibitProperties aep,
BasicVarMgrInterface vars,
boolean force)
throws java.io.IOException
The goodness of each Factor is either -1 or +1, with the correlation/confidence ranging between 0 and 1.
This will return values computed up to one period ago if need be, to help avoid a sudden splurge of CPU effort as we tick from one period to the next.
No particular ordering of the results is guaranteed, but there will be no duplicates and no nulls.
getCorrelates in interface ExhibitPropsComputableMutableVoteCacheIFforce - if true, force complete computation if need be,
else we will just return what we have in cache;
complete recomputation may be expensive but should last a long time
and we will abort with an IOException if we cannot complete
the recomputation in a reasonable time
java.io.IOException - cannot extract required correlates
public java.lang.Boolean isCategoryGood(java.lang.String categoryDir,
AllExhibitProperties aep,
BasicVarMgrInterface vars,
boolean force)
throws java.io.IOException
isCategoryGood in interface ExhibitPropsComputableMutableVoteCacheIFcategoryDir - the initial directory component of an extant exhibitforce - if true may force (expensive) computation to give
a more accurate answer,
else may return a more approximate or stale answer,
or none at all (null)
java.io.IOException
private void _findCorrelates(ExhibitStaticAttr esa,
AllExhibitProperties aep,
long currentPeriod,
java.util.List<ExhibitPropsComputableMutable.Factor> result,
boolean force)
esa - the exhibit name/attr; never nullcurrentPeriod - current VLONG period; strictly positiveresult - found correlates are appended to this valueforce - if false then accept any extant value;
if true then only accept values up to one period old
public void update(AllExhibitProperties aep,
BasicVarMgrInterface vars,
boolean noTimeLimit)
throws java.io.IOException
This may be a relatively expensive call, though if values are up-to-date then this should be quite cheap.
This is thread-safe and will use multiple caller threads to help fetch vote data and concurrently recompute exhibit scores, though second and subsequent concurrent calling threads will return immediately upon reaching the core correlation computations in order to prevent wasted duplicate effort.
If this routine cannot get values it needs then it throws an IOException.
No work will be done for an empty aep.
This will abort with an IOException if taking too long (of the order of many seconds) or cannot otherwise ensure that the correlations data is up-to-date. Thus if this returns without throwing an IOException then the correlations data can be assumed to be up-to-date.
update in interface ExhibitPropsComputableMutableVoteCacheIFaep - current exhibit properties; never nullvars - handle on system variables; never nullnoTimeLimit - if true, this runs until complete if possible
java.io.IOException - if the correlations data cannot be guaranteed
to be up-to-date
and/or a problem was found fetching required data
and/or the routine was taking to long to complete the calculationsprotected java.lang.Object writeReplace()
private static void _clearStaleState(java.util.Hashtable<java.lang.String,Tuple.Pair<java.lang.Long,ExhibitPropsComputableMutable.Factor>> map)
We only remove things more than one period old so that we can gently recompute values in the background rather than being bounced into it as we roll into a new period.
map - non-null map.
protected java.lang.Object readResolve()
throws java.io.ObjectStreamException
java.io.ObjectStreamException
public void validateObject()
throws java.io.InvalidObjectException
validateObject in interface java.io.ObjectInputValidationjava.io.InvalidObjectException - If the object cannot validate itself
|
DHD Multimedia Gallery V1.50.55 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||