viper.comparison.distances
Class AttrMeasure

java.lang.Object
  extended byviper.comparison.distances.AttrMeasure
Direct Known Subclasses:
FramewiseEvaluation.FrameMeasure, TrackingEvaluation.TrackingMeasure

public class AttrMeasure
extends java.lang.Object

Associates distance and metric with a specific type of attribute for a specific descriptor to Object Analysis type evaluation.


Constructor Summary
AttrMeasure(Distance metric, double tol)
          Constructs a new measure with the given metric and localization threshold, with the default statistic and statistic tolerance.
AttrMeasure(java.lang.String attr)
          Gets the default measure for the attribute.
AttrMeasure(java.lang.String attr, java.util.StringTokenizer st)
          Constructs a new measure by parsing the measure in text/epf format.
 
Method Summary
 FrameSpan calculateDistancesAndThresh(Attribute target, FrameSpan targetSpan, Attribute candidate, FrameSpan candSpan, CanonicalFileDescriptor cfd, DistanceHolder dh)
          Calculate the distances between the two attributes using this attribute measure.
 double distanceAgainst(Measurable.Difference D)
          Compares attributes or framespans by the metric this is set to use.
 double distanceAgainstDynamic(Attribute target, FrameSpan gSpan, Attribute candidate, FrameSpan fSpan, CanonicalFileDescriptor cfd)
          compares two dynamic attributes
 boolean equals(java.lang.Object o)
          Tests to see if this is the same kind of measure as the parameter.
 DistanceHolder getDistances()
          Gets the current distances.
 Distance getMetric()
          Gets the metric.
 double[] getStatistics()
          Gets the current statistics
 double getStatThreshold()
          Gets the threshold to apply on the given statstic to count as successfuly statisticked.
 int getStatType()
          Gets the statistic type associated with the measure, e.g.
 double getTolerance()
          Gets the localization tolerance.
 int hashCode()
          Computes a hashcode on the metric, statistic, and thresholds.
 boolean isValidFor(java.lang.String attr)
          Tests that this measure is valid for a given attribute.
static boolean isValidMeasure(java.lang.String attr, AttrMeasure meas)
          Tests to see if the given measure is valid for the given attribute type.
static boolean isValidTolerance(double value)
          Tests to see if the tolerance is a valid number.
 void setMetric(Distance M)
          Sets the metric.
 void setTolerance(double tol)
          Sets the localization tolerance.
 boolean thresh(double value)
          Determines if the given distance value is less than the current tolerance.
 java.lang.String toString()
          Prints out the metric and threshold, without the brackets.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AttrMeasure

public AttrMeasure(Distance metric,
                   double tol)
Constructs a new measure with the given metric and localization threshold, with the default statistic and statistic tolerance.

Parameters:
metric - the metric
tol - the localization threshold

AttrMeasure

public AttrMeasure(java.lang.String attr)
Gets the default measure for the attribute.

Parameters:
attr - the attribute type
Throws:
java.lang.IllegalStateException - if the default metric is null

AttrMeasure

public AttrMeasure(java.lang.String attr,
                   java.util.StringTokenizer st)
            throws ImproperMetricException
Constructs a new measure by parsing the measure in text/epf format. For example: [ metric threshold ].

Parameters:
attr - the attribute to apply to
st - the text to parse
Throws:
ImproperMetricException - if there is a parsing error or a metric is not found
Method Detail

getStatType

public int getStatType()
Gets the statistic type associated with the measure, e.g. Distances.MEDIAN.

Returns:
the statistic

getStatThreshold

public double getStatThreshold()
Gets the threshold to apply on the given statstic to count as successfuly statisticked.

Returns:
the statistic threshold, for the value of appropriate statistic type for the per-frame distances

equals

public boolean equals(java.lang.Object o)
Tests to see if this is the same kind of measure as the parameter.

Parameters:
o - the measure to test against
Returns:
true if they have the same metric, statistic, and localization and statistic thresholds

