Search code examples
javaelki

Elki plots from pure Java API


I've been searching for a way to export ELKI generated visualization into SVG file, which can later be displayed on my application. However, I could not find any example code which uses typical java constructors. My goals are:

  • input Results in a Visualization.
  • set VisualizerParameterizer constructor, adding the previous Visualization.
  • set ExportVisualizations constructor properly to write the file.

For instance, let's say I already have an OutlierResult instance and now I want to plot the scores using BubbleVisualization and produce an SVG file? How can I do that using the pure Java API?


Solution

  • Some classes like VisualizerParameterizer can be a bit annoying to set up manually, because this involves finding all desired visualization factories from the service loader - there is a plug-in layer there, that allows to add new visualizations to be rendered automatically.

    Because of this, the easiest way is to use the parameterization API, for example (git style):

    ExportVisualizations export = new ELKIBuilder<>(ExportVisualizations.class)
        .with(ExportVisualizations.Parameterizer.FOLDER_ID, "folder")
        .build();
    

    or if you are still using an old release / do not like builders:

    ListParameterization params = new ListParameterization();
    params.addParameter(ExportVisualizations.Parameterizer.FOLDER_ID, "folder");
    ExportVisualizations export = ClassGenericsUtil.parameterizeOrAbort(
                                      ExportVisualizations.class, params);
    

    Because you only need to give mandatory parameters, and it can construct nested objects. In this case, it will also construct the VisualizerParameterizer, so you can also add options for that class, such as

    .with(VisualizerParameterizer.Parameterizer.ENABLEVIS_ID, "scatter")
    

    to only enable scatter plot visualizations.