/** Constructs a dialog to edit the given gene simulation parameters object. */
  public FciIndTestParamsEditorOld(FciIndTestParamsOld params) {
    this.params = params;

    // set up text and ties them to the parameters object being edited.
    alphaField =
        new DoubleTextField(indTestParams().getAlpha(), 8, new DecimalFormat("0.0########"));
    alphaField.setFilter(
        new DoubleTextField.Filter() {
          public double filter(double value, double oldValue) {
            try {
              indTestParams().setAlpha(value);
              return value;
            } catch (IllegalArgumentException e) {
              return oldValue;
            }
          }
        });

    depthField = new IntTextField(indTestParams().getDepth(), 5);
    depthField.setFilter(
        new IntTextField.Filter() {
          public int filter(int value, int oldValue) {
            try {
              indTestParams().setDepth(value);
              return value;
            } catch (IllegalArgumentException e) {
              return oldValue;
            }
          }
        });

    buildGui();
  }
Example #2
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();
          }
        });
  }
  public BuildPureClustersIndTestParamsEditor(
      BuildPureClustersIndTestParams paramsPureClusters, boolean discreteData) {
    this.paramsPureClusters = paramsPureClusters;

    DoubleTextField alphaField =
        new DoubleTextField(getParams().getAlpha(), 8, new DecimalFormat("0.0########"));
    alphaField.setFilter(
        new DoubleTextField.Filter() {
          public double filter(double value, double oldValue) {
            try {
              getParams().setAlpha(value);
              return value;
            } catch (IllegalArgumentException e) {
              return oldValue;
            }
          }
        });

    JComboBox testSelector = null;
    JComboBox purifySelector = null;

    if (!discreteData) {
      final String[] descriptions = Bpc.getTestDescriptions();
      testSelector = new JComboBox(descriptions);
      testSelector.setSelectedIndex(getParams().getTetradTestType());

      testSelector.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              JComboBox combo = (JComboBox) e.getSource();
              int index = combo.getSelectedIndex();
              getParams().setTetradTestType(index);
            }
          });

      final String[] purifyDescriptions = Bpc.getPurifyTestDescriptions();
      purifySelector = new JComboBox(purifyDescriptions);
      purifySelector.setSelectedIndex(getParams().getPurifyTestType());

      purifySelector.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              JComboBox combo = (JComboBox) e.getSource();
              int index = combo.getSelectedIndex();
              getParams().setPurifyTestType(index);
            }
          });
    }

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    if (!discreteData) {
      Box b1 = Box.createHorizontalBox();
      b1.add(new JLabel("Test:"));
      b1.add(Box.createHorizontalGlue());
      b1.add(testSelector);
      add(b1);
      add(Box.createHorizontalGlue());

      Box b2 = Box.createHorizontalBox();
      b2.add(new JLabel("Purify:"));
      b2.add(Box.createHorizontalGlue());
      b2.add(purifySelector);
      add(b2);
      add(Box.createHorizontalGlue());
    }

    Box b3 = Box.createHorizontalBox();
    b3.add(new JLabel("Alpha:"));
    b3.add(Box.createHorizontalGlue());
    b3.add(alphaField);
    add(b3);
    add(Box.createHorizontalGlue());

    //        if (discreteData) {
    //            paramsPureClusters.setPurifyTestType(
    //                    BuildPureClusters.PURIFY_TEST_DISCRETE_LRT);
    //            paramsPureClusters.setTetradTestType(BuildPureClusters.TEST_DISCRETE);
    //
    //        }
  }
  /**
   * Constructs the Gui used to edit properties; called from each constructor. Constructs labels and
   * text fields for editing each property and adds appropriate listeners.
   */
  public void setup() {
    setLayout(new BorderLayout());

    JRadioButton manualRetain = new JRadioButton();
    JRadioButton randomRetain = new JRadioButton();

    manualRetain.setText("Manually, retaining previous values where possible.");
    randomRetain.setText(
        "Using a symmetric prior for each row of each conditional" + " probability table.");

    ButtonGroup group = new ButtonGroup();
    group.add(manualRetain);
    group.add(randomRetain);

    final DoubleTextField symmetricAlphaField =
        new DoubleTextField(
            params.getDouble("symmetricAlpha", 1.0),
            5,
            NumberFormatUtil.getInstance().getNumberFormat());
    symmetricAlphaField.setFilter(
        new DoubleTextField.Filter() {
          public double filter(double value, double oldValue) {
            try {
              params.set("symmetricAlpha", value);
              return value;
            } catch (IllegalArgumentException e) {
              return oldValue;
            }
          }
        });

    if (getParams().getString("initializationMode", "manualRetain").equals("manualRetain")) {
      manualRetain.setSelected(true);
      symmetricAlphaField.setEnabled(false);
    } else if (getParams()
        .getString("initializationMode", "manualRetain")
        .equals("symmetricPrior")) {
      randomRetain.setSelected(true);
      symmetricAlphaField.setEnabled(true);
    } else {
      throw new IllegalStateException();
    }

    manualRetain.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            getParams().set("initializationMode", "manualRetain");
            symmetricAlphaField.setEnabled(false);
          }
        });

    randomRetain.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            getParams().set("initializationMode", "symmetricPrior");
            symmetricAlphaField.setEnabled(true);
          }
        });

    // continue workbench construction.
    Box b1 = Box.createVerticalBox();

    Box b2 = Box.createHorizontalBox();
    b2.add(new JLabel("Pseudocounts for this Dirichlet Bayes IM should be initialized:"));
    b2.add(Box.createHorizontalGlue());

    Box b3 = Box.createHorizontalBox();
    b3.add(manualRetain);
    b3.add(Box.createHorizontalGlue());

    Box b4 = Box.createHorizontalBox();
    b4.add(randomRetain);
    b4.add(Box.createHorizontalGlue());

    Box b5 = Box.createHorizontalBox();
    b5.add(Box.createRigidArea(new Dimension(30, 0)));
    b5.add(new JLabel("All pseudocounts = "));
    b5.add(symmetricAlphaField);
    b5.add(Box.createHorizontalGlue());

    b1.add(b2);
    b1.add(Box.createVerticalStrut(5));
    b1.add(b3);
    b1.add(b4);
    b1.add(b5);
    b1.add(Box.createHorizontalGlue());
    add(b1, BorderLayout.CENTER);
  }