import numpy as np
import dimmer
from dimmer.datasets import henneberg
from dimmer.visualization import construct_histogram, construct_scatter_with_labelsVisualizations
dimmer comes with several plotting methods that create plotly interactive figures. These can be used to interrogate the output of dimmer and provide new insights.
Plotting histograms
The first step in understanding GAD or Intersecter output is to consider the distribution of their outputs. The simplest method of understanding is to construct a histogram. We show a simple example of this.
hen_pts = henneberg()
hen_gad = dimmer.GAD(radii=(1.15, 2), max_dim=2, n_jobs=3).fit(X=hen_pts)
hen_gad_ids = hen_gad.predict_labels(X=hen_pts)fig = construct_histogram(values=hen_gad_ids)
fig.show()The labels can be modified by setting the label parameter to any label. By default, the label will be formatted with the value (x-value) of the bin by using the "{value}" string. Other parameters can be added by passing in a dictionary of key-value pairs into label_template_dict, as in:
fig = construct_histogram(
values=hen_gad_ids,
label="All of the {value}-dimensional points, with {x}",
label_template_dict={"x": "nothing extra"},
)
fig.show()The standard plotly figure manipulations are valid here. The returned figure fig can be modified as any plotly figure with fig.update_traces, fig.update_layout and fig.update_scenes. For example, to one can add a title as follows.
fig.update_layout(title=dict(text="My awesome plot"))
fig.show()Specific values can be highlighted or removed from the figure by clicking on their legend entries in the top right.
The values passed into values need not be associated with dimmer at all–any 1-dimensional array of integers will be parsed.
rng = np.random.default_rng(0)
ints = rng.integers(low=-10, high=10, size=1000)
fig = construct_histogram(
values=ints, label="Number of random integers with value {value}"
)
fig.update_layout(title=dict(text="Distribution of random integers"))
fig.show()Plotting scatter plots
When applying the tools of dimmer to a high-dimensional dataset, a helpful technique is to visualize the outputs after performing some projection. In other words, we apply dimmer to the original dataset but then color the points after they’ve been projected down to 2 or 3 dimensions. This is made easier with the construct_scatter_with_labels method.
Here we show an example with 3-d data, but any dimensional data projected down into either 2 or 3 dimensions can be passed into construct_scatter_with_labels.
np.unique(hen_gad_ids)array([1, 2, 3])
fig = construct_scatter_with_labels(
X=hen_pts, values=hen_gad_ids, label="Dimension {value} points"
)
fig.show()More exotic manipulations to label names can be performed, as with all figures in plotly.
names = ["Singular points", "Boundary points", "Manifold points"]
for idx, trace in enumerate(fig.select_traces()):
fig.update_traces(
name=f"{names[idx]}", selector=dict(name=f"Dimension {idx + 1} points")
)
fig.show()