Exemplo n.º 1
0
def modified_constant_increment(data, beta, space_size=(-20, 20), step=1):
    lines = get_lines_modified_constant_increment(data, beta)
    repre = representatives(data, lines)
    trypoints = generate_points(space_size[0], space_size[1], step)
    classified = classify_ross(lines, trypoints, repre)
    data = merge_dicts(data, classified)
    return data
Exemplo n.º 2
0
def rossenblatt(data, space_size=(-20, 20), step=1):
    lines = get_lines_ross(data)
    # plot_lines(lines)  # needs some fixing, but algorithm is ok
    repre = representatives(data, lines)
    trypoints = generate_points(space_size[0], space_size[1], step)
    classified = classify_ross(lines, trypoints, repre)
    data = merge_dicts(data, classified)
    return data
Exemplo n.º 3
0
def minimal_distance(data, classes, space_size=(-20, 20), step=1):
    dist = kmeans(data, classes)
    trypoints = generate_points(space_size[0], space_size[1], step)
    for point in trypoints:
        distances = {key: distanc(point, key)
                     for key in dist.keys()
                     }  # dict for each point -> key: distance to him
        key_of_min = min(distances.keys(), key=(
            lambda key: distances[key]))  # select key with minimum distance
        dist[key_of_min].append(point)  # add point to this key
    return dist
Exemplo n.º 4
0
def nearest_neighbour(data, classes, space_size=(-20, 20), step=1):
    k_means = kmeans(data, classes)
    trypoints = generate_points(space_size[0], space_size[1], step)
    points_in_kmeans = list(itertools.chain(*k_means.values()))
    kmeans_toplot = dict(k_means)
    for trypoint in trypoints:
        sorted_means = sorted(points_in_kmeans,
                              key=lambda p: distanc(trypoint, p))
        for key, value in k_means.items():
            for val in value:
                if val == sorted_means[0]:
                    kmeans_toplot[key].append(trypoint)
    return kmeans_toplot
Exemplo n.º 5
0
def knearest_neighbour(data, classes, space_size=(-20, 20), step=1):
    k_means = kmeans(data, classes)
    trypoints = generate_points(space_size[0], space_size[1], step)
    means_toplot = dict(k_means)
    for trypoint in trypoints:
        for val in k_means.values():
            val.sort(key=lambda p: distanc(trypoint, p))
        newdict = {
            key: average_dist(trypoint, k_means[key])
            for key in k_means.keys()
        }
        keywithminvalue = min(newdict, key=newdict.get)
        means_toplot[keywithminvalue].append(trypoint)
    return means_toplot
Exemplo n.º 6
0
def bayes(data, classes, space_size=(-20, 20), step=1):
    """

    :param data:
    :param classes:
    :param space_size:
    :param float step:
    :return:
    """
    dist = kmeans(data, classes)
    trypoints = generate_points(space_size[0], space_size[1], step)
    prob = probability(dist)
    prumery = means(dist)
    sigm = sigma(dist, prumery)
    for point in trypoints:
        rozhodovaci = {key: normal(point, sigm[key], prumery[key], prob[key]) for key in dist.keys()}
        keywithmaxvalue = max(rozhodovaci, key=rozhodovaci.get)
        dist[keywithmaxvalue].append(point)
    return dist