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); }
private void addEdges() { // remove old edges if available Iterator<String> e = edgeLabelMap.keySet().iterator(); while (e.hasNext()) { graph.removeEdge(e.next()); } edgeLabelMap.clear(); boolean isDistance = measure.isDistance(); Attribute id = exampleSet.getAttributes().getId(); List<SortableEdge> sortableEdges = new LinkedList<SortableEdge>(); for (int i = 0; i < exampleSet.size(); i++) { Example example = exampleSet.getExample(i); for (int j = i + 1; j < exampleSet.size(); j++) { Example comExample = exampleSet.getExample(j); if (isDistance) sortableEdges.add( new SortableEdge( example.getValueAsString(id), comExample.getValueAsString(id), null, measure.calculateDistance(example, comExample), SortableEdge.DIRECTION_INCREASE)); else sortableEdges.add( new SortableEdge( example.getValueAsString(id), comExample.getValueAsString(id), null, measure.calculateSimilarity(example, comExample), SortableEdge.DIRECTION_DECREASE)); } } Collections.sort(sortableEdges); int numberOfEdges = distanceSlider.getValue(); int counter = 0; double minStrength = Double.POSITIVE_INFINITY; double maxStrength = Double.NEGATIVE_INFINITY; Map<String, Double> strengthMap = new HashMap<String, Double>(); for (SortableEdge sortableEdge : sortableEdges) { if (counter > numberOfEdges) break; String idString = edgeFactory.create(); graph.addEdge( idString, sortableEdge.getFirstVertex(), sortableEdge.getSecondVertex(), EdgeType.UNDIRECTED); edgeLabelMap.put(idString, Tools.formatIntegerIfPossible(sortableEdge.getEdgeValue())); double strength = sortableEdge.getEdgeValue(); minStrength = Math.min(minStrength, strength); maxStrength = Math.max(maxStrength, strength); strengthMap.put(idString, strength); counter++; } for (Entry<String, Double> entry : strengthMap.entrySet()) { edgeStrengthMap.put( entry.getKey(), (entry.getValue() - minStrength) / (maxStrength - minStrength)); } }