|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectweka.classifiers.misc.monotone.InstancesUtil
public class InstancesUtil
This class contains some methods for working with objects of
type Instance
and Instances,
not
provided by there respective classes.
This implementation is part of the master's thesis: "Studie en implementatie van instantie-gebaseerde algoritmen voor gesuperviseerd rangschikken", Stijn Lievens, Ghent University, 2004.
Constructor Summary | |
---|---|
InstancesUtil()
|
Method Summary | |
---|---|
static void |
classifyInstances(Instances instances,
Classifier classifier)
Classify a set of instances using a given classifier. |
static boolean |
comparable(Instance i1,
Instance i2)
Checks if two instances are comparable in the data space, this is ignoring the class attribute. |
static int |
containsIgnoreClass(Instances instances,
Instance instance)
Get the index of an instance in a set of instances, where instances are compared ignoring the class attribute. |
static DiscreteEstimator |
countValues(Instances instances,
int attributeIndex)
Return a histogram of the values for the specified attribute. |
static boolean |
doubt(Instance i1,
Instance i2)
Checks it two instances give rise to doubt. |
static boolean |
equalIgnoreClass(Instance i1,
Instance i2)
Compares two instances, ignoring the class attribute (if any) |
static Instances |
generateRandomSample(Instances headerInfo,
int numberOfExamples,
java.util.Random random)
Generates a random sample of instances. |
static BooleanBitMatrix |
getBitMatrix(Instances instances)
Calculates the relation (poset) formed by the instances. |
static boolean |
isHomogeneous(Instances instances)
Check if all instances have the same class value. |
static boolean |
isMonotone(Instances instances)
Checks if the given data set is monotone. |
static boolean |
isQuasiMonotone(Instances ground,
Instances other)
Test if a set of instances is quasi monotone. |
static double |
maximalExtension(Instances instances,
Instance instance)
Computes the maximal extension for a given instance. |
static double |
maximalExtension(Instances instances,
Instance instance,
double maxValue)
Computes the maximal extension of a given instance, but the maximal value returned is maxValue. |
static double |
minimalExtension(Instances instances,
Instance instance)
Computes the minimal extension for a given instance. |
static double |
minimalExtension(Instances instances,
Instance instance,
double minValue)
Computes the minimal extension of a given instance, but the minimal value returned is minValue. |
static int |
nextOccurenceIgnoreClass(Instances instances,
Instance instance,
int index)
Find the next occurence of an instance, ignoring the class, for which the index in the dataset is at least index. |
static int |
nrOfRedundant(Instances instances)
Counts the number of redundant pairs in the sense of OLM. |
static int[] |
nrOfReversedPreferences(Instances instances)
Gather some statistics regarding reversed preferences. |
static int[] |
nrStochasticReversedPreference(Instances instances)
Find the number of stochastic reversed preferences in the dataset. |
static double |
numberInInterval(Instance low,
Instance up)
Calculatus the number of elements in the closed interval [low,up]. |
static double |
numberOfGreaterVectors(Instance instance)
Calculatutes the number of vectors in the data space that are greater or equal than the given instance. |
static double |
numberOfSmallerVectors(Instance instance)
Calculatutes the number of vectors in the data space that are smaller or equal than the given instance. |
static boolean |
reversedPreference(Instance i1,
Instance i2)
Checks if two instances give rise to reversed preference. |
static Instances |
sampleWithoutReplacement(Instances instances,
int size,
java.util.Random random)
Create, without replacement, a random subsample of the given size from the given instances. |
static boolean |
smallerOrEqual(Instance i1,
Instance i2)
Compares two instances in the data space, this is, ignoring the class attribute. |
static boolean |
strictlySmaller(Instance i1,
Instance i2)
Compares two instances in the data space, this is ignoring the class attribute. |
static double[] |
toDataDouble(Instance instance)
Returns an array containing the attribute values (in internal floating point format) of the given instance in data space, this is, the class attribute (if any) is removed. |
static double |
totalLoss(Classifier classifier,
Instances instances,
NominalLossFunction lossFunction)
Calulates the total loss over the instances ,
using the trained classifier and the
specified lossFunction. |
static void |
write(Instances instances,
java.io.BufferedWriter file)
Write the instances in ARFF-format to the indicated BufferedWriter . |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public InstancesUtil()
Method Detail |
---|
public static boolean equalIgnoreClass(Instance i1, Instance i2)
i1
- the first instancei2
- the second instance
public static int containsIgnoreClass(Instances instances, Instance instance)
instances
- the set of instancesinstance
- to instance to be found in the given set of instances
public static int nextOccurenceIgnoreClass(Instances instances, Instance instance, int index)
index.
instances
- the set of instances to be searchedinstance
- the instance to be foundindex
- the minimum index that might be returned
index
that equals the given instance
(ignoring the class attribute), -1 if the instance was not foundpublic static boolean isHomogeneous(Instances instances)
instances
- the instances to be checked for homogeneity
public static boolean strictlySmaller(Instance i1, Instance i2)
Coordinates
based on
these instances.
i1
- the first instancei2
- the second instance
true
if the first instance is strictly smaller
than the second instance, false
otherwisepublic static boolean smallerOrEqual(Instance i1, Instance i2)
Coordinates
based on
these instances.
i1
- the first instancei2
- the second instance
true
if the first instance is smaller or equal
than the second instance, false
otherwisepublic static boolean comparable(Instance i1, Instance i2) throws java.lang.IllegalArgumentException
i1
- the first instancei2
- the second instance
true
if the given instances are comparable,
false
otherwise
java.lang.IllegalArgumentException
- if the two instances don't have the
same lengthpublic static boolean doubt(Instance i1, Instance i2)
Coordinates
are equal, but
their class value is different.
i1
- the first instancei2
- the second instance
true
if there is doubt between the two
given instances, false
otherwisepublic static boolean reversedPreference(Instance i1, Instance i2) throws java.lang.IllegalArgumentException
Coordinates
are comparable but different,
and their class values are not related in the same way.
i1
- the first instancei2
- the second instance
true
if i1
and i2
give rise to reversed preference, false
otherwise
java.lang.IllegalArgumentException
- if the two instances don't have
the same lengthpublic static boolean isMonotone(Instances instances)
instances
- the data set to be checked
true
if the given data set if monotone,
false
otherwisepublic static boolean isQuasiMonotone(Instances ground, Instances other)
S
is quasi monotone with respect to
a set of instances D
iff
[x,y] \cap D \neq \emptyset \implies class(x) \leq class(y).
This implies that D
itself is monotone.
ground
- the instances playing the role of D
other
- the instances playing the role of S
public static int[] nrOfReversedPreferences(Instances instances)
instances
- the instances to be examined
reversedPreference(Instance, Instance)
public static int[] nrStochasticReversedPreference(Instances instances) throws java.lang.IllegalArgumentException
instances
- the instances to be examined
x < y
and
not (F_x leqstoch F_y)
x < y
and F_y leqstoch F_x
and F_x neq F_y
|\{ (x,y)\in S_X \times S_x | x < y\}|
java.lang.IllegalArgumentException
- if there are no instances with
a non-missing class value, or if the class is not setpublic static int nrOfRedundant(Instances instances)
instances
- the instances to be checked
public static double totalLoss(Classifier classifier, Instances instances, NominalLossFunction lossFunction)
instances
,
using the trained classifier
and the
specified lossFunction.
The instances
should not contain missing values in the class attribute.
classifier
- the trained classifier to useinstances
- the test instanceslossFunction
- the loss function to use
public static void classifyInstances(Instances instances, Classifier classifier) throws java.lang.Exception
instances
- the instances to be classifiedclassifier
- a built classifier
java.lang.Exception
- if one of the instances could no be classifiedpublic static BooleanBitMatrix getBitMatrix(Instances instances)
instances
- the instances for which the poset is to be formed
BooleanBitMatrix
for which position
bm.get(i,j) == true
iff
InstancesUtil.strictlySmaller(instances.instance(i),
instances.instance(j)) == true
public static double numberInInterval(Instance low, Instance up) throws java.lang.IllegalArgumentException
[low,up].
If the class index is set, then
the class attribute does not play part in the calculations,
this is we work in the data space. The code also works with
numeric attributes, but is primarily intended for ordinal attributes.
low
- the lower bound of the intervalup
- the upper bound of the interval
java.lang.IllegalArgumentException
- if the given instances do not
constitute an interval.public static double numberOfSmallerVectors(Instance instance) throws java.lang.IllegalArgumentException
instance
- the given instance
java.lang.IllegalArgumentException
- if there are numeric attributespublic static double numberOfGreaterVectors(Instance instance) throws java.lang.IllegalArgumentException
instance
- the given instance
java.lang.IllegalArgumentException
- if there are numeric attributespublic static void write(Instances instances, java.io.BufferedWriter file) throws java.io.IOException
BufferedWriter
.
instances
- the instances to writefile
- the BufferedWriter
to write to
java.io.IOException
- if something goes wrong while writing the instancespublic static DiscreteEstimator countValues(Instances instances, int attributeIndex) throws java.lang.IllegalArgumentException
instances
- the instancesattributeIndex
- the attribute to consider
DiscreteEstimator
where the i
th
java.lang.IllegalArgumentException
- if the attribute at the specified
index is numericpublic static Instances sampleWithoutReplacement(Instances instances, int size, java.util.Random random)
instances
- the instances to sample fromsize
- the requested size of the samplerandom
- the random generator to use
java.lang.IllegalArgumentException
- if the size exceeds the number
of instancespublic static Instances generateRandomSample(Instances headerInfo, int numberOfExamples, java.util.Random random) throws java.lang.IllegalArgumentException
headerInfo
- Instances whose header information is used to determine how the
set of returned instances will looknumberOfExamples
- the desired size of the returned setrandom
- the random number generator to use
java.lang.IllegalArgumentException
- if numeric attributes are givenpublic static double[] toDataDouble(Instance instance)
instance
- the instance to get the attribute values from
public static double minimalExtension(Instances instances, Instance instance)
instances
- the set of instancesinstance
- the instance for which the minimal extension is to be
calculated
public static double minimalExtension(Instances instances, Instance instance, double minValue)
minValue.
This method
may have its applications when the training set is divided into
multiple Instances objects.
instances
- the set of instancesinstance
- the instance for which the minimal extension is to
be calculatedminValue
- a double indicating the minimal value that should
be returned
public static double maximalExtension(Instances instances, Instance instance)
instances
- the set of instancesinstance
- the instance for which the minimal extension is to be
calculated
public static double maximalExtension(Instances instances, Instance instance, double maxValue)
maxValue.
This method
may have its applications when the training set is divided into
multiple Instances objects.
instances
- the set of instancesinstance
- the instance for which the maximal extension is to
be calculatedmaxValue
- a double indicating the maximal value that should
be returned
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |