Class Utils

java.lang.Object
net.lifove.clami.util.Utils

public class Utils
extends java.lang.Object
  • Constructor Summary

    Constructors 
    Constructor Description
    Utils()  
  • Method Summary

    Modifier and Type Method Description
    static double getCutoffForACL​(weka.core.Instances instances, double[] K)  
    static double[] getDoublePrimitive​(java.util.ArrayList<java.lang.Double> values)
    Get primitive double form ArrayList
    static double[] getHigherValueCutoffs​(weka.core.Instances instances, double percentileCutoff)
    Get higher value cutoffs for each attribute
    static double[] getHigherValueCutoffsForACL​(weka.core.Instances instances)
    Get higher value cutoffs for each attribute
    static weka.core.Instances getInstancesByRemovingSpecificAttributes​(weka.core.Instances instances, java.lang.String attributeIndices, boolean invertSelection)
    Get instances by removing specific attributes
    static weka.core.Instances getInstancesByRemovingSpecificInstances​(weka.core.Instances instances, java.lang.String instanceIndices, boolean invertSelection)
    Get instances by removing specific instances
    static java.lang.String getInversedSelectedInstances​(weka.core.Instances instances, double[] cutoffsForHigherValuesOfAttribute, java.lang.String positiveLabel)
    Get the selected instance for the instance selection
    static double getMedian​(java.util.ArrayList<java.lang.Double> values)
    Get median from ArraList
    static java.util.HashMap<java.lang.Integer,​java.lang.String> getMetricIndicesWithTheViolationScores​(weka.core.Instances instances, double[] cutoffsForHigherValuesOfAttribute, java.lang.String positiveLabel)
    Return the HashMap that the key is Metric Violation Score and the value is string of metric indexes
    static java.lang.String getNegLabel​(weka.core.Instances instances, java.lang.String positiveLabel)
    Get the negative label string value from the positive label value
    static double getPDrForACL​(weka.core.Instances instances, double[] K)  
    static double getPercentile​(java.util.ArrayList<java.lang.Double> values, double percentile)
    Get a value in a specific percentile from ArraList
    static java.util.ArrayList<java.lang.Double> getPerformanceResult()
    Return performance result ArrayList
    static java.lang.String getSelectedInstances​(weka.core.Instances instances, double[] cutoffsForHigherValuesOfAttribute, java.lang.String positiveLabel, int inversedMetricIndex)
    Get the selected instance for the instance selection
    static java.lang.String getStringValueOfInstanceLabel​(weka.core.Instances instances, int instanceIndex)
    Get label value of an instance
    static weka.core.Instances loadArff​(java.lang.String path, java.lang.String classAttributeName)
    Load Instances from arff file.
    static void makeFile​(java.lang.String versionName)
    To create a result file
    static void printEvaluationResult​(weka.core.Instances instances, weka.core.Instances testInstances, weka.core.Instances trainingInstances, weka.classifiers.Classifier classifier, java.lang.String positiveLabel, boolean experimental, java.lang.String fileName)
    Print prediction performance in terms of TP, TN, FP, FN, precision, recall, f1, AUC, and MCC.
    static void printEvaluationResultCLA​(int TP, int TN, int FP, int FN, boolean experimental, java.lang.String fileName)
    Print prediction performance in terms of TP, TN, FP, FN, precision, recall, and f1.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • makeFile

      public static void makeFile​(java.lang.String versionName) throws java.io.FileNotFoundException, java.io.IOException
      To create a result file
      Parameters:
      versionName -
      Throws:
      java.io.FileNotFoundException
      java.io.IOException
    • printEvaluationResultCLA

      public static void printEvaluationResultCLA​(int TP, int TN, int FP, int FN, boolean experimental, java.lang.String fileName)
      Print prediction performance in terms of TP, TN, FP, FN, precision, recall, and f1.
      Parameters:
      TP -
      TN -
      FP -
      FN -
      Throws:
      java.io.IOException
      java.io.FileNotFoundException
    • getPerformanceResult

      public static java.util.ArrayList<java.lang.Double> getPerformanceResult()
      Return performance result ArrayList
      Returns:
    • printEvaluationResult

      public static void printEvaluationResult​(weka.core.Instances instances, weka.core.Instances testInstances, weka.core.Instances trainingInstances, weka.classifiers.Classifier classifier, java.lang.String positiveLabel, boolean experimental, java.lang.String fileName)
      Print prediction performance in terms of TP, TN, FP, FN, precision, recall, f1, AUC, and MCC.
      Parameters:
      instances -
      testInstances -
      trainingInstances -
      classifier -
      positiveLabel -
      experimental -
      fileName -
    • getHigherValueCutoffs

      public static double[] getHigherValueCutoffs​(weka.core.Instances instances, double percentileCutoff)
      Get higher value cutoffs for each attribute
      Parameters:
      instances -
      percentileCutoff -
      Returns:
      double[]
    • getHigherValueCutoffsForACL

      public static double[] getHigherValueCutoffsForACL​(weka.core.Instances instances)
      Get higher value cutoffs for each attribute
      Parameters:
      instances -
      Returns:
      double[]
    • getPDrForACL

      public static double getPDrForACL​(weka.core.Instances instances, double[] K)
    • getCutoffForACL

      public static double getCutoffForACL​(weka.core.Instances instances, double[] K)
    • getMetricIndicesWithTheViolationScores

      public static java.util.HashMap<java.lang.Integer,​java.lang.String> getMetricIndicesWithTheViolationScores​(weka.core.Instances instances, double[] cutoffsForHigherValuesOfAttribute, java.lang.String positiveLabel)
      Return the HashMap that the key is Metric Violation Score and the value is string of metric indexes
      Parameters:
      instances -
      cutoffsForHigherValuesOfAttribute -
      positiveLabel -
      Returns:
      HashMap
    • getSelectedInstances

      public static java.lang.String getSelectedInstances​(weka.core.Instances instances, double[] cutoffsForHigherValuesOfAttribute, java.lang.String positiveLabel, int inversedMetricIndex)
      Get the selected instance for the instance selection
      Parameters:
      instances -
      cutoffsForHigherValuesOfAttribute -
      positiveLabel -
      Returns:
      String
    • getInversedSelectedInstances

      public static java.lang.String getInversedSelectedInstances​(weka.core.Instances instances, double[] cutoffsForHigherValuesOfAttribute, java.lang.String positiveLabel)
      Get the selected instance for the instance selection
      Parameters:
      instances -
      cutoffsForHigherValuesOfAttribute -
      positiveLabel -
      Returns:
      String
    • getNegLabel

      public static java.lang.String getNegLabel​(weka.core.Instances instances, java.lang.String positiveLabel)
      Get the negative label string value from the positive label value
      Parameters:
      instances -
      positiveLabel -
      Returns:
      String
    • loadArff

      public static weka.core.Instances loadArff​(java.lang.String path, java.lang.String classAttributeName)
      Load Instances from arff file. Last attribute will be set as class attribute
      Parameters:
      path - arff file path
      Returns:
      Instances
    • getStringValueOfInstanceLabel

      public static java.lang.String getStringValueOfInstanceLabel​(weka.core.Instances instances, int instanceIndex)
      Get label value of an instance
      Parameters:
      instances -
      instanceIndex -
      Returns:
      string label of an instance
    • getMedian

      public static double getMedian​(java.util.ArrayList<java.lang.Double> values)
      Get median from ArraList
      Parameters:
      values -
      Returns:
      double
    • getPercentile

      public static double getPercentile​(java.util.ArrayList<java.lang.Double> values, double percentile)
      Get a value in a specific percentile from ArraList
      Parameters:
      values -
      Returns:
      double
    • getDoublePrimitive

      public static double[] getDoublePrimitive​(java.util.ArrayList<java.lang.Double> values)
      Get primitive double form ArrayList
      Parameters:
      values -
      Returns:
      double[]
    • getInstancesByRemovingSpecificAttributes

      public static weka.core.Instances getInstancesByRemovingSpecificAttributes​(weka.core.Instances instances, java.lang.String attributeIndices, boolean invertSelection)
      Get instances by removing specific attributes
      Parameters:
      instances -
      attributeIndices - attribute indices (e.g., 1,3,4) first index is 1
      invertSelection - for invert selection, if true, select attributes with attributeIndices bug if false, remote attributes with attributeIndices
      Returns:
      new instances with specific attributes
    • getInstancesByRemovingSpecificInstances

      public static weka.core.Instances getInstancesByRemovingSpecificInstances​(weka.core.Instances instances, java.lang.String instanceIndices, boolean invertSelection)
      Get instances by removing specific instances
      Parameters:
      instances -
      instanceIndices - (e.g., 1,3,4) first index is 1
      Returns:
      selected instances