Exemple #1
0
    def __init__(self, df, depth = 3, significance = 0.05, verbose = False, priorKnowledge = None):
        tetradData = pycausal.loadDiscreteData(df)
        indTest = javabridge.JClassWrapper('edu.cmu.tetrad.search.IndTestChiSquare')(tetradData, significance)
        
        cpc = javabridge.JClassWrapper('edu.cmu.tetrad.search.Cpc')(indTest)
        cpc.setDepth(depth)
        cpc.setVerbose(verbose)
        
        if priorKnowledge is not None:    
            cpc.setKnowledge(priorKnowledge)
            
        tetradGraph = cpc.search()
        dags = javabridge.JClassWrapper('edu.cmu.tetrad.search.DagInPatternIterator')(tetradGraph)
        dagGraph = dags.next()
        dag = javabridge.JClassWrapper('edu.cmu.tetrad.graph.Dag')(dagGraph)

        pm = javabridge.JClassWrapper('edu.cmu.tetrad.bayes.BayesPm')(dag)
        est = javabridge.JClassWrapper('edu.cmu.tetrad.bayes.MlBayesEstimator')()
        im = est.estimate(pm, tetradData)

        self.nodes = pycausal.extractTetradGraphNodes(dag)
        self.edges = pycausal.extractTetradGraphEdges(dag)
        self.graph = pycausal.generatePyDotGraph(self.nodes,self.edges)
        self.dag = dag
        self.bayesPm = pm
        self.bayesIm = im
Exemple #2
0
    def __init__(self,
                 df,
                 penaltydiscount=4,
                 maxDegree=3,
                 faithfulnessAssumed=True,
                 numofthreads=2,
                 verbose=False,
                 priorKnowledge=None):

        tetradData = pycausal.loadContinuousData(df)

        score = javabridge.JClassWrapper('edu.cmu.tetrad.search.SemBicScore')(
            tetradData)
        score.setPenaltyDiscount(
            penaltydiscount
        )  # set to 2 if variable# <= 50 otherwise set it to 4

        fgs = javabridge.JClassWrapper('edu.cmu.tetrad.search.Fgs')(score)
        fgs.setMaxDegree(maxDegree)
        fgs.setNumPatternsToStore(0)
        fgs.setFaithfulnessAssumed(faithfulnessAssumed)
        fgs.setParallelism(numofthreads)
        fgs.setVerbose(verbose)

        if priorKnowledge is not None:
            fgs.setKnowledge(priorKnowledge)

        tetradGraph = fgs.search()

        self.nodes = pycausal.extractTetradGraphNodes(tetradGraph)
        self.edges = pycausal.extractTetradGraphEdges(tetradGraph)
        self.graph = pycausal.generatePyDotGraph(self.nodes, self.edges)
Exemple #3
0
    def __init__(self,
                 df,
                 depth=3,
                 significance=0.05,
                 verbose=False,
                 priorKnowledge=None):
        tetradData = pycausal.loadDiscreteData(df)
        indTest = javabridge.JClassWrapper(
            'edu.cmu.tetrad.search.IndTestChiSquare')(tetradData, significance)

        cpc = javabridge.JClassWrapper('edu.cmu.tetrad.search.Cpc')(indTest)
        cpc.setDepth(depth)
        cpc.setVerbose(verbose)

        if priorKnowledge is not None:
            cpc.setKnowledge(priorKnowledge)

        tetradGraph = cpc.search()
        dags = javabridge.JClassWrapper(
            'edu.cmu.tetrad.search.DagInPatternIterator')(tetradGraph)
        dagGraph = dags.next()
        dag = javabridge.JClassWrapper('edu.cmu.tetrad.graph.Dag')(dagGraph)

        pm = javabridge.JClassWrapper('edu.cmu.tetrad.bayes.BayesPm')(dag)
        est = javabridge.JClassWrapper(
            'edu.cmu.tetrad.bayes.MlBayesEstimator')()
        im = est.estimate(pm, tetradData)

        self.nodes = pycausal.extractTetradGraphNodes(dag)
        self.edges = pycausal.extractTetradGraphEdges(dag)
        self.graph = pycausal.generatePyDotGraph(self.nodes, self.edges)
        self.dag = dag
        self.bayesPm = pm
        self.bayesIm = im
