@Override public double[] attributeToDoubleArray(int arg0) { return super.attributeToDoubleArray(arg0); }
/** * Helper method that transforma an Instances object to a Matrix object. * * @param inst The Instances to transform. * @return The resulting Matrix object. */ public static Matrix instancesToMatrix(Instances inst){ double[][] darr = new double[inst.numInstances()][inst.numAttributes()]; for (int i =0 ; i < inst.numAttributes(); i++) { for (int j = 0; j < inst.attributeToDoubleArray(i).length; j++) { darr[j][i] = inst.attributeToDoubleArray(i)[j]; } } return new Matrix(darr); }
/** * Helper method that transforma an Instances object to a Matrix object. * * @param inst The Instances to transform. * @return The resulting Matrix object. */ public static Matrix instancesToMatrix(Instances inst){ double[][] darr = new double[inst.numInstances()][inst.numAttributes()]; for (int i =0 ; i < inst.numAttributes(); i++) { for (int j = 0; j < inst.attributeToDoubleArray(i).length; j++) { darr[j][i] = inst.attributeToDoubleArray(i)[j]; } } return new Matrix(darr); }
/** * Calculates the area under the precision-recall curve (AUPRC). * * @param tcurve a previously extracted threshold curve Instances. * @return the PRC area, or Double.NaN if you don't pass in a ThresholdCurve * generated Instances. */ public static double getPRCArea(Instances tcurve) { final int n = tcurve.numInstances(); if (!RELATION_NAME.equals(tcurve.relationName()) || (n == 0)) { return Double.NaN; } final int pInd = tcurve.attribute(PRECISION_NAME).index(); final int rInd = tcurve.attribute(RECALL_NAME).index(); final double[] pVals = tcurve.attributeToDoubleArray(pInd); final double[] rVals = tcurve.attributeToDoubleArray(rInd); double area = 0; double xlast = rVals[n - 1]; // start from the first real p/r pair (not the artificial zero point) for (int i = n - 2; i >= 0; i--) { double recallDelta = rVals[i] - xlast; area += (pVals[i] * recallDelta); xlast = rVals[i]; } if (area == 0) { return Utils.missingValue(); } return area; }
final double[] tpVals = tcurve.attributeToDoubleArray(tpInd); final double[] fpVals = tcurve.attributeToDoubleArray(fpInd);
/** * Calculates the area under the precision-recall curve (AUPRC). * * @param tcurve a previously extracted threshold curve Instances. * @return the PRC area, or Double.NaN if you don't pass in a ThresholdCurve * generated Instances. */ public static double getPRCArea(Instances tcurve) { final int n = tcurve.numInstances(); if (!RELATION_NAME.equals(tcurve.relationName()) || (n == 0)) { return Double.NaN; } final int pInd = tcurve.attribute(PRECISION_NAME).index(); final int rInd = tcurve.attribute(RECALL_NAME).index(); final double[] pVals = tcurve.attributeToDoubleArray(pInd); final double[] rVals = tcurve.attributeToDoubleArray(rInd); double area = 0; double xlast = rVals[n - 1]; // start from the first real p/r pair (not the artificial zero point) for (int i = n - 2; i >= 0; i--) { double recallDelta = rVals[i] - xlast; area += (pVals[i] * recallDelta); xlast = rVals[i]; } if (area == 0) { return Utils.missingValue(); } return area; }
final double[] tpVals = tcurve.attributeToDoubleArray(tpInd); final double[] fpVals = tcurve.attributeToDoubleArray(fpInd);
@Override public Object getValue(int rowId, int col) { if (!isValueValid(rowId, col)) { return null; } Attribute att = instances.attribute(col); if (att.isNumeric()) { return instances.attributeToDoubleArray(col)[rowId]; } else if (att.isNominal() || att.isString()) { return instances.instance(rowId).stringValue(col); } else if (att.isDate()) { double dateValue = instances.attributeToDoubleArray(col)[rowId]; return att.formatDate(dateValue); } return null; }
/** * Gets the index of the instance with the closest threshold value to the * desired target * * @param tcurve a set of instances that have been generated by this class * @param threshold the target threshold * @return the index of the instance that has threshold closest to the target, * or -1 if this could not be found (i.e. no data, or bad threshold * target) */ public static int getThresholdInstance(Instances tcurve, double threshold) { if (!RELATION_NAME.equals(tcurve.relationName()) || (tcurve.numInstances() == 0) || (threshold < 0) || (threshold > 1.0)) { return -1; } if (tcurve.numInstances() == 1) { return 0; } double[] tvals = tcurve.attributeToDoubleArray(tcurve.numAttributes() - 1); int[] sorted = Utils.sort(tvals); return binarySearch(sorted, tvals, threshold); }
/** * Gets the index of the instance with the closest threshold value to the * desired target * * @param tcurve a set of instances that have been generated by this class * @param threshold the target threshold * @return the index of the instance that has threshold closest to the target, * or -1 if this could not be found (i.e. no data, or bad threshold * target) */ public static int getThresholdInstance(Instances tcurve, double threshold) { if (!RELATION_NAME.equals(tcurve.relationName()) || (tcurve.numInstances() == 0) || (threshold < 0) || (threshold > 1.0)) { return -1; } if (tcurve.numInstances() == 1) { return 0; } double[] tvals = tcurve.attributeToDoubleArray(tcurve.numAttributes() - 1); int[] sorted = Utils.sort(tvals); return binarySearch(sorted, tvals, threshold); }
values = instances.attributeToDoubleArray(m_AttributeIndices[i]); sortedIndices = Utils.sort(values);
values = instances.attributeToDoubleArray(m_AttributeIndices[i]); sortedIndices = Utils.sort(values);
double[] recallVals = tcurve.attributeToDoubleArray(recallInd); int[] sorted = Utils.sort(recallVals); double isize = 1.0 / (n - 1);
double[] recallVals = tcurve.attributeToDoubleArray(recallInd); int[] sorted = Utils.sort(recallVals); double isize = 1.0 / (n - 1);
double[][] transformedDataMatrix = getTransformedDataMatrix(data, m_ClassIndex); double[] classValueVector = data.attributeToDoubleArray(m_ClassIndex);
m_means[i] = m_trainInstances.meanOrMode(i); m_stdDevs[i] = Math.sqrt(Utils.variance(m_trainInstances.attributeToDoubleArray(i)));
m_means[i] = m_trainInstances.meanOrMode(i); m_stdDevs[i] = Math.sqrt(Utils.variance(m_trainInstances.attributeToDoubleArray(i)));
Attribute classAttribute = null; if (classIndex >= 0) { classes = instances.attributeToDoubleArray(instances.classIndex()); classAttribute = (Attribute) instances.classAttribute().copy(); instances.setClassIndex(-1);
double[] column = labels.attributeToDoubleArray(i); double sum =0.0; for(int j = 0; j < column.length; j++){
double[] column = labels.attributeToDoubleArray(i); double sum =0.0; for(int j = 0; j < column.length; j++){