Welcome to sparse_som’s documentation!¶
Module contents¶
enums¶
classes¶
Self-Organizing Maps wrappers for python, intended for sparse input data.
-
class
sparse_som.
BSom
¶ Uses the batch algorithm and can take advantage from multi-core processors to learn efficiently.
Parameters: - h (int) – the network height
- w (int) – the network width
- d (int) – the dimension of input vectors
- topol (
topology.RECT
ortopology.HEXA
) – the network topology - verbose (int (0..2)) – verbosity parameter
-
train
(data, epochs=10, r0=0, rN=0.5, std=0.3, cool=cooling.LINEAR)¶ Train the network with data.
Parameters: - data (
scipy.sparse.spmatrix
) – sparse input matrix (ideallycsr_matrix
of numpy.single) - epochs (int) – number of epochs
- r0 (float) – radius at the first iteration
- rN (float) – radius at the last iteration
- cool (
cooling.LINEAR
orcooling.EXPONENTIAL
) – cooling strategy
- data (
-
bmus
(data, tg_error=False, qt_error=False)¶ Return the best match units for data.
Parameters: Returns: an array of the bmus coordinates (y,x)
Return type: 2D
numpy.ndarray
-
activation_map
(data)¶ Return the distance between each data sample and each codebook unit.
Parameters: data ( scipy.sparse.spmatrix
) – sparse input matrix (ideallycsr_matrix
of numpy.single)Returns: an array with shape (nsample, nunits) Return type: 2D numpy.ndarray
-
codebook
¶ Returns: a view of the internal codebook. Return type: 3D numpy.ndarray
-
umatrix
¶ Returns: the network U-matrix. Return type: 2D numpy.ndarray
-
class
sparse_som.
Som
¶ Uses the SD-SOM algorithm (online learning).
Parameters: - h (int) – the network height
- w (int) – the network width
- d (int) – the dimension of input vectors
- topol (
topology.RECT
ortopology.HEXA
) – the network topology - verbose (int (0..2)) – verbosity parameter
-
train
(data, tmax, r0=0, a0=0.5, rN=0.5, aN=0., std=0.3, rcool=cooling.LINEAR, acool=cooling.LINEAR)¶ Train the network with data.
Parameters: - data (
scipy.sparse.spmatrix
) – sparse input matrix (ideallycsr_matrix
of numpy.single) - tmax (int) – number of iterations
- r0 (float) – radius at the first iteration
- a0 (float) – learning-rate at the first iteration
- rN (float) – radius at the last iteration
- aN (float) – learning-rate at the last iteration
- rcool (
cooling.LINEAR
orcooling.EXPONENTIAL
) – radius cooling strategy - acool (
cooling.LINEAR
orcooling.EXPONENTIAL
) – alpha cooling strategy
- data (
-
bmus
(data, tg_error=False, qt_error=False)¶ Return the best match units for data.
Parameters: Returns: an array of the bmus coordinates (y,x)
Return type: 2D
numpy.ndarray
-
activation_map
(data)¶ Return the distance between each data sample and each codebook unit.
Parameters: data ( scipy.sparse.spmatrix
) – sparse input matrix (ideallycsr_matrix
of numpy.single)Returns: an array with shape (nsample, nunits) Return type: 2D numpy.ndarray
-
codebook
¶ Returns: a view of the internal codebook. Return type: 3D numpy.ndarray
-
umatrix
¶ Returns: the network U-matrix. Return type: 2D numpy.ndarray
Submodules¶
sparse_som.classifier module¶
-
class
sparse_som.
SomClassifier
(cls=<type 'sparse_som.som.BSom'>, height=10, width=10, dim=None, **kwargs)[source]¶ -
__init__
(cls=<type 'sparse_som.som.BSom'>, height=10, width=10, dim=None, **kwargs)[source]¶ Parameters:
-
fit
(data, labels, **kwargs)[source]¶ Training the SOM on the the data and calibrate itself.
After the training, self.quant_error and self.topog_error are respectively set.
Parameters: - data (
scipy.sparse.csr_matrix
) – sparse input matrix (ideal dtype is numpy.float32) - labels (iterable) – the labels associated with data
- **kwargs – optional parameters for
train()
- data (
-
predict
(data, unkown=None)[source]¶ Classify data according to previous calibration.
Parameters: - data (
scipy.sparse.csr_matrix
) – sparse input matrix (ideal dtype is numpy.float32) - unkown – the label to attribute if no label is known
Returns: the labels guessed for data
Return type: numpy.array
- data (
-
fit_predict
(data, labels, unkown=None)[source]¶ Fit and classify data efficiently.
Parameters: - data (
scipy.sparse.csr_matrix
) – sparse input matrix (ideal dtype is numpy.float32) - labels (iterable) – the labels associated with data
- unkown – the label to attribute if no label is known
Returns: the labels guessed for data
Return type: numpy.array
- data (
-