Пример #1
0
  /**
   * Constructs the wrapper given some data and the params.
   *
   * @param data
   * @param params
   */
  public SplitCasesWrapper(DataWrapper data, SplitCasesParams params) {
    if (data == null) {
      throw new NullPointerException("The given data must not be null");
    }
    if (params == null) {
      throw new NullPointerException("The given parameters must not be null");
    }
    DataSet originalData = (DataSet) data.getSelectedDataModel();
    DataModel model = createSplits(originalData, params);
    this.setDataModel(model);
    this.setSourceGraph(data.getSourceGraph());

    LogDataUtils.logDataModelList("One split of the parent data.", getDataModelList());
  }
  public RegressionInterpolatorWrapper(DataWrapper data) {
    if (data == null) {
      throw new NullPointerException("The givan data must not be null");
    }
    DataModel model = data.getSelectedDataModel();
    if ((!(model instanceof DataSet))) {
      throw new IllegalArgumentException("Data must be tabular");
    }
    DataFilter interpolator = new RegressionInterpolator();
    this.setDataModel(interpolator.filter((DataSet) model));
    this.setSourceGraph(data.getSourceGraph());

    LogDataUtils.logDataModelList(
        "Parent data in which missing values have been replaced by regression predictions.",
        getDataModelList());
  }
Пример #3
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());
  }
Пример #4
0
  /**
   * Splits the given data set by collinear columns.
   *
   * @param wrapper
   */
  public SimulateFromCovWrapper(DataWrapper wrapper) {
    if (wrapper == null) {
      throw new NullPointerException("The given data must not be null");
    }

    DataModel model = wrapper.getSelectedDataModel();

    if (model instanceof ICovarianceMatrix) {
      CovarianceMatrix covarianceMatrix = new CovarianceMatrix((CovarianceMatrix) model);

      DataSet dataSet = DataUtils.choleskySimulation(covarianceMatrix);

      setDataModel(dataSet);
      setSourceGraph(wrapper.getSourceGraph());
    } else {
      throw new IllegalArgumentException("Must be a dataset or a covariance  matrix");
    }

    LogDataUtils.logDataModelList(
        "Conversion of data to covariance matrix form.", getDataModelList());
  }
Пример #5
0
 /**
  * Generates a simple exemplar of this class to test serialization.
  *
  * @see edu.cmu.TestSerialization
  * @see edu.cmu.tetradapp.util.TetradSerializableUtils
  */
 public static CopyAllDatasetsWrapper serializableInstance() {
   return new CopyAllDatasetsWrapper(DataWrapper.serializableInstance());
 }
Пример #6
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();
          }
        });
  }
