/** * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model. */ private double localSemScore(int i, int[] parents) { try { ICovarianceMatrix cov = getCovMatrix(); double varianceY = cov.getValue(i, i); double residualVariance = varianceY; int n = sampleSize(); int p = parents.length; int k = (p * (p + 1)) / 2 + p; // int k = (p + 1) * (p + 1); // int k = p + 1; TetradMatrix covxx = cov.getSelection(parents, parents); TetradMatrix covxxInv = covxx.inverse(); TetradVector covxy = cov.getSelection(parents, new int[] {i}).getColumn(0); TetradVector b = covxxInv.times(covxy); residualVariance -= covxy.dotProduct(b); if (residualVariance <= 0 && verbose) { out.println( "Nonpositive residual varianceY: resVar / varianceY = " + (residualVariance / varianceY)); return Double.NaN; } double c = getPenaltyDiscount(); // return -n * log(residualVariance) - 2 * k; //AIC return -n * Math.log(residualVariance) - c * k * Math.log(n); // return -n * log(residualVariance) - c * k * (log(n) - log(2 * PI)); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); // throwMinimalLinearDependentSet(parents, cov); } }
/** Adds the given componet to the given layer. */ public void addEditorWindow(EditorWindowIndirectRef windowRef) { final JInternalFrame window = (JInternalFrame) windowRef; Dimension desktopSize = desktopPane.getSize(); Dimension preferredSize = window.getPreferredSize(); int x = desktopSize.width / 2 - preferredSize.width / 2; int y = desktopSize.height / 2 - preferredSize.height / 2; window.setBounds(x, y, preferredSize.width, preferredSize.height); // This line sometimes hangs, so I'm putting it in a watch process // so it can be stopped by the user. Not ideal. // Window owner = (Window) getTopLevelAncestor(); // // new WatchedProcess(owner) { // public void watch() { getDesktopPane().add(window); window.setLayer(100); window.moveToFront(); try { window.setVisible(true); } catch (Exception e) { if (e instanceof ClassCastException || e instanceof NullPointerException) { // skip. These is being caused apparently the workbench // having labeled nodes and edges. Can't find a // workaround--probably a Java bug. jdramsey } else { e.printStackTrace(); } } // prevents the component from being hidden. // window.addComponentListener(new PositionListener()); // } // }; }