def draw_neuron_activation(mymap, named=True, symbols=False):     # iterates through EACH neuron and finds closest vector
    words = distances = empty_list(mymap.size, 1)

    if named:
        vectors = mymap.vectors
        keys = mymap.keys
    else:
        vectors = []
        keys = []
        idea_names = mymap.space.idea_names
        for item in mymap.space.table:
            keys.append(idea_names[item])
            vectors.append(mymap.space.table[item])   

    if symbols:
        s = mymap.space.symbol_vectors
        keys = []
        vectors = []
        for item in s:
            keys.append(mymap.space.idea_names[item])
            vectors.append(s[item])

    for neuron in flatten(mymap.neurons):
        weight = neuron.weight
        match = fn.find_best_match(weight, vectors)
        distance = fn.distance(weight, vectors[match])
        x = neuron.position
        x = fn.to_int(x)
        words[x[0]][x[1]] = keys[match]
        #       distances[x[0]][x[1]] = distance
    word_plot(words)
    return words
 def setweights(self):
     x = []
     list = flatten(self.neurons)
     for neuron in list:
         #x.append(fn.normalize(neuron.weight))
         x.append(neuron.weight)
     self.weights = scipy.array(x)   
Example #3
0
def get_umatrix(mymap, radius=1):
    umatrix = empty_list(mymap.size, 1)

    xmax = mymap.size[1]
    ymax = mymap.size[0]

    rad = range(-radius, radius + 1)
    #    print rad

    for neuron in flatten(mymap.neurons):
        weight = neuron.weight
        position = neuron.position
        x = position[0]
        y = position[1]
        xrange = []
        yrange = []

        for i in rad:
            xrange.append(int((x + i) % xmax))
            yrange.append(int((y + i) % ymax))

        average_dist = 0
        for x in xrange:
            for y in yrange:
                neighbour_weight = mymap.neurons[x][y].weight
                d = fn.distance(neighbour_weight, weight)
                average_dist += d

        umatrix[x][y] = average_dist
    return umatrix
def get_umatrix(mymap, radius=1):
    umatrix = empty_list(mymap.size, 1)

    xmax = mymap.size[1]
    ymax = mymap.size[0]    

    rad = range(-radius, radius + 1)
#    print rad

    for neuron in flatten(mymap.neurons):
        weight = neuron.weight
        position = neuron.position
        x = position[0]
        y = position[1]
        xrange = []
        yrange = []
  
        for i in rad:
            xrange.append(int((x + i) % xmax))
            yrange.append(int((y + i) % ymax))

        average_dist = 0
        for x in xrange:
            for y in yrange:
                neighbour_weight = mymap.neurons[x][y].weight                
                d = fn.distance(neighbour_weight, weight)   
                average_dist += d
        
        umatrix[x][y] = average_dist 
    return umatrix
def get_distances_to_nearest(mymap):
    distances = empty_list(mymap.size, 1)
    vectors = mymap.vectors
    matches = []
    for neuron in flatten(mymap.neurons):
        weight = neuron.weight
        match = fn.find_best_match(weight, vectors)
        matches.append(match)
        distance = fn.distance(weight, vectors[match])
        x = neuron.position
        x = fn.to_int(x)
        distances[x[0]][x[1]] = distance
    c = Counter(matches)
    print c 
    print 'items mapped : ' + str(len(sorted(c)))
    return distances
def draw_clusters_per_item(mymap, clusters):
    cluster_map = empty_list(mymap.size, 1) 

    vectors = mymap.vectors
    keys = mymap.keys

    for neuron in flatten(mymap.neurons):
        weight = neuron.weight
        match = fn.find_best_match(weight, vectors)
        key = keys[match]
        cluster = clusters[key]
        x = neuron.position
        x = fn.to_int(x)
        cluster_map[x[0]][x[1]] = key
#        cluster_map[x[0]][x[1]] = cluster
    return cluster_map
Example #7
0
def get_distances_to_nearest(mymap):
    distances = empty_list(mymap.size, 1)
    vectors = mymap.vectors
    matches = []
    for neuron in flatten(mymap.neurons):
        weight = neuron.weight
        match = fn.find_best_match(weight, vectors)
        matches.append(match)
        distance = fn.distance(weight, vectors[match])
        x = neuron.position
        x = fn.to_int(x)
        distances[x[0]][x[1]] = distance
    c = Counter(matches)
    print c
    print 'items mapped : ' + str(len(sorted(c)))
    return distances
Example #8
0
def draw_clusters(mymap, clusters):
    cluster_map = empty_list(mymap.size, 1)

    vectors = mymap.vectors
    keys = mymap.keys

    for neuron in flatten(mymap.neurons):
        weight = neuron.weight
        match = fn.find_best_match(weight, vectors)
        key = keys[match]
        cluster = clusters[key]
        x = neuron.position
        x = fn.to_int(x)
        #        cluster_map[x[0]][x[1]] = key
        cluster_map[x[0]][x[1]] = cluster
    return cluster_map
Example #9
0
def draw_neuron_activation(
        mymap,
        named=True,
        symbols=False
):  # iterates through EACH neuron and finds closest vector
    words = distances = empty_list(mymap.size, 1)

    if named:
        vectors = mymap.vectors
        keys = mymap.keys
    else:
        vectors = []
        keys = []
        idea_names = mymap.space.idea_names
        for item in mymap.space.table:
            keys.append(idea_names[item])
            vectors.append(mymap.space.table[item])

    if symbols:
        s = mymap.space.symbol_vectors
        keys = []
        vectors = []
        for item in s:
            keys.append(mymap.space.idea_names[item])
            vectors.append(s[item])

    for neuron in flatten(mymap.neurons):
        weight = neuron.weight
        match = fn.find_best_match(weight, vectors)
        distance = fn.distance(weight, vectors[match])
        x = neuron.position
        x = fn.to_int(x)
        words[x[0]][x[1]] = keys[match]
        #       distances[x[0]][x[1]] = distance
    word_plot(words)
    return words
 def flush_map(self):
     list = flatten(self.neurons)
     for n, neuron in enumerate(list):
         neuron.weight = self.weights[n] 
 def setpositions(self):
     x = []
     list = flatten(self.neurons)
     for neuron in list:
         x.append(fn.to_int(neuron.position))
     self.positions = scipy.array(x)