weka.classifiers.m5
Class M5Utils

java.lang.Object
  |
  +--weka.classifiers.m5.M5Utils

public final class M5Utils
extends java.lang.Object

Class for some small methods used in M5Java

Author:
Yong Wang (yongwang@cs.waikato.ac.nz)

Constructor Summary
M5Utils()
           
 
Method Summary
static double absDev(int attr, Instances inst)
          Returns the absolute deviation value of the instances values of an attribute
static double correlation(double[] y1, double[] y2, int n)
          Returns the correlation coefficient of two double vectors
static java.lang.StringBuffer deleteTrailingZerosAndDot(java.lang.StringBuffer stringBuffer)
          Deletes the trailing zeros and decimal point in a stringBuffer
static java.lang.String doubleToStringF(double value, int width, int afterDecimalPoint)
          Rounds a double and converts it into a formatted right-justified String.
static java.lang.String doubleToStringG(double value, int width, int precision)
          Rounds a double and converts it into a formatted right-justified String.
static boolean eqDouble(double a, double b)
          Tests if two double values are equal to each other
static void errorMsg(java.lang.String err)
          Prints error message and exits
static long floorDouble(double value)
          Returns the largest (closest to positive infinity) long integer value that is not greater than the argument.
static boolean hasEnumAttr(Instances inst)
          Tests if enumerated attribute(s) exists in the instances
static boolean hasMissing(Instances inst)
          Tests if missing value(s) exists in the instances
static java.lang.String headToString()
          Prints the head lines of the output
static long roundDouble(double value)
          Rounds a double
static java.lang.String separatorToString()
          Prints sepearating line
static double smoothenValue(double p, double q, int n, int k)
          Returns the smoothed values according to the smoothing formula (np+kq)/(n+k)
static double sqrSum(int attr, Instances inst)
          Returns the squared sum of the instances values of an attribute
static double stdDev(int attr, Instances inst)
          Returns the standard deviation value of the instances values of an attribute
static double sum(int attr, Instances inst)
          Returns the sum of the instances values of an attribute
static double variance(int attr, Instances inst)
          Returns the variance value of the instances values of an attribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

M5Utils

public M5Utils()
Method Detail

hasEnumAttr

public static final boolean hasEnumAttr(Instances inst)
Tests if enumerated attribute(s) exists in the instances
Parameters:
inst - instances
Returns:
true if there is at least one; false if none

hasMissing

public static final boolean hasMissing(Instances inst)
Tests if missing value(s) exists in the instances
Parameters:
inst - instances
Returns:
true if there is missing value(s); false if none

sum

public static final double sum(int attr,
                               Instances inst)
Returns the sum of the instances values of an attribute
Parameters:
attr - an attribute
inst - instances
Returns:
the sum value

sqrSum

public static final double sqrSum(int attr,
                                  Instances inst)
Returns the squared sum of the instances values of an attribute
Parameters:
attr - an attribute
inst - instances
Returns:
the squared sum value

stdDev

public static final double stdDev(int attr,
                                  Instances inst)
Returns the standard deviation value of the instances values of an attribute
Parameters:
attr - an attribute
inst - instances
Returns:
the standard deviation value

absDev

public static final double absDev(int attr,
                                  Instances inst)
Returns the absolute deviation value of the instances values of an attribute
Parameters:
attr - an attribute
inst - instances
Returns:
the absolute deviation value

variance

public static final double variance(int attr,
                                    Instances inst)
Returns the variance value of the instances values of an attribute
Parameters:
attr - an attribute
inst - instances
Returns:
the variance value

roundDouble

public static final long roundDouble(double value)
Rounds a double
Parameters:
value - the double value
Returns:
the double rounded

floorDouble

public static final long floorDouble(double value)
Returns the largest (closest to positive infinity) long integer value that is not greater than the argument.
Parameters:
value - the double value
Returns:
the floor integer

doubleToStringF

public static final java.lang.String doubleToStringF(double value,
                                                     int width,
                                                     int afterDecimalPoint)
Rounds a double and converts it into a formatted right-justified String. It is like %f format in C language.
Parameters:
value - the double value
width - the width of the string
afterDecimalPoint - the number of digits after the decimal point
Returns:
the double as a formatted string

doubleToStringG

public static final java.lang.String doubleToStringG(double value,
                                                     int width,
                                                     int precision)
Rounds a double and converts it into a formatted right-justified String. If the double is not equal to zero and not in the range [10e-3,10e7] it is returned in scientific format. It is like %g format in C language.
Parameters:
value - the double value
width - the width of the string
precision - the number of valid digits
Returns:
the double as a formatted string

deleteTrailingZerosAndDot

public static final java.lang.StringBuffer deleteTrailingZerosAndDot(java.lang.StringBuffer stringBuffer)
Deletes the trailing zeros and decimal point in a stringBuffer
Parameters:
stringBuffer - string buffer return string buffer with deleted trailing zeros and decimal point

smoothenValue

public static final double smoothenValue(double p,
                                         double q,
                                         int n,
                                         int k)
Returns the smoothed values according to the smoothing formula (np+kq)/(n+k)
Parameters:
p - a double, normally is the prediction of the model at the current node
q - a double, normally is the prediction of the model at the up node
n - the number of instances at the up node
k - the smoothing constance, default =15
Returns:
the smoothed value

correlation

public static final double correlation(double[] y1,
                                       double[] y2,
                                       int n)
Returns the correlation coefficient of two double vectors
Parameters:
y1 - double vector 1
y2 - double vector 2
n - the length of two double vectors
Returns:
the correlation coefficient

eqDouble

public static final boolean eqDouble(double a,
                                     double b)
Tests if two double values are equal to each other
Parameters:
a - double 1
b - double 2
Returns:
true if equal; false if not equal

errorMsg

public static final void errorMsg(java.lang.String err)
Prints error message and exits
Parameters:
err - error message

separatorToString

public static final java.lang.String separatorToString()
Prints sepearating line

headToString

public static final java.lang.String headToString()
Prints the head lines of the output