Exemple #4
0
    def __init__(self,
                 df,
                 continuous=True,
                 depth=3,
                 aggressivelyPreventCycles=False,
                 significance=0.05,
                 verbose=False,
                 priorKnowledge=None):
        indTest = None

        if (continuous):
            tetradData = pycausal.loadContinuousData(df)
            indTest = javabridge.JClassWrapper(
                'edu.cmu.tetrad.search.IndTestFisherZ')(tetradData,
                                                        significance)
        else:
            tetradData = pycausal.loadDiscreteData(df)
            indTest = javabridge.JClassWrapper(
                'edu.cmu.tetrad.search.IndTestChiSquare')(tetradData,
                                                          significance)

        cpcstable = javabridge.JClassWrapper(
            'edu.cmu.tetrad.search.CpcStable')(indTest)
        cpcstable.setDepth(depth)
        cpcstable.setAggressivelyPreventCycles(aggressivelyPreventCycles)
        cpcstable.setVerbose(verbose)

        if priorKnowledge is not None:
            cpcstable.setKnowledge(priorKnowledge)

        tetradGraph = cpcstable.search()

        self.nodes = pycausal.extractTetradGraphNodes(tetradGraph)
        self.edges = pycausal.extractTetradGraphEdges(tetradGraph)
        self.graph = pycausal.generatePyDotGraph(self.nodes, self.edges)
Exemple #5
0
    def __init__(self,
                 df,
                 structurePrior=1.0,
                 samplePrior=1.0,
                 maxDegree=3,
                 faithfulnessAssumed=True,
                 numofthreads=2,
                 verbose=False,
                 priorKnowledge=None):

        tetradData = pycausal.loadDiscreteData(df)

        score = javabridge.JClassWrapper('edu.cmu.tetrad.search.BDeuScore')(
            tetradData)
        score.setStructurePrior(structurePrior)
        score.setSamplePrior(samplePrior)

        fgs = javabridge.JClassWrapper('edu.cmu.tetrad.search.Fgs')(score)
        fgs.setMaxDegree(maxDegree)
        fgs.setNumPatternsToStore(0)
        fgs.setFaithfulnessAssumed(faithfulnessAssumed)
        fgs.setParallelism(numofthreads)
        fgs.setVerbose(verbose)

        if priorKnowledge is not None:
            fgs.setKnowledge(priorKnowledge)

        tetradGraph = fgs.search()

        self.nodes = pycausal.extractTetradGraphNodes(tetradGraph)
        self.edges = pycausal.extractTetradGraphEdges(tetradGraph)
        self.graph = pycausal.generatePyDotGraph(self.nodes, self.edges)
Exemple #6
0
 def __init__(self, seed = None, numNodes = 10, numEdges = 10):
     if seed is not None:
         RandomUtil = javabridge.static_call("edu/cmu/tetrad/util/RandomUtil","getInstance","()Ledu/cmu/tetrad/util/RandomUtil;")
         javabridge.call(RandomUtil, "setSeed", "(J)V", seed)
     
     dag = None
     initEdges = -1
     while initEdges < numEdges:
         graph = javabridge.static_call("edu/cmu/tetrad/graph/GraphUtils","randomGraph","(IIIIIIZ)Ledu/cmu/tetrad/graph/Graph;",numNodes,0,numEdges,30,15,15,False)
         dag = javabridge.JClassWrapper("edu.cmu.tetrad.graph.Dag")(graph)
         initEdges = dag.getNumEdges()
         
     self.nodes = pycausal.extractTetradGraphNodes(dag)
     self.edges = pycausal.extractTetradGraphEdges(dag)
     self.graph = pycausal.generatePyDotGraph(self.nodes,self.edges)
     self.dag = dag
Exemple #7
0
    def __init__(self, seed=None, numNodes=10, numEdges=10):
        if seed is not None:
            RandomUtil = javabridge.static_call(
                "edu/cmu/tetrad/util/RandomUtil", "getInstance",
                "()Ledu/cmu/tetrad/util/RandomUtil;")
            javabridge.call(RandomUtil, "setSeed", "(J)V", seed)

        dag = None
        initEdges = -1
        while initEdges < numEdges:
            graph = javabridge.static_call(
                "edu/cmu/tetrad/graph/GraphUtils", "randomGraph",
                "(IIIIIIZ)Ledu/cmu/tetrad/graph/Graph;", numNodes, 0, numEdges,
                30, 15, 15, False)
            dag = javabridge.JClassWrapper("edu.cmu.tetrad.graph.Dag")(graph)
            initEdges = dag.getNumEdges()

        self.nodes = pycausal.extractTetradGraphNodes(dag)
        self.edges = pycausal.extractTetradGraphEdges(dag)
        self.graph = pycausal.generatePyDotGraph(self.nodes, self.edges)
        self.dag = dag