Пример #7
0
  /** Builds the panel. */
  public void setup() {
    DataModelList dataModelList = null;

    for (Object parentModel : parentModels) {
      if (parentModel instanceof DataWrapper) {
        DataWrapper dataWrapper = (DataWrapper) parentModel;
        dataModelList = dataWrapper.getDataModelList();
      }
    }

    if (dataModelList == null) {
      throw new NullPointerException("Null data model list.");
    }

    for (DataModel model : dataModelList) {
      if (!(model instanceof DataSet)) {
        JOptionPane.showMessageDialog(
            JOptionUtils.centeringComp(),
            "For the shift search, all of the data in the data box must be in the form of data sets.");
        return;
      }
    }

    final List<DataSet> dataSets = new ArrayList<DataSet>();

    for (Object aDataModelList : dataModelList) {
      dataSets.add((DataSet) aDataModelList);
    }

    SpinnerModel maxVarsModel =
        new SpinnerNumberModel(
            Preferences.userRoot().getInt("shiftSearchMaxNumShifts", 3), 1, 50, 1);
    JSpinner maxVarsSpinner = new JSpinner(maxVarsModel);
    maxVarsSpinner.setMaximumSize(maxVarsSpinner.getPreferredSize());

    maxVarsSpinner.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            SpinnerNumberModel model = (SpinnerNumberModel) spinner.getModel();
            int value = (Integer) model.getValue();
            Preferences.userRoot().putInt("shiftSearchMaxNumShifts", value);
          }
        });

    SpinnerModel maxShiftModel =
        new SpinnerNumberModel(Preferences.userRoot().getInt("shiftSearchMaxShift", 2), 1, 50, 1);
    JSpinner maxShiftSpinner = new JSpinner(maxShiftModel);
    maxShiftSpinner.setMaximumSize(maxShiftSpinner.getPreferredSize());

    maxShiftSpinner.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            SpinnerNumberModel model = (SpinnerNumberModel) spinner.getModel();
            int value = (Integer) model.getValue();
            Preferences.userRoot().putInt("shiftSearchMaxShift", value);
          }
        });

    JButton searchButton = new JButton("Search");
    final JButton stopButton = new JButton("Stop");

    final JTextArea textArea = new JTextArea();
    JScrollPane textScroll = new JScrollPane(textArea);
    textScroll.setPreferredSize(new Dimension(500, 200));

    searchButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            final Thread thread =
                new Thread() {
                  public void run() {
                    textArea.setText("");
                    doShiftSearch(dataSets, textArea);
                  }
                };

            thread.start();
          }
        });

    stopButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            if (search != null) {
              search.stop();
            }
          }
        });

    JComboBox directionBox = new JComboBox(new String[] {"forward", "backward"});
    directionBox.setSelectedItem(params.isForwardSearch() ? "forward" : "backward");
    directionBox.setMaximumSize(directionBox.getPreferredSize());

    directionBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            JComboBox source = (JComboBox) actionEvent.getSource();
            String selected = (String) source.getSelectedItem();
            params.setForwardSearch("forward".equals(selected));
          }
        });

    Box b1 = Box.createVerticalBox();

    Box b2 = Box.createHorizontalBox();
    b2.add(new JLabel("Maximum number of variables in shift set is: "));
    b2.add(maxVarsSpinner);
    b2.add(Box.createHorizontalGlue());
    b1.add(b2);

    Box b3 = Box.createHorizontalBox();
    b3.add(new JLabel("Maximum "));
    b3.add(directionBox);
    b3.add(new JLabel(" shift: "));
    b3.add(maxShiftSpinner);
    b3.add(Box.createHorizontalGlue());
    b1.add(b3);

    Box b4 = Box.createHorizontalBox();
    b4.add(new JLabel("Output:"));
    b4.add(Box.createHorizontalGlue());
    b1.add(b4);

    Box b5 = Box.createHorizontalBox();
    b5.add(textScroll);
    b1.add(b5);

    Box b6 = Box.createHorizontalBox();
    b6.add(searchButton);
    b6.add(stopButton);
    b1.add(b6);

    final Box a1 = Box.createVerticalBox();

    Box a2 = Box.createHorizontalBox();
    a2.add(new JLabel("Specify the shift (positive or negative) for each variable:"));
    a2.add(Box.createHorizontalGlue());
    a1.add(a2);

    a1.add(Box.createVerticalStrut(20));

    setUpA1(dataSets, a1);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Shift", new JScrollPane(a1));
    tabbedPane.addTab("Search", new JScrollPane(b1));

    add(tabbedPane, BorderLayout.CENTER);

    tabbedPane.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent changeEvent) {
            System.out.println("a1 shown");
            a1.removeAll();
            setUpA1(dataSets, a1);
          }
        });
  }
 /**
  * Generates a simple exemplar of this class to test serialization.
  *
  * @see edu.cmu.TestSerialization
  * @see TetradSerializableUtils
  */
 public static RegressionInterpolatorWrapper serializableInstance() {
   return new RegressionInterpolatorWrapper(DataWrapper.serializableInstance());
 }
Пример #9
0
 /**
  * Generates a simple exemplar of this class to test serialization.
  *
  * @see edu.cmu.TestSerialization
  * @see TetradSerializableUtils
  */
 public static DataWrapper serializableInstance() {
   SplitCasesParams params = new SplitCasesParams();
   params.setNumSplits(1);
   params.setSpec(new SplitCasesSpec(1, new int[1], Collections.singletonList("1")));
   return new SplitCasesWrapper(DataWrapper.serializableInstance(), params);
 }