Package se.hb.jcp.cli

Class IOTools


  • public class IOTools
    extends java.lang.Object
    Utility functions for reading/writing data to/from JSON.
    Author:
    anders.gidenstam(at)hb.se
    • Constructor Summary

      Constructors 
      Constructor Description
      IOTools()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean readInstanceFromJSON​(org.json.JSONTokener instanceReader, cern.colt.matrix.DoubleMatrix1D instance)
      Read an instance from a JSON stream.
      static void writeAsJSON​(cern.colt.matrix.DoubleMatrix1D instance, double target, org.json.JSONWriter jsonWriter)
      Write an instance to a JSON writer.
      static void writeAsJSON​(cern.colt.matrix.DoubleMatrix1D instance, org.json.JSONWriter jsonWriter)
      Write an instance to a JSON writer.
      static void writeAsJSON​(ConformalClassification prediction, cern.colt.matrix.DoubleMatrix1D instance, double target, org.json.JSONWriter resultWriter)
      Write a ConformalClassification including internal state as JSON to a JSON writer.
      static void writeAsJSON​(ConformalClassification prediction, org.json.JSONWriter resultWriter)
      Write a ConformalClassification as JSON to a JSON writer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IOTools

        public IOTools()
    • Method Detail

      • writeAsJSON

        public static void writeAsJSON​(cern.colt.matrix.DoubleMatrix1D instance,
                                       org.json.JSONWriter jsonWriter)
        Write an instance to a JSON writer. The sparse format is: { "<attribute index>":<attribute value>, ... } and indices are 0-based.
        Parameters:
        instance - the instance to write.
        jsonWriter - the JSON writer.
      • writeAsJSON

        public static void writeAsJSON​(cern.colt.matrix.DoubleMatrix1D instance,
                                       double target,
                                       org.json.JSONWriter jsonWriter)
        Write an instance to a JSON writer. The sparse format is: { "<attribute index>":<attribute value>, ... } and indices are 0-based.
        Parameters:
        instance - the instance to write.
        target - the instance target/label.
        jsonWriter - the JSON writer.
      • readInstanceFromJSON

        public static boolean readInstanceFromJSON​(org.json.JSONTokener instanceReader,
                                                   cern.colt.matrix.DoubleMatrix1D instance)
        Read an instance from a JSON stream. The sparse format is: { "<attribute index>":<attribute value>, ... } and indices are 0-based.
        Parameters:
        instanceReader - the JSON reader.
        instance - the instance to read into.
        Returns:
        true if an instance was successfully read; false otherwise.
      • writeAsJSON

        public static void writeAsJSON​(ConformalClassification prediction,
                                       org.json.JSONWriter resultWriter)
        Write a ConformalClassification as JSON to a JSON writer. The format is: { "p-values":{["<label>":<p-value>]*}, "point-prediction":{"label":<label>, "confidence":<confidence>, "credibility":<credibility>} }.
        Parameters:
        prediction - the prediction to write.
        resultWriter - the JSON writer.
      • writeAsJSON

        public static void writeAsJSON​(ConformalClassification prediction,
                                       cern.colt.matrix.DoubleMatrix1D instance,
                                       double target,
                                       org.json.JSONWriter resultWriter)
        Write a ConformalClassification including internal state as JSON to a JSON writer. The format is: { "p-values":{["<label>":<p-value>]*}, "point-prediction":{"label":<label>, "confidence":<confidence>, "credibility":<credibility>}, "true-label":<label>, "nc-scores":{ ["<label>":<nc-score>]* } }.
        Parameters:
        prediction - the prediction to write.
        instance - the instance.
        target - the instance target/label.
        resultWriter - the JSON writer.