コード例 #1
0
  public SimilarityVisualization(SimilarityMeasureObject sim, ExampleSet exampleSet) {
    super();
    setLayout(new BorderLayout());

    DistanceMeasure measure = sim.getDistanceMeasure();
    ButtonGroup group = new ButtonGroup();
    JPanel togglePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));

    // similarity table
    final JComponent tableView = new SimilarityTable(measure, exampleSet);
    final JRadioButton tableButton = new JRadioButton("Table View", true);
    tableButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (tableButton.isSelected()) {
              remove(1);
              add(tableView, BorderLayout.CENTER);
              repaint();
            }
          }
        });
    group.add(tableButton);
    togglePanel.add(tableButton);

    // graph view
    final JComponent graphView =
        new GraphViewer<String, String>(new SimilarityGraphCreator(measure, exampleSet));
    final JRadioButton graphButton = new JRadioButton("Graph View", false);
    graphButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (graphButton.isSelected()) {
              remove(1);
              add(graphView, BorderLayout.CENTER);
              repaint();
            }
          }
        });
    group.add(graphButton);
    togglePanel.add(graphButton);

    // histogram view
    DataTable dataTable = new SimpleDataTable("Histogram", new String[] {"Histogram"});
    double sampleRatio = Math.min(1.0d, 500.0d / exampleSet.size());

    Random random = new Random();
    int i = 0;
    for (Example example : exampleSet) {
      int j = 0;
      for (Example compExample : exampleSet) {
        if (i != j && random.nextDouble() < sampleRatio) {
          double simValue = measure.calculateSimilarity(example, compExample);
          dataTable.add(new SimpleDataTableRow(new double[] {simValue}));
        }
        j++;
      }
      i++;
    }

    final PlotterConfigurationModel settings =
        new PlotterConfigurationModel(PlotterConfigurationModel.HISTOGRAM_PLOT, dataTable);
    settings.enablePlotColumn(0);
    settings.setParameterAsInt(HistogramChart.PARAMETER_NUMBER_OF_BINS, 100);

    final JRadioButton histogramButton = new JRadioButton("Histogram View", false);
    histogramButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (histogramButton.isSelected()) {
              remove(1);
              add(settings.getPlotter().getPlotter(), BorderLayout.CENTER);
              repaint();
            }
          }
        });
    group.add(histogramButton);
    togglePanel.add(histogramButton);

    // K distance view
    final SimilarityKDistanceVisualization kDistancePlotter =
        new SimilarityKDistanceVisualization(measure, exampleSet);
    final JRadioButton kdistanceButton = new JRadioButton("k-Distance View", false);
    kdistanceButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (kdistanceButton.isSelected()) {
              remove(1);
              add(kDistancePlotter, BorderLayout.CENTER);
              repaint();
            }
          }
        });
    group.add(kdistanceButton);
    togglePanel.add(kdistanceButton);

    add(togglePanel, BorderLayout.NORTH);
    add(tableView, BorderLayout.CENTER);
  }
コード例 #2
0
 @Override
 public TableModel getTableModel(Object renderable, IOContainer ioContainer, boolean isReporting) {
   SimilarityMeasureObject similarity = (SimilarityMeasureObject) renderable;
   return new SimilarityTableModel(similarity.getDistanceMeasure(), similarity.getExampleSet());
 }