edu.udo.cs.mySVM.Examples
Class ExampleSet

java.lang.Object
  extended by edu.udo.cs.mySVM.Examples.ExampleSet

public class ExampleSet
extends java.lang.Object

Implementation of a sparse example set which can be used for learning. This data structure is also used as SVM model.

Version:
$Id: ExampleSet.java,v 1.29 2006/09/30 00:05:31 ingomierswa Exp $
Author:
Stefan Rueping, Ingo Mierswa

Nested Class Summary
static class ExampleSet.MeanVariance
          This class holds information aboud the means and variances of an attribute.
 
Field Summary
private  double[] alphas
          The SVM alpha values.
 double[][] atts
          The known attribute values for each example.
private  double b
          The hyperplane offset.
private  int dim
          The dimension of the example set.
 java.lang.String[] ids
          The ids of all examples.
 int[][] index
          The corresponding indices for the known attribute values for each example.
private  java.util.Map<java.lang.Integer,ExampleSet.MeanVariance> meanVarianceMap
          This map stores the mean-variance informations about all attributes (att index --> mean-variance).
private  int train_size
          The number of examples.
private  Example x
          This example will be once constructed and delivered with the asked values.
private  double[] ys
          The labels of the examples if known. -1 and +1 for classification or the real value for regression tasks.
 
Constructor Summary
ExampleSet(ExampleSet exampleSet, Attribute labelAttribute, boolean scale)
           
ExampleSet(ExampleSet exampleSet, Attribute labelAttribute, java.util.Map<java.lang.Integer,ExampleSet.MeanVariance> meanVariances)
          Creates a fresh example set of the given size from the Yale example reader.
ExampleSet(int size, double b)
          Creates an empty example set of the given size.
ExampleSet(java.io.ObjectInputStream in)
          Reads an example set from the given input stream.
 
Method Summary
 void clearAlphas()
           
 int count_examples()
          Counts the training examples.
 int count_pos_examples()
          Counts the positive training examples
private static java.util.Map<java.lang.Integer,ExampleSet.MeanVariance> createMeanVariances(ExampleSet exampleSet)
           
 double get_alpha(int pos)
          Gets an alpha-value.
 double[] get_alphas()
          Gets the alpha array.
 double get_b()
          get b
 int get_dim()
          Gets the dimension of the examples
 Example get_example(int pos)
          Gets an example.
 double get_y(int pos)
          Gets an y-value.
 double[] get_ys()
          Gets the y array
 java.lang.String getId(int index)
           
 java.util.Map<java.lang.Integer,ExampleSet.MeanVariance> getMeanVariances()
           
 int getNumberOfSupportVectors()
           
 void set_alpha(int pos, double alpha)
          sets an alpha value.
 void set_b(double new_b)
          set b
 void set_y(int pos, double y)
          Sets the label value for the specified example.
 void swap(int pos1, int pos2)
          swap two training examples
 java.lang.String toString()
           
 java.lang.String toString(boolean onlySV)
           
 java.lang.String toString(int numberOfExamples, boolean onlySV)
           
 void writeSupportVectors(java.io.ObjectOutputStream out)
          Writes the example set into the given output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dim

private int dim
The dimension of the example set.


train_size

private int train_size
The number of examples.


atts

public double[][] atts
The known attribute values for each example.


index

public int[][] index
The corresponding indices for the known attribute values for each example.


ids

public java.lang.String[] ids
The ids of all examples.


alphas

private double[] alphas
The SVM alpha values. Will be filled by learning.


ys

private double[] ys
The labels of the examples if known. -1 and +1 for classification or the real value for regression tasks. Will be filled by prediction.


b

private double b
The hyperplane offset.


x

private Example x
This example will be once constructed and delivered with the asked values.


meanVarianceMap

private java.util.Map<java.lang.Integer,ExampleSet.MeanVariance> meanVarianceMap
This map stores the mean-variance informations about all attributes (att index --> mean-variance). This information is used to scale the data from the test set.

Constructor Detail

ExampleSet

public ExampleSet(int size,
                  double b)
Creates an empty example set of the given size.


ExampleSet

public ExampleSet(ExampleSet exampleSet,
                  Attribute labelAttribute,
                  boolean scale)

ExampleSet

public ExampleSet(ExampleSet exampleSet,
                  Attribute labelAttribute,
                  java.util.Map<java.lang.Integer,ExampleSet.MeanVariance> meanVariances)
Creates a fresh example set of the given size from the Yale example reader. The alpha values and b are zero, the label will be set if it is known.


ExampleSet

public ExampleSet(java.io.ObjectInputStream in)
           throws java.io.IOException
Reads an example set from the given input stream.

Throws:
java.io.IOException

Method Detail

createMeanVariances

private static java.util.Map<java.lang.Integer,ExampleSet.MeanVariance> createMeanVariances(ExampleSet exampleSet)

getMeanVariances

public java.util.Map<java.lang.Integer,ExampleSet.MeanVariance> getMeanVariances()

getNumberOfSupportVectors

public int getNumberOfSupportVectors()

writeSupportVectors

public void writeSupportVectors(java.io.ObjectOutputStream out)
                         throws java.io.IOException
Writes the example set into the given output stream.

Throws:
java.io.IOException


count_examples

public int count_examples()
Counts the training examples.

Returns:
Number of examples


count_pos_examples

public int count_pos_examples()
Counts the positive training examples

Returns:
Number of positive examples


get_dim

public int get_dim()
Gets the dimension of the examples

Returns:
dim


get_example

public Example get_example(int pos)
Gets an example.

Parameters:
pos - Number of example
Returns:
Array of example attributes in their default order


get_y

public double get_y(int pos)
Gets an y-value.

Parameters:
pos - Number of example
Returns:
y


set_y

public void set_y(int pos,
                  double y)
Sets the label value for the specified example.


get_ys

public double[] get_ys()
Gets the y array

Returns:
y


get_alpha

public double get_alpha(int pos)
Gets an alpha-value. Please note that the alpha values are already multiplied by the corresponding y-value.

Parameters:
pos - Number of example
Returns:
alpha


get_alphas

public double[] get_alphas()
Gets the alpha array. Please note that the alpha values are already multiplied by the corresponding y-value.

Returns:
alpha


swap

public void swap(int pos1,
                 int pos2)
swap two training examples

Parameters:
pos1 -
pos2 -


get_b

public double get_b()
get b

Returns:
b


set_b

public void set_b(double new_b)
set b

Parameters:
new_b -


set_alpha

public void set_alpha(int pos,
                      double alpha)
sets an alpha value.

Parameters:
pos - Number of example
alpha - New value


clearAlphas

public void clearAlphas()

getId

public java.lang.String getId(int index)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(boolean onlySV)

toString

public java.lang.String toString(int numberOfExamples,
                                 boolean onlySV)


Copyright © 2001-2006