DatasetError Class Reference

An Uncertainty which applies to a whole set of axes and points, i.e. More...

Inheritance diagram for DatasetError:

Inheritance graph
[legend]

Collaboration diagram for DatasetError:

Collaboration graph
[legend]

List of all members.


Public Member Functions

 DatasetError ()
 Default constructor.
 DatasetError (Double plusminus, ErrorSource sourcetype, ErrorNorm normtype)
 Constructor for symmetric error.
 DatasetError (Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype)
 Constructor for asymmetric errors.
 DatasetError (Dataset dataset, Double plusminus, ErrorSource sourcetype, ErrorNorm normtype)
 Constructor for symmetric error, with attachment to parent Dataset.
 DatasetError (Dataset dataset, Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype)
 Constructor for asymmetric errors, with attachment to parent Dataset.
Integer getId ()
 Get the dataset error ID.
DatasetError setId (Integer datasetErrorId)
 Set the dataset error ID.
DatasetError setNormType (ErrorNorm normtype)
 Set the error normalization type (abs, frac, pct, etc.
Uncertainty setNormTypeString (String normtypeStr) throws HDException
 Try to set the error normalization type (abs, frac, pct, etc.
int compareTo (DatasetError other)
boolean equals (Object other)
 Override equals method with business key equality.
int hashCode ()
 Override hashcode method.
boolean isSymmetric ()
 Are the plus and minus errors symmetric?
boolean hasZeroSize ()
 Are the plus and minus errors both zero?
Uncertainty getAbsoluteError (Point p) throws HDException
 Calculate the absolute error object for this error and the given Point.
Double getPlus ()
 Get the upward error.
Uncertainty setPlus (Double plus)
 Set the upward error.
Double getMinus ()
 Get the downward error.
Uncertainty setMinus (Double minus)
 Set the downward error.
ErrorSource getSourceType ()
 Get the error source type (stat, sys, etc.
Uncertainty setSourceType (ErrorSource sourcetype)
 Set the error source type (stat, sys, etc.
ErrorNorm getNormType ()
 Get the error normalization type (abs, frac, pct, etc.
String getComment ()
 Get the modification comment string.
Uncertainty setComment (String comment)
 Set the modification comment string.
int compareTo (Uncertainty other)
String toString ()
 String representation.
String toString (Integer indentBy)
 Indented string representation.

Package Functions

Logger log ()
 Neat method to allow every class to get hold of a custom-named Logger.

Detailed Description

An Uncertainty which applies to a whole set of axes and points, i.e.

as stored by a Dataset. These errors tend to be systematic and have relative normalisation, but this isn't necessarily the case.

Todo:
Does this only apply to the y-axes on the dataset?
Author:
Andy Buckley
Version:
Date
Revision

Definition at line 16 of file DatasetError.java.


Constructor & Destructor Documentation

DatasetError (  ) 

Default constructor.

Definition at line 25 of file DatasetError.java.

00025 { super(); }

DatasetError ( Double  plusminus,
ErrorSource  sourcetype,
ErrorNorm  normtype 
)

Constructor for symmetric error.

Parameters:
plusminus : size of symmetric error
sourcetype : origin of error, i.e. systematic, statistical, etc.
normtype : normalisation of error, i.e. absolute, fractional, percentage, etc.

Definition at line 33 of file DatasetError.java.

00033                                                                                       {
00034         super(plusminus, sourcetype, normtype);
00035     }

DatasetError ( Double  plus,
Double  minus,
ErrorSource  sourcetype,
ErrorNorm  normtype 
)

Constructor for asymmetric errors.

Parameters:
plus input < 0 gives -err1
minus input < 0 gives +err2
sourcetype : origin of error, i.e. systematic, statistical, etc.
normtype : normalisation of error, i.e. absolute, fractional, percentage, etc.

Definition at line 44 of file DatasetError.java.

00044                                                                                                {
00045         super(plus, minus, sourcetype, normtype);
00046     }

DatasetError ( Dataset  dataset,
Double  plusminus,
ErrorSource  sourcetype,
ErrorNorm  normtype 
)

Constructor for symmetric error, with attachment to parent Dataset.

Parameters:
plusminus : size of symmetric error
sourcetype : origin of error, i.e. systematic, statistical, etc.
normtype : normalisation of error, i.e. absolute, fractional, percentage, etc.

Definition at line 54 of file DatasetError.java.

References Dataset.addError().

00054                                                                                                        {
00055         super(plusminus, sourcetype, normtype);
00056         dataset.addError(this);
00057     }

DatasetError ( Dataset  dataset,
Double  plus,
Double  minus,
ErrorSource  sourcetype,
ErrorNorm  normtype 
)

Constructor for asymmetric errors, with attachment to parent Dataset.

Parameters:
plus input <0 gives -err1
minus input <0 gives +err2
sourcetype : origin of error, i.e. systematic, statistical, etc.
normtype : normalisation of error, i.e. absolute, fractional, percentage, etc.

Definition at line 66 of file DatasetError.java.

References Dataset.addError().

00066                                                                                                                 {
00067         super(plus, minus, sourcetype, normtype);
00068         dataset.addError(this);
00069     }


Member Function Documentation

Integer getId (  ) 

Get the dataset error ID.

Definition at line 76 of file DatasetError.java.

Referenced by Dataset.addError(), DatasetError.compareTo(), and DatasetError.hashCode().

00076                            {
00077         return _localId;
00078     }

DatasetError setId ( Integer  datasetErrorId  ) 

Set the dataset error ID.

Definition at line 81 of file DatasetError.java.

Referenced by Dataset.addError().

00081                                                       {
00082         _localId = datasetErrorId;
00083         return this;
00084     }

DatasetError setNormType ( ErrorNorm  normtype  ) 

Set the error normalization type (abs, frac, pct, etc.

) from the enum. Note that this method overrides the normal version from Uncertainty, since DatasetErrors cannot have absolute normalization. No exception is thrown because that would force a try block in general.

Todo:
Add a test for this exceptional behaviour.

Reimplemented from Uncertainty.

Definition at line 98 of file DatasetError.java.

References Storeable.log(), and DatasetError.setNormType().

Referenced by DatasetError.setNormType(), and DatasetError.setNormTypeString().

00098                                                         {
00099         if (normtype != ErrorNorm.ABS) {
00100             super.setNormType(normtype);
00101         } else {
00102             log().warn("Tried to set an absolute normalization on a DatasetError");
00103             //throw new HDErrorNormException("Tried to set an absolute normalization on a DatasetError");
00104         }
00105         return this;
00106     }

Uncertainty setNormTypeString ( String  normtypeStr  )  throws HDException

Try to set the error normalization type (abs, frac, pct, etc.

) from a String. Note that this method overrides the normal version from Uncertainty, since DatasetErrors cannot have absolute normalization.

Todo:
Can I avoid replicating this method? If left in the Uncertainty class, will it call the DatasetError-overridden version of setNormType?

Definition at line 115 of file DatasetError.java.

References DatasetError.setNormType().

00115                                                                                 {
00116         try {
00117             ErrorNorm normtype = Enum.valueOf(ErrorNorm.class, normtypeStr.toUpperCase());
00118             setNormType(normtype);
00119         } catch (IllegalArgumentException e) {
00120             throw new HDException(e);
00121         }
00122         return this;
00123     }

int compareTo ( DatasetError  other  ) 

Definition at line 129 of file DatasetError.java.

References DatasetError.getId(), and Storeable.log().

Referenced by Uncertainty.compareTo().

00129                                              {
00130         log().debug("Comparing dataset errors...");
00131         if (getId() == null) {
00132             log().warn("Null dataset error ID");
00133             return 1; // Sort null errors at the end
00134         } else if (getId() > other.getId()) {
00135             log().debug("Greater than");
00136             return 1;
00137         } else if (getId() < other.getId()) {
00138             log().debug("Less than");
00139             return -1;
00140         } else {
00141             log().debug("Equal to");
00142             return 0;
00143         }
00144     }

boolean equals ( Object  other  ) 

Override equals method with business key equality.

Definition at line 151 of file DatasetError.java.

References DatasetError.hashCode().

00151                                         {
00152         if (this == other) return true;
00153         if (! (other instanceof DatasetError)) return false;
00154         return hashCode() == other.hashCode();
00155     }

int hashCode (  ) 

Override hashcode method.

Definition at line 158 of file DatasetError.java.

References DatasetError.getId(), Uncertainty.getMinus(), Uncertainty.getNormType(), Uncertainty.getPlus(), and Uncertainty.getSourceType().

Referenced by DatasetError.equals().

00158                           {
00159         int code = 29;
00160         if (getId() != null) code ^= getId().hashCode();
00161         if (getSourceType() != null) code ^= getSourceType().hashCode();
00162         if (getNormType() != null) code ^= getNormType().hashCode();
00163         if (getPlus() != null) code ^= 2 * getPlus().hashCode(); // ensure this is even
00164         if (getMinus() != null) code ^= 2 * getMinus().hashCode(); // ensure this is even
00165         return code;
00166     }

boolean isSymmetric (  )  [inherited]

Are the plus and minus errors symmetric?

Definition at line 88 of file Uncertainty.java.

References Uncertainty.getMinus(), and Uncertainty.getPlus().

Referenced by Uncertainty.toString().

00088                                  {
00089         return (getPlus().equals(getMinus()));
00090     }

boolean hasZeroSize (  )  [inherited]

Are the plus and minus errors both zero?

Definition at line 94 of file Uncertainty.java.

References Uncertainty.getMinus(), and Uncertainty.getPlus().

00094                                  {
00095         return (getPlus().equals(0.0) && getMinus().equals(0.0));
00096     }

Uncertainty getAbsoluteError ( Point  p  )  throws HDException [inherited]

Calculate the absolute error object for this error and the given Point.

Reimplemented in PointError.

Definition at line 105 of file Uncertainty.java.

References Uncertainty.getMinus(), Uncertainty.getNormType(), Uncertainty.getPlus(), Uncertainty.getSourceType(), and Uncertainty.Uncertainty().

Referenced by PointError.getAbsoluteError().

00105                                                                     {
00106         if (getNormType() == ErrorNorm.UNKNOWN) {
00107             throw new HDException("Attempted to get the absolute error from an unknown error type.");
00108         }
00109 
00110         Double absplus = getPlus();
00111         Double absminus = getMinus();
00112         if (getNormType() != ErrorNorm.ABS) {
00113             if (getNormType() == ErrorNorm.FRAC) {
00114                 absplus *= p.getValue();
00115                 absminus *= p.getValue();
00116             } else if (getNormType() == ErrorNorm.PCT) {
00117                 absplus *= (p.getValue() / 100.0);
00118                 absminus *= (p.getValue() / 100.0);
00119             }
00120         }
00121         Uncertainty err = new Uncertainty(absplus, absminus, getSourceType(), ErrorNorm.ABS);
00122         return err;
00123     }

Double getPlus (  )  [inherited]

Get the upward error.

Definition at line 132 of file Uncertainty.java.

Referenced by AxisError.equals(), Uncertainty.getAbsoluteError(), PointError.hashCode(), DatasetError.hashCode(), AxisError.hashCode(), Uncertainty.hasZeroSize(), Uncertainty.isSymmetric(), and Uncertainty.toString().

00132                             {
00133         return _plus;
00134     }

Uncertainty setPlus ( Double  plus  )  [inherited]

Set the upward error.

Definition at line 137 of file Uncertainty.java.

Referenced by Uncertainty.Uncertainty().

00137                                             {
00138         _plus = plus;
00139         return this;
00140     }

Double getMinus (  )  [inherited]

Get the downward error.

Definition at line 145 of file Uncertainty.java.

Referenced by AxisError.equals(), Uncertainty.getAbsoluteError(), PointError.hashCode(), DatasetError.hashCode(), AxisError.hashCode(), Uncertainty.hasZeroSize(), Uncertainty.isSymmetric(), and Uncertainty.toString().

00145                              {
00146         return _minus;
00147     }

Uncertainty setMinus ( Double  minus  )  [inherited]

Set the downward error.

Definition at line 150 of file Uncertainty.java.

Referenced by Uncertainty.Uncertainty().

00150                                               {
00151         _minus = minus;
00152         return this;
00153     }

ErrorSource getSourceType (  )  [inherited]

Get the error source type (stat, sys, etc.

) as an enum.

Definition at line 158 of file Uncertainty.java.

Referenced by AxisError.equals(), Uncertainty.getAbsoluteError(), PointError.hashCode(), DatasetError.hashCode(), AxisError.hashCode(), and Uncertainty.toString().

00158                                        {
00159         return _sourcetype;
00160     }

Uncertainty setSourceType ( ErrorSource  sourcetype  )  [inherited]

Set the error source type (stat, sys, etc.

) from the enum.

Definition at line 163 of file Uncertainty.java.

Referenced by Uncertainty.Uncertainty().

00163                                                              {
00164         _sourcetype = sourcetype;
00165         return this;
00166     }

ErrorNorm getNormType (  )  [inherited]

Get the error normalization type (abs, frac, pct, etc.

) as an enum.

Definition at line 170 of file Uncertainty.java.

Referenced by AxisError.equals(), Uncertainty.getAbsoluteError(), PointError.hashCode(), DatasetError.hashCode(), AxisError.hashCode(), and Uncertainty.toString().

00170                                    {
00171         return _normtype;
00172     }

String getComment (  )  [inherited]

Get the modification comment string.

Definition at line 181 of file Uncertainty.java.

Referenced by Uncertainty.toString().

00181                                {
00182         return _comment;
00183     }

Uncertainty setComment ( String  comment  )  [inherited]

Set the modification comment string.

Definition at line 185 of file Uncertainty.java.

00185                                                   {
00186         _comment = comment;
00187         return this;
00188     }

int compareTo ( Uncertainty  other  )  [inherited]

Todo:
Compare otherwise-equals based on stat vs sys

Definition at line 194 of file Uncertainty.java.

References DatasetError.compareTo(), AxisError.compareTo(), PointError.compareTo(), and Storeable.log().

00194                                             {
00195         log().debug("Comparing errors...");
00196 
00197         // For point errors
00198         if (this instanceof PointError) {
00199             if (other instanceof PointError) {
00200                 PointError test = (PointError) this;
00201                 int result = test.compareTo((PointError) other);
00202                 if (result != 0) return result;
00203             } else return 1;
00204         }
00205 
00206         // For axis errors
00207         if (this instanceof AxisError) {
00208             if (other instanceof AxisError) {
00209                 AxisError test = (AxisError) this;
00210                 int result = test.compareTo((AxisError) other);
00211                 if (result != 0) return result;
00212             } else return (other instanceof PointError) ? -1 : 1;
00213         }
00214 
00215         // For dataset errors
00216         if (this instanceof DatasetError) {
00217             if (other instanceof DatasetError) {
00218                 DatasetError test = (DatasetError) this;
00219                 int result = test.compareTo((DatasetError) other);
00220                 if (result != 0) return result;
00221             } else return 1;
00222         }
00223 
00225         return 0;
00226     }

String toString (  )  [inherited]

String representation.

Reimplemented from Storeable.

Definition at line 234 of file Uncertainty.java.

Referenced by Uncertainty.toString().

00234                              {
00235         return toString(0);
00236     }

String toString ( Integer  indentBy  )  [inherited]

Indented string representation.

Definition at line 240 of file Uncertainty.java.

References Uncertainty.getComment(), Uncertainty.getMinus(), Uncertainty.getNormType(), Uncertainty.getPlus(), Uncertainty.getSourceType(), Uncertainty.isSymmetric(), Storeable.log(), and Uncertainty.toString().

00240                                              {
00241         log().debug("Writing out error as a string");
00242         StringBuffer s = new StringBuffer();
00243         String indent = "";
00244         for (int i  = 0; i < indentBy; ++i) indent += " ";
00245 
00246         //if (! hasZeroSize()) {
00247         s.append(indent);
00248         Double plusval = getPlus();
00249         Double minusval = getMinus();
00250 
00251         String numFormat = "###.##";
00252         // Use the number formatter to recalculate and display everything as a percentage
00253         if (getNormType() == ErrorNorm.PCT) {
00254             plusval /= 100;
00255             minusval /= 100;
00256         }
00257         if (getNormType() == ErrorNorm.FRAC || getNormType() == ErrorNorm.PCT) {
00258             numFormat += "%"; // multiplies by 100 and sticks "%" on the end
00259         }
00260         DecimalFormat numFormatter = new DecimalFormat(numFormat);
00261         if (isSymmetric()) {
00262             s.append("+- " + numFormatter.format(plusval));
00263         } else {
00264             s.append("+ " + numFormatter.format(plusval));
00265             s.append(" - " + numFormatter.format(minusval));
00266         }
00267         s.append(" (");
00268         //s.append(getNormType().toString());
00269         //s.append(", ");
00270         s.append(getSourceType().toString());
00271         s.append(")");
00272         if (getComment() != null && getComment().length() != 0) {
00273             s.append(" [" + getComment() + "]");
00274         }
00275         //}
00276         return s.toString();
00277     }

Logger log (  )  [package, inherited]

Neat method to allow every class to get hold of a custom-named Logger.

Definition at line 14 of file Storeable.java.

Referenced by Uncertainty.compareTo(), Reference.compareTo(), PointError.compareTo(), Modification.compareTo(), Experiment.compareTo(), DatasetError.compareTo(), AxisError.compareTo(), Data.makeExample(), Data.makeExampleDataset(), Data.makeExampleExperiment(), Data.makeExamplePaper(), Data.makeExampleXAxes(), Data.makeExampleYAxes(), DatasetError.setNormType(), and Uncertainty.toString().

00014                  {
00015         return Logger.getLogger(this.getClass());
00016     }


The documentation for this class was generated from the following file:
Generated on Thu Sep 20 11:41:38 2007 by  doxygen 1.5.3