apollon.som.som module¶
-
class
apollon.som.som.BatchMap(dims: Tuple[int, int, int], n_iter: int, eta: float, nhr: float, nh_shape: str = 'gaussian', init_weights: Union[Callable[[numpy.ndarray, Tuple[int, int]], numpy.ndarray], str] = 'rnd', metric: Union[Callable[[numpy.ndarray, numpy.ndarray], float], str] = 'euclidean', seed: Optional[int] = None)¶ Bases:
apollon.som.som.SomBase
-
class
apollon.som.som.IncrementalKDTReeMap(dims: tuple, n_iter: int, eta: float, nhr: float, nh_shape: str = 'star2', init_distr: str = 'uniform', metric: str = 'euclidean', seed: Optional[int] = None)¶ Bases:
apollon.som.som.SomBase-
fit(train_data, verbose=False)¶ Fit SOM to input data.
-
-
class
apollon.som.som.IncrementalMap(dims: Tuple[int, int, int], n_iter: int, eta: float, nhr: float, nh_shape: str = 'gaussian', init_weights: Union[Callable[[numpy.ndarray, Tuple[int, int]], numpy.ndarray], str] = 'rnd', metric: Union[Callable[[numpy.ndarray, numpy.ndarray], float], str] = 'euclidean', seed: Optional[int] = None)¶ Bases:
apollon.som.som.SomBase-
fit(train_data, verbose=False, output_weights=False)¶
-
-
class
apollon.som.som.SomBase(dims: Tuple[int, int, int], n_iter: int, eta: float, nhr: float, nh_shape: str, init_weights: Union[Callable[[numpy.ndarray, Tuple[int, int]], numpy.ndarray], str], metric: Union[Callable[[numpy.ndarray, numpy.ndarray], float], str], seed: Optional[float] = None)¶ Bases:
object-
calibrate(data: numpy.ndarray, target: numpy.ndarray) → numpy.ndarray¶ Retrieve the target value of the best matching input data vector for each unit weight vector.
- Parameters
data – Input data set.
target – Target labels.
- Returns
Array of target values.
-
property
dims¶ Return the SOM dimensions.
-
distribute(data: numpy.ndarray) → Dict[int, List[int]]¶ Distribute the vectors of
dataon the SOM.Indices of vectors n
dataare mapped to the index of their best matching unit.- Parameters
data – Input data set.
- Returns
Dictionary with SOM unit indices as keys. Each key maps to a list that holds the indices of rows in
data, which best match this key.
-
property
dists¶ Return the distance matrix of the grid points.
-
property
dw¶ Return the dimension of the weight vectors.
-
property
dx¶ Return the number of units along the first dimension.
-
property
dy¶ Return the number of units along the second dimension.
-
property
grid¶ Return the grid.
-
property
hit_counts¶ Return total hit counts for each SOM unit.
-
match(data: numpy.ndarray) → numpy.ndarray¶ Return the multi index of the best matching unit for each vector in
data.Caution: This function returns the multi index into the array.
- Parameters
data – Input data set.
- Returns
Array of SOM unit indices.
-
match_flat(data: numpy.ndarray) → numpy.ndarray¶ Return the index of the best matching unit for each vector in
data.- Parameters
data – Input data set.
- Returns
Array of SOM unit indices.
-
property
n_units¶ Return the total number of units on the SOM.
-
predict(data: numpy.ndarray) → numpy.ndarray¶ Predict the SOM index of the best matching unit for each item in
data.- Parameters
data – Input data. Rows are items, columns are features.
- Returns
One-dimensional array of indices.
-
property
quantization_error¶ Return quantization error.
-
save(path) → None¶ Save som object to file using pickle.
- Parameters
path – Save SOM to this path.
-
save_weights(path) → None¶ Save weights only.
- Parameters
path – File path
-
property
shape¶ Return the map shape.
-
property
topographic_error¶ Return topographic error.
-
transform(data: numpy.ndarray) → numpy.ndarray¶ Transform each item in
datato feature space.This, in principle, returns best matching unit’s weight vectors.
- Parameters
data – Input data. Rows are items, columns are features.
- Returns
Position of each data item in the feature space.
-
umatrix(radius: int = 1, scale: bool = True, norm: bool = True)¶ Compute U-matrix of SOM instance.
- Parameters
radius – Map neighbourhood radius.
scale – If
True, scale each U-height by the number of the associated unit’s neighbours.norm – Normalize U-matrix if
True.
- Returns
Unified distance matrix.
-
property
weights¶ Return the weight vectors.
-
-
class
apollon.som.som.SomGrid(shape: Tuple[int, int])¶ Bases:
object-
cr()¶
-
nhb(point: Tuple[int, int], radius: float) → numpy.ndarray¶ Compute neighbourhood within
radiusaroundpouint.- Parameters
point – Coordinate in a two-dimensional array.
radius – Lenght of radius.
- Returns
Array of positions of neighbours.
-
nhb_idx(point: Tuple[int, int], radius: float) → numpy.ndarray¶ Compute the neighbourhood within
radiusaroundpoint.- Parameters
point – Coordinate in a two-dimensional array.
radius – Lenght of radius.
- Returns
Array of indices of neighbours.
-
rc()¶
-