Somz module¶
This is the SOMZ class in some detail, refer to the source code for more information and methods.
Module author: Matias Carrasco Kind
- class SOMZ.SelfMap(X, Y, topology='grid', som_type='online', Ntop=28, iterations=30, periodic='no', dict_dim='', astart=0.8, aend=0.5, importance=None)¶
Create a som class instance
Parameters: - X (float) – Attributes array (all columns used)
- Y (float) – Attribute to be predicted (not really needed, can be zeros)
- topology (str) – Which 2D topology, ‘grid’, ‘hex’ or ‘sphere’
- som_type (str) – Which updating scheme to use ‘online’ or ‘batch’
- Ntop (int) – Size of map, for grid Size=Ntop*Ntop, for hex Size=Ntop*(Ntop+1[2]) if Ntop is even[odd] and for sphere Size=12*Ntop*Ntop and top must be power of 2
- iterations (int) – Number of iteration the entire sample is processed
- periodic (str) – Use periodic boundary conditions (‘yes’/’no’), valid for ‘hex’ and ‘grid’ only
- dict_dim (dict) – dictionary with attributes names
- astar (float) – Initial value of alpha
- aend (float) – End value of alpha
- importance (str) – Path to the file with importance ranking for attributes, default is none
- create_map(evol='no', inputs_weights='')¶
This is same as above but uses python routines instead
- create_mapF(evol='no', inputs_weights='')¶
This functions actually create the maps, it uses random values to initialize the weights It uses a Fortran subroutine compiled with f2py
- evaluate_map(inputX='', inputY='')¶
This functions evaluates the map created using the input Y or a new Y (array of labeled attributes) It uses the X array passed or new data X as well, the map doesn’t change
Parameters: - inputX (float) – Use this if another set of values for X is wanted using the weigths already computed
- inputY (float) – One dimensional array of the values to be assigned to each cell in the map based on the in-memory X passed
- get_best(line)¶
Get the predictions given a line search, where the line is a vector of attributes per individual object for THE best cell
Parameters: line (float) – input data to look in the tree Returns: array with the cell content
- get_vals(line)¶
Get the predictions given a line search, where the line is a vector of attributes per individual object fot the 10 closest cells.
Parameters: line (float) – input data to look in the tree Returns: array with the cell content
- plot_map(min_m=-100, max_m=-100, colbar='yes')¶
Plots the map after evaluating, the cells are colored with the mean value inside each one of them
Parameters: - min_m (float) – Lower limit for coloring the cells, -100 uses min value
- max_m (float) – Upper limit for coloring the cells, -100 uses max value
- colbar (str) – Include a colorbar (‘yes’,’no’)
- save_map(itn=-1, fileout='SOM', path='')¶
Saves the map
Parameters: - itn (int) – Number of map to be included on path, use -1 to ignore this number
- fileout (str) – Name of output file
- path (str) – path for the output file
- save_map_dict(path='', fileout='SOM', itn=-1)¶
Saves the map in dictionary format
Parameters: - itn (int) – Number of map to be included on path, use -1 to ignore this number
- fileout (str) – Name of output file
- path (str) – path for the output file
- som_best_cell(inputs, return_vals=1)¶
Return the closest cell to the input object It can return more than one value if needed
- SOMZ.geometry(top, Ntop, periodic='no')¶
Pre-compute distances between cells in a given topology and store it on a distLib array
Parameters: - top (str) – Topology (‘grid’,’hex’,’sphere’)
- Ntop (int) – Size of map, for grid Size=Ntop*Ntop, for hex Size=Ntop*(Ntop+1[2]) if Ntop is even[odd] and for sphere Size=12*Ntop*Ntop and top must be power of 2
- periodic (str) – Use periodic boundary conditions (‘yes’/’no’), valid for ‘hex’ and ‘grid’ only
Returns: 2D array with distances pre computed between cells and total number of units
Return type: 2D float array, int
- SOMZ.get_alpha(t, alphas, alphae, NT)¶
Get value of alpha at a given time
- SOMZ.get_ns(ix, iy, nx, ny, index=False)¶
Get neighbors for rectangular grid given its coordinates and size of grid
Parameters: - ix (int) – Coordinate in the x-axis
- iy (int) – Coordinate in the y-axis
- nx (int) – Number fo cells along the x-axis
- ny (int) – Number fo cells along the y-axis
- index (bool) – Return indexes in the map format
Returns: Array of indexes for direct neighbors
- SOMZ.get_ns_hex(ix, iy, nx, ny, index=False)¶
Get neighbors for hexagonal grid given its coordinates and size of grid Same parameters as get_ns()
- SOMZ.get_sigma(t, sigma0, sigmaf, NT)¶
Get value of sigma at a given time
- SOMZ.h(bmu, mapD, sigma)¶
Neighborhood function which quantifies how much cells around the best matching one are modified
Parameters: - bmu (int) – best matching unit
- mapD (float) – array of distances computed with geometry()
- SOMZ.is_power_2(value)¶
Check if passed value is a power of 2