/**
   * Constructs a wrapper for the given DataWrapper. The DatWrapper must contain a DataSet that is
   * either a DataSet or a DataSet or a DataList containing either a DataSet or a DataSet as its
   * selected model.
   *
   * @param knowledgeBoxModel
   */
  public AbstractAlgorithmRunner(
      DataWrapper dataWrapper,
      Parameters params,
      KnowledgeBoxModel knowledgeBoxModel,
      IndependenceFactsModel facts) {
    if (dataWrapper == null) {
      throw new NullPointerException();
    }
    if (params == null) {
      throw new NullPointerException();
    }

    this.params = params;
    this.sourceGraph = dataWrapper.getSourceGraph();

    DataModel dataSource = getSelectedDataModel(dataWrapper);

    this.dataWrapper = dataWrapper;

    // temporary workaround to get the knowledge box to coexist with the dataWrapper's knowledge
    if (knowledgeBoxModel == null) {
      getParams().set("knowledge", dataWrapper.getKnowledge());
    } else {
      getParams().set("knowledge", knowledgeBoxModel.getKnowledge());
    }

    getParams().set("independenceFacts", facts.getFacts());
    List names = dataSource.getVariableNames();
    transferVarNamesToParams(names);
  }
Esempio n. 2
0
  public CopyAllDatasetsWrapper(DataWrapper wrapper) {
    LogDataUtils.logDataModelList(
        "Parent data in which constant columns have been removed.", getDataModelList());

    DataModelList inList = wrapper.getDataModelList();
    DataModelList outList = new DataModelList();

    for (DataModel model : inList) {
      if (!(model instanceof DataSet)) {
        throw new IllegalArgumentException("Not a data set: " + model.getName());
      }

      this.setDataModel(model);
      outList.add(model);
    }

    setDataModel(outList);
    setSourceGraph(wrapper.getSourceGraph());
  }
  public AbstractAlgorithmRunner(
      IndependenceFactsModel model, Parameters params, KnowledgeBoxModel knowledgeBoxModel) {
    if (model == null) {
      throw new NullPointerException();
    }
    if (params == null) {
      throw new NullPointerException();
    }

    this.params = params;

    DataModel dataSource = model.getFacts();

    if (knowledgeBoxModel != null) {
      getParams().set("knowledge", knowledgeBoxModel.getKnowledge());
    }

    List names = dataSource.getVariableNames();
    transferVarNamesToParams(names);
    this.dataModel = dataSource;
  }
  public AbstractAlgorithmRunner(DataWrapper dataWrapper, Parameters params) {
    if (dataWrapper == null) {
      throw new NullPointerException();
    }
    if (params == null) {
      throw new NullPointerException();
    }

    this.params = params;
    this.sourceGraph = dataWrapper.getSourceGraph();

    DataModel dataSource = getSelectedDataModel(dataWrapper);

    //        if (dataSource instanceof ColtDataSet) {
    //            dataSource = new ColtDataSet((ColtDataSet) dataSource);
    //        }

    this.dataWrapper = dataWrapper;

    List names = dataSource.getVariableNames();
    transferVarNamesToParams(names);
  }
