public XChartPanel buildPanel() throws IOException { System.out.println("fetching data..."); updateData(); // create chart Chart chart = new ChartBuilder() .chartType(ChartType.Area) .width(800) .height(400) .title("Real-time Bitcoinium Order Book - BITSTAMP_BTC_USD") .xAxisTitle("BTC") .yAxisTitle("USD") .build(); chart.getStyleManager().setLegendPosition(LegendPosition.InsideNE); // add series Series series = chart.addSeries(BIDS_SERIES_NAME, xAxisBidData, yAxisBidData); series.setMarker(SeriesMarker.NONE); series = chart.addSeries(ASKS_SERIES_NAME, xAxisAskData, yAxisAskData); series.setMarker(SeriesMarker.NONE); return new XChartPanel(chart); }
@Override public Chart getChart() { // Create Chart Chart chart = new Chart(800, 600); // generates linear data Collection<Date> xData = new ArrayList<Date>(); Collection<Number> yData = new ArrayList<Number>(); DateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); Date date = null; for (int i = 1; i <= 10; i++) { try { date = sdf.parse(i + ".10.2008"); } catch (ParseException e) { e.printStackTrace(); } xData.add(date); yData.add(Math.random() * i); } // Customize Chart chart.setChartTitle("LineChart03"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); chart.getStyleManager().setPlotBackgroundColor(ChartColor.getAWTColor(ChartColor.GREY)); chart.getStyleManager().setPlotGridLinesColor(new Color(255, 255, 255)); chart.getStyleManager().setChartBackgroundColor(Color.WHITE); chart.getStyleManager().setLegendBackgroundColor(Color.PINK); chart.getStyleManager().setChartFontColor(Color.MAGENTA); chart.getStyleManager().setChartTitleBoxBackgroundColor(new Color(0, 222, 0)); chart.getStyleManager().setChartTitleBoxVisible(true); chart.getStyleManager().setChartTitleBoxBorderColor(Color.BLACK); chart.getStyleManager().setPlotGridLinesVisible(false); chart.getStyleManager().setAxisTickPadding(20); chart.getStyleManager().setAxisTickMarkLength(15); chart.getStyleManager().setPlotPadding(20); chart.getStyleManager().setChartTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24)); chart.getStyleManager().setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18)); chart.getStyleManager().setLegendPosition(LegendPosition.InsideSE); chart.getStyleManager().setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18)); chart.getStyleManager().setAxisTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11)); chart.getStyleManager().setDatePattern("dd-MMM"); chart.getStyleManager().setNormalDecimalPattern("#0.000"); chart.getStyleManager().setLocale(Locale.GERMAN); Series series = chart.addDateSeries("Fake Data", xData, yData); series.setLineColor(SeriesColor.BLUE); series.setMarkerColor(Color.ORANGE); series.setMarker(SeriesMarker.CIRCLE); series.setLineStyle(SeriesLineStyle.SOLID); return chart; }
@Override public Chart getChart() { // Create Chart Chart chart = new Chart(800, 600); // Customize Chart chart.setChartTitle("LineChart05"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); chart.getStyleManager().setLegendPosition(LegendPosition.InsideSW); double[] xData = new double[] {0.0, 1.0, 2.0, 3.0, 4.0, 5, 6}; double[] yData = new double[] {106, 44, 26, 10, 7.5, 3.4, .88}; double[] yData2 = new double[] {102, 49, 23.6, 11.3, 5.4, 2.6, 1.25}; Series series = chart.addSeries("A", xData, yData); series.setLineStyle(SeriesLineStyle.NONE); series.setMarker(SeriesMarker.DIAMOND); series.setMarkerColor(Color.BLACK); Series series2 = chart.addSeries("B", xData, yData2); series2.setMarker(SeriesMarker.NONE); series2.setLineStyle(SeriesLineStyle.DASH_DASH); series2.setLineColor(Color.BLACK); chart.getStyleManager().setYAxisLogarithmic(true); chart.getStyleManager().setYAxisMin(0.01); chart.getStyleManager().setYAxisMax(1000); chart.getStyleManager().setXAxisMin(2); chart.getStyleManager().setXAxisMax(7); return chart; }
private void go() throws IOException { // initialize the ahahNode double readPeriod = 1E-5; // increase the learning rate from default double writePeriod = 1E-5; int numBias = 15; int numInputs = 70; // max number of inputs/spikes MemristorType memristorType = MemristorType.AgChalc; AHaH21Circuit ahahNodeCircuit = new AHaH21CircuitBuilder() .numInputs(numInputs) .numBiasInputs(numBias) .readPeriod(readPeriod) .writePeriod(writePeriod) .memristorType(memristorType) .build(); // initialize the feature factory. This code converts the raw data to a spiking representation. BreastCancerSpikeEncoder breastCancerSpikeEncoder = new BreastCancerSpikeEncoder(); SpikeConverter spikeConverter = new SpikeConverter(); // converts the spike code produced by the feature factory to one that // can be used by the circuit. // train the classifier---> List<BreastCancer> breastCancerTrainingData = BreastCancerDAO.selectTrainData(); System.out.println("Learning..."); for (BreastCancer breastCancer : breastCancerTrainingData) { String[] topicTrueLabels = new String[1]; topicTrueLabels[0] = breastCancer.getCellClass() + ""; long[] spikes = breastCancerSpikeEncoder.encode(breastCancer); // get the spike representation Set<Integer> convertedSpikes = spikeConverter.convert(spikes); int superviseSignal = 0; if (breastCancer.getCellClass() == 2) { superviseSignal = 1; } else { superviseSignal = -1; } System.out.println("Spike Pattern Length = " + convertedSpikes.size()); // System.out.println("Spikes = " + Arrays.toString(convertedSpikes.toArray())); double y = ahahNodeCircuit.update(convertedSpikes, superviseSignal); } System.out.println("Spike Pattern Space = " + breastCancerSpikeEncoder.getSpikePatternSpace()); // Test the classifier List<BreastCancer> breastCancerTestData = BreastCancerDAO.selectTestData(); System.out.println("Testing..."); Set<String> labels = new HashSet<String>(); // these are the labels we are evaluating the performance of labels.add("2"); labels.add("4"); // we are testing the performance for a range of confidence values, from 0 to 1. int numSteps = 100; double[] confidenceThresholds = new double[numSteps]; double inc = .061 / numSteps; for (int i = 0; i < confidenceThresholds.length; i++) { confidenceThresholds[i] = i * inc; } // create evaluators for keeping track of performance ClassificationEvaluator[] evaluators = new ClassificationEvaluator[numSteps]; for (int i = 0; i < evaluators.length; i++) { evaluators[i] = new ClassificationEvaluator(labels); } // run through the test set for (BreastCancer breastCancer : breastCancerTestData) { long[] spikes = breastCancerSpikeEncoder.encode(breastCancer); Set<Integer> convertedSpikes = spikeConverter.convert(spikes); double y = ahahNodeCircuit.update(convertedSpikes, 0); // NOTE: no supervised labels are passed here. // true labels for evaluation. Set<String> trueLabels = new HashSet<String>(); trueLabels.add(breastCancer.getCellClass() + ""); for (int i = 0; i < evaluators.length; i++) { List<String> labelOutput = new ArrayList<String>(); if (y > confidenceThresholds[i]) { labelOutput.add("2"); } else if (y < -confidenceThresholds[i]) { labelOutput.add("4"); } evaluators[i].update(trueLabels, labelOutput); } } // plot results----> double maxF1 = 0; int cIdx = 0; double[] accuracy = new double[numSteps]; double[] precision = new double[numSteps]; double[] recall = new double[numSteps]; double[] f1 = new double[numSteps]; for (int i = 0; i < numSteps; i++) { accuracy[i] = evaluators[i].getAccuracyMicroAve(); precision[i] = evaluators[i].getPrecisionMicroAve(); recall[i] = evaluators[i].getRecallMicroAve(); f1[i] = evaluators[i].getF1MicroAve(); if (f1[i] > maxF1) { // get the best confidence threshold maxF1 = f1[i]; cIdx = i; } } Chart chart = new Chart(300, 300, ChartTheme.Matlab); // chart.setChartTitle("Wisconsin Breast Cancer Benchmark - F1=" + df.format(maxF1) + " // w/ConfidenceThreshold=" + df.format(confidenceThresholds[cIdx])); chart.setChartTitle("Breast Cancer - Circuit"); chart.setXAxisTitle("Confidence Threshold"); chart.setYAxisTitle("Score"); chart.getStyleManager().setLegendPosition(LegendPosition.InsideSW); Series accuracy_series = chart.addSeries("Accuracy", confidenceThresholds, accuracy); accuracy_series.setMarker(SeriesMarker.NONE); Series precision_series = chart.addSeries("Precision", confidenceThresholds, precision); precision_series.setMarker(SeriesMarker.NONE); Series recall_series = chart.addSeries("Recall", confidenceThresholds, recall); recall_series.setMarker(SeriesMarker.NONE); Series f1_series = chart.addSeries("F1", confidenceThresholds, f1); f1_series.setMarker(SeriesMarker.NONE); BitmapEncoder.savePNGWithDPI(chart, "./PLOS_AHAH/Figures/Breast_Cancer_Circuit.png", 300); new SwingWrapper(chart).displayChart(); }