@Override public Document getXmlContent() { // assert null != urlFactory : // Messages.getInstance().getString("FilterPanelComponent.ERROR_0000_FACTORY_CANNOT_BE_NULL"); // //$NON-NLS-1$ boolean ok = filterPanel.populate(getParameterProviders(), defaultValues); if (!ok) { String msg = Messages.getInstance() .getString("FilterPanelComponent.ERROR_0001_POPULATE"); // $NON-NLS-1$ FilterPanelComponent.log.error(msg); throw new UIException(msg); } String actionUrl = urlFactory.getActionUrlBuilder().getUrl(); Document xForm = filterPanel.getXForm(actionUrl); setXsl("text/html", xslName); // $NON-NLS-1$ return xForm; }
/** * Once the probability image and weight histograms are behaving satisfactorily, we plot the * learned filter for each hidden neuron, one per column of W. Each filter is of the same * dimension as the input data, and it is most useful to visualize the filters in the same way as * the input data is visualized. * * @throws Exception */ public BufferedImage renderFilters( INDArray data, String filename, int patchWidth, int patchHeight, int patchesPerRow) throws Exception { int[] equiv = new int[data.length()]; int numberCols = data.columns(); double approx = (double) numberCols / (double) patchesPerRow; int numPatchRows = (int) Math.round(approx); if (numPatchRows < 1) numPatchRows = 1; int patchBorder = 2; int filterImgWidth = (patchWidth + patchBorder) * patchesPerRow; int filterImgHeight = numPatchRows * (patchHeight + patchBorder); img = new BufferedImage(filterImgWidth, filterImgHeight, BufferedImage.TYPE_BYTE_GRAY); WritableRaster r = img.getRaster(); // for each hidden neuron // plot the learned filter (same dim as the input data) outer: for (int col = 0; col < numberCols; col++) { int curX = (col % patchesPerRow) * (patchWidth + patchBorder); int curY = col / patchesPerRow * (patchHeight + patchBorder); INDArray column = data.getColumn(col); double col_min = column.min(Integer.MAX_VALUE).getDouble(0); double col_max = column.max(Integer.MAX_VALUE).getDouble(0); // reshape the column into the shape of the filter patch // render the filter patch log.debug( "Rendering " + column.length() + " pixels in column " + col + " for filter patch " + patchWidth + " x " + patchHeight + ", total size: " + (patchWidth * patchHeight) + " at " + curX); for (int i = 0; i < column.length(); i++) { // double patch_normal = ( column.getFromOrigin(i) - min ) / ( max - min + 0.000001 ); double patch_normal = (column.getDouble(0) - col_min) / (col_max - col_min + 0.000001f); equiv[i] = (int) (255 * patch_normal); } // now draw patch to raster image boolean outOfBounds = false; if (curX >= filterImgWidth) { curX = filterImgWidth - 1; outOfBounds = true; break outer; } if (curY >= filterImgHeight) { curY = filterImgHeight - 1; outOfBounds = true; break outer; } r.setPixels(curX, curY, patchWidth, patchHeight, equiv); if (outOfBounds) break outer; } try { saveImageToDisk(img, filename); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); if (!ge.isHeadlessInstance()) { log.info("Rendering filter images..."); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); FilterPanel panel = new FilterPanel(img); frame.add(panel); Dimension d = new Dimension(numberCols * patchWidth, numPatchRows * patchHeight); frame.setSize(d); frame.setMinimumSize(d); panel.setMinimumSize(d); frame.pack(); frame.setVisible(true); Thread.sleep(10000); frame.dispose(); } } catch (IOException e) { throw new RuntimeException(e); } return img; }
public List getFilters() { return filterPanel.getFilters(); }
/** Display a frame for browsing issues. */ private JPanel constructView() { // sort the original issues list final SortedList<Issue> issuesSortedList = new SortedList<Issue>(issuesEventList, null); // filter the sorted issues FilterList<Issue> filteredIssues = new FilterList<Issue>(issuesSortedList, filterPanel.getMatcherEditor()); SeparatorList<Issue> separatedIssues = new SeparatorList<Issue>( filteredIssues, GlazedLists.beanPropertyComparator(Issue.class, "subcomponent"), 0, Integer.MAX_VALUE); EventList<Issue> separatedIssuesProxyList = GlazedListsSwing.swingThreadProxyList(separatedIssues); // build the issues table issuesTableModel = GlazedListsSwing.eventTableModel(separatedIssuesProxyList, new IssueTableFormat()); final TableColumnModel issuesTableColumnModel = new EventTableColumnModel<TableColumn>(new BasicEventList<TableColumn>()); JSeparatorTable issuesJTable = new JSeparatorTable(issuesTableModel, issuesTableColumnModel); issuesJTable.setAutoCreateColumnsFromModel(true); issuesJTable.setSeparatorRenderer(new IssueSeparatorTableCell(separatedIssues)); issuesJTable.setSeparatorEditor(new IssueSeparatorTableCell(separatedIssues)); issuesSelectionModel = GlazedListsSwing.eventSelectionModel(separatedIssuesProxyList); issuesSelectionModel.setSelectionMode( ListSelection .MULTIPLE_INTERVAL_SELECTION_DEFENSIVE); // multi-selection best demos our awesome // selection management issuesSelectionModel.addListSelectionListener(new IssuesSelectionListener()); issuesJTable.setSelectionModel(issuesSelectionModel); issuesJTable.getColumnModel().getColumn(0).setPreferredWidth(150); issuesJTable.getColumnModel().getColumn(1).setPreferredWidth(400); issuesJTable.getColumnModel().getColumn(2).setPreferredWidth(300); issuesJTable.getColumnModel().getColumn(3).setPreferredWidth(300); issuesJTable.getColumnModel().getColumn(4).setPreferredWidth(250); issuesJTable.getColumnModel().getColumn(5).setPreferredWidth(300); issuesJTable.getColumnModel().getColumn(6).setPreferredWidth(300); issuesJTable.getColumnModel().getColumn(7).setPreferredWidth(1000); // turn off cell focus painting issuesJTable.setDefaultRenderer( String.class, new NoFocusRenderer(issuesJTable.getDefaultRenderer(String.class))); issuesJTable.setDefaultRenderer( Integer.class, new NoFocusRenderer(issuesJTable.getDefaultRenderer(Integer.class))); issuesJTable.setDefaultRenderer( Priority.class, new NoFocusRenderer(new PriorityTableCellRenderer())); LookAndFeelTweaks.tweakTable(issuesJTable); TableComparatorChooser.install( issuesJTable, issuesSortedList, TableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD); JScrollPane issuesTableScrollPane = new JScrollPane( issuesJTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); issuesTableScrollPane.getViewport().setBackground(UIManager.getColor("EditorPane.background")); issuesTableScrollPane.setBorder(BorderFactory.createEmptyBorder()); issueDetails = new IssueDetailsComponent(filteredIssues); // projects EventList<Project> projects = Project.getProjects(); TransformedList<Project, Project> projectsProxyList = GlazedListsSwing.swingThreadProxyList(projects); // project select combobox DefaultEventComboBoxModel projectsComboModel = new DefaultEventComboBoxModel<Project>(projectsProxyList); JComboBox projectsCombo = new JComboBox(projectsComboModel); projectsCombo.setEditable(false); projectsCombo.setOpaque(false); projectsCombo.addItemListener(new ProjectChangeListener()); projectsComboModel.setSelectedItem(new Project(null, "Select a Java.net project...")); // build a label to display the number of issues in the issue table issueCounter = new IssueCounterLabel(filteredIssues); issueCounter.setHorizontalAlignment(SwingConstants.CENTER); issueCounter.setForeground(Color.WHITE); // throbber throbber = new JLabel(THROBBER_STATIC); throbber.setHorizontalAlignment(SwingConstants.RIGHT); // header bar JPanel iconBar = new GradientPanel(GLAZED_LISTS_MEDIUM_BROWN, GLAZED_LISTS_DARK_BROWN, true); iconBar.setLayout(new GridLayout(1, 3)); iconBar.add(projectsCombo); iconBar.add(issueCounter); iconBar.add(throbber); iconBar.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); // assemble all data components on a common panel JPanel dataPanel = new JPanel(); JComponent issueDetailsComponent = issueDetails; dataPanel.setLayout(new GridLayout(2, 1)); dataPanel.add(issuesTableScrollPane); dataPanel.add(issueDetailsComponent); // draw lines between components JComponent filtersPanel = filterPanel.getComponent(); filtersPanel.setBorder(BorderFactory.createEmptyBorder()); // filtersPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, // IssuesBrowser.GLAZED_LISTS_DARK_BROWN)); issueDetailsComponent.setBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, GLAZED_LISTS_DARK_BROWN)); // the outermost panel to layout the icon bar with the other panels final JPanel mainPanel = new JPanel(new GridBagLayout()); mainPanel.add( iconBar, new GridBagConstraints( 0, 0, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); mainPanel.add( filtersPanel, new GridBagConstraints( 0, 1, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); mainPanel.add( Box.createHorizontalStrut(240), new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); mainPanel.add( dataPanel, new GridBagConstraints( 1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); return mainPanel; }