|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.aliasi.corpus.Corpus<ObjectHandler<E>>
com.aliasi.corpus.XValidatingObjectCorpus<E>
E - the type of objects handled.public class XValidatingObjectCorpus<E>
An XValidatingObjectCorpus holds a list of items
which it uses to provide training and testing items using
cross-validation.
handle(Object) is used to add items to the
corpus. The items will be stored in the order in which they
are received (though they may be permuted later).
When used as a handler, this class simply collects the items and stores them in a list. This allows an instance of this class to be used like any other object handler.
Initially, the fold will be set to 0, but the fold may be reset
later using setFold(int). Iterating between 0 and the
number of folds minus 1 will work through all folds. The method
size() returns the size of the corpus and fold()
is the current fold.
For cases where numFolds() is greater than zero,
the start and end of a fold are defined by:
Ifstart(fold) = (int) (size() * fold() / (double) numFolds()) end(fold) = start(fold+1)
numFolds() is 0, the start and end for the fold
are 0, so that visiting the training part of the corpus visits
the entire corpus.
The randomization method permuteCorpus(Random) randomizes
the list of items. This can be useful for removing local
dependencies.
Corpus.visitCorpus(Handler) will run the specified handler over all of
the data collected in this corpus.
If the number of folds is set to 1, then Corpus.visitTest(Handler) visits the entire corpus.
If the number of folds is set to 0, Corpus.visitTrain(Handler)
visits the entire corpus.
This class must be used with external read/write synchronization. The write operations include the constructor, set-fold, set number of folds, permute corpus, and handle methods. The read operations include the visit num instances and fold reporting methods.
| Constructor Summary | |
|---|---|
XValidatingObjectCorpus(int numFolds)
Construct a cross-validating corpus with the specified number of folds. |
|
| Method Summary | |
|---|---|
int |
fold()
Returns the current fold. |
void |
handle(E e)
Add the specified item to the end of the corpus. |
int |
numFolds()
Return the number of folds for this cross-validating corpus. |
void |
permuteCorpus(Random random)
Randomly permutes the corpus using the specified randomizer. |
void |
setFold(int fold)
Set the current fold to the specified value. |
void |
setNumFolds(int numFolds)
Sets the number of folds to the specified value. |
int |
size()
Return the number of items in this corpus. |
void |
visitCorpus(ObjectHandler<E> handler)
Visit the entire corpus, sending all extracted events to the specified handler. |
void |
visitCorpus(ObjectHandler<E> trainHandler,
ObjectHandler<E> testHandler)
Visit the entire corpus, first sending training events to the specified training handler and then sending testing events to the test handler. |
void |
visitTest(ObjectHandler<E> handler)
Send all of the test items to the specified handler. |
void |
visitTrain(ObjectHandler<E> handler)
Send all of the training items to the specified handler. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public XValidatingObjectCorpus(int numFolds)
See the class documentation above for information on how the number of folds is used.
numFolds - Number of folds in the corpus.
IllegalArgumentException - If the number of folds is
negative.| Method Detail |
|---|
public int numFolds()
public void setNumFolds(int numFolds)
See the class documentation above for information on how the number of folds is used.
numFolds - Number of folds.
IllegalArgumentException - If the number of folds is
negative.public int fold()
public void permuteCorpus(Random random)
random - Randomizer to use for permutation.public void setFold(int fold)
Warning: If the number of folds is set to zero, this method will throw an exception.
IllegalArgumentException - If the fold is not greater than
or equal to 0 and less than the number of folds.public int size()
public void handle(E e)
handle in interface ObjectHandler<E>e - Item to add to corpus.public void visitTrain(ObjectHandler<E> handler)
visitTrain in class Corpus<ObjectHandler<E>>handler - Handler receiving training items.public void visitTest(ObjectHandler<E> handler)
visitTest in class Corpus<ObjectHandler<E>>handler - Handler receiving training items.public void visitCorpus(ObjectHandler<E> handler)
CorpusThis is just a convenience method that is defined by:
visitCorpus(handler,handler);
visitCorpus in class Corpus<ObjectHandler<E>>handler - Handler for events extracted from the corpus.
public void visitCorpus(ObjectHandler<E> trainHandler,
ObjectHandler<E> testHandler)
CorpusThis is just a convenience method that is defined by:
visitTrain(trainHandler); visitTest(testHandler);
visitCorpus in class Corpus<ObjectHandler<E>>trainHandler - Handler for training events from the corpus.testHandler - Handler for testing events from the corpus.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||