Class TrainingSet<S extends Observation,T extends Category>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
java.util.HashSet<Pair<S,T>>
org.tweetyproject.machinelearning.TrainingSet<S,T>
Type Parameters:
S - The type of the observations.
T - The type of the categories.
All Implemented Interfaces:
Serializable, Cloneable, Iterable<Pair<S,T>>, Collection<Pair<S,T>>, Set<Pair<S,T>>

public class TrainingSet<S extends Observation,T extends Category> extends HashSet<Pair<S,T>>
A set of observations together with their category.
Author:
Matthias Thimm
See Also:
  • Constructor Details

    • TrainingSet

      public TrainingSet()
  • Method Details

    • add

      public boolean add(S obs, T cat)
      Adds the specified elements as a pair to this set if it is not already present. More formally, adds the specified element e to this set if this set contains no element e2 such that (e==null ? e2==null : e.equals(e2)). If this set already contains the element, the call leaves the set unchanged and returns false.
      Parameters:
      obs - some observation
      cat - the category of the observation.
      Returns:
      see above.
    • getCategories

      public Collection<T> getCategories()
      Returns the collection of categories present in this training set.
      Returns:
      a set of categories.
    • getObservations

      public TrainingSet<S,T> getObservations(T cat)
      Returns all observations of the given category.
      Parameters:
      cat - a category
      Returns:
      all observations of the given category.
    • toLibsvmProblem

      public libsvm.svm_problem toLibsvmProblem()
      Returns a svm_problem (the data data model of libsvm) of this training set.
      Returns:
      a svm_problem (the data data model of libsvm) of this training set.
    • loadLibsvmTrainingFile

      public static TrainingSet<DefaultObservation,DoubleCategory> loadLibsvmTrainingFile(File file) throws NumberFormatException, IOException
      Loads a training file in LIBSVM syntax
      Parameters:
      file - some file
      Returns:
      a training set.
      Throws:
      IOException - if some IO exception occurs.
      NumberFormatException - if the format of the file is not valid.