Example usage for weka.core Instance value

List of usage examples for weka.core Instance value

Introduction

In this page you can find the example usage for weka.core Instance value.

Prototype

public double value(Attribute att);

Source Link

Document

Returns an instance's attribute value in internal format.

Usage

From source file:moa.cluster.Riffle.java

License:Apache License

/**
 * Create a new cluster from an exemplar data point
 * @param x /*from  w ww  .j a  v  a  2 s .  com*/
 */
public Riffle(Instance x) {
    safeInit(x);
    this.numLabeledPoints = (int) Math.ceil(x.weight());
    this.labelFrequencies[(int) x.classValue()] += x.weight();
    this.gtLabelFrequencies[(int) x.classValue()]++;
    for (int i = 0; (i < this.symbolFrequencies.length) && (i < x.numAttributes()); ++i) {
        double value = x.value(i);
        if (this.symbolFrequencies[i] == null) {
            if ((this.parentClusterer != null) && (this.parentClusterer.getUniverse() != null)) {
                this.variances[i] = this.parentClusterer.getUniverse().variances[i];
            } else {
                this.variances[i] = this.initialStandardDeviationOption.getValue();
            }
        } else {
            this.variances[i] = 1;
            this.symbolFrequencies[i][(int) value]++;
        }
    }
    this.numTotalPoints = 1;
    this.setGroundTruth(x.classValue());
    this.setCenter(x.toDoubleArray());
    this.setWeight(x.weight());
    this.setRadius(this.initialStandardDeviationOption.getValue());
    this.runningSumOfSquares = 0.0;
    this.setId(autoindex.getAndIncrement());
}

From source file:moa.cluster.Riffle.java

License:Apache License

/**
 * Use the multi-variate Gaussian probability estimation approach to determine probability x is a member of this cluster.
 * This is not the same as a true Mahalanobis distance derived from a full covariance matrix as we take the heuristic shortcut
 * of assuming variable independence (rho = 0), and thus have an axis-parallel hyper-ellipse (i.e. diagonal covariance matrix)
 * under the same 'naive' assumption as in Naive Bayes. The computational speed-up here is worth the reduced accuracy.
 * @param x instance in question/*from   w  ww.j  a  v  a2s. co  m*/
 * @return probability that point x is a member of this cluster
 * @deprecated 
 */
@Deprecated
public double getInclusionMVGProbability(Instance x) {

    double[] diagonalCovariance = this.getVariances();
    int degreesOfFreedom = 0;
    double axisParallelSquaredMahalanobusDistance = 0;
    // Compute Mahalanobis (axis-parallel estimation) distance and tally degrees of freedom
    for (int i = 0; i < centroid.length; ++i) {
        if (i == x.classIndex()) {
            continue;
        }
        double attributeDelta = (this.symbolFrequencies[i] == null) ? x.value(i) - centroid[i]
                : (Math.abs(x.value(i) - centroid[i]) < 1e-32) ? 0 : 1;
        if ((diagonalCovariance[i] != 0) && Double.isFinite(diagonalCovariance[i])) {
            axisParallelSquaredMahalanobusDistance += attributeDelta * attributeDelta / diagonalCovariance[i];
        }
        degreesOfFreedom++;
    }

    // Zero distance means exact match, so stop working on more computations...
    if ((axisParallelSquaredMahalanobusDistance == 0) && (degreesOfFreedom > 0)) {
        return 1.0;
    }

    // Compute the determinant of the Covariance matrix (which is O(N) if we only have the diagonal of the matrix)
    double covarianceDet = 1;
    for (int i = 0; i < diagonalCovariance.length; ++i) {
        if (i == x.classIndex()) {
            continue;
        }
        if ((diagonalCovariance[i] != 0) && Double.isFinite(diagonalCovariance[i])) {
            covarianceDet *= diagonalCovariance[i];
        } else {
            covarianceDet *= weka.core.Utils.SMALL;
        }
    }
    if (covarianceDet == 0) {
        covarianceDet = weka.core.Utils.SMALL / 1000.0;
    } // Safety
    double score = Math.exp(0.0 - 0.5 * axisParallelSquaredMahalanobusDistance)
            / (Math.pow(2.0 * Math.PI, degreesOfFreedom / 2.0) * Math.sqrt(Math.abs(covarianceDet)));
    return (1.0 - weka.core.FastStats.chiSquaredProbability(score, degreesOfFreedom));
}

