コード例 #1
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
コード例 #2
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
コード例 #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
コード例 #4
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
コード例 #5
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
コード例 #6
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
コード例 #7
0
 def average_distance_to_bmu0(self):
     dd = 0.0
     for vector in self.vectors: 
         bmu = self.find_bmu0(vector)
         dd += fn.distance(self.weights[bmu], vector)
     return dd / len(self.vectors)
コード例 #8
0
 def average_distance_to_bmu(self):
     dd = 0.0
     for item in self.space.table:
         bmu = self.find_bmu(item)
         dd += fn.distance(bmu.weight , self.space.table[item])
     return dd / len(self.space.table)