Esempio n. 1
0
    def get_rate(self, count1, count2):
        rate = 0
        if (is_empty(count1) or is_empty(count2)):
            print('割合を取得する際に必要な二つの数値が取得できていない。')
            return rate

        try:
            if to_int(count1) > 0 or to_int(count2) > 0:
                rate = round(
                    to_int(count1) / (to_int(count1) + to_int(count2)), 2)

            return rate
        except Exception as e:
            print('割合の取得に失敗しました。')
            print(str(e))
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
Esempio n. 3
0
    def validate_count(self, evaluation_item, count):
        try:
            if (is_empty(count)):
                print(evaluation_item['name'] + 'が取得できていない。')
                return False

            if ('min' in evaluation_item
                    and (to_int(count) < evaluation_item['min'])):
                print(evaluation_item['name'] + 'が' +
                      str(evaluation_item['min']) + '未満')
                return False

            if ('max' in evaluation_item
                    and (to_int(count) > evaluation_item['max'])):
                print(evaluation_item['name'] + 'が' +
                      str(evaluation_item['max']) + '以上')
                return False

            return True
        except Exception as e:
            print('カウントのバリデーションに失敗')
            print(sys._getframe().f_code.co_name)
            print(e.args)
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
def draw_basis_activation(
    map
):  # This mapping finds the closest neuron for each basis vector and prints the "name" of the basis vector on the neuron position
    words = empty_list(map.size, 1)

    basis_vectors = []
    d = map.space.dimension
    for i in range(d):
        b = scipy.zeros(d, int)
        b[i] = 1
        basis_vectors.append(b)

    for i, bv in enumerate(basis_vectors):
        bmu = map.find_bmu0(bv)
        x = map.positions[bmu]
        x = fn.to_int(x)
        words[x[0]][x[1]] = map.space.words[i]

    word_plot(words)
    return words
def draw_item_activation(mymap, named=True, overwrite=False, symbols=False):
    words = empty_list(mymap.size, 1)
    mymap.renormalize()

    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(item)
            vectors.append(s[item])

    for i, vector in enumerate(vectors):
        match = fn.find_best_match(vector, mymap.weights)
        x = mymap.positions[match]
        x = fn.to_int(x)
        w = words[x[0]][x[1]]
        if w == "" or overwrite:
            if overwrite:
                winner = fn.find_best_match(mymap.weights[match], mymap.vectors)
                w = keys[winner]
            else:
                w = keys[i]
        else:
            w = w + "," + keys[i]
        words[x[0]][x[1]] = w
    word_plot(words)
    return words
 def setpositions(self):
     x = []
     list = flatten(self.neurons)
     for neuron in list:
         x.append(fn.to_int(neuron.position))
     self.positions = scipy.array(x)