Search in sources :

Example 1 with SingleValue

use of edu.cmu.tetrad.util.dist.SingleValue in project tetrad by cmu-phil.

the class SemPm method initializeParams.

private void initializeParams() {
    // Note that a distinction between parameterizable and non-parameterizable nodes is being added
    // to accomodate time lag graphs. jdramsey 4/14/10.
    List<Parameter> parameters = new ArrayList<>();
    Set<Edge> edges = graph.getEdges();
    Collections.sort(new ArrayList<>(edges), new Comparator<Edge>() {

        public int compare(Edge o1, Edge o2) {
            int compareFirst = o1.getNode1().getName().compareTo(o2.getNode1().toString());
            int compareSecond = o1.getNode2().getName().compareTo(o2.getNode2().toString());
            if (compareFirst != 0) {
                return compareFirst;
            }
            if (compareSecond != 0) {
                return compareSecond;
            }
            return 0;
        }
    });
    // aren't error edges *and are into parameterizable node* (the last bit jdramsey 4/14/10).
    for (Edge edge : edges) {
        if (edge.getNode1() == edge.getNode2()) {
            continue;
        // throw new IllegalStateException("There should not be any" +
        // "edges from a node to itself in a SemGraph: " + edge);
        }
        if (!SemGraph.isErrorEdge(edge) && edge.getEndpoint1() == Endpoint.TAIL && edge.getEndpoint2() == Endpoint.ARROW) {
            if (!graph.isParameterizable(edge.getNode2())) {
                continue;
            }
            Parameter param = new Parameter(newBName(), ParamType.COEF, edge.getNode1(), edge.getNode2());
            param.setDistribution(new Split(0.5, 1.5));
            // param.setDistribution(new SplitDistributionSpecial(0.5, 1.5));
            // param.setDistribution(new UniformDistribution(-0.2, 0.2));
            // param.setDistribution(coefDistribution);
            parameters.add(param);
        }
    }
    // Add error variance freeParameters for exogenous nodes of all *parameterizable* nodes.
    for (Node node : getVariableNodes()) {
        if (!graph.isParameterizable(node)) {
            continue;
        }
        Parameter param = new Parameter(newTName(), ParamType.VAR, node, node);
        param.setDistribution(new Uniform(1.0, 3.0));
        parameters.add(param);
    }
    // connect exogenous nodes.)
    for (Edge edge : edges) {
        if (Edges.isBidirectedEdge(edge)) {
            Node node1 = edge.getNode1();
            Node node2 = edge.getNode2();
            // no...
            if (!graph.isParameterizable(node1) || !graph.isParameterizable(node2)) {
                continue;
            }
            node1 = getGraph().getVarNode(node1);
            node2 = getGraph().getVarNode(node2);
            Parameter param = new Parameter(newTName(), ParamType.COVAR, node1, node2);
            param.setDistribution(new SingleValue(0.2));
            parameters.add(param);
        }
    }
    // Add mean freeParameters for all parameterizable nodes.
    for (Node node : getVariableNodes()) {
        if (!graph.isParameterizable(node)) {
            continue;
        }
        Parameter mean = new Parameter(newMName(), ParamType.MEAN, node, node);
        mean.setDistribution(new Normal(0.0, 1.0));
        parameters.add(mean);
    }
    this.parameters = Collections.unmodifiableList(parameters);
}
Also used : SingleValue(edu.cmu.tetrad.util.dist.SingleValue) Uniform(edu.cmu.tetrad.util.dist.Uniform) Split(edu.cmu.tetrad.util.dist.Split) Normal(edu.cmu.tetrad.util.dist.Normal)

Aggregations

Normal (edu.cmu.tetrad.util.dist.Normal)1 SingleValue (edu.cmu.tetrad.util.dist.SingleValue)1 Split (edu.cmu.tetrad.util.dist.Split)1 Uniform (edu.cmu.tetrad.util.dist.Uniform)1