Exemple #8
0
    def __init__(self, df, penaltydiscount = 4, maxDegree = 3, faithfulnessAssumed = True, numofthreads = 2, verbose = False, priorKnowledge = None):
            
        tetradData = pycausal.loadContinuousData(df)

        score = javabridge.JClassWrapper('edu.cmu.tetrad.search.SemBicScore')(tetradData)
        score.setPenaltyDiscount(penaltydiscount) # set to 2 if variable# <= 50 otherwise set it to 4
        
        fges = javabridge.JClassWrapper('edu.cmu.tetrad.search.Fgs')(score)
        fges.setMaxDegree(maxDegree)
        fges.setNumPatternsToStore(0)
        fges.setFaithfulnessAssumed(faithfulnessAssumed)
        fges.setParallelism(numofthreads)
        fges.setVerbose(verbose)
        
        if priorKnowledge is not None:    
            fges.setKnowledge(priorKnowledge)
            
        tetradGraph = fges.search()
        
        self.nodes = pycausal.extractTetradGraphNodes(tetradGraph)
        self.edges = pycausal.extractTetradGraphEdges(tetradGraph)            
        self.graph = pycausal.generatePyDotGraph(self.nodes,self.edges)
Exemple #9
0
 def __init__(self, df, continuous = True, depth = 3, aggressivelyPreventCycles = False, significance = 0.05, verbose = False, priorKnowledge = None):
     indTest = None
 
     if(continuous):
         tetradData = pycausal.loadContinuousData(df)
         indTest = javabridge.JClassWrapper('edu.cmu.tetrad.search.IndTestFisherZ')(tetradData, significance)
     else:
         tetradData = pycausal.loadDiscreteData(df)
         indTest = javabridge.JClassWrapper('edu.cmu.tetrad.search.IndTestChiSquare')(tetradData, significance)
     
     cpcstable = javabridge.JClassWrapper('edu.cmu.tetrad.search.CpcStable')(indTest)
     cpcstable.setDepth(depth)
     cpcstable.setAggressivelyPreventCycles(aggressivelyPreventCycles)
     cpcstable.setVerbose(verbose)
     
     if priorKnowledge is not None:    
         cpcstable.setKnowledge(priorKnowledge)
         
     tetradGraph = cpcstable.search()
     
     self.nodes = pycausal.extractTetradGraphNodes(tetradGraph)
     self.edges = pycausal.extractTetradGraphEdges(tetradGraph)
     self.graph = pycausal.generatePyDotGraph(self.nodes,self.edges)
Exemple #10
0
 def __init__(self, df, structurePrior = 1.0, samplePrior = 1.0, maxDegree = 3, faithfulnessAssumed = True, numofthreads = 2, verbose = False, priorKnowledge = None):
     
     tetradData = pycausal.loadDiscreteData(df)
     
     score = javabridge.JClassWrapper('edu.cmu.tetrad.search.BDeuScore')(tetradData)
     score.setStructurePrior(structurePrior)
     score.setSamplePrior(samplePrior)
     
     fges = javabridge.JClassWrapper('edu.cmu.tetrad.search.Fgs')(score)
     fges.setMaxDegree(maxDegree)
     fges.setNumPatternsToStore(0)
     fges.setFaithfulnessAssumed(faithfulnessAssumed)
     fges.setParallelism(numofthreads)
     fges.setVerbose(verbose)
     
     if priorKnowledge is not None:    
         fges.setKnowledge(priorKnowledge)
         
     tetradGraph = fges.search()
     
     self.nodes = pycausal.extractTetradGraphNodes(tetradGraph)
     self.edges = pycausal.extractTetradGraphEdges(tetradGraph)            
     self.graph = pycausal.generatePyDotGraph(self.nodes,self.edges)