diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/404.html b/404.html new file mode 100644 index 0000000..bb4dc11 --- /dev/null +++ b/404.html @@ -0,0 +1,895 @@ + + + +
+ + + + + + + + + + + + + + + + + + +A self-organizing map (SOM) is a type of artificial neural network that is trained using unsupervised learning to produce a low-dimensional, typically two-dimensional, representation of input data. It's like a map that organizes itself to represent different patterns or features found in the input data, arranging similar data close together and dissimilar data far apart. This makes it useful for visualizing complex data in a way that highlights its inherent similarities and differences.
+SOMs can take any kind of input data as long as it can be represented as vectors of values. For example, a 28x28 MNIST image will be internally represented as a flatten vector of 784 values. You can directly pass your unflatten values to a Somap SOM so that it remembers the shape of your data during the rendering step.
+To help you test quickly your SOMs against common datasets, you can load them via somap.datasets
:
import somap as smp
+
+# Load the MNIST dataset as a Numpy array of shape (60000, 28, 28)
+data = smp.datasets.MNIST().data
+
See this page for a list of integrated datasets.
+In addition to classic bottum-up driving inputs described above, future versions of Somap will support extra inputs for lateral contextual and top-down modulatory inputs.
+In Somap, SOMs are defined by:
+The SOM algorithm involves initializing a grid of nodes, each with a randomly assigned weight vector. During training, each input data point is compared to all nodes, and the node with the weight vector most similar to the input (the "Best Matching Unit", aka BMU) is identified. The weights of this node and its neighbors are then adjusted to become more like the input data, gradually organizing the grid so that similar data points are mapped to nearby nodes.
+Different kinds of SOMs can be imagined depending on:
+The simplest SOM available in Somap is a time-independent version of the Kohonen SOM, called StaticKsom
. It is defined by 2 parameters:
sigma
: The width of the Gaussian neighborhood function around the Best Matching Unit (BMU). A larger sigma value means a wider neighborhood, where more nodes are influenced significantly during each training step. The influence of the BMU on neighboring nodes decreases with distance in a Gaussian manner, meaning nodes closer to the BMU are adjusted more significantly than those further away.alpha
: The learning rate for the SOM. It dictates how much the weights of the nodes in the network are adjusted in response to each input data point.model = smp.StaticKsom(
+ shape = (11, 13),
+ topography = "hex",
+ borderless = False,
+ input_shape = (28, 28),
+ params = smp.KsomParams(sigma=0.3, alpha=0.5)
+)
+
The classic Kohonen SOM is defined by the following parameters:
+t_f
: The final time or iteration step of the training process. It represents when the training of the SOM will end. The training typically involves gradually decreasing the learning rate and the neighborhood radius over time.sigma_i
and sigma_f
: The initial and final values of the width of the Gaussian neighborhood function around the Best Matching Unit (BMU). A larger sigma value means a wider neighborhood, where more nodes are influenced significantly during each training step. sigma_i
is larger to allow broader learning initially, and sigma_f
is smaller, focusing the learning more locally towards the end of training.alpha_i
and alpha_f
: The initial and final learning rates. The learning rate controls how much the weights of the SOM nodes are adjusted during training. A higher initial learning rate allows the network to quickly adapt to the data, while the lower final rate allows for finer adjustments as the training progresses.model = smp.Ksom(
+ shape = (11, 13),
+ topography = "hex",
+ borderless = False,
+ input_shape = (28, 28),
+ params = smp.KsomParams(
+ t_f=60000,
+ sigma_i=0.7,
+ sigma_f=0.01,
+ alpha_i=0.1,
+ alpha_f=0.001
+ )
+)
+
The Dynamic SOM was introduced by N. Rougier and Y. Boniface in 2011. It is a variation of the self-organising map algorithm where the original time-dependent (learning rate and neighbourhood) learning function is replaced by a time-invariant one. This allows for on-line and continuous learning on both static and dynamic data distributions.
+ +plasticity
: This parameter controls the overall ability of the network to adapt to new data over time. High plasticity allows the network to change rapidly in response to new data, making it more flexible but potentially less stable. Lower plasticity means slower adaptation, leading to more stability but less responsiveness to new or changing patterns in the data.alpha
: Similar to traditional SOMs, alpha in the Dynamic SOM represents the learning rate. It determines the extent to which the weights of the nodes are adjusted in response to each input data point. This parameter works in conjunction with the plasticity
parameter to regulate the network's adaptation to the input data over time.model = smp.Dsom(
+ shape = (11, 13),
+ topography = "hex",
+ borderless = False,
+ input_shape = (28, 28),
+ params = smp.DsomParams(alpha=0.001, plasticity=0.02)
+)
+
You can also define your custom SOM by choosing functions over the existing catalog:
+import somap as smp
+from jaxtyping import Array, Float
+
+class MyCustomSomParams(smp.AbstractSomParams):
+ sigma: float | Float[Array, "..."]
+ alpha: float | Float[Array, "..."]
+
+class MyCustomSom(smp.AbstractSom):
+
+ @staticmethod
+ def generate_algo(p: MyCustomSomParams) -> smp.SomAlgo:
+ return smp.SomAlgo(
+ f_dist=smp.EuclidianDist(),
+ f_nbh=smp.GaussianNbh(sigma=p.sigma),
+ f_lr=smp.ConstantLr(alpha=p.alpha),
+ f_update=smp.SomUpdate(),
+ )
+
If you need custom distance, neighborhood, learning rate and update functions for your SOM, you can define them by inheriting from smp.AbstractDist
, smp.AbstractNbh
, smp.AbstractLr
and smp.AbstractUpdate
. See the library source code for how to do it.
SOMs utilize online learning, continuously updating their weights after processing each input. Due to JAX's immutable nature, SOM models are generated as new objects at every step. Additionally, an auxiliary variable is returned, containing metrics or information for debugging purposes.
+For running a single step: +
data = ... # Array whose leading axis represents the different data examples
+
+# Do a single iteration on the first element of data
+model, aux = smp.make_step(model, {"bu_v": data[0]})
+
For running multiple steps when input data is known in advance, prefer the more optimized somap.make_steps
function:
+
data = ... # Array whose leading axis represents the different data examples
+
+# Iterate over all the elements in `data`
+model, aux = smp.make_steps(model, {"bu_v": data})
+
Somap
comes with several plotting backends to visualize a SOM.
The default plotting backend relies on the altair
plotting library. This enables the dynamic rendering of both square and hexagonal grids. Additionally, tooltips are provided to offer supplementary information when hovering the mouse over a node.
Show the prototypes: +
import matplotlib
+smp.plot(model, show_prototypes=True, show_activity=False, img_inverted_colors=True, img_cmap=matplotlib.cm.gnuplot2)
+
Show the activity of each node (how many times they have been activated): +
+ +Impact of the borderless
parameter
This is a map with borderless=False
. You can observe the unequal repartition of activity between the nodes, with a high biais toward corners and borders. A borderless map won't have this effect.
See this page for details about available options.
+This plotting backend leverages the array2image
library, offering a quicker and more direct method for rendering square grids.
To use this backend, set the following environment variable: SOMAP_PLOT_BACKEND=array2image
See this page for details about available options.
+Evaluating SOMs typically involves the following metrics:
+Those metrics are available in the auxilarry data returned by the somap.make_step
and somap.make_steps
functions.
# Iterate over all the elements in `data`
+model, aux = smp.make_steps(model, {"bu_v": data})
+
+# Retrieve the errors from all steps
+quantization_errors = aux["metrics"]["quantization_error"]
+topographic_errors = aux["metrics"]["topographic_error"]
+
You can save and load SOM models via the following functions (which act as a pass-through the corresponding Equinox functions because SOM models are Equinox modules).
+ + + + + + + + + + + + + + +Abstract base classes for defining SOMs.
+ + + +AbstractSom
+
+
+
+ Bases: Module
Abstract base class for SOM models.
+ +src/somap/core.py
50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 |
|
__call__(input)
+
+Makes a single iteration.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
input |
+
+ InputData
+ |
+
+
+
+ Data array for the given SOM models. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ | +
+
+
+ A tuple with the new SOM model and the auxilary data. + |
+
src/somap/core.py
115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 |
|
__init__(shape, topography, borderless, input_shape, params, metrics=True, debug=False, key=jax.random.PRNGKey(0))
+
+Creates a SOM models.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
shape |
+ + | +
+
+
+ Shape of the 2D map. + |
+ + required + | +
topography |
+ + | +
+
+
+ Topography of the 2D map. Either 'square' for a square grid +or 'hex' for hexagonal grid. + |
+ + required + | +
borderless |
+ + | +
+
+
+ Toroidal topography if True, meaning that the top (resp. left) +border meets the bottom (resp. right) border. + |
+ + required + | +
input_shape |
+ + | +
+
+
+ Shape of the input data. + |
+ + required + | +
params |
+ + | +
+
+
+ Parameters of the SOM (depends on the SOM flavor). + |
+ + required + | +
metrics |
+ + | +
+
+
+ If True, returns quantization and topographic errors as auxilary +data. + |
+
+ True
+ |
+
debug |
+ + | +
+
+
+ If True, returns debug data as auxilary data. + |
+
+ False
+ |
+
key |
+
+ PRNGKeyArray
+ |
+
+
+
+ JAX random key used during map initialization. + |
+
+ PRNGKey(0)
+ |
+
src/somap/core.py
bulk_set(attr_dict)
+
+Sets multiples attributes at once.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
attr_dict |
+ + | +
+
+
+ dictionary where keys are attribute names and values are +attributes values to be set. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ | +
+
+
+ A new instance of the updated object. + |
+
src/somap/core.py
generate_algo(params)
+
+Converts specific SOM parameters into generic SOM functions.
+ + +set(attribute, value)
+
+Sets an attribute to a specific value.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
attribute |
+
+ str
+ |
+
+
+
+ name of the attribute. + |
+ + required + | +
value |
+ + | +
+
+
+ new value of the attribute. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ | +
+
+
+ A new instance of the updated object. + |
+
src/somap/core.py
AbstractSomParams
+
+
+InputData
+
+
+
+ Bases: TypedDict
Structure of the input data.
+ +Classical SOMs only have the 'bu_v' bottum-up input value. +Other inputs allow to create more complex SOMs receiving top-down and lateral +inputs with a mask.
+TypedDict instead of dataclass to facilitate future modifications.
+src/somap/core.py
SomAlgo
+
+
+make_step(model, input)
+
+Makes a single iteration.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
model |
+
+ AbstractSom
+ |
+
+
+
+ SOM model. + |
+ + required + | +
input |
+
+ InputData
+ |
+
+
+
+ Data array for the given SOM models. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ | +
+
+
+ A tuple with the new SOM model and the auxilary data. + |
+
src/somap/core.py
make_steps(model, inputs)
+
+Makes multiple iterations at once.
+Uses the jax.lax.scan()
function to optimize computations.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
model |
+
+ AbstractSom
+ |
+
+
+
+ SOM model. + |
+ + required + | +
inputs |
+ + | +
+
+
+ Batch data array for the given SOM models. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ | +
+
+
+ A tuple with the new SOM model and the auxilary data. + |
+
src/somap/core.py
Ready-to-use datasets.
+A set of toy datasets formated for somap
Self-Organizing Maps.
Digits
+
+
+
+ Bases: SomDataset
Kind of mini-MNIST.
+~2k grayscale 8x8 images of digits from 0 to 9.
+ +src/somap/datasets/mnist.py
__init__()
+
+Loads the mini-MNIST dataset from scikit-learn.
+ +src/somap/datasets/mnist.py
MNIST
+
+
+
+ Bases: SomDataset
Classic MNIST.
+60k grayscale 28x28 images of digits from 0 to 9.
+ +src/somap/datasets/mnist.py
__init__()
+
+Loads the classic MNIST dataset.
+ +src/somap/datasets/mnist.py
Catalog of distance functions.
+dist
means distance
+wdist
means weighted distance
All distance functions are defined for comparison between 2 1D vectors.
+ + + +AbstractDist
+
+
+
+ Bases: Module
Ensures that all distance functions have the same signatures.
+ +src/somap/distance.py
__call__(a, b)
+
+
+ abstractmethod
+
+
+SOM distance function.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
a |
+
+ Float[Array, ' n']
+ |
+
+
+
+ 1D array. + |
+ + required + | +
b |
+
+ Float[Array, ' n']
+ |
+
+
+
+ 1D array. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Float[Array, '']
+ |
+
+
+
+ The distance as a scalar. + |
+
src/somap/distance.py
CyclicEuclidianDist
+
+
+
+ Bases: AbstractDist
Cyclic euclidian distance function.
+ +src/somap/distance.py
__call__(a, b)
+
+Returns a cyclic euclidian distance where 0 and 1 are equals.
+More optimized than the arccos(cos())
based cyclic distance.
+Takes advantage of data type's limits.
src/somap/distance.py
EuclidianDist
+
+
+
+ Bases: AbstractDist
Euclidian distance function.
+ +src/somap/distance.py
__call__(a, b)
+
+dist_cim(v1, v2, sigma)
+
+The Correntropy Induced Metric (CIM) distance.
+It is based on correntropy which is a generalized correlation. +It computes the distance between two vectors without suffering from the curse of +dimensionality like the Euclidian distance thanks to a kernel function. +The chosen kernel is a Gaussian function (parameterised by 'sigma'). +For large sigma, the CIM distance tends to the L2 metric. +For very small sigma, the CIM distance tends to the L0 norm.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
v1 |
+ + | +
+
+
+ first vector to be compared + |
+ + required + | +
v2 |
+ + | +
+
+
+ second vector to be compared + |
+ + required + | +
sigma |
+ + | +
+
+
+ kernel bandwidth + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ | +
+
+
+ A scalar value between 0 and 1 corresponding to the similarity between v1 and v2 + |
+
Raises:
+Type | +Description | +
---|---|
+ ValueError
+ |
+
+
+
+ incompatible shapes of v1 and v2 + |
+
src/somap/distance.py
wdist_l2(a, b, w)
+
+Computes a weighted version of the euclidian norm.
+ +src/somap/distance.py
Catalog of learning rate functions.
+ + + +AbstractLr
+
+
+
+ Bases: Module
Ensures that all learning rate functions have the same signatures.
+ +src/somap/learning_rate.py
__call__(t, distances)
+
+
+ abstractmethod
+
+
+SOM learning rate function.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
t |
+
+ Integer[Array, '']
+ |
+
+
+
+ Current iteration. + |
+ + required + | +
distances |
+
+ Float[Array, 'x y']
+ |
+
+
+
+ Distances between the prototype weights and the input data. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Float[Array, ''] | Float[Array, 'x y']
+ |
+
+
+
+ A scalar ar 2D array containing the learning rate. + |
+
src/somap/learning_rate.py
ConstantLr
+
+
+
+ Bases: AbstractLr
Basic SOM learning rate function.
+ +src/somap/learning_rate.py
DsomLr
+
+
+
+ Bases: AbstractLr
DSOM learning rate function.
+ +src/somap/learning_rate.py
KsomLr
+
+
+
+ Bases: AbstractLr
Kohonen SOM learning rate function.
+ +src/somap/learning_rate.py
__call__(t, _)
+
+Catalog of neighborhood functions.
+Neighborhood functions are defined as equinox.Module
parametrized functions
AbstractNbh
+
+
+
+ Bases: Module
Ensures that all neighborhood functions have the same signatures.
+ +src/somap/neighborhood.py
__call__(distance_map, t, quantization_error)
+
+
+ abstractmethod
+
+
+SOM Neighborhood function.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
distance_map |
+
+ Float[Array, 'x y']
+ |
+
+
+
+ Distance of each grid elements from the winning element. + |
+ + required + | +
t |
+
+ Integer[Array, '']
+ |
+
+
+
+ Current iteration. + |
+ + required + | +
quantization_error |
+
+ Float[Array, '']
+ |
+
+
+
+ The computed difference between the winner prototype +and the input. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Float[Array, 'x y']
+ |
+
+
+
+ The neighborhood distance. + |
+
src/somap/neighborhood.py
DsomNbh
+
+
+
+ Bases: AbstractNbh
Dynamic Kohonen neighborhood function.
+ +src/somap/neighborhood.py
__call__(distance_map, _, quantization_error)
+
+Computes the Dynamic SOM neighboring value of each grid element.
+ +Nicolas P. Rougier, Yann Boniface. Dynamic Self-Organising Map. +Neurocomputing, Elsevier, 2011, 74 (11), pp.1840-1847. +ff10.1016/j.neucom.2010.06.034ff. ffinria-00495827
+Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
self |
+ + | +
+
+
+ self.plasticity: Dynamic value to compute the neighbourhood distance. + |
+ + required + | +
distance_map |
+
+ Float[Array, 'x y']
+ |
+
+
+
+ Distance of each element from the winner element. + |
+ + required + | +
_ |
+ + | +
+
+
+ Not used + |
+ + required + | +
quantization_error |
+
+ Float[Array, '']
+ |
+
+
+
+ The computed difference between the winner prototype +and the input. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Float[Array, 'x y']
+ |
+
+
+
+ The neighborhood distance, as calculated in the article. + |
+
src/somap/neighborhood.py
GaussianNbh
+
+
+
+ Bases: AbstractNbh
Exponentially decreasing neighborhood function.
+ +src/somap/neighborhood.py
__call__(distance_map, t, __)
+
+Return the Kohonen time-independent neighboring value of each element.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
self |
+ + | +
+
+
+ Module's parameters +self.sigma: Neighbourhood distance. + |
+ + required + | +
distance_map |
+
+ Float[Array, 'x y']
+ |
+
+
+
+ Distance of each element from the winner element. + |
+ + required + | +
t |
+ + | +
+
+
+ Not used + |
+ + required + | +
__ |
+ + | +
+
+
+ Not used + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Float[Array, 'x y']
+ |
+
+
+
+ The kohonen neighborhood distance. + |
+
src/somap/neighborhood.py
KsomNbh
+
+
+
+ Bases: AbstractNbh
Kohonen neighborhood function.
+ +src/somap/neighborhood.py
__call__(distance_map, t, _)
+
+Returns the Kohonen neighboring value of each element.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
self |
+ + | +
+
+
+ Module's parameters +self.t_f: Aimed iteration. +self.sigma_i: Current neighborhood distance. +self.sigma_f: Aimed neighborhood distance. + |
+ + required + | +
distance_map |
+
+ Float[Array, 'x y']
+ |
+
+
+
+ Distance of each grid elements from the winning element. + |
+ + required + | +
t |
+
+ Integer[Array, '']
+ |
+
+
+
+ Current iteration. + |
+ + required + | +
_ |
+ + | +
+
+
+ Not used + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Float[Array, 'x y']
+ |
+
+
+
+ The kohonen neighborhood distance. + |
+
src/somap/neighborhood.py
MexicanHatNbh
+
+
+
+ Bases: AbstractNbh
Mexican Hat neighborhood function.
+ +src/somap/neighborhood.py
__call__(distance_map, _, __)
+
+Computes the Mexican Hat neighboring value of each grid element.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
self |
+ + | +
+
+
+ self.sigma: Scale factor for the spread of the neighborhood. + |
+ + required + | +
distance_map |
+
+ Float[Array, 'x y']
+ |
+
+
+
+ Distance of each element from the winner element. + |
+ + required + | +
_ |
+ + | +
+
+
+ Not used + |
+ + required + | +
__ |
+ + | +
+
+
+ Not used + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Float[Array, 'x y']
+ |
+
+
+
+ The Mexican Hat neighborhood distance. + |
+
src/somap/neighborhood.py
Plot functions for somap.Som objects.
+ + + +plot(som, *args, **kwargs)
+
+Returns a graph/plot object of the SOM.
+Extra args depend on the chosen backend.
+See .plot_backends.{name_of_backend}
for details.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
som |
+
+ AbstractSom
+ |
+
+
+
+ Self-Organizing Map as a Som object. + |
+ + required + | +
args |
+ + | +
+
+
+ Positional arguments passed to the |
+
+ ()
+ |
+
kwargs |
+ + | +
+
+
+ Keyword arguments passed to the |
+
+ {}
+ |
+
src/somap/plot.py
save_plot(som, filename, *args, **kwargs)
+
+Saves a graph/plot image of the SOM.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
som |
+
+ AbstractSom
+ |
+
+
+
+ Self-Organizing Map as a Som object. + |
+ + required + | +
filename |
+
+ str | IO
+ |
+
+
+
+ File in which to write the chart. + |
+ + required + | +
args |
+ + | +
+
+
+ Positional arguments passed to the |
+
+ ()
+ |
+
kwargs |
+ + | +
+
+
+ Keyword arguments passed to the |
+
+ {}
+ |
+
src/somap/plot.py
Abstract base class for plot backends.
+ + + +AbstractSomPlot
+
+
+
+ Bases: ABC
SomPlot.
+ +src/somap/plot_backends/base.py
__init__(som, *, show_prototypes=True, show_activity=False, **kwargs)
+
+
+ abstractmethod
+
+
+Creates a SomPlot.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
som |
+ + | +
+
+
+ Self-Organizing Map as a Som object. + |
+ + required + | +
args |
+ + | +
+
+
+ Positional arguments passed to the |
+ + required + | +
show_prototypes |
+ + | +
+
+
+ Show prototypes of each node as an image. + |
+
+ True
+ |
+
show_activity |
+ + | +
+
+
+ Show activity value of each node as a color. + |
+
+ False
+ |
+
kwargs |
+ + | +
+
+
+ Keyword arguments passed to the |
+
+ {}
+ |
+
src/somap/plot_backends/base.py
plot()
+
+
+ abstractmethod
+
+
+Altair plot backends.
+ + + +SomPlot
+
+
+
+ Bases: AbstractSomPlot
SomPlot.
+ +src/somap/plot_backends/altair.py
__init__(som, *, show_prototypes=True, show_activity=False, **kwargs)
+
+Creates a SomPlot.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
som |
+
+ AbstractSom
+ |
+
+
+
+ Self-Organizing Map as a Som object. + |
+ + required + | +
args |
+ + | +
+
+
+ Positional arguments passed to the |
+ + required + | +
show_prototypes |
+ + | +
+
+
+ Show prototypes of each node as an image. + |
+
+ True
+ |
+
show_activity |
+ + | +
+
+
+ Show activity value of each node as a color. + |
+
+ False
+ |
+
kwargs |
+ + | +
+
+
+ Keyword arguments passed to the |
+
+ {}
+ |
+
src/somap/plot_backends/altair.py
plot()
+
+plot(data, shape, topography, *, bin_size_scale=1.0, w_scale=1.0, h_scale=1.0, values=True, images=True, tooltip=True, color_scale=alt.Scale(scheme='lighttealblue'), color_legend=None, title=None)
+
+Return an Altair chart containing shape[0] * shape[1] hexagons.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
data |
+
+ DataFrame
+ |
+
+
+
+ Pandas dataframe with the following columns: +x: Horizontal coordinate in the hex grid. +y: Vertical coordonates in the hex grid. +values: one scalar value per hexagon (optional). +images: one encoded image per hexagon (optional). +image: one encoded image per hexagon (for tooltip) (optional). +infos: one text value per hexagon(optional). + |
+ + required + | +
shape |
+
+ tuple[int, int]
+ |
+
+
+
+ column and line numbers of the hex grid. + |
+ + required + | +
topography |
+
+ str
+ |
+
+
+
+ Topography of the 2D map, either 'square' or 'hex'. + |
+ + required + | +
bin_size_scale |
+
+ float
+ |
+
+
+
+ size of the hexagons. + |
+
+ 1.0
+ |
+
w_scale |
+
+ float
+ |
+
+
+
+ horizontal scaling factor (sometimes needed to go around rendering +bugs of external libs). + |
+
+ 1.0
+ |
+
h_scale |
+
+ float
+ |
+
+
+
+ vertical scaling factor (sometimes needed to go around rendering bugs +of external libs). + |
+
+ 1.0
+ |
+
values |
+
+ bool
+ |
+
+
+
+ if True, fill the hexagons with a color corresponding to data['values']. + |
+
+ True
+ |
+
images |
+
+ bool
+ |
+
+
+
+ if True, show the image of all hexagon with an image corresponding to +data['images']. + |
+
+ True
+ |
+
tooltip |
+
+ bool
+ |
+
+
+
+ if True, show an interactive tooltip given detailed values of the +selected hexagon + |
+
+ True
+ |
+
color_scale |
+
+ Scale
+ |
+
+
+
+ color scale used if color is True. Continous scale from light blue +to dark blue by default. + |
+
+ Scale(scheme='lighttealblue')
+ |
+
color_legend |
+
+ Legend | None
+ |
+
+
+
+ arr color legend used if color is True. Dynamic legend by default. +(set to 'None' to hide the legend). + |
+
+ None
+ |
+
title |
+
+ str | None
+ |
+
+
+
+ Title of the plot. + |
+
+ None
+ |
+
Returns:
+Type | +Description | +
---|---|
+ LayerChart
+ |
+
+
+
+ The altair chart. + |
+
src/somap/plot_backends/altair.py
54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 |
|
Array2image plot backends.
+ + + +SomPlot
+
+
+
+ Bases: AbstractSomPlot
SomPlot.
+ +src/somap/plot_backends/array2image.py
__init__(som, *, show_prototypes=True, show_activity=False, **kwargs)
+
+Creates a SomPlot.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
som |
+
+ AbstractSom
+ |
+
+
+
+ Self-Organizing Map as a Som object. + |
+ + required + | +
args |
+ + | +
+
+
+ Positional arguments passed to the |
+ + required + | +
show_prototypes |
+ + | +
+
+
+ Show prototypes of each node as an image. + |
+
+ True
+ |
+
show_activity |
+ + | +
+
+
+ Show activity value of each node as a color. + |
+
+ False
+ |
+
kwargs |
+ + | +
+
+
+ Keyword arguments passed to the |
+
+ {}
+ |
+
src/somap/plot_backends/array2image.py
plot()
+
+add_text_border(image, text, border_height=50, font_size=20, font_path=FONT_PATH)
+
+Adds a header with a text to an image.
+ +src/somap/plot_backends/array2image.py
Loading and saving functions.
+ + + +load(path_or_file, model_like)
+
+Loads model data contained in a file into a model_like
structure.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
path_or_file |
+ + | +
+
+
+ The file location to save values to or a binary file-like object. + |
+ + required + | +
model_like |
+ + | +
+
+
+ A PyTree model of same structure, and with leaves of the same type, +as the PyTree being loaded. Those leaves which are loaded will replace the +corresponding leaves of like. + |
+ + required + | +
src/somap/serialisation.py
save(path_or_file, model)
+
+Saves model data to file.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
path_or_file |
+ + | +
+
+
+ The file location to save values to or a binary file-like object. + |
+ + required + | +
model |
+ + | +
+
+
+ The PyTree model whose leaves will be saved + |
+ + required + | +
src/somap/serialisation.py
Catalog of different flavors of SOMs.
+To add a new SOMs, define the 2 following classes: +
+ + + +Dsom
+
+
+
+ Bases: AbstractSom
Dynamic SOM.
+ +src/somap/som.py
generate_algo(p)
+
+
+ staticmethod
+
+
+Converts Dynamic SOM parameters into generic SOM functions.
+ +src/somap/som.py
DsomParams
+
+
+
+ Bases: AbstractSomParams
Dynamic SOM parameters.
+ +src/somap/som.py
Ksom
+
+
+
+ Bases: AbstractSom
Kohonen SOM.
+ +src/somap/som.py
generate_algo(p)
+
+
+ staticmethod
+
+
+Converts Kohonen SOM parameters into generic SOM functions.
+ +src/somap/som.py
KsomParams
+
+
+
+ Bases: AbstractSomParams
Kohonen SOM parameters.
+ +src/somap/som.py
Som
+
+
+
+ Bases: AbstractSom
Generic SOM.
+Distance, neighborhood, learning rate and update functions are directly specified. +This is the more flexible way of defining a SOM.
+ +src/somap/som.py
generate_algo(p)
+
+
+ staticmethod
+
+
+Identity function returning generic SOM functions.
+ + +SomParams
+
+
+
+ Bases: AbstractSomParams
, SomAlgo
Generic SOM parameters.
+Same as the SomAlgo
class but with the AbstractSomParams
parent.
StaticKsom
+
+
+
+ Bases: AbstractSom
Time-independant Kohonen SOM.
+ +src/somap/som.py
generate_algo(p)
+
+
+ staticmethod
+
+
+Converts Static Kohonen SOM parameters into generic SOM functions.
+ +src/somap/som.py
StaticKsomParams
+
+
+
+ Bases: AbstractSomParams
Time-independant Kohonen SOM parameters.
+ +src/somap/som.py
Catalog of update functions.
+ + + +AbstractUpdate
+
+
+
+ Bases: Module
Ensures that all update functions have the same signatures.
+ +src/somap/update.py
__call__(lr, nbh, input_bu, w_bu)
+
+
+ abstractmethod
+
+
+SOM Update function.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
lr |
+ + | +
+
+
+ Learning rate. + |
+ + required + | +
nbh |
+ + | +
+
+
+ Neighborhood. + |
+ + required + | +
input_bu |
+ + | +
+
+
+ Data input. + |
+ + required + | +
w_bu |
+ + | +
+
+
+ Prototype weights. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ | +
+
+
+ The updated prototype weights. + |
+
src/somap/update.py
CyclicSomUpdate
+
+
+
+ Bases: AbstractUpdate
Cyclic update functions.
+ +src/somap/update.py
__call__(lr, nbh, input_bu, w_bu)
+
+Updates the prototype weights where 0 is the same as 1.
+ +src/somap/update.py
SomUpdate
+
+
+
+ Bases: AbstractUpdate
Generic update function.
+ +src/somap/update.py
__call__(lr, nbh, input_bu, w_bu)
+
+Updates the prototype weights.
+ +src/somap/update.py