Exemple #1
0
class Som:
    def init(self):
        self.core = MiniSom(50,50,6,sigma=.8,learning_rate=.5) # needs to match generating minisom command (specifically the load_map)
        self.core.load_map()
        self.callme = rospy.Service("mapping", Compute, self.callback)
	print "SOM setup complete"
    
    def callback(self, data):
        vector = np.array([data.fx, data.fy, data.fz, data.tx, data.ty, data.tz]) # format as needed
	print vector        
	w = self.core.winner(vector)
        return w[0],w[1]
Exemple #2
0
data = tacitus.cv_21
num = tacitus.cv_21w
n_samples, n_features = data.shape
######################################

# Functional Code Below:
if mode == 1:
    print "Using SOM"
    drmap = MiniSom(50,50,6,sigma=.8,learning_rate=.5) # Replace 64 with the dimensions of desired target (6)
    if fresh_data == 1:
        print "Training..."
        drmap.train_random(data,1500) # random training
        print "\n...ready!"
    elif fresh_data == 0:
        print "Loading Data"
        drmap.load_map()

    # plotting the results
    from pylab import text,show,cm,axis,figure,subplot,imshow,zeros
    figure(1)
    im = 0
    result = np.array([])
    for x,t in zip(data,num): # scatterplot
     w = drmap.winner(x)
     result.resize((im+1,3))
     result[im][0]=w[0]
     result[im][1]=w[1]
     result[im][2]=num[im]
     text(w[0]+.5, w[1]+.5, str(t), color=cm.Dark2(t / 8.), fontdict={'weight': 'bold', 'size': 11})
     im = im + 1
     axis([0,drmap.weights.shape[0],0,drmap.weights.shape[1]])