Class MixedUtils

java.lang.Object
edu.pitt.csb.mgm.MixedUtils

public class MixedUtils extends Object
Created by ajsedgewick on 7/29/15.
Version:
$Id: $Id
  • Field Details

    • EdgeStatHeader

      public static final String EdgeStatHeader
      Constant EdgeStatHeader="TD\tTU\tFL\tFD\tFU\tFPD\tFPU\tFND\tFNU\"{trunked}
      See Also:
  • Method Details

    • getDiscreteInds

      public static int[] getDiscreteInds(List<Node> nodes)

      getDiscreteInds.

      Parameters:
      nodes - a List object
      Returns:
      an array of int objects
    • getContinuousInds

      public static int[] getContinuousInds(List<Node> nodes)

      getContinuousInds.

      Parameters:
      nodes - a List object
      Returns:
      an array of int objects
    • makeContinuousData

      public static DataSet makeContinuousData(DataSet dsMix)

      makeContinuousData.

      Parameters:
      dsMix - a DataSet object
      Returns:
      a DataSet object
    • makeMixedData

      public static DataSet makeMixedData(DataSet dsCont, Map<String,String> nodeDists, int numCategories)

      makeMixedData.

      Parameters:
      dsCont - a DataSet object
      nodeDists - a Map object
      numCategories - a int
      Returns:
      a DataSet object
    • makeMixedData

      public static DataSet makeMixedData(DataSet dsCont, Map<String,Integer> nodeDists)

      makeMixedData.

      Parameters:
      dsCont - a DataSet object
      nodeDists - a Map object
      Returns:
      a DataSet object
    • deepCopy

      public static DataSet deepCopy(DataSet ds)
      Makes a deep copy of a dataset (Nodes copied as well). Useful for paralellization
      Parameters:
      ds - dataset to be copied
      Returns:
      a DataSet object
    • getContinousData

      public static DataSet getContinousData(DataSet ds)

      getContinousData.

      Parameters:
      ds - a DataSet object
      Returns:
      a DataSet object
    • getDiscreteData

      public static DataSet getDiscreteData(DataSet ds)

      getDiscreteData.

      Parameters:
      ds - a DataSet object
      Returns:
      a DataSet object
    • getDiscLevels

      public static int[] getDiscLevels(DataSet ds)

      getDiscLevels.

      Parameters:
      ds - a DataSet object
      Returns:
      an array of int objects
    • colMax

      public static int[] colMax(cern.colt.matrix.DoubleMatrix2D m)
      return vector of the maximum of each column in m (as ints, i.e. for discrete data)
      Parameters:
      m - a DoubleMatrix2D object
      Returns:
      an array of int objects
    • vecMax

      public static double vecMax(cern.colt.matrix.DoubleMatrix1D vec)

      vecMax.

      Parameters:
      vec - a DoubleMatrix1D object
      Returns:
      a double
    • numVals

      public static double numVals(cern.colt.matrix.DoubleMatrix1D vec)

      numVals.

      Parameters:
      vec - a DoubleMatrix1D object
      Returns:
      a double
    • valSet

      public static Set<Double> valSet(cern.colt.matrix.DoubleMatrix1D vec)

      valSet.

      Parameters:
      vec - a DoubleMatrix1D object
      Returns:
      a Set object
    • GaussianTrinaryPm

      public static GeneralizedSemPm GaussianTrinaryPm(Graph trueGraph, HashMap<String,String> nodeDists, int maxSample, String paramTemplate) throws IllegalStateException

      GaussianTrinaryPm.

      Parameters:
      trueGraph - a Graph object
      nodeDists - a HashMap object
      maxSample - a int
      paramTemplate - a String object
      Returns:
      a GeneralizedSemPm object
      Throws:
      IllegalStateException - if any.
    • GaussianCategoricalPm

      public static GeneralizedSemPm GaussianCategoricalPm(Graph trueGraph, String paramTemplate) throws IllegalStateException

      GaussianCategoricalPm.

      Parameters:
      trueGraph - a Graph object
      paramTemplate - a String object
      Returns:
      a GeneralizedSemPm object
      Throws:
      IllegalStateException - if any.
    • setStartsWith

      public static void setStartsWith(String sta, String template, GeneralizedSemPm pm)
      Set all existing parameters that begins with sta to template and also set template for any new parameters
      Parameters:
      sta - a String object
      template - a String object
      pm - a GeneralizedSemPm object
    • GaussianCategoricalIm

      public static GeneralizedSemIm GaussianCategoricalIm(GeneralizedSemPm pm)

      GaussianCategoricalIm.

      Parameters:
      pm - a GeneralizedSemPm object
      Returns:
      a GeneralizedSemIm object
    • GaussianCategoricalIm

      public static GeneralizedSemIm GaussianCategoricalIm(GeneralizedSemPm pm, boolean discParamRand)
      This method is needed to normalize edge parameters for an Instantiated Mixed Model Generates edge parameters for c-d and d-d edges from a single weight, abs(w), drawn by the normal IM constructor. Abs(w) is used for d-d edges.

      For deterministic, c-d are evenly spaced between -w and w, and d-d are a matrix with w on the diagonal and -w/(categories-1) in the rest. For random, c-d params are uniformly drawn from 0 to 1 then transformed to have w as max value and sum to 0.

      Parameters:
      pm - a GeneralizedSemPm object
      discParamRand - true for random edge generation behavior, false for deterministic
      Returns:
      a GeneralizedSemIm object
    • getEdgeParams

      public static List<String> getEdgeParams(String s1, String s2, GeneralizedSemPm pm)

      getEdgeParams.

      Parameters:
      s1 - a String object
      s2 - a String object
      pm - a GeneralizedSemPm object
      Returns:
      a List object
    • arrayPermute

      public static double[] arrayPermute(double[] a)

      arrayPermute.

      Parameters:
      a - an array of double objects
      Returns:
      an array of double objects
    • arrayPermute

      public static int[] arrayPermute(int[] a)

      arrayPermute.

      Parameters:
      a - an array of int objects
      Returns:
      an array of int objects
    • evenSplitVector

      public static double[] evenSplitVector(double w, int L)

      evenSplitVector.

      Parameters:
      w - a double
      L - a int
      Returns:
      an array of double objects
    • getEdgeParams

      public static List<String> getEdgeParams(Node n1, Node n2, GeneralizedSemPm pm)

      getEdgeParams.

      Parameters:
      n1 - a Node object
      n2 - a Node object
      pm - a GeneralizedSemPm object
      Returns:
      a List object
    • generateMixedEdgeParams

      public static double[] generateMixedEdgeParams(double w, int L)

      generateMixedEdgeParams.

      Parameters:
      w - a double
      L - a int
      Returns:
      an array of double objects
    • allEdgeStats

      public static int[][] allEdgeStats(Graph pT, Graph pE)

      allEdgeStats.

      Parameters:
      pT - a Graph object
      pE - a Graph object
      Returns:
      an array of int objects
    • allEdgeStats

      public static int[][] allEdgeStats(Graph pT, Graph pE, HashMap<String,String> nodeDists)

      allEdgeStats.

      Parameters:
      pT - a Graph object
      pE - a Graph object
      nodeDists - a HashMap object
      Returns:
      an array of int objects
    • makeMixedGraph

      public static Graph makeMixedGraph(Graph g, Map<String,Integer> m)

      makeMixedGraph.

      Parameters:
      g - a Graph object
      m - a Map object
      Returns:
      a Graph object
    • stringFrom2dArray

      public static String stringFrom2dArray(int[][] arr)

      stringFrom2dArray.

      Parameters:
      arr - an array of int objects
      Returns:
      a String object
    • loadDataSet

      public static DataSet loadDataSet(String dir, String filename) throws IOException

      loadDataSet.

      Parameters:
      dir - a String object
      filename - a String object
      Returns:
      a DataSet object
      Throws:
      IOException - if any.
    • loadDelim

      public static DataSet loadDelim(String dir, String filename) throws IOException

      loadDelim.

      Parameters:
      dir - a String object
      filename - a String object
      Returns:
      a DataSet object
      Throws:
      IOException - if any.
    • getNodeDists

      public static Map<String,Integer> getNodeDists(Graph g)

      getNodeDists.

      Parameters:
      g - a Graph object
      Returns:
      a Map object
    • loadData

      public static DataSet loadData(String dir, String filename) throws IOException

      loadData.

      Parameters:
      dir - a String object
      filename - a String object
      Returns:
      a DataSet object
      Throws:
      IOException - if any.
    • isColinear

      public static boolean isColinear(DataSet ds, boolean verbose)
      Check each pair of variables to see if correlation is 1. WARNING: calculates correlation matrix, memory heavy when there are lots of variables
      Parameters:
      ds - a DataSet object
      verbose - a boolean
      Returns:
      a boolean
    • graphToMatrix

      public static cern.colt.matrix.DoubleMatrix2D graphToMatrix(Graph graph, double undirectedWeight, double directedWeight)

      graphToMatrix.

      Parameters:
      graph - a Graph object
      undirectedWeight - a double
      directedWeight - a double
      Returns:
      a DoubleMatrix2D object
    • skeletonToMatrix

      public static cern.colt.matrix.DoubleMatrix2D skeletonToMatrix(Graph graph)

      skeletonToMatrix.

      Parameters:
      graph - a Graph object
      Returns:
      a DoubleMatrix2D object
    • graphToMatrix

      public static cern.colt.matrix.DoubleMatrix2D graphToMatrix(Graph graph)

      graphToMatrix.

      Parameters:
      graph - a Graph object
      Returns:
      a DoubleMatrix2D object
    • IndTestFromString

      public static IndependenceTest IndTestFromString(String name, DataSet data, double alpha)
      Returns independence tests by name located in edu.cmu.tetrad.search and edu.pitt.csb.mgm also supports shorthand for LRT ("lrt) and t-tests ("tlin" for prefer linear (fastest) or "tlog" for prefer logistic)
      Parameters:
      name - a String object
      data - a DataSet object
      alpha - a double
      Returns:
      a IndependenceTest object
    • main

      public static void main(String[] args)

      main.

      Parameters:
      args - an array of String objects