dice.data
Class CVInstances

java.lang.Object
  extended by dice.data.CVInstances
All Implemented Interfaces:
Instances, java.io.Serializable

public class CVInstances
extends java.lang.Object
implements Instances

An implementation of Instances that support cross validation well. That means CVInstances can automatically fold the data set. Before the use of the CVInstances, we can set the number of folds. Then we can use different fold of the data set holds by CVInstances, according a parameter. There are two model of CVInstances, "Train" and "Test" model. Then for training, we can set the CVInstances to "Train" mode, and set it to "Test" for testing. An example to exhibit how to use CVInstances can be found in BinaryClassificationByCV.

Author:
Zhang Xiatian
See Also:
Serialized Form

Field Summary
protected  int[] attributes
           
protected  int cursor
           
protected  int fb
          fold begin, end and fold size,default size;
protected  int fds
          fold begin, end and fold size,default size;
protected  int fe
          fold begin, end and fold size,default size;
protected  int foldNum
          The number of folds the data should be folded.
protected  int fs
          fold begin, end and fold size,default size;
protected  int[][] ids
           
protected  Instance instance
           
protected  boolean isSparse
           
protected  boolean isTrain
          Is the model in the "train" model.
protected  java.util.Iterator<Instance> iterator
           
protected  double[][] mat
           
protected  double miss
           
protected  java.lang.String relation
           
private static long serialVersionUID
           
protected  Instances thiz
           
 
Constructor Summary
CVInstances(int[] attributes, double[][] matrix, int[][] ids, java.lang.String relation)
          Create an CVInstances.
CVInstances(SimpleInstances simpleInstances)
          Create the CVInstances from an SimpleInstances
 
Method Summary
 Instance get(int index)
          Get an instance by the assigned index or position.
 int[] getAttributes()
          Get the arrays, whose elements indicate the types of attributes.
 int getAttrSize()
          Get the number of attributes.
 int[][] getIds()
          Get the index matrix.
 double[][] getMat()
          Get the data matrix.
 java.lang.String getRelation()
          Get the relation name of the data set.
 boolean isSparse()
          Get the storage status of the Instances.
 boolean isTrainModel()
          Get current model of the CVInstances.
 java.util.Iterator<Instance> iterator()
          Return a Iterator of the Instance
 void set2TestModel()
          Change to "Test" model.
 void set2TrainModel()
          Change the model to "Train" model.
 void setData(int[][] ids, double[][] mat)
          Put the index and data matrix into it.
 void setFold(int fold)
          Set current fold index.
 void setFoldNum(int foldNum)
          Set the number of folds.
 void setMiss(double miss)
          Set the default value for the ignored element in the sparse storage form.
 int size()
          Get the number of Instances.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

thiz

protected Instances thiz
See Also:
SimpleInstances.thiz

isSparse

protected boolean isSparse
See Also:
SimpleInstances.isSparse

attributes

protected int[] attributes
See Also:
SimpleInstances.attributes

ids

protected int[][] ids
See Also:
SimpleInstances.ids

mat

protected double[][] mat
See Also:
SimpleInstances.mat

instance

protected Instance instance
See Also:
SimpleInstances.instance

cursor

protected int cursor
See Also:
SimpleInstances.cursor

iterator

protected java.util.Iterator<Instance> iterator
See Also:
SimpleInstances.iterator

relation

protected java.lang.String relation
See Also:
SimpleInstances.relation

miss

protected double miss
See Also:
SimpleInstances.miss

foldNum

protected int foldNum
The number of folds the data should be folded.


fb

protected int fb
fold begin, end and fold size,default size;


fe

protected int fe
fold begin, end and fold size,default size;


fs

protected int fs
fold begin, end and fold size,default size;


fds

protected int fds
fold begin, end and fold size,default size;


isTrain

protected boolean isTrain
Is the model in the "train" model. True means in the "train" model, otherwise means "test" model.

Constructor Detail

CVInstances

public CVInstances(SimpleInstances simpleInstances)
Create the CVInstances from an SimpleInstances

Parameters:
simpleInstances - @see SimpleInstances

CVInstances

public CVInstances(int[] attributes,
                   double[][] matrix,
                   int[][] ids,
                   java.lang.String relation)
Create an CVInstances.

Parameters:
attrs - The attribute type array, @see attributes
matrix - The data matrix, @see mat
indexes - The index matrix, @see ids
relation - The name of the data set, @see relation
Method Detail

setFoldNum

public void setFoldNum(int foldNum)
Set the number of folds.

Parameters:
foldNum - Number of folds.

set2TrainModel

public void set2TrainModel()
Change the model to "Train" model.


set2TestModel

public void set2TestModel()
Change to "Test" model.


isTrainModel

public boolean isTrainModel()
Get current model of the CVInstances.

Returns:
True means current model is "Train", otherwise is "Test".

setFold

public void setFold(int fold)
Set current fold index.

Parameters:
fold -

iterator

public java.util.Iterator<Instance> iterator()
Description copied from interface: Instances
Return a Iterator of the Instance

Specified by:
iterator in interface Instances
Returns:
The iteraotr of Instance.

getAttributes

public int[] getAttributes()
Description copied from interface: Instances
Get the arrays, whose elements indicate the types of attributes. 0 indicates the attribute is numeric or real attribute. The number is greater than 0 indicate the numbers of values of each attributes.

Specified by:
getAttributes in interface Instances
Returns:
The attribute type indicator array.
See Also:
Instances.getAttributes()

getRelation

public java.lang.String getRelation()
Description copied from interface: Instances
Get the relation name of the data set.

Specified by:
getRelation in interface Instances
Returns:
The relation name of the data set.
See Also:
Instances.getRelation()

getAttrSize

public int getAttrSize()
Description copied from interface: Instances
Get the number of attributes.

Specified by:
getAttrSize in interface Instances
Returns:
The number of attributes.
See Also:
Instances.getAttrSize()

size

public int size()
Description copied from interface: Instances
Get the number of Instances.

Specified by:
size in interface Instances
Returns:
The number of Instances.
See Also:
Instances.size();

get

public Instance get(int index)
Description copied from interface: Instances
Get an instance by the assigned index or position.

Specified by:
get in interface Instances
Parameters:
index - The index or position of the Instance wanted.
Returns:
The instance wanted.

isSparse

public boolean isSparse()
Description copied from interface: Instances
Get the storage status of the Instances.

Specified by:
isSparse in interface Instances
Returns:
If the data storage form is sparse, then return true. Otherwise, return false.

getIds

public int[][] getIds()
Description copied from interface: Instances
Get the index matrix.

Specified by:
getIds in interface Instances
Returns:
The index matrix. If the Instances.isSparse() return false, the return will be null.

getMat

public double[][] getMat()
Description copied from interface: Instances
Get the data matrix.

Specified by:
getMat in interface Instances
Returns:
The data matrix.

setMiss

public void setMiss(double miss)
Description copied from interface: Instances
Set the default value for the ignored element in the sparse storage form.

Specified by:
setMiss in interface Instances

setData

public void setData(int[][] ids,
                    double[][] mat)
Description copied from interface: Instances
Put the index and data matrix into it.

Specified by:
setData in interface Instances
Parameters:
ids - The index matrix.
mat - The data matrix.
See Also:
Instances.setData(int[][], double[][])