當前位置: 首頁>>代碼示例>>Java>>正文


Java Utils.sort方法代碼示例

本文整理匯總了Java中weka.core.Utils.sort方法的典型用法代碼示例。如果您正苦於以下問題:Java Utils.sort方法的具體用法?Java Utils.sort怎麽用?Java Utils.sort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在weka.core.Utils的用法示例。


在下文中一共展示了Utils.sort方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCurve

import weka.core.Utils; //導入方法依賴的package包/類
/**
 * Calculates the cumulative margin distribution for the set of predictions,
 * returning the result as a set of Instances. The structure of these
 * Instances is as follows:
 * <p>
 * <ul>
 * <li><b>Margin</b> contains the margin value (which should be plotted as an
 * x-coordinate)
 * <li><b>Current</b> contains the count of instances with the current margin
 * (plot as y axis)
 * <li><b>Cumulative</b> contains the count of instances with margin less than
 * or equal to the current margin (plot as y axis)
 * </ul>
 * <p>
 * 
 * @return datapoints as a set of instances, null if no predictions have been
 *         made.
 */
public Instances getCurve(ArrayList<Prediction> predictions) {

  if (predictions.size() == 0) {
    return null;
  }

  Instances insts = makeHeader();
  double[] margins = getMargins(predictions);
  int[] sorted = Utils.sort(margins);
  int binMargin = 0;
  int totalMargin = 0;
  insts.add(makeInstance(-1, binMargin, totalMargin));
  for (int element : sorted) {
    double current = margins[element];
    double weight = ((NominalPrediction) predictions.get(element)).weight();
    totalMargin += weight;
    binMargin += weight;
    if (true) {
      insts.add(makeInstance(current, binMargin, totalMargin));
      binMargin = 0;
    }
  }
  return insts;
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:43,代碼來源:MarginCurve.java

示例2: getThresholdInstance

import weka.core.Utils; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:24,代碼來源:ThresholdCurve.java

示例3: toStringRanking

import weka.core.Utils; //導入方法依賴的package包/類
/**
 * returns the ranking in a string representation.
 * 
 * @return		the ranking
 */
public String toStringRanking() {
  String        result;
  int[]         ranking;
  int           i;
  int           curr;

  if (m_RankingWins == null)
    return "-ranking data not set-";

  result = ">-<,>,<,Resultset\n";

  ranking = Utils.sort(m_RankingDiff);

  for (i = getColCount() - 1; i >= 0; i--) {
    curr = ranking[i];

    if (getColHidden(curr))
      continue;

    result += m_RankingDiff[curr] + ","
      + m_RankingWins[curr] + ","
      + m_RankingLosses[curr] + ","
      + removeFilterName(m_ColNames[curr]) + "\n";
  }

  return result;
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:33,代碼來源:ResultMatrixCSV.java

示例4: toStringRanking

import weka.core.Utils; //導入方法依賴的package包/類
/**
 * returns the ranking in a string representation.
 * 
 * @return the ranking
 */
@Override
public String toStringRanking() {
  int biggest;
  int width;
  String result;
  int[] ranking;
  int i;
  int curr;

  if (m_RankingWins == null) {
    return "-ranking data not set-";
  }

  biggest = Math.max(m_RankingWins[Utils.maxIndex(m_RankingWins)],
    m_RankingLosses[Utils.maxIndex(m_RankingLosses)]);
  width = Math.max(2 + (int) (Math.log(biggest) / Math.log(10)),
    ">-<".length());
  result = Utils.padLeft(">-<", width) + ' ' + Utils.padLeft(">", width)
    + ' ' + Utils.padLeft("<", width) + " Resultset\n";

  ranking = Utils.sort(m_RankingDiff);

  for (i = getColCount() - 1; i >= 0; i--) {
    curr = ranking[i];

    if (getColHidden(curr)) {
      continue;
    }

    result += Utils.padLeft("" + m_RankingDiff[curr], width) + ' '
      + Utils.padLeft("" + m_RankingWins[curr], width) + ' '
      + Utils.padLeft("" + m_RankingLosses[curr], width) + ' '
      + removeFilterName(m_ColNames[curr]) + '\n';
  }

  return result;
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:43,代碼來源:ResultMatrixPlainText.java

示例5: toStringRanking

import weka.core.Utils; //導入方法依賴的package包/類
/**
 * returns the ranking in a string representation.
 * 
 * @return 		the ranking
 */
public String toStringRanking() {
  int           biggest;
  int           width;
  String        result;
  int[]         ranking;
  int           i;
  int           curr;

  if (m_RankingWins == null)
    return "-ranking data not set-";

  biggest = Math.max(m_RankingWins[Utils.maxIndex(m_RankingWins)],
                     m_RankingLosses[Utils.maxIndex(m_RankingLosses)]);
  width = Math.max(2 + (int)(Math.log(biggest) / Math.log(10)),
	 ">-<".length());
  result = "\\begin{table}[thb]\n\\caption{\\label{labelname}Table Caption"
    + "}\n\\footnotesize\n{\\centering \\begin{tabular}{rlll}\\\\\n\\hline\n";
  result +=   "Resultset & Wins$-$ & Wins & Losses \\\\\n& Losses & & "
            + "\\\\\n\\hline\n";

  ranking = Utils.sort(m_RankingDiff);
  for (i = getColCount() - 1; i >= 0; i--) {
    curr = ranking[i];
    
    if (getColHidden(curr))
      continue;

    result +=   "(" + (curr + 1) + ") & " 
              + Utils.padLeft("" + m_RankingDiff[curr], width) 
              + " & " + Utils.padLeft("" + m_RankingWins[curr], width)
              + " & " + Utils.padLeft("" + m_RankingLosses[curr], width)
              + "\\\\\n";
  }

  result += "\\hline\n\\end{tabular} \\footnotesize \\par}\n\\end{table}";

  return result;
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:44,代碼來源:ResultMatrixLatex.java

示例6: toStringRanking

import weka.core.Utils; //導入方法依賴的package包/類
/**
 * returns the ranking in a string representation.
 * 
 * @return		the ranking
 */
public String toStringRanking() {
  String        result;
  int[]         ranking;
  int           i;
  int           curr;

  if (m_RankingWins == null)
    return "-ranking data not set-";

  result = "<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\">\n";
  result +=  "   <tr>" 
           + "<td align=\"center\"><b>&gt;-&lt;</b></td>"
           + "<td align=\"center\"><b>&gt;</b></td>"
           + "<td align=\"center\"><b>&lt;</b></td>"
           + "<td><b>Resultset</b></td>"
           + "</tr>\n";

  ranking = Utils.sort(m_RankingDiff);

  for (i = getColCount() - 1; i >= 0; i--) {
    curr = ranking[i];

    if (getColHidden(curr))
      continue;

    result += "   <tr>"
      + "<td align=\"right\">" + m_RankingDiff[curr] + "</td>"
      + "<td align=\"right\">" + m_RankingWins[curr] + "</td>"
      + "<td align=\"right\">" + m_RankingLosses[curr] + "</td>"
      + "<td>" + removeFilterName(m_ColNames[curr]) + "</td>"
      + "<tr>\n";
  }

  result += "</table>\n";

  return result;
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:43,代碼來源:ResultMatrixHTML.java

示例7: computeAverageClassValues

import weka.core.Utils; //導入方法依賴的package包/類
/** Computes average class values for each attribute and value */
private void computeAverageClassValues() {

  double totalCounts, sum;
  Instance instance;
  double[] counts;

  double[][] avgClassValues = new double[getInputFormat().numAttributes()][0];
  m_Indices = new int[getInputFormat().numAttributes()][0];
  for (int j = 0; j < getInputFormat().numAttributes(); j++) {
    Attribute att = getInputFormat().attribute(j);
    if (att.isNominal()) {
      avgClassValues[j] = new double[att.numValues()];
      counts = new double[att.numValues()];
      for (int i = 0; i < getInputFormat().numInstances(); i++) {
        instance = getInputFormat().instance(i);
        if (!instance.classIsMissing() && (!instance.isMissing(j))) {
          counts[(int) instance.value(j)] += instance.weight();
          avgClassValues[j][(int) instance.value(j)] += instance.weight()
            * instance.classValue();
        }
      }
      sum = Utils.sum(avgClassValues[j]);
      totalCounts = Utils.sum(counts);
      if (Utils.gr(totalCounts, 0)) {
        for (int k = 0; k < att.numValues(); k++) {
          if (Utils.gr(counts[k], 0)) {
            avgClassValues[j][k] /= counts[k];
          } else {
            avgClassValues[j][k] = sum / totalCounts;
          }
        }
      }
      m_Indices[j] = Utils.sort(avgClassValues[j]);
    }
  }
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:38,代碼來源:NominalToBinary.java

示例8: rankedAttributes

import weka.core.Utils; //導入方法依賴的package包/類
/**
 * Sorts the evaluated attribute list
 * 
 * @return an array of sorted (highest eval to lowest) attribute indexes
 * @throws Exception of sorting can't be done.
 */
@Override
public double[][] rankedAttributes() throws Exception {
  int i, j;

  if (m_attributeList == null || m_attributeMerit == null) {
    throw new Exception("Search must be performed before a ranked "
      + "attribute list can be obtained");
  }

  int[] ranked = Utils.sort(m_attributeMerit);
  // reverse the order of the ranked indexes
  double[][] bestToWorst = new double[ranked.length][2];

  for (i = ranked.length - 1, j = 0; i >= 0; i--) {
    bestToWorst[j++][0] = ranked[i];
  }

  // convert the indexes to attribute indexes
  for (i = 0; i < bestToWorst.length; i++) {
    int temp = ((int) bestToWorst[i][0]);
    bestToWorst[i][0] = m_attributeList[temp];
    bestToWorst[i][1] = m_attributeMerit[temp];
  }

  // if (m_numToSelect > bestToWorst.length) {
  // throw new Exception("More attributes requested than exist in the data");
  // }

  if (m_numToSelect <= 0) {
    if (m_threshold == -Double.MAX_VALUE) {
      m_calculatedNumToSelect = bestToWorst.length;
    } else {
      determineNumToSelectFromThreshold(bestToWorst);
    }
  }
  /*
   * if (m_numToSelect > 0) { determineThreshFromNumToSelect(bestToWorst); }
   */

  return bestToWorst;
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:48,代碼來源:Ranker.java

示例9: getNPointPrecision

import weka.core.Utils; //導入方法依賴的package包/類
/**
 * Calculates the n point precision result, which is the precision averaged
 * over n evenly spaced (w.r.t recall) samples of the curve.
 * 
 * @param tcurve a previously extracted threshold curve Instances.
 * @param n the number of points to average over.
 * @return the n-point precision.
 */
public static double getNPointPrecision(Instances tcurve, int n) {

  if (!RELATION_NAME.equals(tcurve.relationName())
    || (tcurve.numInstances() == 0)) {
    return Double.NaN;
  }
  int recallInd = tcurve.attribute(RECALL_NAME).index();
  int precisInd = tcurve.attribute(PRECISION_NAME).index();
  double[] recallVals = tcurve.attributeToDoubleArray(recallInd);
  int[] sorted = Utils.sort(recallVals);
  double isize = 1.0 / (n - 1);
  double psum = 0;
  for (int i = 0; i < n; i++) {
    int pos = binarySearch(sorted, recallVals, i * isize);
    double recall = recallVals[sorted[pos]];
    double precis = tcurve.instance(sorted[pos]).value(precisInd);
    /*
     * System.err.println("Point " + (i + 1) + ": i=" + pos + " r=" + (i *
     * isize) + " p'=" + precis + " r'=" + recall);
     */
    // interpolate figures for non-endpoints
    while ((pos != 0) && (pos < sorted.length - 1)) {
      pos++;
      double recall2 = recallVals[sorted[pos]];
      if (recall2 != recall) {
        double precis2 = tcurve.instance(sorted[pos]).value(precisInd);
        double slope = (precis2 - precis) / (recall2 - recall);
        double offset = precis - recall * slope;
        precis = isize * i * slope + offset;
        /*
         * System.err.println("Point2 " + (i + 1) + ": i=" + pos + " r=" + (i
         * * isize) + " p'=" + precis2 + " r'=" + recall2 + " p''=" + precis);
         */
        break;
      }
    }
    psum += precis;
  }
  return psum / n;
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:49,代碼來源:ThresholdCurve.java

示例10: calculateRegionProbs

import weka.core.Utils; //導入方法依賴的package包/類
private double[] calculateRegionProbs(int j, int i) throws Exception {
  double[] sumOfProbsForRegion = new double[m_trainingData.classAttribute()
    .numValues()];

  for (int u = 0; u < m_numOfSamplesPerRegion; u++) {

    double[] sumOfProbsForLocation = new double[m_trainingData
      .classAttribute().numValues()];

    m_weightingAttsValues[m_xAttribute] = getRandomX(j);
    m_weightingAttsValues[m_yAttribute] = getRandomY(m_panelHeight - i - 1);

    m_dataGenerator.setWeightingValues(m_weightingAttsValues);

    double[] weights = m_dataGenerator.getWeights();
    double sumOfWeights = Utils.sum(weights);
    int[] indices = Utils.sort(weights);

    // Prune 1% of weight mass
    int[] newIndices = new int[indices.length];
    double sumSoFar = 0;
    double criticalMass = 0.99 * sumOfWeights;
    int index = weights.length - 1;
    int counter = 0;
    for (int z = weights.length - 1; z >= 0; z--) {
      newIndices[index--] = indices[z];
      sumSoFar += weights[indices[z]];
      counter++;
      if (sumSoFar > criticalMass) {
        break;
      }
    }
    indices = new int[counter];
    System.arraycopy(newIndices, index + 1, indices, 0, counter);

    for (int z = 0; z < m_numOfSamplesPerGenerator; z++) {

      m_dataGenerator.setWeightingValues(m_weightingAttsValues);
      double[][] values = m_dataGenerator.generateInstances(indices);

      for (int q = 0; q < values.length; q++) {
        if (values[q] != null) {
          System.arraycopy(values[q], 0, m_vals, 0, m_vals.length);
          m_vals[m_xAttribute] = m_weightingAttsValues[m_xAttribute];
          m_vals[m_yAttribute] = m_weightingAttsValues[m_yAttribute];

          // classify the instance
          m_dist = m_classifier.distributionForInstance(m_predInst);

          for (int k = 0; k < sumOfProbsForLocation.length; k++) {
            sumOfProbsForLocation[k] += (m_dist[k] * weights[q]);
          }
        }
      }
    }

    for (int k = 0; k < sumOfProbsForRegion.length; k++) {
      sumOfProbsForRegion[k] += (sumOfProbsForLocation[k] * sumOfWeights);
    }
  }

  // average
  Utils.normalize(sumOfProbsForRegion);

  // cache
  double[] tempDist = new double[sumOfProbsForRegion.length];
  System.arraycopy(sumOfProbsForRegion, 0, tempDist, 0,
    sumOfProbsForRegion.length);

  return tempDist;
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:72,代碼來源:RemoteBoundaryVisualizerSubTask.java

示例11: computeParams

import weka.core.Utils; //導入方法依賴的package包/類
private void computeParams() throws Exception {
  // Calculate the minimum and maximum values
  m_Min = new double[m_instances.numAttributes()];
  m_Max = new double[m_instances.numAttributes()];
  for (int i = 0; i < m_instances.numAttributes(); i++) {
    m_Min[i] = m_Max[i] = Double.NaN;
  }
  for (int i = 0; i < m_instances.numInstances(); i++) {
    updateMinMax(m_instances.instance(i));
  }

  double[] distances = new double[m_instances.numInstances()];
  for (int i = 0; i < m_instances.numInstances(); i++) {
    Instance current = m_instances.instance(i);
    for (int j = 0; j < m_instances.numInstances(); j++) {
      distances[j] = distance(current, m_instances.instance(j));
    }
    int[] sorted = Utils.sort(distances);
    int k = m_kernelBandwidth;
    double bandwidth = distances[sorted[k]];

    // Check for bandwidth zero
    if (bandwidth <= 0) {
      for (int j = k + 1; j < sorted.length; j++) {
        if (distances[sorted[j]] > bandwidth) {
          bandwidth = distances[sorted[j]];
          break;
        }
      }
      if (bandwidth <= 0) {
        throw new Exception("All training instances coincide with "
          + "test instance!");
      }
    }
    for (int j = 0; j < m_instances.numAttributes(); j++) {
      if ((m_Max[j] - m_Min[j]) > 0) {
        m_kernelParams[i][j] = bandwidth * (m_Max[j] - m_Min[j]);
      }
    }
  }
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:42,代碼來源:KDDataGenerator.java

示例12: calculateRegionProbs

import weka.core.Utils; //導入方法依賴的package包/類
private double[] calculateRegionProbs(int j, int i) throws Exception {
  double[] sumOfProbsForRegion = new double[m_trainingData.classAttribute()
    .numValues()];

  for (int u = 0; u < m_numOfSamplesPerRegion; u++) {

    double[] sumOfProbsForLocation = new double[m_trainingData
      .classAttribute().numValues()];

    m_weightingAttsValues[m_xAttribute] = getRandomX(j);
    m_weightingAttsValues[m_yAttribute] = getRandomY(m_panelHeight - i - 1);

    m_dataGenerator.setWeightingValues(m_weightingAttsValues);

    double[] weights = m_dataGenerator.getWeights();
    double sumOfWeights = Utils.sum(weights);
    int[] indices = Utils.sort(weights);

    // Prune 1% of weight mass
    int[] newIndices = new int[indices.length];
    double sumSoFar = 0;
    double criticalMass = 0.99 * sumOfWeights;
    int index = weights.length - 1;
    int counter = 0;
    for (int z = weights.length - 1; z >= 0; z--) {
      newIndices[index--] = indices[z];
      sumSoFar += weights[indices[z]];
      counter++;
      if (sumSoFar > criticalMass) {
        break;
      }
    }
    indices = new int[counter];
    System.arraycopy(newIndices, index + 1, indices, 0, counter);

    for (int z = 0; z < m_numOfSamplesPerGenerator; z++) {

      m_dataGenerator.setWeightingValues(m_weightingAttsValues);
      double[][] values = m_dataGenerator.generateInstances(indices);

      for (int q = 0; q < values.length; q++) {
        if (values[q] != null) {
          System.arraycopy(values[q], 0, m_vals, 0, m_vals.length);
          m_vals[m_xAttribute] = m_weightingAttsValues[m_xAttribute];
          m_vals[m_yAttribute] = m_weightingAttsValues[m_yAttribute];

          // classify the instance
          m_dist = m_classifier.distributionForInstance(m_predInst);
          for (int k = 0; k < sumOfProbsForLocation.length; k++) {
            sumOfProbsForLocation[k] += (m_dist[k] * weights[q]);
          }
        }
      }
    }

    for (int k = 0; k < sumOfProbsForRegion.length; k++) {
      sumOfProbsForRegion[k] += (sumOfProbsForLocation[k] * sumOfWeights);
    }
  }

  // average
  Utils.normalize(sumOfProbsForRegion);

  // cache
  if ((i < m_panelHeight) && (j < m_panelWidth)) {
    m_probabilityCache[i][j] = new double[sumOfProbsForRegion.length];
    System.arraycopy(sumOfProbsForRegion, 0, m_probabilityCache[i][j], 0,
      sumOfProbsForRegion.length);
  }

  return sumOfProbsForRegion;
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:73,代碼來源:BoundaryPanel.java

示例13: computeThresholds

import weka.core.Utils; //導入方法依賴的package包/類
/**
 * computes the thresholds for outliers and extreme values
 * 
 * @param instances the data to work on
 */
protected void computeThresholds(Instances instances) {
  int i;
  double[] values;
  int[] sortedIndices;
  int half;
  int quarter;
  double q1;
  double q2;
  double q3;

  m_UpperExtremeValue = new double[m_AttributeIndices.length];
  m_UpperOutlier = new double[m_AttributeIndices.length];
  m_LowerOutlier = new double[m_AttributeIndices.length];
  m_LowerExtremeValue = new double[m_AttributeIndices.length];
  m_Median = new double[m_AttributeIndices.length];
  m_IQR = new double[m_AttributeIndices.length];

  for (i = 0; i < m_AttributeIndices.length; i++) {
    // non-numeric attribute?
    if (m_AttributeIndices[i] == NON_NUMERIC) {
      continue;
    }

    // sort attribute data
    values = instances.attributeToDoubleArray(m_AttributeIndices[i]);
    sortedIndices = Utils.sort(values);

    // determine indices
    half = sortedIndices.length / 2;
    quarter = half / 2;

    if (sortedIndices.length % 2 == 1) {
      q2 = values[sortedIndices[half]];
    } else {
      q2 = (values[sortedIndices[half]] + values[sortedIndices[half + 1]]) / 2;
    }

    if (half % 2 == 1) {
      q1 = values[sortedIndices[quarter]];
      q3 = values[sortedIndices[sortedIndices.length - quarter - 1]];
    } else {
      q1 = (values[sortedIndices[quarter]] + values[sortedIndices[quarter + 1]]) / 2;
      q3 = (values[sortedIndices[sortedIndices.length - quarter - 1]] + values[sortedIndices[sortedIndices.length
        - quarter]]) / 2;
    }

    // determine thresholds and other values
    m_Median[i] = q2;
    m_IQR[i] = q3 - q1;
    m_UpperExtremeValue[i] = q3 + getExtremeValuesFactor() * m_IQR[i];
    m_UpperOutlier[i] = q3 + getOutlierFactor() * m_IQR[i];
    m_LowerOutlier[i] = q1 - getOutlierFactor() * m_IQR[i];
    m_LowerExtremeValue[i] = q1 - getExtremeValuesFactor() * m_IQR[i];
  }
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:61,代碼來源:InterquartileRange.java


注:本文中的weka.core.Utils.sort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。