public static Clusters convertToClusters(Graph clusterGraph,List<Node> measuredVariables){
  List<String> latents=new ArrayList<>();
  Clusters clusters=new Clusters();
  clusterGraph=GraphUtils.replaceNodes(clusterGraph,measuredVariables);
  for (  Node node : clusterGraph.getNodes()) {
    if (!measuredVariables.contains(node)) {
      latents.add(node.getName());
    }
  }
  Collections.sort(latents);
  for (int i=0; i < latents.size(); i++) {
    String name=latents.get(i);
    clusters.setClusterName(i,name);
    Node latent=clusterGraph.getNode(name);
    List<Node> measured=clusterGraph.getNodesOutTo(latent,Endpoint.ARROW);
    for (    Node _node : measured) {
      if (measuredVariables.contains(_node)) {
        clusters.addToCluster(i,_node.getName());
      }
    }
  }
  return clusters;
}

public static Clusters convertToClusters ( Graph clusterGraph , List < Node > measuredVariables ) { List < String > latents = new ArrayList < > ( ) ; Clusters clusters = new Clusters ( ) ; clusterGraph = GraphUtils . replaceNodes ( clusterGraph , measuredVariables ) ; for ( Node node : clusterGraph . getNodes ( ) ) { if ( ! measuredVariables . contains ( node ) ) { latents . add ( node . getName ( ) ) ; } } Collections . sort ( latents ) ; for ( int i = 0 ; i < latents . size ( ) ; i ++ ) { String name = latents . get ( i ) ; clusters . setClusterName ( i , name ) ; Node latent = clusterGraph . getNode ( name ) ; List < Node > measured = clusterGraph . getNodesOutTo ( latent , Endpoint . ARROW ) ; for ( Node _node : measured ) { if ( measuredVariables . contains ( _node ) ) { clusters . addToCluster ( i , _node . getName ( ) ) ; } } } return clusters ; }
converts a disconnected multiple indicator model into a set of clusters . assumes the given graph contains a number of latents li , i = 0 , . . . , n - 1 , for each of which there is a list of indicators wj , j = 0 , . . . , m_i - 1 , such that , li - - > wj . returns a clusters object mapping i to wj . the name for cluster i is set to li .
