Class CompareTwoGraphs

java.lang.Object
edu.cmu.tetrad.algcomparison.CompareTwoGraphs

public class CompareTwoGraphs extends Object
Gives the comparison of a target graph to a reference graph that is implemented in the interface. Three methods are given, one to return the edgewise comparison, one to return the stats list comparison, and one to return the misclassification comparison. Each returns a String, which can be printed.
Version:
$Id: $Id
Author:
josephramsey
  • Method Details

    • getEdgewiseComparisonString

      @NotNull public static @NotNull String getEdgewiseComparisonString(Graph trueGraph, Graph targetGraph)
      Returns an edgewise comparison of two graphs. This says, edge by edge, what the differences and similarities are between the two graphs.
      Parameters:
      trueGraph - The true graph.
      targetGraph - The target graph.
      Returns:
      The comparison string.
    • getStatsListTable

      public static String getStatsListTable(Graph trueGraph, Graph targetGraph)
      Returns a string representing a table of statistics that can be printed.
      Parameters:
      trueGraph - The true graph.
      targetGraph - The target graph.
      Returns:
      The comparison string.
    • getStatsListTable

      public static String getStatsListTable(Graph trueGraph, Graph targetGraph, DataModel dataModel, long elapsedTime)
      Returns a string representing a table of statistics that can be printed.
      Parameters:
      trueGraph - The true graph.
      targetGraph - The target graph.
      dataModel - The data model; some statistics (like BIC) may use this.
      elapsedTime - a long
      Returns:
      The comparison string.
    • getStatsListTable

      public static String getStatsListTable(Graph trueDag, Graph trueGraph, Graph targetGraph, DataModel dataModel, long elapsedTime)
      As getStatsListTable(Graph, Graph, DataModel, long), but with the true DAG given separately from the comparison graph; see getStatsListTable(Graph, Graph, Graph, DataModel, long, List).
      Parameters:
      trueDag - The true DAG, including latents, or null if none is available.
      trueGraph - The comparison graph (the true DAG, or its CPDAG or PAG).
      targetGraph - The target graph.
      dataModel - The data model; some statistics (like BIC) may use this. May be null.
      elapsedTime - Elapsed wall time in milliseconds; < 0 to omit the Elapsed row.
      Returns:
      The comparison string.
    • getStatsListTable

      public static String getStatsListTable(Graph trueGraph, Graph targetGraph, DataModel dataModel, long elapsedTime, List<Statistic> statistics)
      As getStatsListTable(Graph, Graph, DataModel, long), but with the statistics to show given explicitly, in display order.
      Parameters:
      trueGraph - The true graph.
      targetGraph - The target graph.
      dataModel - The data model; some statistics (like BIC) may use this. May be null.
      elapsedTime - Elapsed wall time in milliseconds; < 0 to omit the Elapsed row.
      statistics - The statistics to show.
      Returns:
      The comparison string.
    • getStatsListTable

      public static String getStatsListTable(Graph trueDag, Graph trueGraph, Graph targetGraph, DataModel dataModel, long elapsedTime, List<Statistic> statistics)
      As getStatsListTable(Graph, Graph, DataModel, long, List), but with the true DAG given separately from the comparison graph. Statistics that ask DAG-level questions (ancestry, latent confounding) read them off trueDag; statistics that compare adjacencies and endpoints use trueGraph, which may be the CPDAG or PAG of trueDag. The overloads without a trueDag pass trueGraph for both.
      Parameters:
      trueDag - The true DAG, including latents, or null if none is available.
      trueGraph - The comparison graph (the true DAG, or its CPDAG or PAG).
      targetGraph - The target graph.
      dataModel - The data model; some statistics (like BIC) may use this. May be null.
      elapsedTime - Elapsed wall time in milliseconds; < 0 to omit the Elapsed row.
      statistics - The statistics to show.
      Returns:
      The comparison string.
    • getStatsListTable

      public static String getStatsListTable(Graph trueGraph, List<Graph> targetGraphs, List<String> targetNames, DataModel dataModel, List<Long> elapsedTimes)
      Returns a string representing a table of statistics for several target graphs against a single true graph, one column per target. Statistics that fail (or return NaN) for a target are shown as "-" in that column; rows where every target fails are omitted. This is the multi-target generalization of getStatsListTable(Graph, Graph, DataModel, long), used by the GUI comparison boxes when more than one graph source is attached, and usable from py-tetrad as well.
      Parameters:
      trueGraph - The true graph.
      targetGraphs - The target graphs, in display order.
      targetNames - Column headers for the targets, same length as targetGraphs.
      dataModel - The data model; some statistics (like BIC) may use this. May be null.
      elapsedTimes - Elapsed wall times in milliseconds, one per target, or null; entries < 0 print as "-".
      Returns:
      The comparison table string.
    • getStatsListTable

      public static String getStatsListTable(Graph trueDag, Graph trueGraph, List<Graph> targetGraphs, List<String> targetNames, DataModel dataModel, List<Long> elapsedTimes)
      As getStatsListTable(Graph, List, List, DataModel, List), but with the true DAG given separately from the comparison graph; see getStatsListTable(Graph, Graph, Graph, DataModel, long, List).
      Parameters:
      trueDag - The true DAG, including latents, or null if none is available.
      trueGraph - The comparison graph (the true DAG, or its CPDAG or PAG).
      targetGraphs - The target graphs, in display order.
      targetNames - Column headers for the targets, same length as targetGraphs.
      dataModel - The data model; some statistics (like BIC) may use this. May be null.
      elapsedTimes - Elapsed wall times in milliseconds, one per target, or null; entries < 0 print as "-".
      Returns:
      The comparison table string.
    • getStatsListTable

      public static String getStatsListTable(Graph trueGraph, List<Graph> targetGraphs, List<String> targetNames, DataModel dataModel, List<Long> elapsedTimes, List<Statistic> statistics)
      As getStatsListTable(Graph, List, List, DataModel, List), but with the statistics to show given explicitly, in display order.
      Parameters:
      trueGraph - The true graph.
      targetGraphs - The target graphs, in display order.
      targetNames - Column headers for the targets, same length as targetGraphs.
      dataModel - The data model; some statistics (like BIC) may use this. May be null.
      elapsedTimes - Elapsed wall times in milliseconds, one per target, or null; entries < 0 print as "-".
      statistics - The statistics to show.
      Returns:
      The comparison table string.
    • getStatsListTable

      public static String getStatsListTable(Graph trueDag, Graph trueGraph, List<Graph> targetGraphs, List<String> targetNames, DataModel dataModel, List<Long> elapsedTimes, List<Statistic> statistics)
      As getStatsListTable(Graph, List, List, DataModel, List, List), but with the true DAG given separately from the comparison graph; see getStatsListTable(Graph, Graph, Graph, DataModel, long, List) for the division of labor between the two.
      Parameters:
      trueDag - The true DAG, including latents, or null if none is available.
      trueGraph - The comparison graph (the true DAG, or its CPDAG or PAG).
      targetGraphs - The target graphs, in display order.
      targetNames - Column headers for the targets, same length as targetGraphs.
      dataModel - The data model; some statistics (like BIC) may use this. May be null.
      elapsedTimes - Elapsed wall times in milliseconds, one per target, or null; entries < 0 print as "-".
      statistics - The statistics to show.
      Returns:
      The comparison table string.
    • defaultStatistics

      public static List<Statistic> defaultStatistics()
      Returns the statistics shown by default in the stats list comparison, in display order. The Elapsed (wall time) row is not a statistic; the table methods append it separately when an elapsed time is supplied.
      Returns:
      a new list of the default statistics.
    • curatedStatistics

      public static List<Statistic> curatedStatistics()
      Returns a broader, curated set of statistics suitable for the stats list comparison, with duplicate abbreviations removed. This includes some statistics (e.g., SHD compared to the CPDAG) that need constructor arguments and so cannot be found by a reflection scan for no-argument constructors; choosers should offer these in addition to the defaults.
      Returns:
      a new list of the curated statistics.
    • getMisclassificationTable

      @NotNull public static @NotNull String getMisclassificationTable(Graph trueGraph, Graph targetGraph)
      Returns a misclassification comparison of two graphs. This includes both an edge misclassiifcation matrix as well as an endpoint misclassification matrix.
      Parameters:
      trueGraph - The true graph.
      targetGraph - The target graph.
      Returns:
      The comparison string.