Class TrainingSet<S extends Observation,​T extends Category>

  • Type Parameters:
    S - The type of the observations.
    T - The type of the categories.
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<Pair<S,​T>>, java.util.Collection<Pair<S,​T>>, java.util.Set<Pair<S,​T>>

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

      Constructors 
      Constructor Description
      TrainingSet()  
    • Method Summary

      Modifier and Type Method Description
      boolean add​(S obs, T cat)
      Adds the specified elements as a pair to this set if it is not already present.
      java.util.Collection<T> getCategories()
      Returns the collection of categories present in this training set.
      TrainingSet<S,​T> getObservations​(T cat)
      Returns all observations of the given category.
      static TrainingSet<DefaultObservation,​DoubleCategory> loadLibsvmTrainingFile​(java.io.File file)
      Loads a training file in LIBSVM syntax
      libsvm.svm_problem toLibsvmProblem()
      Returns a svm_problem (the data data model of libsvm) of this training set.
      • Methods inherited from class java.util.HashSet

        add, clear, clone, contains, isEmpty, iterator, remove, size, spliterator
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class java.util.AbstractCollection

        addAll, containsAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
    • Constructor Detail

      • TrainingSet

        public TrainingSet()
    • Method Detail

      • 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 java.util.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​(java.io.File file)
                                                                                           throws java.lang.NumberFormatException,
                                                                                                  java.io.IOException
        Loads a training file in LIBSVM syntax
        Parameters:
        file - some file
        Returns:
        a training set.
        Throws:
        java.io.IOException - if some IO exception occurs.
        java.lang.NumberFormatException - if the format of the file is not valid.