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;
}
}
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();
}
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();
}
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();
}
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();
}
Aggregations