hashCode

public int hashCode()
Computes a hashcode on the metric, statistic, and thresholds.

Returns:
a hash code

toString

public java.lang.String toString()
Prints out the metric and threshold, without the brackets. Threshold is either a number or the string (INFINITY)

Returns:
metric threshold

setTolerance

public final void setTolerance(double tol)
Sets the localization tolerance.

Parameters:
tol - the new localization tolerance

getTolerance

public final double getTolerance()
Gets the localization tolerance.

Returns:
the localization tolerance

setMetric

public final void setMetric(Distance M)
Sets the metric.

Parameters:
M - the new metric

getMetric

public final Distance getMetric()
Gets the metric.

Returns:
the metric

thresh

public boolean thresh(double value)
Determines if the given distance value is less than the current tolerance. It deals with the case that the distance may be a score (larger = better) or a distance (smaller = better). Although I generally prefer distances, there will be people who wish to do it the other way.

Parameters:
value - the distance value (or score)
Returns:
if the value is considered good enough to count as a localization

calculateDistancesAndThresh

public FrameSpan calculateDistancesAndThresh(Attribute target,
                                             FrameSpan targetSpan,
                                             Attribute candidate,
                                             FrameSpan candSpan,
                                             CanonicalFileDescriptor cfd,
                                             DistanceHolder dh)
                                      throws MethodNotSupportedException
Calculate the distances between the two attributes using this attribute measure. It returns the set of frames that were successfully localized.

Parameters:
target - the target attribute
targetSpan - the framespan of the target attribute's descriptor
candidate - the candidate attribute
candSpan - the framespan of the candidate attribute's parent descriptor
cfd - information about the media file
dh - this will hold the computed distance information
Returns:
the frames that qualify as localized
Throws:
MethodNotSupportedException - if there is an error in the data types or in the metric

distanceAgainst

public double distanceAgainst(Measurable.Difference D)
                       throws MethodNotSupportedException
Compares attributes or framespans by the metric this is set to use.

Parameters:
D - the difference comparison
Returns:
the value of the metric's Distance.getDistance(viper.descriptors.attributes.Measurable.Difference)method.
Throws:
MethodNotSupportedException

getDistances

public DistanceHolder getDistances()
Gets the current distances.

Returns:
the distances from the last call to calculateDistancesAndThresh(Attribute, FrameSpan, Attribute, FrameSpan, CanonicalFileDescriptor, DistanceHolder).

getStatistics

public double[] getStatistics()
Gets the current statistics

Returns:
the statistics from the last call to calculateDistancesAndThresh(Attribute, FrameSpan, Attribute, FrameSpan, CanonicalFileDescriptor, DistanceHolder).

distanceAgainstDynamic

public double distanceAgainstDynamic(Attribute target,
                                     FrameSpan gSpan,
                                     Attribute candidate,
                                     FrameSpan fSpan,
                                     CanonicalFileDescriptor cfd)
                              throws MethodNotSupportedException
compares two dynamic attributes

Parameters:
target - the target attribute
gSpan - the target attribute span
candidate - the candidate attribute
fSpan - the candidate span
cfd - the source media description
Returns:
the distance
Throws:
MethodNotSupportedException

isValidFor

public boolean isValidFor(java.lang.String attr)
Tests that this measure is valid for a given attribute. Of course, it might not work, anyway, as it only goes by metric name and not implementation.

Parameters:
attr - the attribute type to see if this metric is valid for
Returns:
true if this measure is defined for the specified attribute type

isValidMeasure

public static boolean isValidMeasure(java.lang.String attr,
                                     AttrMeasure meas)
Tests to see if the given measure is valid for the given attribute type.

Parameters:
attr - the attribute type
meas - the measure
Returns:
true when the measure works

isValidTolerance

public static boolean isValidTolerance(double value)
Tests to see if the tolerance is a valid number.

Parameters:
value - the tolerance
Returns:
if the number is between zero and positive infinity