Esempio n. 5
0
  public void setup() {
    this.varNames = params.getVarNames();

    for (Object parentModel : parentModels) {
      if (parentModel instanceof DataWrapper) {
        DataWrapper wrapper = (DataWrapper) parentModel;
        DataModel dataModel = wrapper.getSelectedDataModel();
        new IndTestChooser().adjustIndTestParams(dataModel, params);
        break;
      } else if (parentModel instanceof GraphWrapper) {
        GraphWrapper wrapper = (GraphWrapper) parentModel;
        new IndTestChooser().adjustIndTestParams(wrapper.getGraph(), params);
        break;
      } else if (parentModel instanceof DagWrapper) {
        DagWrapper wrapper = (DagWrapper) parentModel;
        new IndTestChooser().adjustIndTestParams(wrapper.getGraph(), params);
        break;
      } else if (parentModel instanceof SemGraphWrapper) {
        SemGraphWrapper wrapper = (SemGraphWrapper) parentModel;
        new IndTestChooser().adjustIndTestParams(wrapper.getGraph(), params);
        break;
      }
    }

    DataModel dataModel1 = null;
    Graph graph = null;

    for (Object parentModel1 : parentModels) {
      if (parentModel1 instanceof DataWrapper) {
        DataWrapper dataWrapper = (DataWrapper) parentModel1;
        dataModel1 = dataWrapper.getSelectedDataModel();
      }

      if (parentModel1 instanceof GraphWrapper) {
        GraphWrapper graphWrapper = (GraphWrapper) parentModel1;
        graph = graphWrapper.getGraph();
      }

      if (parentModel1 instanceof DagWrapper) {
        DagWrapper dagWrapper = (DagWrapper) parentModel1;
        graph = dagWrapper.getDag();
      }

      if (parentModel1 instanceof SemGraphWrapper) {
        SemGraphWrapper semGraphWrapper = (SemGraphWrapper) parentModel1;
        graph = semGraphWrapper.getGraph();
      }
    }

    if (dataModel1 != null) {
      varNames = new ArrayList(dataModel1.getVariableNames());
    } else if (graph != null) {
      Iterator it = graph.getNodes().iterator();
      varNames = new ArrayList();

      Node temp;

      while (it.hasNext()) {
        temp = (Node) it.next();

        if (temp.getNodeType() == NodeType.MEASURED) {
          varNames.add(temp.getName());
        }
      }
    } else {
      throw new NullPointerException(
          "Null model (no graph or data model " + "passed to the search).");
    }

    params.setVarNames(varNames);
    JButton knowledgeButton = new JButton("Edit");

    IntTextField depthField = new IntTextField(params.getIndTestParams().getDepth(), 4);
    depthField.setFilter(
        new IntTextField.Filter() {
          public int filter(int value, int oldValue) {
            try {
              params.getIndTestParams().setDepth(value);
              Preferences.userRoot().putInt("depth", value);
              return value;
            } catch (Exception e) {
              return oldValue;
            }
          }
        });

    double alpha = params.getIndTestParams().getAlpha();

    if (!Double.isNaN(alpha)) {
      alphaField = new DoubleTextField(alpha, 4, NumberFormatUtil.getInstance().getNumberFormat());
      alphaField.setFilter(
          new DoubleTextField.Filter() {
            public double filter(double value, double oldValue) {
              try {
                params.getIndTestParams().setAlpha(value);
                Preferences.userRoot().putDouble("alpha", value);
                return value;
              } catch (Exception e) {
                return oldValue;
              }
            }
          });
    }

    setBorder(new MatteBorder(10, 10, 10, 10, super.getBackground()));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    Box b2 = Box.createHorizontalBox();
    b2.add(new JLabel("Knowledge:"));
    b2.add(Box.createGlue());
    b2.add(knowledgeButton);
    add(b2);
    add(Box.createVerticalStrut(10));

    if (!Double.isNaN(alpha)) {
      Box b0 = Box.createHorizontalBox();
      b0.add(new JLabel("Alpha Value:"));
      b0.add(Box.createGlue());
      b0.add(alphaField);
      add(b0);
      add(Box.createVerticalStrut(10));
    }

    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Search Depth:"));
    b1.add(Box.createGlue());
    b1.add(depthField);
    add(b1);
    add(Box.createVerticalStrut(10));

    knowledgeButton.addActionListener(
        new ActionListener() {
          public final void actionPerformed(ActionEvent e) {
            openKnowledgeEditor();
          }
        });
  }
Esempio n. 6
0
  /**
   * Executes the algorithm, producing (at least) a result workbench. Must be implemented in the
   * extending class.
   */
  public void execute() {
    Object source = dataWrapper.getSelectedDataModel();

    DataModel dataModel = (DataModel) source;

    IKnowledge knowledge = params2.getKnowledge();

    if (initialGraph == null) {
      initialGraph = new EdgeListGraph(dataModel.getVariables());
    }

    Graph graph2 = new EdgeListGraph(initialGraph);
    graph2 = GraphUtils.replaceNodes(graph2, dataModel.getVariables());

    Bff search;

    if (dataModel instanceof DataSet) {
      DataSet dataSet = (DataSet) dataModel;

      if (getAlgorithmType() == AlgorithmType.BEAM) {
        search = new BffBeam(graph2, dataSet, knowledge);
      } else if (getAlgorithmType() == AlgorithmType.GES) {
        search = new BffGes(graph2, dataSet);
        search.setKnowledge(knowledge);
      } else {
        throw new IllegalStateException();
      }
    } else if (dataModel instanceof CovarianceMatrix) {
      CovarianceMatrix covarianceMatrix = (CovarianceMatrix) dataModel;

      if (getAlgorithmType() == AlgorithmType.BEAM) {
        search = new BffBeam(graph2, covarianceMatrix, knowledge);
      } else if (getAlgorithmType() == AlgorithmType.GES) {
        throw new IllegalArgumentException(
            "GES method requires a dataset; a covariance matrix was provided.");
        //                search = new BffGes(graph2, covarianceMatrix);
        //                search.setKnowledge(knowledge);
      } else {
        throw new IllegalStateException();
      }
    } else {
      throw new IllegalStateException();
    }

    PcIndTestParams indTestParams = (PcIndTestParams) getParams().getIndTestParams();

    search.setAlpha(indTestParams.getAlpha());
    search.setBeamWidth(indTestParams.getBeamWidth());
    search.setHighPValueAlpha(indTestParams.getZeroEdgeP());
    this.graph = search.search();

    //        this.graph = search.getNewSemIm().getSemPm().getGraph();

    setOriginalSemIm(search.getOriginalSemIm());
    this.newSemIm = search.getNewSemIm();
    fireGraphChange(graph);

    if (getSourceGraph() != null) {
      GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
    } else if (knowledge.isDefaultToKnowledgeLayout()) {
      SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
    } else {
      GraphUtils.circleLayout(graph, 200, 200, 150);
    }

    setResultGraph(SearchGraphUtils.patternForDag(graph, knowledge));
  }