def main(scale, x_offset, y_offset, display, source, smoothing): '''A GTK-based example program for Kohonen maps. Press q to quit. Press h to change the source data to a horseshoe shape. Press s to change the source data to a square shape. Press c to change the source data to a circle shape. Press + and - to grow and shrink the source data. Press the arrow keys to move the location of the source data. Press space bar to toggle training. Press 1, 2, etc. to toggle display of the first, second, etc. controller's neurons and error bars. ''' ET = kohonen.ExponentialTimeseries kw = dict(dimension=2, learning_rate=ET(-5e-4, 1, 0.1), noise_variance=0.2) m = kohonen.Map(shape=(8, 8), **kw); m.reset() g = kohonen.Gas(shape=(8, ), **kw); g.reset() gg = kohonen.GrowingGas( shape=(8, ), growth_interval=7, max_connection_age=17, **kw) gg.reset() fm = kohonen.Filter(kohonen.Map(shape=(8, 8), **kw)); fm.reset() fg = kohonen.Filter(kohonen.Gas(shape=(8, ), **kw)); fg.reset() v = Viewer(Controller(m, DARK_GRAY), Controller(g, RED), GrowingGasController(gg, BLUE), Controller(fm, GREEN), Controller(fg, YELLOW), source=source, x_offset=x_offset, y_offset=y_offset, scale=scale, smoothing=smoothing, display=display) v.show() w = Gtk.Window() w.set_title('Kohonen') w.set_default_size(800, 600) w.add(v) w.present() w.connect('key-press-event', v.do_keypress) w.connect('delete-event', Gtk.main_quit) Gtk.main()
def createKohonenSOM(iterations=epochs): import kohonen params = kohonen.Parameters(dimension=data_processor.num_features, shape=cluster_units_number, learning_rate=learning_rate, neighborhood_size=neighborhood_number) m = kohonen.Map(params) m.reset() # Need to reset after initialization return m
def __init__(self, side_rows, side_cols, size_vector, metric_name='euclidean_metric'): """Register the map as main object.""" accepted_metrics = ['euclidean_metric', 'cosine_metric'] assert metric_name in accepted_metrics, 'Use either cosine or ' \ 'euclidean metric.' if metric_name == 'euclidean_metric': metric = kohonen.euclidean_metric elif metric_name == 'cosine_metric': metric = kohonen.cosine_metric # Initializes the Kohonen map as a rectangular map params = kohonen.Parameters(dimension=size_vector, shape=(side_rows, side_cols), metric=metric) kohonen_map = kohonen.Map(params) self._map = kohonen_map self._trained = False self._distances = None self._samples_dict = None
logging.basicConfig(stream=sys.stdout, level=opts.verbose and logging.DEBUG or logging.INFO, format='%(levelname).1s %(asctime)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S') ET = kohonen.ExponentialTimeseries def kwargs(shape=(8, 8), z=0.2): return dict(dimension=2, shape=shape, learning_rate=ET(-5e-4, 1, 0.1), noise_variance=z) kw = kwargs() m = kohonen.Map(kohonen.Parameters(**kw)) m.reset() kw = kwargs((64, )) g = kohonen.Gas(kohonen.Parameters(**kw)) g.reset() kw = kwargs((64, )) kw['growth_interval'] = 7 kw['max_connection_age'] = 17 gg = kohonen.GrowingGas(kohonen.GrowingGasParameters(**kw)) gg.reset() kw = kwargs() fm = kohonen.Filter(kohonen.Map(kohonen.Parameters(**kw))) fm.reset()