Search in sources :

Example 41 with SemIm

use of edu.cmu.tetrad.sem.SemIm in project tetrad by cmu-phil.

the class PurifyScoreBased method scoreCandidate.

private double scoreCandidate() {
    SemGraph graph = updatedGraph();
    initializeGaussianEM(graph);
    SemPm semPm = new SemPm(graph);
    SemIm semIm = new SemIm(semPm, covarianceMatrix);
    gaussianMaximization(semIm);
    try {
        System.out.println("trunk ll = " + semIm.getTruncLL());
        return -semIm.getTruncLL() - 0.5 * semIm.getNumFreeParams() * Math.log(covarianceMatrix.getSampleSize());
    } catch (IllegalArgumentException e) {
        return -Double.MAX_VALUE;
    }
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm)

Example 42 with SemIm

use of edu.cmu.tetrad.sem.SemIm in project tetrad by cmu-phil.

the class PcStableLocalSearchEditor method reportIfContinuous.

private String reportIfContinuous(Graph dag, DataSet dataSet) {
    SemPm semPm = new SemPm(dag);
    SemEstimator estimator = new SemEstimator(dataSet, semPm);
    estimator.estimate();
    SemIm semIm = estimator.getEstimatedSem();
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(4);
    StringBuilder buf = new StringBuilder();
    buf.append("\nDegrees of Freedom = ").append(semPm.getDof()).append("Chi-Square = ").append(nf.format(semIm.getChiSquare())).append("\nP Value = ").append(nf.format(semIm.getPValue())).append("\nBIC Score = ").append(nf.format(semIm.getBicScore()));
    buf.append("\n\nThe above chi square test assumes that the maximum " + "likelihood function over the measured variables has been " + "maximized. Under that assumption, the null hypothesis for " + "the test is that the population covariance matrix over all " + "of the measured variables is equal to the estimated covariance " + "matrix over all of the measured variables written as a function " + "of the free model parameters--that is, the unfixed parameters " + "for each directed edge (the linear coefficient for that edge), " + "each exogenous variable (the variance for the error term for " + "that variable), and each bidirected edge (the covariance for " + "the exogenous variables it connects).  The model is explained " + "in Bollen, Structural Equations with Latent Variable, 110. ");
    return buf.toString();
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm) NumberFormat(java.text.NumberFormat)

Example 43 with SemIm

use of edu.cmu.tetrad.sem.SemIm in project tetrad by cmu-phil.

the class PcGesSearchEditor method reportIfCovMatrix.

private String reportIfCovMatrix(Graph dag, ICovarianceMatrix dataSet) {
    SemPm semPm = new SemPm(dag);
    SemEstimator estimator = new SemEstimator(dataSet, semPm);
    estimator.estimate();
    SemIm semIm = estimator.getEstimatedSem();
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(4);
    StringBuilder buf = new StringBuilder();
    buf.append("\nDegrees of Freedom = ").append(semPm.getDof()).append(" Chi-Square = ").append(nf.format(semIm.getChiSquare())).append("\nP Value = ").append(nf.format(semIm.getPValue())).append("\nBIC Score = ").append(nf.format(semIm.getBicScore()));
    buf.append("\n\nThe above chi square test assumes that the maximum " + "likelihood function over the measured variables has been " + "maximized. Under that assumption, the null hypothesis for " + "the test is that the population covariance matrix over all " + "of the measured variables is equal to the estimated covariance " + "matrix over all of the measured variables written as a function " + "of the free model parameters--that is, the unfixed parameters " + "for each directed edge (the linear coefficient for that edge), " + "each exogenous variable (the variance for the error term for " + "that variable), and each bidirected edge (the covariance for " + "the exogenous variables it connects).  The model is explained " + "in Bollen, Structural Equations with Latent Variable, 110. ");
    return buf.toString();
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm) NumberFormat(java.text.NumberFormat)

Example 44 with SemIm

use of edu.cmu.tetrad.sem.SemIm in project tetrad by cmu-phil.

the class PcGesSearchEditor method reportIfContinuous.

private String reportIfContinuous(Graph dag, DataSet dataSet) {
    SemPm semPm = new SemPm(dag);
    SemEstimator estimator = new SemEstimator(dataSet, semPm);
    estimator.estimate();
    SemIm semIm = estimator.getEstimatedSem();
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(4);
    StringBuilder buf = new StringBuilder();
    buf.append("\nDegrees of Freedom = ").append(semPm.getDof()).append(" Chi-Square = ").append(nf.format(semIm.getChiSquare())).append("\nP Value = ").append(nf.format(semIm.getPValue())).append("\nBIC Score = ").append(nf.format(semIm.getBicScore()));
    buf.append("\n\nThe above chi square test assumes that the maximum " + "likelihood function over the measured variables has been " + "maximized. Under that assumption, the null hypothesis for " + "the test is that the population covariance matrix over all " + "of the measured variables is equal to the estimated covariance " + "matrix over all of the measured variables written as a function " + "of the free model parameters--that is, the unfixed parameters " + "for each directed edge (the linear coefficient for that edge), " + "each exogenous variable (the variance for the error term for " + "that variable), and each bidirected edge (the covariance for " + "the exogenous variables it connects).  The model is explained " + "in Bollen, Structural Equations with Latent Variable, 110. ");
    return buf.toString();
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm) NumberFormat(java.text.NumberFormat)

Example 45 with SemIm

use of edu.cmu.tetrad.sem.SemIm in project tetrad by cmu-phil.

the class SemThenDiscretize method simulate.

private DataSet simulate(Graph graph, Parameters parameters) {
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet continuousData = im.simulateData(parameters.getInt("sampleSize"), false);
    if (this.shuffledOrder == null) {
        List<Node> shuffledNodes = new ArrayList<>(continuousData.getVariables());
        Collections.shuffle(shuffledNodes);
        this.shuffledOrder = shuffledNodes;
    }
    Discretizer discretizer = new Discretizer(continuousData);
    for (int i = 0; i < shuffledOrder.size() * parameters.getDouble("percentDiscrete") * 0.01; i++) {
        discretizer.equalIntervals(continuousData.getVariable(shuffledOrder.get(i).getName()), parameters.getInt("numCategories"));
    }
    return discretizer.discretize();
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) Discretizer(edu.cmu.tetrad.data.Discretizer)

Aggregations

SemIm (edu.cmu.tetrad.sem.SemIm)81 SemPm (edu.cmu.tetrad.sem.SemPm)71 Test (org.junit.Test)46 DataSet (edu.cmu.tetrad.data.DataSet)28 ArrayList (java.util.ArrayList)28 Graph (edu.cmu.tetrad.graph.Graph)26 Node (edu.cmu.tetrad.graph.Node)19 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)16 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)16 SemEstimator (edu.cmu.tetrad.sem.SemEstimator)15 Dag (edu.cmu.tetrad.graph.Dag)10 DMSearch (edu.cmu.tetrad.search.DMSearch)9 StandardizedSemIm (edu.cmu.tetrad.sem.StandardizedSemIm)9 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)7 NumberFormat (java.text.NumberFormat)7 GraphNode (edu.cmu.tetrad.graph.GraphNode)5 IndependenceTest (edu.cmu.tetrad.search.IndependenceTest)4 DecimalFormat (java.text.DecimalFormat)4 List (java.util.List)4 CovarianceMatrix (edu.cmu.tetrad.data.CovarianceMatrix)3