/** * Create a plot canvas with the scatter plot of given data. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of n points. * @param labels labels of points. */ public static PlotCanvas plot(double[][] data, String[] labels) { return plot(null, data, labels); }
/** * Create a plot canvas with the scatter plot of given data and specific color. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points. * @param color the color used to draw points. */ public static PlotCanvas plot(double[][] data, Color color) { return plot(null, data, color); }
/** * Create a plot canvas with the scatter plot of given data. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of n points. */ public static PlotCanvas plot(double[]... data) { return plot(null, data); }
/** * Create a plot canvas with the scatter plot of given data with specific legend. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points. * @param legend the legend used to draw points. * <ul> * <li> . : dot * <li> + : + * <li> - : - * <li> | : | * <li> * : star * <li> x : x * <li> o : circle * <li> O : large circle * <li> @ : solid circle * <li> # : large solid circle * <li> s : square * <li> S : large square * <li> q : solid square * <li> Q : large solid square * <li> others : dot * </ul> */ public static PlotCanvas plot(double[][] data, char legend) { return plot(null, data, legend); }
/** * Create a plot canvas with the scatter plot of given data with specific legend and color. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points. * @param color the color used to draw points. * @param legend the legend used to draw points. * <ul> * <li> . : dot * <li> + : + * <li> - : - * <li> | : | * <li> * : star * <li> x : x * <li> o : circle * <li> O : large circle * <li> @ : solid circle * <li> # : large solid circle * <li> s : square * <li> S : large square * <li> q : solid square * <li> Q : large solid square * <li> others : dot * </ul> */ public static PlotCanvas plot(double[][] data, char legend, Color color) { return plot(null, data, legend, color); }
/** * Create a plot canvas with the scatter plot of given data with specific legend and color. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points. * @param y the class labels of data. * @param palette the colors for each class. * @param legend the legend used to draw points. * <ul> * <li> . : dot * <li> + : + * <li> - : - * <li> | : | * <li> * : star * <li> x : x * <li> o : circle * <li> O : large circle * <li> @ : solid circle * <li> # : large solid circle * <li> s : square * <li> S : large square * <li> q : solid square * <li> Q : large solid square * <li> others : dot * </ul> */ public static PlotCanvas plot(double[][] data, int[] y, char legend, Color[] palette) { return plot(null, data, y, legend, palette); }
/** * Create a plot canvas with the scatter plot of given data with specific legend and color. * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points. * @param y the class labels of data. * @param palette the colors for each class. * @param legend the legend used to draw points. * <ul> * <li> . : dot * <li> + : + * <li> - : - * <li> | : | * <li> * : star * <li> x : x * <li> o : circle * <li> O : large circle * <li> @ : solid circle * <li> # : large solid circle * <li> s : square * <li> S : large square * <li> q : solid square * <li> Q : large solid square * <li> others : dot * </ul> */ public static PlotCanvas plot(double[][] data, int[] y, char[] legend, Color[] palette) { return plot(null, data, y, legend, palette); }
/** * Plot plot canvas. * * @param title the title * @param data the data * @return the plot canvas */ @Nonnull public static PlotCanvas plot(final String title, final double[][] data) { @Nonnull final PlotCanvas plot = ScatterPlot.plot(data); plot.setTitle(title); plot.setAxisLabels("x", "y"); plot.setSize(600, 400); return plot; }
/** * Print history. * * @param log the logger * @param history the history */ public static void printHistory(@Nonnull final NotebookOutput log, @Nonnull final List<StepRecord> history) { if (!history.isEmpty()) { log.out("Convergence Plot: "); log.eval(() -> { final DoubleSummaryStatistics valueStats = history.stream().mapToDouble(x -> x.fitness).filter(x -> x > 0).summaryStatistics(); @Nonnull final PlotCanvas plot = ScatterPlot.plot(history.stream().map(step -> new double[]{step.iteration, Math.log10(Math.max(valueStats.getMin(), step.fitness))}) .toArray(i -> new double[i][])); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Iteration", "log10(Fitness)"); plot.setSize(600, 400); return plot; }); } }
/** * Plot plot canvas. * * @param history the history * @return the plot canvas */ public static PlotCanvas plotTime(@Nonnull final List<StepRecord> history) { try { final LongSummaryStatistics timeStats = history.stream().mapToLong(x -> x.epochTime).summaryStatistics(); final DoubleSummaryStatistics valueStats = history.stream().mapToDouble(x -> x.fitness).filter(x -> x > 0).summaryStatistics(); @Nonnull final PlotCanvas plot = ScatterPlot.plot(history.stream().map(step -> new double[]{ (step.epochTime - timeStats.getMin()) / 1000.0, Math.log10(Math.max(valueStats.getMin(), step.fitness))}) .filter(x -> Arrays.stream(x).allMatch(Double::isFinite)) .toArray(i -> new double[i][])); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Time", "log10(Fitness)"); plot.setSize(600, 400); return plot; } catch (@Nonnull final Exception e) { e.printStackTrace(System.out); return null; } }
/** * Plot plot canvas. * * @param history the history * @return the plot canvas */ public static PlotCanvas plotTime(@Nonnull final List<StepRecord> history) { try { final LongSummaryStatistics timeStats = history.stream().mapToLong(x -> x.epochTime).summaryStatistics(); final DoubleSummaryStatistics valueStats = history.stream().mapToDouble(x -> x.fitness).filter(x -> x > 0).summaryStatistics(); @Nonnull final PlotCanvas plot = ScatterPlot.plot(history.stream().map(step -> new double[]{ (step.epochTime - timeStats.getMin()) / 1000.0, Math.log10(Math.max(valueStats.getMin(), step.fitness))}) .filter(x -> Arrays.stream(x).allMatch(Double::isFinite)) .toArray(i -> new double[i][])); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Time", "log10(Fitness)"); plot.setSize(600, 400); return plot; } catch (@Nonnull final Exception e) { e.printStackTrace(System.out); return null; } }
.toArray(i -> new double[i][]); if (Arrays.stream(data).mapToInt(x -> x.length).sum() == 0) return null; @Nonnull final PlotCanvas plot = ScatterPlot.plot(data); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Iteration", "log10(Fitness)"); .toArray(i -> new double[i][]); if (Arrays.stream(data).mapToInt(x -> x.length).sum() == 0) return null; @Nonnull final PlotCanvas plot = ScatterPlot.plot(data); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Iteration", "Fitness");
.toArray(i -> new double[i][]); if (Arrays.stream(data).mapToInt(x -> x.length).sum() == 0) return null; @Nonnull final PlotCanvas plot = ScatterPlot.plot(data); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Iteration", "log10(Fitness)"); .toArray(i -> new double[i][]); if (Arrays.stream(data).mapToInt(x -> x.length).sum() == 0) return null; @Nonnull final PlotCanvas plot = ScatterPlot.plot(data); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Iteration", "Fitness");
/** * Print history. * * @param log the logger * @param history the history */ public static void printHistory(@Nonnull final NotebookOutput log, @Nonnull final List<StepRecord> history) { if (!history.isEmpty()) { log.out("Convergence Plot: "); log.eval(() -> { final DoubleSummaryStatistics valueStats = history.stream().mapToDouble(x -> x.fitness).filter(x -> x > 0).summaryStatistics(); @Nonnull final PlotCanvas plot = ScatterPlot.plot(history.stream().map(step -> new double[]{step.iteration, Math.log10(Math.max(valueStats.getMin(), step.fitness))}) .toArray(i -> new double[i][])); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Iteration", "log10(Fitness)"); plot.setSize(600, 400); return plot; }); } }
/** * Plot plot canvas. * * @param history the history * @return the plot canvas */ public static PlotCanvas plotTime(@Nonnull final List<StepRecord> history) { try { final LongSummaryStatistics timeStats = history.stream().mapToLong(x -> x.epochTime).summaryStatistics(); final DoubleSummaryStatistics valueStats = history.stream().mapToDouble(x -> x.fitness).filter(x -> x > 0).summaryStatistics(); @Nonnull final PlotCanvas plot = ScatterPlot.plot(history.stream().map(step -> new double[]{ (step.epochTime - timeStats.getMin()) / 1000.0, Math.log10(Math.max(valueStats.getMin(), step.fitness))}) .filter(x -> Arrays.stream(x).allMatch(Double::isFinite)) .toArray(i -> new double[i][])); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Time", "log10(Fitness)"); plot.setSize(600, 400); return plot; } catch (@Nonnull final Exception e) { e.printStackTrace(System.out); return null; } }
/** * Print history. * * @param log the logger * @param history the history */ public static void printHistory(@Nonnull final NotebookOutput log, @Nonnull final List<StepRecord> history) { if (!history.isEmpty()) { log.out("Convergence Plot: "); log.eval(() -> { final DoubleSummaryStatistics valueStats = history.stream().mapToDouble(x -> x.fitness).filter(x -> x > 0).summaryStatistics(); @Nonnull final PlotCanvas plot = ScatterPlot.plot(history.stream().map(step -> new double[]{step.iteration, Math.log10(Math.max(valueStats.getMin(), step.fitness))}) .toArray(i -> new double[i][])); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Iteration", "log10(Fitness)"); plot.setSize(600, 400); return plot; }); } }
.toArray(i -> new double[i][]); if (Arrays.stream(data).mapToInt(x -> x.length).sum() == 0) return null; @Nonnull final PlotCanvas plot = ScatterPlot.plot(data); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Iteration", "log10(Fitness)"); .toArray(i -> new double[i][]); if (Arrays.stream(data).mapToInt(x -> x.length).sum() == 0) return null; @Nonnull final PlotCanvas plot = ScatterPlot.plot(data); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Iteration", "Fitness");