|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectLBJ2.parse.FoldParser
public class FoldParser
Useful when performing k-fold cross validation, this parser filters the examples coming from another parser. Conceptually, the examples from the original parser are first split into k "folds" (or partitions) depending on the selected splitting strategy. A particular fold is then selected as the pivot, and this parser can be configured either to return all and only the examples from that fold, or all and only the examples from other folds.
The k folds are referred to by their indexes, which are 0, 1, ..., k - 1. This index is used to select the pivot fold.
FoldParser.SplitStrategy| Nested Class Summary | |
|---|---|
static class |
FoldParser.SplitStrategy
Immutable type representing the way in which examples are partitioned into folds. |
| Field Summary | |
|---|---|
protected int |
exampleIndex
Keeps track of the index of the next example to be returned. |
protected int |
examples
The total number of examples coming from parser. |
protected int |
fold
Keeps track of the current fold; used only in manual splitting. |
protected boolean |
fromPivot
Whether examples will come from the pivot fold or not. |
protected int |
K
The total number of folds. |
protected int |
lowerBound
A lower bound for an index relating to the pivot fold. |
protected Parser |
parser
The parser whose examples are being filtered. |
protected int |
pivot
The examples from this fold are exclusively selected for or excluded from the set of examples returned by this parser. |
protected int[] |
shuffled
Used only by the random splitting strategy to remember which example indexes are in which folds. |
protected int |
shuffleIndex
An index pointing into shuffled. |
protected FoldParser.SplitStrategy |
splitStrategy
The way in which examples are partitioned into folds. |
protected int |
upperBound
An upper bound for an index relating to the pivot fold. |
| Constructor Summary | |
|---|---|
FoldParser(Parser parser,
FoldParser.SplitStrategy split,
int pivot,
boolean f)
Constructor for when you know neither how many examples are in the data nor K, i.e., how many folds are in the data. |
|
FoldParser(Parser parser,
int K,
FoldParser.SplitStrategy split,
int pivot,
boolean f)
Constructor for when you don't know how many examples are in the data. |
|
FoldParser(Parser parser,
int K,
FoldParser.SplitStrategy split,
int pivot,
boolean f,
int e)
Full constructor. |
|
| Method Summary | |
|---|---|
protected boolean |
filter(java.lang.Object example)
Convenient for determining if the next example should be returned or not. |
int |
getK()
Retrieves the value of K, which may have been computed in the
constructor if the splitting strategy is manual. |
protected void |
increment(java.lang.Object example)
Changes state to reflect retrieval of the next example from the parser. |
java.lang.Object |
next()
Retrieves the next example object. |
void |
reset()
Sets this parser back to the beginning of the raw data. |
void |
setFromPivot(boolean f)
Sets the value of fromPivot, which controls whether examples
will be taken from the pivot fold or from all other folds. |
void |
setPivot(int p)
Sets the pivot fold, which also causes parser to be reset. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Parser parser
protected int K
protected FoldParser.SplitStrategy splitStrategy
protected int pivot
protected boolean fromPivot
protected int examples
parser.
protected int exampleIndex
protected int fold
protected int lowerBound
exampleIndex or
shuffleIndex.
protected int upperBound
exampleIndex or
shuffleIndex.
protected int[] shuffled
protected int shuffleIndex
shuffled.
| Constructor Detail |
|---|
public FoldParser(Parser parser,
int K,
FoldParser.SplitStrategy split,
int pivot,
boolean f)
parser - The parser whose examples are being filtered.K - The total number of folds; this value is ignored if the
splitting strategy is manual.split - The way in which examples are partitioned into folds.pivot - The index of the pivot fold.f - Whether to extract examples from the pivot.
public FoldParser(Parser parser,
FoldParser.SplitStrategy split,
int pivot,
boolean f)
parser - The parser whose examples are being filtered.split - The way in which examples are partitioned into folds.pivot - The index of the pivot fold.f - Whether to extract examples from the pivot.
public FoldParser(Parser parser,
int K,
FoldParser.SplitStrategy split,
int pivot,
boolean f,
int e)
parser - The parser whose examples are being filtered.K - The total number of folds; this value is ignored if the
splitting strategy is manual.split - The way in which examples are partitioned into folds.pivot - The index of the pivot fold.f - Whether to extract examples from the pivot.e - The total number of examples coming from
parser, or -1 if unknown.| Method Detail |
|---|
public int getK()
K, which may have been computed in the
constructor if the splitting strategy is manual.
public void setFromPivot(boolean f)
fromPivot, which controls whether examples
will be taken from the pivot fold or from all other folds.
f - The new value for fromPivot.public void setPivot(int p)
parser to be reset.
p - The index of the new pivot fold.public void reset()
pivot may have changed.
reset in interface ParsersetPivot(int)protected boolean filter(java.lang.Object example)
example - The next example object.
true iff the next example should be returned.protected void increment(java.lang.Object example)
example - The previous example object.public java.lang.Object next()
next in interface Parser
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||