List of usage examples for weka.core Instances attribute
publicAttribute attribute(String name)
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingFrame.java
License:Open Source License
private void showEnvelope(final int[] arr, final List<XYAnnotation> aaa) throws Exception { final Color cc = ColorHelper.getColorForAString(attr.name()); final Color newcc = new Color(cc.getRed(), cc.getGreen(), cc.getBlue(), cc.getAlpha() / 4).brighter(); final Map<Double, Double> minMap = new HashMap<Double, Double>(); final Map<Double, Double> maxMap = new HashMap<Double, Double>(); for (final Algo aall : Algo.values()) { Instances filteredDs2 = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSet, arr); filteredDs2 = WekaDataProcessingUtil.buildFilteredDataSet(filteredDs2, 0, filteredDs2.numAttributes() - 1, Math.max(0, this.position - this.valuesBeforeAndAfter), Math.min(this.position + this.gapsize + this.valuesBeforeAndAfter, filteredDs2.numInstances() - 1)); final GapFiller gp = GapFillerFactory.getGapFiller(aall); final Instances completedds2 = gp.fillGaps(filteredDs2); final Instances diff2 = WekaTimeSeriesUtil.buildDiff(filteredDs2, completedds2); //final double mae2=this.gapFiller.evaluateMeanAbsoluteError(filteredDs2,valuesBeforeAndAfterForMAE); final Instances decomposition2 = WekaTimeSeriesUtil.buildMergedDataSet(filteredDs2, diff2); final Attribute diffAttribute2 = decomposition2.attribute(attr.name() + "_diff"); final Attribute timestampDiffAttribute2 = decomposition2 .attribute(WekaDataStatsUtil.getFirstDateAttributeIdx(decomposition2)); for (int i = 1; i < decomposition2.numInstances() - 1; i++) { if (!decomposition2.instance(i).isMissing(diffAttribute2)/*&&i%10==0*/) { final double d = decomposition2.instance(i).value(diffAttribute2); final double timestamp = decomposition2.instance(i).value(timestampDiffAttribute2); aaa.add(new XYDrawableAnnotation(timestamp, d, 1, 1, new AnnotationDrawer(newcc))); if (!minMap.containsKey(timestamp) || minMap.get(timestamp) > d) minMap.put(timestamp, d); if (!maxMap.containsKey(timestamp) || maxMap.get(timestamp) < d) maxMap.put(timestamp, d); }//from w w w .ja v a 2s . c om } } for (final Map.Entry<Double, Double> entry : minMap.entrySet()) { final Double timestamp = entry.getKey(); final Double min = minMap.get(timestamp); final Double max = maxMap.get(timestamp); if (min > max) throw new IllegalStateException("min>max -> " + min + ">" + max); else if (max > min) { final double step = (max - min) / 20d; for (double dd = min; dd <= max; dd += step) { aaa.add(new XYDrawableAnnotation(timestamp, dd, 1, 1, new AnnotationDrawer(newcc))); } } } System.out.println("done"); }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingFrame.java
License:Open Source License
private void showError(final double mae, final Instances decomposition, final Attribute diffAttribute, final List<XYAnnotation> aaa) { //System.out.println("*************** SHOW ERROR **************************"); final Attribute timestampDiffAttribute = decomposition .attribute(WekaDataStatsUtil.getFirstDateAttributeIdx(decomposition)); final Color cc = ColorHelper.getColorForAString(diffAttribute.name()); final Color newcc = new Color(cc.getRed(), cc.getGreen(), cc.getBlue(), cc.getAlpha() / 4).brighter(); for (int i = 1; i < decomposition.numInstances() - 1; i++) { //if (i%10!=1) continue; if (!decomposition.instance(i).isMissing(diffAttribute)/*&&i%10==0*/) { final double d = decomposition.instance(i).value(diffAttribute); final double timestamp = decomposition.instance(i).value(timestampDiffAttribute); aaa.add(new XYDrawableAnnotation(timestamp, d + mae, 0.5, 0.5, new AnnotationDrawer(newcc))); aaa.add(new XYDrawableAnnotation(timestamp, d - mae, 0.5, 0.5, new AnnotationDrawer(newcc))); for (double dd = d - mae; dd <= d + mae; dd += mae / 20) { aaa.add(new XYDrawableAnnotation(timestamp, dd, 1, 1, new AnnotationDrawer(newcc))); }/*from w w w . java 2 s . c om*/ //aaa.add(new XYDrawableAnnotation(timestamp,d,1,1,new AnnotationDrawer(cc))); } } //System.out.println("*****************************************************"); }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingKnowledgeDBExplorerFrame.java
License:Open Source License
/** * Constructor./*from w w w. ja v a 2 s. co m*/ */ GapFillingKnowledgeDBExplorerFrame(final Instances ds, final int dateIdx, final StationsDataProvider gcp) throws Exception { LogoHelper.setLogo(this); this.setTitle("KnowledgeDB: explorer"); this.gcp = gcp; this.tablePanel = new JXPanel(); this.tablePanel.setBorder(new TitledBorder("Cases")); final JXPanel highPanel = new JXPanel(); highPanel.setLayout(new BoxLayout(highPanel, BoxLayout.X_AXIS)); highPanel.add(this.tablePanel); this.geomapPanel = new JXPanel(); this.geomapPanel.add(buildGeoMapChart(new ArrayList<String>(), new ArrayList<String>())); highPanel.add(this.geomapPanel); this.caseChartPanel = new JXPanel(); this.caseChartPanel.setBorder(new TitledBorder("Inspected fake gap")); this.mostSimilarChartPanel = new JXPanel(); this.mostSimilarChartPanel.setBorder(new TitledBorder("Most similar")); this.nearestChartPanel = new JXPanel(); this.nearestChartPanel.setBorder(new TitledBorder("Nearest")); this.downstreamChartPanel = new JXPanel(); this.downstreamChartPanel.setBorder(new TitledBorder("Downstream")); this.upstreamChartPanel = new JXPanel(); this.upstreamChartPanel.setBorder(new TitledBorder("Upstream")); getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS)); //getContentPane().add(new JCheckBox("Use incomplete series")); getContentPane().add(highPanel); //getContentPane().add(new JXButton("Export")); getContentPane().add(caseChartPanel); getContentPane().add(mostSimilarChartPanel); getContentPane().add(nearestChartPanel); getContentPane().add(downstreamChartPanel); getContentPane().add(upstreamChartPanel); //final Instances kdbDS=GapFillingKnowledgeDB.getKnowledgeDBWithBestCasesOnly(); final Instances kdbDS = GapFillingKnowledgeDB.getKnowledgeDB(); final JXTable gapsTable = buidJXTable(kdbDS); final JScrollPane tableScrollPane = new JScrollPane(gapsTable); tableScrollPane.setPreferredSize( new Dimension(COMPONENT_WIDTH - 100, 40 + (int) (tableScrollPane.getPreferredSize().getHeight()))); this.tablePanel.add(tableScrollPane); gapsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); gapsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final int modelRow = gapsTable.getSelectedRow(); final String attrname = gapsTable.getModel().getValueAt(modelRow, 1).toString(); final int gapsize = (int) Double .valueOf(gapsTable.getModel().getValueAt(modelRow, 4).toString()).doubleValue(); final int position = (int) Double .valueOf(gapsTable.getModel().getValueAt(modelRow, 5).toString()).doubleValue(); final String mostSimilarFlag = gapsTable.getModel().getValueAt(modelRow, 14).toString(); final String nearestFlag = gapsTable.getModel().getValueAt(modelRow, 15).toString(); final String downstreamFlag = gapsTable.getModel().getValueAt(modelRow, 16).toString(); final String upstreamFlag = gapsTable.getModel().getValueAt(modelRow, 17).toString(); final String algoname = gapsTable.getModel().getValueAt(modelRow, 12).toString(); final boolean useDiscretizedTime = Boolean .valueOf(gapsTable.getModel().getValueAt(modelRow, 13).toString()); try { geomapPanel.removeAll(); caseChartPanel.removeAll(); mostSimilarChartPanel.removeAll(); nearestChartPanel.removeAll(); downstreamChartPanel.removeAll(); upstreamChartPanel.removeAll(); final Set<String> selected = new HashSet<String>(); final Instances tmpds = WekaDataProcessingUtil.buildFilteredDataSet(ds, 0, ds.numAttributes() - 1, Math.max(0, position - GapsUtil.getCountOfValuesBeforeAndAfter(gapsize)), Math.min(position + gapsize + GapsUtil.getCountOfValuesBeforeAndAfter(gapsize), ds.numInstances() - 1)); final List<String> attributeNames = WekaTimeSeriesUtil .getNamesOfAttributesWithoutGap(tmpds); //final List<String> attributeNames=WekaDataStatsUtil.getAttributeNames(ds); attributeNames.remove(attrname); attributeNames.remove("timestamp"); if (Boolean.valueOf(mostSimilarFlag)) { final String mostSimilarStationName = WekaTimeSeriesSimilarityUtil .findMostSimilarTimeSerie(tmpds, tmpds.attribute(attrname), attributeNames, false); selected.add(mostSimilarStationName); final Attribute mostSimilarStationAttr = tmpds.attribute(mostSimilarStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, mostSimilarStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); mostSimilarChartPanel.add(cp0); } if (Boolean.valueOf(nearestFlag)) { final String nearestStationName = gcp.findNearestStation(attrname, attributeNames); selected.add(nearestStationName); final Attribute nearestStationAttr = ds.attribute(nearestStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, nearestStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); nearestChartPanel.add(cp0); } if (Boolean.valueOf(downstreamFlag)) { final String downstreamStationName = gcp.findDownstreamStation(attrname, attributeNames); selected.add(downstreamStationName); final Attribute downstreamStationAttr = ds.attribute(downstreamStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, downstreamStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); downstreamChartPanel.add(cp0); } if (Boolean.valueOf(upstreamFlag)) { final String upstreamStationName = gcp.findUpstreamStation(attrname, attributeNames); selected.add(upstreamStationName); final Attribute upstreamStationAttr = ds.attribute(upstreamStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, upstreamStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); upstreamChartPanel.add(cp0); } final GapFiller gapFiller = GapFillerFactory.getGapFiller(algoname, useDiscretizedTime); final ChartPanel cp = GapsUIUtil.buildGapChartPanelWithCorrection(ds, dateIdx, ds.attribute(attrname), gapsize, position, gapFiller, selected); cp.getChart().removeLegend(); cp.setPreferredSize(new Dimension((int) CHART_DIMENSION.getWidth(), (int) (CHART_DIMENSION.getHeight() * 1.5))); caseChartPanel.add(cp); geomapPanel.add(buildGeoMapChart(Arrays.asList(attrname), selected)); getContentPane().repaint(); pack(); } catch (Exception e1) { e1.printStackTrace(); } } } }); gapsTable.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(final MouseEvent e) { if (!e.isPopupTrigger()) { // nothing? } else { final JPopupMenu jPopupMenu = new JPopupMenu("feur"); final JMenuItem mExport = new JMenuItem("Export this table as CSV"); mExport.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); final int returnVal = fc.showSaveDialog(gapsTable); if (returnVal == JFileChooser.APPROVE_OPTION) { try { final File file = fc.getSelectedFile(); WekaDataAccessUtil.saveInstancesIntoCSVFile(kdbDS, file); } catch (Exception ee) { ee.printStackTrace(); } } } }); jPopupMenu.add(mExport); jPopupMenu.show(gapsTable, e.getX(), e.getY()); } } }); setPreferredSize(new Dimension(FRAME_WIDTH, 1000)); pack(); setVisible(true); /* select the first row */ gapsTable.setRowSelectionInterval(0, 0); }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingKnowledgeDBExplorerFrame.java
License:Open Source License
private JXTable buidJXTable(final Instances cases) { final InstanceTableModel outputCasesTableModel = new InstanceTableModel(); outputCasesTableModel.setDataset(cases); final JXTable outputCasesTable = new JXTable(outputCasesTableModel); outputCasesTable.setEditable(false); outputCasesTable.setShowHorizontalLines(false); outputCasesTable.setShowVerticalLines(false); outputCasesTable.setVisibleRowCount(5); outputCasesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); final HighlightPredicate myPredicate = new HighlightPredicate() { @Override/*from w w w . java 2 s . c om*/ public boolean isHighlighted(final Component arg0, final ComponentAdapter arg1) { final String trueColumnName = (arg1.column > 0) ? cases.attribute(arg1.column - 1).name() : "id"; final java.util.List<String> inputFieldsList = Arrays.asList(GapFillingKnowledgeDB.INPUT_FIELDS); return (inputFieldsList.contains(trueColumnName)); } }; outputCasesTable.addHighlighter(new ColorHighlighter(myPredicate, null, Color.BLUE)); outputCasesTable.packAll(); return outputCasesTable; }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsOverviewPanel.java
License:Open Source License
public void refresh(final Instances dataSet, final int dateIdx) { final Instances gapsDescriptionsDataset = GapsUtil.buildGapsDescription(gcp, dataSet, dateIdx); final JXTable gapsDescriptionsTable = new JXTable(); final InstanceTableModel gapsDescriptionsTableModel = new InstanceTableModel(false); gapsDescriptionsTableModel.setDataset(gapsDescriptionsDataset); gapsDescriptionsTable.setModel(gapsDescriptionsTableModel); gapsDescriptionsTable.setEditable(true); gapsDescriptionsTable.setShowHorizontalLines(false); gapsDescriptionsTable.setShowVerticalLines(false); gapsDescriptionsTable.setVisibleRowCount(5); gapsDescriptionsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); gapsDescriptionsTable.setSortable(false); gapsDescriptionsTable.packAll();// ww w .j a va 2s.c o m gapsDescriptionsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); gapsDescriptionsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int modelRow = gapsDescriptionsTable.getSelectedRow(); if (modelRow < 0) modelRow = 0; final String attrname = gapsDescriptionsTableModel.getValueAt(modelRow, 1).toString(); final Attribute attr = dataSet.attribute(attrname); final int gapsize = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 5).toString()).doubleValue(); final int position = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 6).toString()).doubleValue(); try { final ChartPanel cp = GapsUIUtil.buildGapChartPanel(dataSet, dateIdx, attr, gapsize, position); visualOverviewPanel.removeAll(); visualOverviewPanel.add(cp, BorderLayout.CENTER); geomapPanel.removeAll(); geomapPanel.add(gcp.getMapPanel(Arrays.asList(attrname), new ArrayList<String>(), false)); jxp.updateUI(); } catch (Exception ee) { ee.printStackTrace(); } } } }); gapsDescriptionsTable.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(final MouseEvent e) { final InstanceTableModel instanceTableModel = (InstanceTableModel) gapsDescriptionsTable.getModel(); final int row = gapsDescriptionsTable.rowAtPoint(e.getPoint()); //final int row=gapsDescriptionsTable.getSelectedRow(); final int modelRow = gapsDescriptionsTable.convertRowIndexToModel(row); //final int modelRow=(int)Double.valueOf(instanceTableModel.getValueAt(row,0).toString()).doubleValue(); //System.out.println(row+" "+modelRow); final String attrname = instanceTableModel.getValueAt(modelRow, 1).toString(); final Attribute attr = dataSet.attribute(attrname); final int gapsize = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 5).toString()) .doubleValue(); final int position = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 6).toString()) .doubleValue(); if (!e.isPopupTrigger()) { // nothing? } else { final JPopupMenu jPopupMenu = new JPopupMenu("feur"); final JMenuItem interactiveFillMenuItem = new JMenuItem("Fill this gap (interactively)"); interactiveFillMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final GapFillingFrame jxf = new GapFillingFrame(atv, dataSet, attr, dateIdx, GapsUtil.getCountOfValuesBeforeAndAfter(gapsize), position, gapsize, gcp, false); jxf.setSize(new Dimension(900, 700)); //jxf.setExtendedState(Frame.MAXIMIZED_BOTH); jxf.setLocationRelativeTo(jPopupMenu); jxf.setVisible(true); //jxf.setResizable(false); } }); jPopupMenu.add(interactiveFillMenuItem); final JMenuItem lookupInKnowledgeDBMenuItem = new JMenuItem( "Show the most similar cases from KnowledgeDB"); lookupInKnowledgeDBMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final double x = gcp.getCoordinates(attrname)[0]; final double y = gcp.getCoordinates(attrname)[1]; final String season = instanceTableModel.getValueAt(modelRow, 3).toString() .split("/")[0]; final boolean isDuringRising = instanceTableModel.getValueAt(modelRow, 11).toString() .equals("true"); try { final Calendar cal = Calendar.getInstance(); final String dateAsString = instanceTableModel.getValueAt(modelRow, 2).toString() .replaceAll("'", ""); cal.setTime(FormatterUtil.DATE_FORMAT.parse(dateAsString)); final int year = cal.get(Calendar.YEAR); new SimilarCasesFrame(dataSet, dateIdx, gcp, attrname, gapsize, position, x, y, year, season, isDuringRising); } catch (Exception e1) { e1.printStackTrace(); } } }); jPopupMenu.add(lookupInKnowledgeDBMenuItem); final JMenuItem mExport = new JMenuItem("Export this table as CSV"); mExport.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); final int returnVal = fc.showSaveDialog(gapsDescriptionsTable); if (returnVal == JFileChooser.APPROVE_OPTION) { try { final File file = fc.getSelectedFile(); WekaDataAccessUtil.saveInstancesIntoCSVFile(gapsDescriptionsDataset, file); } catch (Exception ee) { ee.printStackTrace(); } } } }); jPopupMenu.add(mExport); jPopupMenu.show(gapsDescriptionsTable, e.getX(), e.getY()); } } }); final int tableWidth = (int) gapsDescriptionsTable.getPreferredSize().getWidth() + 30; final JScrollPane scrollPane = new JScrollPane(gapsDescriptionsTable); scrollPane.setPreferredSize(new Dimension(Math.min(tableWidth, 500), 500)); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); this.tablePanel.removeAll(); this.tablePanel.add(scrollPane, BorderLayout.CENTER); this.visualOverviewPanel.removeAll(); /* automatically compute the most similar series and the 'rising' flag */ new AbstractSimpleAsync<Void>(false) { @Override public Void execute() throws Exception { final int rc = gapsDescriptionsTableModel.getRowCount(); for (int i = 0; i < rc; i++) { final int modelRow = i; try { final String attrname = gapsDescriptionsTableModel.getValueAt(modelRow, 1).toString(); final Attribute attr = dataSet.attribute(attrname); final int gapsize = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 5).toString()) .doubleValue(); final int position = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 6).toString()) .doubleValue(); /* most similar */ gapsDescriptionsTableModel.setValueAt("...", modelRow, 7); final int cvba = GapsUtil.getCountOfValuesBeforeAndAfter(gapsize); Instances gapds = WekaDataProcessingUtil.buildFilteredDataSet(dataSet, 0, dataSet.numAttributes() - 1, Math.max(0, position - cvba), Math.min(position + gapsize + cvba, dataSet.numInstances() - 1)); final String mostsimilar = WekaTimeSeriesSimilarityUtil.findMostSimilarTimeSerie(gapds, attr, WekaTimeSeriesUtil.getNamesOfAttributesWithoutGap(gapds), false); gapsDescriptionsTableModel.setValueAt(mostsimilar, modelRow, 7); /* 'rising' flag */ gapsDescriptionsTableModel.setValueAt("...", modelRow, 11); final List<String> attributeNames = WekaDataStatsUtil.getAttributeNames(dataSet); attributeNames.remove("timestamp"); final String nearestStationName = gcp.findNearestStation(attr.name(), attributeNames); final Attribute nearestStationAttr = dataSet.attribute(nearestStationName); //System.out.println(nearestStationName+" "+nearestStationAttr); final boolean isDuringRising = GapsUtil.isDuringRising(dataSet, position, gapsize, new int[] { dateIdx, attr.index(), nearestStationAttr.index() }); gapsDescriptionsTableModel.setValueAt(isDuringRising, modelRow, 11); gapsDescriptionsTableModel.fireTableDataChanged(); } catch (Exception e) { gapsDescriptionsTableModel.setValueAt("n/a", modelRow, 7); gapsDescriptionsTableModel.setValueAt("n/a", modelRow, 11); e.printStackTrace(); } } return null; } @Override public void onSuccess(Void result) { } @Override public void onFailure(Throwable caught) { caught.printStackTrace(); } }.start(); /* select the first row */ gapsDescriptionsTable.setRowSelectionInterval(0, 0); }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsTabView.java
License:Open Source License
private void fillTabs(final Instances dataSet) { if (dataSet.numInstances() > MAX_SIZE) { throw new IllegalStateException("Time series are too long (" + dataSet.numInstances() + "), and records count should be > " + MAX_SIZE + ": please filter data before using it."); }/*from www. j ava2 s. co m*/ final int dateIdx = dataSet.attribute(dateAttributeField.getSelectedItem().toString()).index(); System.out.println("TimeSeriesTabView: building 'gaps' subpanel ..."); gapsPanel.refresh(dataSet, dateIdx); }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsTabView.java
License:Open Source License
/** * {@inheritDoc}//from w w w .ja v a2s . c om */ @Override public void update0(final Instances dataSet) throws Exception { if (this.dateAttributeField != null) { this.jxp.remove(this.dateAttributeField); this.dateAttributeField = null; this.jxp.updateUI(); } final java.util.List<String> dateAttributeNames = WekaDataStatsUtil.getDateAttributeNames(dataSet); final boolean hasDateAttributes = (!dateAttributeNames.isEmpty()) /*&&(WekaDataStatsUtil.getNumericAttributesIndexes(dataSet).size()>0)*/; if (hasDateAttributes) { this.dateAttributeField = new JXComboBox(dateAttributeNames.toArray()); this.dateAttributeField.setBorder(new TitledBorder("Date attribute")); this.jxp.add(this.dateAttributeField, BorderLayout.SOUTH); this.dateAttributeField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { fillTabs(dataSet); } }); new AbstractSimpleAsync<Void>(true) { @Override public Void execute() throws Exception { fillTabs(dataSet); return null; } @Override public void onSuccess(Void result) { } @Override public void onFailure(Throwable caught) { caught.printStackTrace(); } }.start(); this.actionsForFictiveGapsPanel.removeAll(); //final JComboBox seriesWithoutGapCB=new JComboBox(WekaTimeSeriesUtil.getNamesOfAttributesWithoutGap(dataSet).toArray()); final JComboBox seriesWithoutGapCB = new JComboBox( WekaDataStatsUtil.getAttributeNames(dataSet).toArray()); seriesWithoutGapCB.setBorder(new TitledBorder("Fictive gap in")); this.actionsForFictiveGapsPanel.add(seriesWithoutGapCB); final JComboBox sizeGapCB = new JComboBox(new Object[] { 10, 50, 100, 200, 400, 500 }); sizeGapCB.setBorder(new TitledBorder("Size of the fictive gap")); this.actionsForFictiveGapsPanel.add(sizeGapCB); final Object[] partChoice = new Object[PARTS_COUNT]; for (int iii = 0; iii < PARTS_COUNT; iii++) { partChoice[iii] = iii + "/" + PARTS_COUNT; } final JComboBox positionGapCB = new JComboBox(partChoice); positionGapCB.setBorder(new TitledBorder("Position of the fictive gap")); this.actionsForFictiveGapsPanel.add(positionGapCB); this.fictiveGapButton = new JXButton("Create a fictive gap"); this.actionsForFictiveGapsPanel.add(this.fictiveGapButton); this.fictiveGapButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { /* create a fake gap */ final Attribute attr = dataSet.attribute(seriesWithoutGapCB.getSelectedItem().toString()); final int dateIdx = WekaDataStatsUtil.getFirstDateAttributeIdx(dataSet); final int position = ((positionGapCB.getSelectedIndex() + 1) * dataSet.numInstances()) / PARTS_COUNT; final int gapsize = Integer.valueOf(sizeGapCB.getSelectedItem().toString()); /* show it */ final GapFillingFrame jxf = new GapFillingFrame(getAbstractTabView(), new Instances(dataSet), attr, dateIdx, GapsUtil.getCountOfValuesBeforeAndAfter(gapsize), position, gapsize, gcp, false); //jxf.setSize(new Dimension(900,700)); //jxf.setExtendedState(Frame.MAXIMIZED_BOTH); jxf.setLocationRelativeTo(jxp); jxf.setVisible(true); //jxf.setResizable(false); } }); this.showKnowledgeDBButton = new JXButton("Show KDB"); this.actionsForFictiveGapsPanel.add(this.showKnowledgeDBButton); this.showKnowledgeDBButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { try { final DatasetView view = new DatasetView("KnowledgeDB", eventPublisher, commandDispatcher, applicationContext); view.setDataSet(GapFillingKnowledgeDB.getKnowledgeDB()).setAsVisible(true); } catch (final Exception ee) { ee.printStackTrace(); } } }); this.inspectKnowledgeDBButton = new JXButton("Inspect KDB"); this.actionsForFictiveGapsPanel.add(this.inspectKnowledgeDBButton); this.inspectKnowledgeDBButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { try { final int dateIdx = WekaDataStatsUtil.getFirstDateAttributeIdx(dataSet); new GapFillingKnowledgeDBExplorerFrame(dataSet, dateIdx, gcp); } catch (final Exception ee) { ee.printStackTrace(); } } }); this.showKnowledgeDBWithTrueCasesButton = new JXButton("Show KDB with true cases"); this.actionsForFictiveGapsPanel.add(this.showKnowledgeDBWithTrueCasesButton); this.showKnowledgeDBWithTrueCasesButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { try { final StringBuilder sb = new StringBuilder("@relation blabla\n"); sb.append("@attribute serieName string\n"); sb.append("@attribute serieX numeric\n"); sb.append("@attribute serieY numeric\n"); sb.append("@attribute year numeric\n"); sb.append("@attribute season {Winter,Spring,Summer,Autumn}\n"); sb.append("@attribute gapSize numeric\n"); sb.append("@attribute gapPosition numeric\n"); sb.append("@attribute isDuringRising {true,false}\n"); sb.append("@attribute flow string\n"); sb.append("@attribute hasDownstream {false,true}\n"); sb.append("@attribute hasUpstream {false,true}\n"); sb.append("@attribute isReal {false,true}\n"); sb.append( "@attribute algo {Interpolation,EM,REG,REPTREE,M5P,ZeroR,ANN,NEARESTNEIGHBOUR}\n"); sb.append("@attribute useDiscretizedTime {false,true}\n"); sb.append("@attribute useMostSimilar {false,true}\n"); sb.append("@attribute useNearest {true,false}\n"); sb.append("@attribute useDownstream {false,true}\n"); sb.append("@attribute useUpstream {true,false}\n"); sb.append("@attribute mae numeric\n"); sb.append("@attribute rmse numeric\n"); sb.append("@attribute rsr numeric\n"); sb.append("@attribute pbias numeric\n"); sb.append("@attribute ns numeric\n"); sb.append("@attribute ioa numeric\n"); sb.append("@attribute wasTheBestSolution {true,false}\n"); sb.append("@data\n"); /* true cases */ final Calendar cal = Calendar.getInstance(); final int dateIdx = WekaDataStatsUtil.getFirstDateAttributeIdx(dataSet); final Instances gapsDescriptionsDataset = GapsUtil.buildGapsDescription(gcp, dataSet, dateIdx); final int gddc = gapsDescriptionsDataset.numInstances(); for (int i = 0; i < gddc; i++) { final Instance trueCase = gapsDescriptionsDataset.instance(i); sb.append(trueCase.stringValue(0)); // serie sb.append(","); sb.append(gcp.getCoordinates(trueCase.stringValue(0))[0]); // x sb.append(","); sb.append(gcp.getCoordinates(trueCase.stringValue(0))[1]); // y sb.append(","); cal.setTime(FormatterUtil.DATE_FORMAT.parse(trueCase.stringValue(1))); // year sb.append(cal.get(Calendar.YEAR)); sb.append(","); sb.append(trueCase.stringValue(2).split("/")[0]); // season sb.append(","); sb.append(trueCase.value(4)); //gapsize sb.append(","); sb.append(trueCase.value(5)); //gap position sb.append(","); sb.append(trueCase.stringValue(10).equals("true")); //rising sb.append(","); sb.append(trueCase.stringValue(11)); // flow sb.append(","); sb.append(!trueCase.stringValue(9).equals("n/a")); //downstream sb.append(","); sb.append(!trueCase.stringValue(8).equals("n/a")); // upstream sb.append(","); sb.append("true"); sb.append(","); sb.append("?"); sb.append(","); sb.append("?"); sb.append(","); sb.append("?"); sb.append(","); sb.append("?"); sb.append(","); sb.append("?"); sb.append(","); sb.append("?"); sb.append(","); sb.append("?"); sb.append(","); sb.append("?"); sb.append(","); sb.append("?"); sb.append(","); sb.append("?"); sb.append(","); sb.append("?"); sb.append(","); sb.append("?"); sb.append(","); sb.append("?"); sb.append("\n"); } /* the simulated cases from the knowledge DB */ final Instances knowledgeDB = GapFillingKnowledgeDB.getKnowledgeDB(); final int kni = knowledgeDB.numInstances(); for (int i = 0; i < kni; i++) { final Instance simulatedCase = knowledgeDB.instance(i); sb.append(simulatedCase.stringValue(0)); // name sb.append(","); sb.append(simulatedCase.value(1)); //x sb.append(","); sb.append(simulatedCase.value(2)); //y sb.append(","); sb.append(simulatedCase.value(6)); //year sb.append(","); sb.append(simulatedCase.stringValue(5)); //season sb.append(","); sb.append(simulatedCase.value(3)); // size sb.append(","); sb.append(simulatedCase.value(4)); // position sb.append(","); sb.append(simulatedCase.stringValue(7)); // rising sb.append(","); sb.append(simulatedCase.stringValue(8)); //flow sb.append(","); sb.append(simulatedCase.stringValue(9)); //downstream sb.append(","); sb.append(simulatedCase.stringValue(10)); // upstream sb.append(","); sb.append("false"); // real sb.append(","); sb.append(simulatedCase.stringValue(11)); //algo sb.append(","); sb.append(simulatedCase.stringValue(12)); // discr time sb.append(","); sb.append(simulatedCase.stringValue(13)); // most similar sb.append(","); sb.append(simulatedCase.stringValue(14)); // nearest sb.append(","); sb.append(simulatedCase.stringValue(15)); //downstream sb.append(","); sb.append(simulatedCase.stringValue(16)); //upstream sb.append(","); sb.append(simulatedCase.value(17)); //mae sb.append(","); sb.append(simulatedCase.value(18)); //rmse sb.append(","); sb.append(simulatedCase.value(19)); //rsr sb.append(","); sb.append(simulatedCase.value(20)); //pbias sb.append(","); sb.append(simulatedCase.value(21)); //ns sb.append(","); sb.append(simulatedCase.value(22)); //ioa sb.append(","); sb.append(simulatedCase.stringValue(23)); // best sb.append("\n"); } //System.out.println(sb.toString()); final Instances newds = WekaDataAccessUtil.loadInstancesFromARFFString(sb.toString(), false, false); final DatasetView view = new DatasetView("KnowledgeDB with true cases", eventPublisher, commandDispatcher, applicationContext); view.setDataSet(newds).setAsVisible(true); } catch (final Exception ee) { ee.printStackTrace(); } } }); this.rebuildKnowledgeDBButton = new JXButton("Rebuild KDB"); this.actionsForFictiveGapsPanel.add(this.rebuildKnowledgeDBButton); this.rebuildKnowledgeDBButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { rebuildKnowledgeDB(dataSet); } }); } else { throw new Exception("No date attributes in the dataset."); } }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsTabView.java
License:Open Source License
private void rebuildKnowledgeDB(final Instances dataSet) { GapFillingKnowledgeDB.clear();//from w ww . j a v a2 s. c om final int dateIdx = WekaDataStatsUtil.getFirstDateAttributeIdx(dataSet); //for (final String serie:WekaTimeSeriesUtil.getNamesOfAttributesWithoutGap(dataSet)) for (final String serie : WekaDataStatsUtil.getAttributeNames(dataSet)) { if (serie.equals("timestamp")) continue; for (int part = 1; part < PARTS_COUNT; part++) { //for (final int gapsize:new int[]{10}) //for (final int gapsize:new int[]{2,3,4,5,6,7,8,10,20,50,75,100}) //*for (final int gapsize:new int[]{2,3,4,5,6,7,8}) //for (final int gapsize:new int[]{10,20,50,75,100}) for (final int gapsize : new int[] { 40 }) { System.out.println(serie + ": part=" + part + "/" + PARTS_COUNT + " gapsize=" + gapsize); /* create a fake gap */ final Attribute attr = dataSet.attribute(serie); final int position = (part * dataSet.numInstances()) / PARTS_COUNT; /* process it for each algo and for different combination */ final GapFillingFrame jxf = new GapFillingFrame(getAbstractTabView(), new Instances(dataSet), attr, dateIdx, GapsUtil.getCountOfValuesBeforeAndAfter(gapsize), position, gapsize, gcp, true); if (!jxf.isGapSimulated()) { System.out.println("Gap already present here - skip it"); continue; } final java.util.List<GapFillingCase> l = new ArrayList<GapFillingCase>(); for (final Algo algo : Algo.values()) { System.out.println("\t" + algo); try { final int idxNearest = jxf.getUsedAttributes().indexOf(jxf.getNearest()); l.add(jxf.refresh(algo, new int[] { idxNearest })); final int idxMostSimilar = jxf.getUsedAttributes().indexOf(jxf.getMostSimilar()); l.add(jxf.refresh(algo, new int[] { idxMostSimilar })); l.add(jxf.refresh(algo, new int[] { idxNearest, idxMostSimilar })); final String up = jxf.getUpstream(); final int idxUpstream = (up != null) ? jxf.getUsedAttributes().indexOf(up) : -1; if (up != null) { l.add(jxf.refresh(algo, new int[] { idxUpstream })); l.add(jxf.refresh(algo, new int[] { idxNearest, idxUpstream })); l.add(jxf.refresh(algo, new int[] { idxMostSimilar, idxUpstream })); l.add(jxf.refresh(algo, new int[] { idxNearest, idxMostSimilar, idxUpstream })); } final String down = jxf.getDownstream(); final int idxDownstream = (down != null) ? jxf.getUsedAttributes().indexOf(down) : -1; if (down != null) { l.add(jxf.refresh(algo, new int[] { idxDownstream })); l.add(jxf.refresh(algo, new int[] { idxNearest, idxDownstream })); l.add(jxf.refresh(algo, new int[] { idxMostSimilar, idxDownstream })); l.add(jxf.refresh(algo, new int[] { idxNearest, idxMostSimilar, idxDownstream })); } if (up != null && down != null) { l.add(jxf.refresh(algo, new int[] { idxNearest, idxUpstream, idxDownstream })); l.add(jxf.refresh(algo, new int[] { idxMostSimilar, idxUpstream, idxDownstream })); l.add(jxf.refresh(algo, new int[] { idxNearest, idxMostSimilar, idxUpstream, idxDownstream })); l.add(jxf.refresh(algo, new int[] { idxUpstream, idxDownstream })); } } catch (Exception e1) { e1.printStackTrace(); } } /* mark the best solution */ double minRMSE = Double.POSITIVE_INFINITY; int minIDX = -1; for (int i = 0; i < l.size(); i++) { final GapFillingCase curr = l.get(i); if (curr.getRMSE() < minRMSE) { minRMSE = curr.getRMSE(); minIDX = i; } } if (minIDX >= 0) l.get(minIDX).setWasTheBestSolution(true); else throw new IllegalStateException("no best solution?"); GapFillingKnowledgeDB.storeCasesIntoKnowledgeDB(l); } } //break; } System.out.println("finished"); }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsUIUtil.java
License:Open Source License
public static ChartPanel buildGapChartPanelWithCorrection(final Instances pdataSet, final int dateIdx, final Attribute attr, final int gapsize, final int position, final GapFiller gapFiller, final java.util.Collection<String> attrs) throws Exception { final Instances dataSetWithTheGap = new Instances(pdataSet); for (int i = position; i < position + gapsize; i++) dataSetWithTheGap.instance(i).setMissing(attr); int[] arr = new int[] { attr.index(), dateIdx }; for (final String sss : attrs) { arr = ArraysUtil.concat(arr, new int[] { dataSetWithTheGap.attribute(sss).index() }); }/*ww w . ja v a 2s . c om*/ Instances filteredDsWithTheGap = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSetWithTheGap, arr); filteredDsWithTheGap = WekaDataProcessingUtil.buildFilteredDataSet(filteredDsWithTheGap, 0, filteredDsWithTheGap.numAttributes() - 1, Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize), Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize, filteredDsWithTheGap.numInstances() - 1)); final Instances completedds = gapFiller.fillGaps(filteredDsWithTheGap); final Instances diff = WekaTimeSeriesUtil.buildDiff(filteredDsWithTheGap, completedds); Instances filteredDsWithoutTheGap = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(pdataSet, arr); filteredDsWithoutTheGap = WekaDataProcessingUtil.buildFilteredDataSet(filteredDsWithoutTheGap, 0, filteredDsWithoutTheGap.numAttributes() - 1, Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize), Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize, filteredDsWithoutTheGap.numInstances() - 1)); diff.insertAttributeAt(new Attribute(attr.name() + "_orig"), diff.numAttributes()); for (int i = 0; i < filteredDsWithoutTheGap.numInstances(); i++) { diff.instance(i).setValue(diff.numAttributes() - 1, filteredDsWithoutTheGap.instance(i).value(filteredDsWithoutTheGap.attribute(attr.name()))); } //System.out.println(attr.name()+"\n"+diff.toSummaryString()); final java.util.List<String> toRemove = new java.util.ArrayList<String>(); for (int j = 0; j < diff.numAttributes(); j++) { final String consideredAttrName = diff.attribute(j).name(); if (!consideredAttrName.contains("timestamp") && !consideredAttrName.contains(attr.name())) toRemove.add(consideredAttrName); } diff.setClassIndex(-1); for (final String ssss : toRemove) diff.deleteAttributeAt(diff.attribute(ssss).index()); //System.out.println(attr.name()+"\n"+diff.toSummaryString()); final ChartPanel cp = TimeSeriesChartUtil.buildChartPanelForAllAttributes(diff, false, WekaDataStatsUtil.getFirstDateAttributeIdx(diff), null); final XYPlot xyp = (XYPlot) cp.getChart().getPlot(); xyp.getDomainAxis().setLabel(""); xyp.getRangeAxis().setLabel(""); final Marker gapBeginMarker = new ValueMarker( dataSetWithTheGap.instance(Math.max(0, position - 1)).value(dateIdx)); gapBeginMarker.setPaint(Color.RED); gapBeginMarker.setLabel("Gap begin"); gapBeginMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); gapBeginMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); cp.getChart().getXYPlot().addDomainMarker(gapBeginMarker); final Marker gapEndMarker = new ValueMarker(dataSetWithTheGap .instance(Math.min(dataSetWithTheGap.numInstances() - 1, position + gapsize)).value(dateIdx)); gapEndMarker.setPaint(Color.RED); gapEndMarker.setLabel("Gap end"); gapEndMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); gapEndMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT); cp.getChart().getXYPlot().addDomainMarker(gapEndMarker); addExportPopupMenu(diff, cp); return cp; }
From source file:lu.lippmann.cdb.ext.hydviga.ui.HydroDatasetView.java
License:Open Source License
private void updateFiltersPane(final Instances instances) throws Exception { filterPanel.removeAll();//from w w w. j ava2 s . c o m gbc.gridx = 0; gbc.gridy = 0; final int numAttributes = instances.numAttributes(); final RangeSlider[] rangeSliders = new RangeSlider[numAttributes]; final JComboBox[] nominalCombos = new JComboBox[numAttributes]; boolean hasNumeric = false; boolean hasDate = false; for (int i = 0; i < numAttributes; i++) { final int attrIdx = i; if ((WekaDataStatsUtil.isInteger(instances, i)) || instances.attribute(i).isDate()) { hasNumeric = hasNumeric || (instances.attribute(i).isNumeric() && !instances.attribute(i).isDate()); hasDate = hasDate || instances.attribute(i).isDate(); final long[] minmax = WekaDataStatsUtil.getMinMaxForAttribute(instances, i); if (Math.abs(minmax[1] - minmax[0]) < 0.00001) continue; if (instances.attribute(i).isDate()) { minmax[0] = (int) (minmax[0] / (1000l)); minmax[1] = (int) (minmax[1] / (1000l)); } long[] oldminmax; try { final Attribute goodAttr = notFilteredDataSet.attribute(instances.attribute(i).name()); oldminmax = WekaDataStatsUtil.getMinMaxForAttribute(notFilteredDataSet, goodAttr.index()); if (instances.attribute(i).isDate()) { oldminmax[0] = (int) (oldminmax[0] / (1000l)); oldminmax[1] = (int) (oldminmax[1] / (1000l)); } } catch (Throwable t) { oldminmax = minmax; } rangeSliders[i] = new RangeSlider(); //System.out.println("pref size -> "+this.scrollPane.getPreferredSize().getWidth()); rangeSliders[i].setPreferredSize(new Dimension(600, rangeSliders[i].getPreferredSize().height)); rangeSliders[i].setMinimum((int) oldminmax[0]); rangeSliders[i].setMaximum((int) oldminmax[1]); rangeSliders[i].setValue((int) minmax[0]); rangeSliders[i].setUpperValue((int) minmax[1]); // hack... rangeSliders[i].setValue((int) minmax[0]); rangeSliders[i].setUpperValue((int) minmax[1]); if (!instances.attribute(i).isDate()) { rangeSliders[i].setPaintTicks(true); rangeSliders[i].setPaintLabels(true); final int rangeWidth = (int) (oldminmax[1] - oldminmax[0]); rangeSliders[i].setMinorTickSpacing(rangeWidth / 10); rangeSliders[i].setMajorTickSpacing(rangeWidth / 2); } rangeSliders[i].addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent e) { if (!rangeSliders[attrIdx].getValueIsAdjusting()) { processfilters(rangeSliders, nominalCombos, instances.attribute(attrIdx).name(), attrIdx); } else { if (instances.attribute(attrIdx).isDate()) { final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(rangeSliders[attrIdx].getValue() * 1000l); final String minDate = FormatterUtil.DATE_FORMAT.format(cal.getTime()); cal.setTimeInMillis(rangeSliders[attrIdx].getUpperValue() * 1000l); final String maxDate = FormatterUtil.DATE_FORMAT.format(cal.getTime()); rangeSliders[attrIdx].setBorder(new TitledBorder(instances.attribute(attrIdx).name() + " [" + minDate + " - " + maxDate + "]")); } else { rangeSliders[attrIdx].setBorder(new TitledBorder(instances.attribute(attrIdx).name() + " [" + rangeSliders[attrIdx].getValue() + " - " + rangeSliders[attrIdx].getUpperValue() + "]")); } } } }); if (instances.attribute(i).isDate()) { filterPanel.add(rangeSliders[i], gbc); gbc.gridx++; final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(rangeSliders[i].getValue() * 1000l); final String minDate = FormatterUtil.DATE_FORMAT.format(cal.getTime()); cal.setTimeInMillis(rangeSliders[i].getUpperValue() * 1000l); final String maxDate = FormatterUtil.DATE_FORMAT.format(cal.getTime()); rangeSliders[i].setBorder(new TitledBorder( instances.attribute(i).name() + " [" + minDate + " - " + maxDate + "]")); } else { filterPanel.add(rangeSliders[i], gbc); gbc.gridx++; rangeSliders[i].setBorder(new TitledBorder(instances.attribute(i).name() + " [" + rangeSliders[i].getValue() + " - " + rangeSliders[i].getUpperValue() + "]")); } } else { rangeSliders[i] = null; } } for (int i = 0; i < numAttributes; i++) { if (instances.attribute(i).isNominal()) { final ArrayList<String> possibleValuesList = new ArrayList<String>(); final Enumeration<?> es = notFilteredDataSet .attribute(notFilteredDataSet.attribute(instances.attribute(i).name()).index()) .enumerateValues(); possibleValuesList.add(ALL_VAL); while (es.hasMoreElements()) { possibleValuesList.add(es.nextElement().toString().trim()); } if (possibleValuesList.size() == 2) continue; // only one choice, no filter needed! nominalCombos[i] = new JComboBox(possibleValuesList.toArray()); if (WekaDataStatsUtil.getPresentValuesForNominalAttribute(instances, i).size() == 1) { nominalCombos[i].setSelectedItem(instances.instance(0).stringValue(i)); } nominalCombos[i].setBorder(new TitledBorder(instances.attribute(i).name())); final int nominalAttrIdx = i; nominalCombos[i].addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { processfilters(rangeSliders, nominalCombos, instances.attribute(nominalAttrIdx).name(), nominalAttrIdx); } }); filterPanel.add(nominalCombos[i], gbc); gbc.gridx++; } } filterPanel.setVisible(gbc.gridx > 0); filterPanel.updateUI(); scrollPane.setVisible(gbc.gridx > 0); scrollPane.updateUI(); /* automatically set the timestamp range */ /*SwingUtilities.invokeLater(new Runnable() { @Override public void run() { for (int i = 0 ; i < numAttributes ; i++) { if (rangeSliders[i]!=null&&instances.attribute(i).isDate()) { System.out.println(rangeSliders[i].getValue()+" "+rangeSliders[i].getMinimum()+" "+rangeSliders[i].getUpperValue()+" "+rangeSliders[i].getMaximum()); if (rangeSliders[i].getValue()==rangeSliders[i].getMinimum()&&rangeSliders[i].getUpperValue()==rangeSliders[i].getMaximum()) { final int toadd=(rangeSliders[i].getMaximum()-rangeSliders[i].getMinimum())/2; rangeSliders[i].setValue(rangeSliders[i].getMinimum()+toadd); break; } } } } });*/ }