-
Notifications
You must be signed in to change notification settings - Fork 1
/
guiInf.py
753 lines (559 loc) · 24 KB
/
guiInf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
#! /usr/bin/som python
import pygtk
pygtk.require('2.0')
import gtk, gobject, cairo, glib
from gtk import gdk
import gobject
import random as r
import copy as cop
import os
from minisom import MiniSom
import matplotlib
matplotlib.use('gtkagg')
from pylab import plot,axis,show,pcolor,colorbar,bone,ion, hold
import numpy as np
import matplotlib.pyplot as plt
#from numpy import arange, sin, pi
# uncomment to select /GTK/GTKAgg/GTKCairo
#from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
#from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas
# or NavigationToolbar for classic
#from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar
from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar
# implement the default mpl key bindings
from matplotlib.backend_bases import key_press_handler
def Random(max_value, min_value = 0):
"Random integer from min_value to max_value"
return int(r.randint(min_value, max_value))
#return int(round(r.random()*(max_value-min_value) + min_value))
def div(l, d):
return [x/d for x in l]
#red = [255, 20, 0]
#red = div(red, 255.0)
red = [1.0, 0.1, 0.2]
blue = [0.0, 0.1, 1.0]
#blue = div(blue,255.0)
#green = [50, 180, 30]
#green = div(green,255.0)
grey = [0.9, 0.9, 0.9]
#purple = [255, 20, 255]
#purple = div(purple,255.0)
#yellow = [255, 200, 10]
#yellow = div(yellow, 255.0)
#cyan = [0, 255, 255]
#cyan = div(cyan, 255.0)
white = [1, 1, 1]
black = [0, 0, 0]
def random_colour():
colours = [red, blue]
return colours[Random(len(colours)-1)]
def get_resource_path(rel_path):
dir_of_py_file = os.path.dirname(__file__)
rel_path_to_resource = os.path.join(dir_of_py_file, rel_path)
abs_path_to_resource = os.path.abspath(rel_path_to_resource)
return abs_path_to_resource
#Environment Globals
padding = 10
#height = 60
#width = 60
#ticks = 1
#Agent Globals
living_cost = 0.3
reproduction_energy = 10 #minmum energy value for reproducing
mutation_probability = 5 #per cent
mouth_size = 3 #amount of food that can be eaten in one go
s = 1
d = 0
max_age = 500
death_percent = 0#20
PERCEPTION = 2
#import pygame
#from pygame.locals import *
#pygame.init()
#screen = pygame.display.set_mode((569, 569))
#pygame.display.set_caption("Map")
#background = pygame.Surface(screen.get_size())
#background = background.convert()
#background.fill((255, 255, 255))
#screen.blit(background, (0, 0))
##----------------------------------------------------------------------------------------------------##
class SOM:
def If_running(self):
#print som.running
self.play.set_sensitive(not self.som.running)
return self.som.running
def If_paused(self):
#print som.running
#self.pause.set_sensitive(self.som.running)
return False
def Status_update(self):
if self.som.running:
context_id = self.status_bar.get_context_id("Running")
#print context_id
text = "Iteration: " + str(self.som.tick).zfill(len(str(self.som.ticks))) + "/" + str(self.som.ticks).zfill(len(str(self.som.ticks)))
if self.som.paused:
text += ", Paused"
self.status_bar.push(context_id, text)
return True # we need it to keep updating if the model is running
elif not self.som.running:
if not self.som.paused:
self.status_bar.remove_all(self.status_bar.get_context_id("Running"))
self.status_bar.remove_all(self.status_bar.get_context_id("Ready"))
context_id = self.status_bar.get_context_id("Ready")
#print context_id
text = "Ready"
self.status_bar.push(context_id, text)
return False
#def Quit(self, widget, data=None):
##print 'Byez!'
#gtk.main_quit()
#def Pause(self, widget=None, data=None):
#self.som.Pause()
#if self.som.paused:
#self.pause.set_label("Unpause")
#else:
#self.pause.set_label("Pause")
#glib.idle_add(self.som.Run)
#glib.idle_add(self.If_running)
#glib.idle_add(self.Status_update)
def open_file(self, file_name):
try:
#cols = self.columns[self.combobox.get_active()]
#print cols
self.data = np.genfromtxt(file_name, delimiter=',',usecols=(self.visual_and_acoustic),skip_header=1)
self.pattern_labels = np.genfromtxt(file_name, delimiter=',',usecols=(self.visual_and_acoustic), skip_footer=14, dtype=str)
self.file_name = file_name
self.update_treeview(self.data, self.patterns_liststore)
#print self.data
except:
print "File is probably not in the right format:", file_name
raise
def select_file(self, widget=None, data=None):
#response = self.dialog.run()
#if response == gtk.RESPONSE_OK:
#self.open_file(self.dialog.get_filename())
#elif response == gtk.RESPONSE_CANCEL:
#print 'Closed, no files selected'
#self.dialog.destroy()
dialog = gtk.FileChooserDialog("Open..", None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
tmp = os.getcwd()
tmp = 'file://' + tmp
#print tmp
#print dialog.set_current_folder_uri(tmp)
#print dialog.get_current_folder_uri()
filter = gtk.FileFilter()
filter.set_name("All files")
filter.add_pattern("*")
dialog.add_filter(filter)
filter = gtk.FileFilter()
filter.set_name("Comma-separated values")
filter.add_pattern("*.csv")
dialog.add_filter(filter)
dialog.set_filter(filter)
#dialog = gtk.FileChooserDialog("Please choose a file", self,
#gtk.FileChooserAction.OPEN,
#(gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL,
#gtk.STOCK_OPEN, gtk.ResponseType.OK))
response = dialog.run()
if response == gtk.RESPONSE_OK:
#print("Open clicked")
#print("File selected: " + dialog.get_filename())
self.open_file(dialog.get_filename())
#elif response == gtk.RESPONSE_CANCEL:
#print("Cancel clicked")
dialog.destroy()
def Run(self, widget=None, data=None):
#self.som.ticks += self.iterations_spin_button.get_value_as_int()
if not self.som.running:
### Initialization and training ###
#self.som = MiniSom(5, 15, 8,sigma=1.2,learning_rate=0.5)
#self.init_som()
for i in range(1):
self.train_som()
#self.figure.clf()
self.Draw_figure()
self.canvas.draw()
self.canvas.draw_idle()
#We need to draw *and* flush
self.figure.canvas.draw()
self.figure.canvas.flush_events()
#print "draw"
self.update_treeview(self.test_data, self.test_liststore)
self.update_treeview(self.data, self.patterns_liststore)
glib.idle_add(self.Status_update)
glib.idle_add(self.If_running)
glib.idle_add(self.If_paused)
def Test(self, widget=None, data=None):
#self.som.ticks += self.iterations_spin_button.get_value_as_int()
if not self.som.running:
### Initialization and training ###
#self.som = MiniSom(5, 15, 8,sigma=1.2,learning_rate=0.5)
self.test_som()
#self.figure.clf()
self.Draw_figure()
self.canvas.draw()
self.canvas.draw_idle()
#We need to draw *and* flush
self.figure.canvas.draw()
self.figure.canvas.flush_events()
#print "draw"
glib.idle_add(self.Status_update)
glib.idle_add(self.If_running)
glib.idle_add(self.If_paused)
def Reset(self, widget=None, data=None):
self.init_som()
self.Draw_figure()
self.canvas.draw()
self.canvas.draw_idle()
#We need to draw *and* flush
self.figure.canvas.draw()
self.figure.canvas.flush_events()
#print "draw"
self.update_treeview(self.test_data, self.test_liststore)
self.update_treeview(self.data, self.patterns_liststore)
glib.idle_add(self.Status_update)
glib.idle_add(self.If_running)
glib.idle_add(self.If_paused)
def delete_event(self, widget=None, event=None, data=None):
# If you return FALSE in the "delete_event" signal handler,
# GTK will emit the "destroy" signal. Returning TRUE means
# you don't want the window to be destroyed.
# This is useful for popping up 'are you sure you want to quit?'
# type dialogs.
#print "delete event occurred"
# Change FALSE to TRUE and the main window will not be destroyed
# with a "delete_event".
return False
#def on_key_event(self, event):
#print('you pressed %s'%event.key)
#key_press_handler(event, self.canvas, self.toolbar)
def destroy(self, widget=None, data=None):
#print "destroy signal occurred"
gtk.main_quit()
# T
def Draw_figure(self):
# this function draws the exemplars on the best matching units
self.axes.cla() # Clear axis
cols = self.columns[self.combobox.get_active()]
data = self.data[:, 0:len(cols)]
test_data = self.test_data[:, 0:len(cols)]
#ion() # Turn on interactive mode.
#hold(True) # Clear the plot before adding new data.
#print som.distance_map().T
#exit()
bone()
background = self.axes.pcolor(self.som.distance_map().T) # plotting the distance map as background
#f.colorbar(a)
t = np.zeros(len(self.target),dtype=int)
t[self.target == 'A'] = 0
t[self.target == 'B'] = 1
#t[self.target == 'C'] = 2
#t[self.target == 'D'] = 3
tTest = np.zeros(len(self.test_target),dtype=int)
tTest[self.test_target == 'A'] = 2 #0
tTest[self.test_target == 'B'] = 3 #1
# use different colors and markers for each label
markers = ['o','s','*', '+']
colors = ['r','g','b', 'y']
for cnt,xx in enumerate(data): # training data ( noisy simulation)
w = self.som.winner(xx) # getting the winner
# place a marker on the winning position for the sample xx
tmp = self.axes.plot(w[0]+.5,w[1]+.5,markers[t[cnt]],markerfacecolor='None',
markeredgecolor=colors[t[cnt]],markersize=12,markeredgewidth=2)
# plot the test data (ideal input)
for cnt,xx in enumerate(test_data): # test data ( ideal )
w = self.som.winner(xx) # getting the winner
# place a marker on the winning position for the sample xx
tmp = self.axes.plot(w[0]+.5,w[1]+.5,markers[tTest[cnt]],markerfacecolor='None',
markeredgecolor=colors[tTest[cnt]],markersize=12,markeredgewidth=2)
self.axes.axis([0,self.som.weights.shape[0],0,self.som.weights.shape[1]])
#show() # show the figure
#print "drawing"
#self.figure.canvas.draw()
def init_som(self, widget=None, data=None):
##print self.data
### Initialization and training ###
cols = self.columns[self.combobox.get_active()]
data = self.data[:, 0:len(cols)]
#print len(cols)
self.som = MiniSom(self.width_spin_button.get_value_as_int(), self.height_spin_button.get_value_as_int(), len(cols),sigma=1.2,learning_rate=0.5)
# self.som.weights_init_gliozzi(data)
self.som.random_weights_init(data)
def train_som(self):
cols = self.columns[self.combobox.get_active()]
data = self.data[:, 0:len(cols)]
print("Training...")
#self.som.train_gliozzi(data) # Gliozzi et al training
self.som.train_random(data,100)
print("\n...ready!")
def make_treeview(self, data, liststore):
#i = 0
cols = self.columns[self.combobox.get_active()]
#print type(cols)
#print len(cols)
for d in data:
#i += 1
tmp = d.tolist()
#print 'tmp', tmp
#while len(tmp) < cols:
#tmp.append(False)
#print 'tmp', tmp
#cols = cols - 1
Qe = MiniSom.quantization_error_subset(self.som,d,len(cols))
#print tmp
tmp.append(Qe)
tmp.append(4 * Qe ** 0.5)
liststore.append(tmp)
treeview = gtk.TreeView(model=liststore)
#i = 0
for d in range(len(self.test_data[0])): # not sure what this is doing
#print i
#i += 1
renderer_text = gtk.CellRendererText()
column_text = gtk.TreeViewColumn(self.pattern_labels[d], renderer_text, text=d)
treeview.append_column(column_text)
column_text = gtk.TreeViewColumn('Qe', renderer_text, text=d+1)
treeview.append_column(column_text)
column_text = gtk.TreeViewColumn('NLT', renderer_text, text=d+2)
treeview.append_column(column_text)
return treeview
def update_treeview(self, data, liststore):
cols = len(self.columns[self.combobox.get_active()])
for i, d in enumerate(data):
for j in range(len(d)):
#print j
liststore[i][j] = d[j]
if j >= cols:
liststore[i][j] = -999
Qe = MiniSom.quantization_error_subset(self.som,d,cols)
#print d, liststore[i]
liststore[i][-2]= Qe
liststore[i][-1]= 4 * Qe ** 0.5
def select_columns(self, widget=None):
#self.open_file(self.file_name)
#self.init_som()
self.update_treeview(self.test_data, self.test_liststore)
self.update_treeview(self.data, self.patterns_liststore)
#----------------------------------------
# SAM added these functions here
def pertSomWeights( self, widget=None, data=None ):
#if scale == None:
scale = .5
print( 'Adding noise to SOM weights')
# print( self.som.weights )
# print( self.som.weights.shape )
pertAmount = scale*(np.random.random_sample( self.som.weights.shape)-.5)
self.som.weights = self.som.weights + pertAmount
# print self.som.weights
self.Draw_figure()
self.canvas.draw()
self.canvas.draw_idle()
#We need to draw *and* flush
self.figure.canvas.draw()
self.figure.canvas.flush_events()
def pertInputs( self, widget=None, data=None ):
#if scale == None:
p = .2
print( 'Making %f prop of inputs 0.5' %p)
#print( self.data.shape )
# randomly get indices to switch, then replace
noiseIndex = np.random.binomial(1,p, self.data.shape) #ones at p proportion of samples
self.data[noiseIndex ==1 ] = .5
print( self.data )
# update the treeview for the "Patterns" tab to see the result graphically
self.update_treeview(self.data, self.patterns_liststore)
#----------------------------------------
def __init__(self):
# create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
# When the window is given the "delete_event" signal (this is given
# by the window manager, usually by the "close" option, or on the
# titlebar), we ask it to call the delete_event () function
# as defined above. The data passed to the callback
# function is NULL and is ignored in the callback function.
self.window.connect("delete_event", self.delete_event)
# Here we connect the "destroy" event to a signal handler.
# This event occurs when we call gtk_widget_destroy() on the window,
# or if we return FALSE in the "delete_event" callback.
self.window.connect("destroy", self.destroy)
#window.set_icon_from_file(get_resource_path("icon.png"))
#window.connect("delete-event", Quit)
#window.connect("destroy", Quit)
self.window.set_title("SOM model")
self.window.set_default_size(500, 500) #this si to ensure the window is always the smallest it can be
#self.window.set_resizable(False)
#window.set_border_width(10)
# Args are: homogeneous, spacing, expand, fill, padding
homogeneous = False
spacing = 0
expand = False
fill = False
padding = 10
self.hbox = gtk.HBox(homogeneous, spacing)
self.vbox = gtk.VBox(homogeneous, spacing)
self.window.add(self.vbox)
#self.adjustment = gtk.Adjustment(value=10000, lower=1, upper=100000000, step_incr=1000, page_incr=10000)
#self.iterations_spin_button = gtk.SpinButton(self.adjustment, climb_rate=0, digits=0)
self.label = gtk.Label("Dimensions:")
self.adjustment = gtk.Adjustment(value=5, lower=1, upper=100, step_incr=2, page_incr=5)
self.width_spin_button = gtk.SpinButton(self.adjustment, climb_rate=0, digits=0)
self.adjustment = gtk.Adjustment(value=10, lower=1, upper=100, step_incr=2, page_incr=5)
self.height_spin_button = gtk.SpinButton(self.adjustment, climb_rate=0, digits=0)
# Create a series of buttons with the appropriate settings
image = gtk.Image()
# (from http://www.pygtk.org/docs/pygtk/gtk-stock-items.html)
image.set_from_stock(gtk.STOCK_EXECUTE, 1)
self.play = gtk.Button()
self.play.set_image(image)
self.play.set_label("Train")
#image = gtk.Image()
## (from http://www.pygtk.org/docs/pygtk/gtk-stock-items.html)
#image.set_from_stock(gtk.STOCK_APPLY, 1)
#self.test = gtk.Button()
#self.test.set_image(image)
#self.test.set_label("Test")
image = gtk.Image()
# (from http://www.pygtk.org/docs/pygtk/gtk-stock-items.html)
image.set_from_stock(gtk.STOCK_OPEN, 1)
self.open = gtk.Button()
self.open.set_image(image)
self.open.set_label("Open patterns")
#self.pause = gtk.Button(stock = gtk.STOCK_MEDIA_PAUSE)
image = gtk.Image()
image.set_from_stock(gtk.STOCK_REFRESH, 1)
self.reset = gtk.Button()
self.reset.set_image(image)
self.reset.set_label("Reset")
self.play.connect("clicked", self.Run, None)
#self.test.connect("clicked", self.Test, None)
self.open.connect("clicked", self.select_file, None)
#self.pause.connect("clicked", self.Pause, None)
self.reset.connect("clicked", self.Reset, None)
self.height_spin_button.connect("value-changed", self.Reset, "Height changed")
self.width_spin_button.connect("value-changed", self.Reset, "Width changed")
# add perturb button to disturb trained som weights
self.perturb = gtk.Button("Perturb SOM") # create gtk button to perturb som weights
self.perturb.connect( "clicked", self.pertSomWeights, None ) # run self.pertSomWeights
self.perturb.show() # tell GTK to show button, but not where
# add button to add noisy encoding to training inputs
self.perturbInputButton = gtk.Button("Perturb Inputs") # create gtk button to perturb som weights
self.perturbInputButton.connect( "clicked", self.pertInputs, None ) # run self.pertSomWeights
self.perturbInputButton.show() # tell GTK to show button, but not where
#self.width_spin_button.connect("value_changed", self.init_som)
#self.height_spin_button.connect("value_changed", self.init_som)
#self.som = Environment(width = self.width_spin_button.get_value_as_int(), height = self.height_spin_button.get_value_as_int())
#self.som.show()
#self.pause.set_sensitive(self.som.paused)
#self.vbox.pack_start(self.som, True, True, 0)
file_names = ['4749.csv'] #['stimuli.csv']
self.visual_only = [0,1,2,3,4,5,6,7]
self.visual_and_acoustic = [0,1,2,3,4,5,6,7,8]
self.columns = [self.visual_only, self.visual_and_acoustic]
self.file_name = file_names[0] # the cusom noisy data to load
self.test_file_name = 'stimuli.csv' # idealized exemplar data
#f = Figure(figsize=(5,4), dpi=100)
#a = f.add_subplot(111)
self.combobox = gtk.combo_box_new_text()
self.combobox.append_text('Visual only')
self.combobox.append_text('Visual and acoustic')
self.test_data = np.genfromtxt(self.test_file_name, delimiter=',',usecols=(self.visual_and_acoustic),skip_header=1)
self.test_data += -.5 #0.00001
self.test_data = np.apply_along_axis(lambda x: x/np.linalg.norm(x),1,self.test_data) # data normalization
# here specify the labels (for coloring them nicely on the figure)
self.target = np.genfromtxt(self.file_name,delimiter=',',usecols=(9),dtype=str,skip_header=1) # loading the labels for use in the figure (corresponding to data)
self.test_target = np.genfromtxt(self.test_file_name,delimiter=',',usecols=(9),dtype=str,skip_header=1) # corresponding to test_data
self.combobox.set_active(1)
self.combobox.connect('changed', self.Reset)
#cols = self.columns[self.combobox.get_active()]
#print cols
self.data = np.genfromtxt(self.file_name, delimiter=',',usecols=(self.visual_and_acoustic),skip_header=1)
self.data += -.5 #0.00001
self.data = np.apply_along_axis(lambda x: x/np.linalg.norm(x),1,self.data) # data normalization
self.pattern_labels = np.genfromtxt(self.file_name, delimiter=',',usecols=(self.visual_and_acoustic), skip_footer=14, dtype=str)
#print self.pattern_labels
self.init_som()
#self.toolbar = NavigationToolbar(self.canvas, self.window)
#self.vbox.pack_start(self.toolbar, False, False)
#self.vbox.pack_start(self.canvas)
self.test_liststore = gtk.ListStore(float, float, float, float, float, float, float, float, float, float, float)
self.patterns_liststore = gtk.ListStore(float, float, float, float, float, float, float, float, float, float, float)
self.test_treeview = self.make_treeview(self.test_data, self.test_liststore)
self.patterns_treeview = self.make_treeview(self.data, self.patterns_liststore)
#self.data = np.genfromtxt(self.file_name, delimiter=',',usecols=(0,1,2,3,4,5,6,7),skip_header=1)
#self.pattern_labels = np.genfromtxt(self.file_name, delimiter=',',usecols=(0,1,2,3,4,5,6,7), skip_footer=8, dtype=str)
##self.data = np.apply_along_axis(lambda x: x/np.linalg.norm(x),1,self.data) # data normalization
self.figure, self.axes= plt.subplots()
# Create canvas.
self.canvas = FigureCanvas(self.figure) # a gtk.DrawingArea
self.canvas.set_size_request(300, 400)
self.Draw_figure()
self.notebook = gtk.Notebook()
self.notebook.set_tab_pos(gtk.POS_TOP)
self.vbox.pack_start(self.notebook)
label = gtk.Label("Distance map")
self.notebook.append_page(self.canvas, label)
label = gtk.Label("Patterns")
self.notebook.append_page(self.patterns_treeview, label)
label = gtk.Label("Testing")
#hbox = gtk.HBox(homogeneous, spacing)
self.notebook.append_page(self.test_treeview, label)
#hbox.pack_start(test_treeview, expand, fill, 0)
#hbox.pack_start(test_treeview, expand, fill, 0)
self.patterns_treeview.show()
self.test_treeview.show()
self.canvas.draw_idle()
self.canvas.show()
self.figure.canvas.draw()
self.vbox.pack_start(self.hbox, expand, fill, 10)
self.status_bar = gtk.Statusbar()
self.vbox.pack_start(self.status_bar, expand, fill, 0)
self.status_bar.show()
glib.idle_add(self.Status_update)
self.hbox.show()
self.vbox.show()
self.play.show()
#self.test.show()
self.open.show()
#self.pause.show()
self.reset.show()
#self.iterations_spin_button.show()
self.width_spin_button.show()
self.height_spin_button.show()
self.hbox.pack_start(self.play, expand, fill, padding)
#self.hbox.pack_start(self.test, expand, fill, padding)
self.hbox.pack_start(self.open, expand, fill, padding)
self.hbox.pack_start(self.combobox, expand, fill, padding)
#self.hbox.pack_start(self.pause, expand, fill, 0)
self.hbox.pack_start(self.reset, expand, fill, padding)
#self.hbox.pack_start(self.iterations_spin_button, expand, fill, 0)
self.hbox.pack_start(self.label, expand, fill, padding)
self.hbox.pack_start(self.width_spin_button, expand, fill, padding)
self.hbox.pack_start(self.height_spin_button, expand, fill, 0)
self.hbox.pack_start( self.perturb, expand, fill, padding)
self.hbox.pack_start( self.perturbInputButton, expand, fill, padding)
#self.quit = gtk.Button("Quit")
self.quit = gtk.Button(stock = gtk.STOCK_QUIT)
self.combobox.connect('changed', self.select_columns)
self.quit.connect("clicked", self.destroy, None)
self.hbox.pack_end(self.quit, expand, fill, padding)
self.quit.show()
#print window.get_size()
self.window.show_all()
self.window.present()
#gtk.main()
# And of course, our main loop.
#gtk.main()
# Control returns here when main_quit() is called
return None
def main(self):
# All PyGTK applications must have a gtk.main(). Control ends here
# and waits for an event to occur (like a key press or mouse event).
gtk.main()
##----------------------------------------------------------------------------------------------------##
# If the program is run directly or passed as an argument to the python
# interpreter then create a HelloWorld instance and show it
if __name__ == "__main__":
model = SOM()
model.main()