From source file:moa.cluster.SphereCluster.java

License:Apache License

public double getCenterDistance(Instance instance) {
    double distance = 0.0;
    //get the center through getCenter so subclass have a chance
    double[] center = getCenter();
    for (int i = 0; i < center.length; i++) {
        double d = center[i] - instance.value(i);
        distance += d * d;//from  www  .  j a  v  a 2s .  c  o m
    }
    return Math.sqrt(distance);
}

From source file:moa.clusterers.clustream.ClustreamKernel.java

License:Apache License

public void insert(Instance instance, long timestamp) {
    N++;/*from w  w  w .  j  a va 2s  . co m*/
    LST += timestamp;
    SST += timestamp * timestamp;

    for (int i = 0; i < instance.numValues(); i++) {
        LS[i] += instance.value(i);
        SS[i] += instance.value(i) * instance.value(i);
    }
}

From source file:moa.clusterers.clustream.ClustreamKernel.java

License:Apache License

/**
 * See interface <code>Cluster</code>
 * @param point/*  w ww.  ja v a 2 s  .com*/
 * @return
 */
@Override
public double getInclusionProbability(Instance instance) {
    //trivial cluster
    if (N == 1) {
        double distance = 0.0;
        for (int i = 0; i < LS.length; i++) {
            double d = LS[i] - instance.value(i);
            distance += d * d;
        }
        distance = Math.sqrt(distance);
        if (distance < EPSILON)
            return 1.0;
        return 0.0;
    } else {
        double dist = calcNormalizedDistance(instance.toDoubleArray());
        if (dist <= getRadius()) {
            return 1;
        } else {
            return 0;
        }
        //            double res = AuxiliaryFunctions.distanceProbabilty(dist, LS.length);
        //            return res;
    }
}

From source file:moa.clusterers.clustree.ClusKernel.java

License:Apache License

@Override
public double getInclusionProbability(Instance instance) {
    //trivial cluster
    if (N == 1) {
        double distance = 0.0;
        for (int i = 0; i < LS.length; i++) {
            double d = LS[i] - instance.value(i);
            distance += d * d;/*from   w  w  w .ja va  2s.co  m*/
        }
        distance = Math.sqrt(distance);
        if (distance < EPSILON)
            return 1.0;
        return 0.0;
    } else {
        double dist = calcNormalizedDistance(instance.toDoubleArray());
        if (dist <= getRadius()) {
            return 1;
        } else {
            return 0;
        }
        //            double res = AuxiliaryFunctions.distanceProbabilty(dist, LS.length);
        //            return res;
    }
}

From source file:moa.clusterers.denstream.MicroCluster.java

License:Apache License

public void insert(Instance instance, long timestamp) {
    N++;/* ww w .  ja v  a 2  s.  c  om*/
    super.setWeight(super.getWeight() + 1);
    this.lastEditT = timestamp;

    for (int i = 0; i < instance.numValues(); i++) {
        LS[i] += instance.value(i);
        SS[i] += instance.value(i) * instance.value(i);
    }
}

From source file:moa.clusterers.outliers.MyBaseOutlierDetector.java

License:Apache License

public double[] getInstanceValues(Instance inst) {
    double[] values = new double[inst.numValues() - 1]; // last attribute is the class
    for (int i = 0; i < inst.numValues() - 1; i++) {
        values[i] = inst.value(i);
    }//w  w  w .  j  av a 2  s.  c om
    return values;
}

From source file:moa.clusterers.outliers.MyBaseOutlierDetector.java

License:Apache License

public void PrintInstance(Instance inst) {
    Print("instance: [ ");
    for (int i = 0; i < inst.numValues() - 1; i++) { // last value is the class
        Printf("%.2f ", inst.value(i));
    }/*  ww w . ja v  a  2 s .c  o m*/
    Print("] ");
    Println("");
}

From source file:moa.core.utils.Converter.java

License:Open Source License

public List<Integer> getRelevantLabels(Instance x) {
    List<Integer> classValues = new LinkedList<Integer>();
    //get all class attributes
    for (int j = 0; j < m_L; j++) {
        if (x.value(j) > 0.0) {
            classValues.add(j);//from  ww  w.  ja  va2s  . com
        }
    }
    return classValues;
}