def test_ultimate(self):

        array = ['a', 'ab', 'abc', 13.2, False, 'yarn', 0, 33]
        if type(Task_2.SecondSolution(array)) == bool:
            self.fail(msg="Решение не представлено")
        result = [0, False, 'abc', 'a']

        self.assertListEqual(Task_2.SecondSolution(array), result,
                             "Test ULTIMATE not passed")
Пример #2
0
def hundred_runs(items):
    population = Task_2.generate_initial_population(items)
    for generations in range(100):
        pairs = Task_2.roulette(population, items)
        children = Task_2.mutation(Task_2.crossover_population(pairs, items),
                                   items)
        population = Task_2.new_population(population, children, items)
    res = sorted([val for val in population], key=lambda x: x[1], reverse=True)
    return res[0]
    def test_odd(self):
        n = 7
        result = [[0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1],
                  [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]]

        self.assertListEqual(Task_2.ChessPlate(n),
                             result,
                             msg="Test 2 not passed")
    def test_stress(self):
        n = 250
        result = []
        with open('big_chess.txt') as file:
            for line in file:
                result.append(list(map(int, line.split())))

        clock = time.time()
        work = Task_2.ChessPlate(n)
        clock = time.time() - clock

        self.assertListEqual(work, result, msg="Test 3 not passed")
        self.assertLessEqual(clock,
                             0.0001,
                             msg='Reached time limit of 80 microseconds')
if __name__ == "__main__":

    prior = give_prior_distribution((1, 10))
    y_values = (-10, 10)
    h_values = (1, 10)
    summation = sum(prior.values())
    print(summation)
    print(prior)
    plot_bar(prior, "Hypothesis", "Raw Uninformative Prior")
    sigma = {k: v / summation for k, v in prior.items()}
    plot_bar(sigma, "Hypothesis", "Normalized Uninformative Prior Probability")
    print(sigma)
    print(sum(sigma.values()))

    posterior_3 = Task_2.give_posterior_probability(sigma, [(2.2, -0.2)])
    print(posterior_3)
    gen_pred_3 = Task_3.give_general_prediction(y_values, h_values, posterior_3)
    print(gen_pred_3)
    Task_3.plot_contour(y_values, gen_pred_3, "Generalized Predictions with X = {(2.2, -2)}")
    # part b
    posterior_4 = Task_2.give_posterior_probability(sigma, [(2.2, -0.2), (0.5, 0.5)])
    print(posterior_4)
    gen_pred_4 = Task_3.give_general_prediction(y_values, h_values, posterior_4)
    print(gen_pred_4)
    Task_3.plot_contour(y_values, gen_pred_4, "Generalized Predictions with X = {(2.2, -2),(0.5, 0.5)}")
    # part c
    posterior_5 = Task_2.give_posterior_probability(sigma, [(2.2, -0.2), (0.5, 0.5), (1.5, 1)])
    print(posterior_5)
    gen_pred_5 = Task_3.give_general_prediction(y_values, h_values, posterior_5)
    print(gen_pred_5)
    def test_A(self):
        array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
        result = [10, 8, 6, 4, 2]

        self.assertListEqual(Task_2.EachSecondReverse(array), result,
                             "Test 1 not passed")
    def test_B(self):
        array = ['a', 'ab', 'abc', 13.2, False, 'yarn', 0, 33]
        result = [0, False, 'abc', 'a']

        self.assertListEqual(Task_2.EachSecondReverse(array), result,
                             "Test 2 not passed")
Пример #8
0
import numpy as np 
import cv2 
import Task_1, Task_2
"""
We implement dividing the image at centroid algorithm for the OTSU binarized image.
"""

def divide_image(img_file, top, bottom, right, left, cx, cy):
	img = cv2.imread(img_file, 0)
	print("Forming Cuts!")
	cut_img = cv2.rectangle(img, (top, left), (cy, cx), (0,255,0), 3)
	cut_img = cv2.rectangle(cut_img, (top, cx), (cy, right), (0,255,0), 3)
	cut_img = cv2.rectangle(cut_img, (cy, left), (bottom, cx), (0,255,0), 3)
	cut_img = cv2.rectangle(cut_img, (cy, cx), (bottom, right), (0,255,0), 3)
	
	top_left = img[left:cx, top:cy]
	bottom_left = img[cx:right, top:cy]
	top_right = img[left:cx, cy:bottom]
	bottom_right = img[cx:right, cy:bottom]

	cv2.imwrite("x_y_cut_image.png", cut_img)
	cv2.imwrite("top_left_image.png", top_left)
	cv2.imwrite("bottom_left_image.png", bottom_left)
	cv2.imwrite("top_right_image.png", top_right)
	cv2.imwrite("bottom_right_image.png", bottom_right)
	return top_left, bottom_left, top_right, bottom_right

top, bottom, right, left = Task_1.bounding_box("bin_sig.png")
cx, cy = Task_2.centroid_computation("detected_box.png")
divide_image("centeroid_image.png", top, bottom, right, left, cx, cy)
Пример #9
0
            w = line.split(
                " ")  # Extracting id and word from the document created
            # print(len(w))
            word_id = w[0]
            word = "[" + w[1][1:-1]  # + w[2][:-1] + ")"
            for i in range(2, len(w)):
                word = word + ", " + w[i][:-1]

            words[word_id] = word

    # Creating a set of all words that have occured in the word vector file
    set_words = set(words.values())
    list_set = list(set_words)
    list_set = sorted(list_set)

    tf = t2.tf_values(words, list_set)

    ty = input(
        "Enter which value needs to be plotted: (tf, tf-idf, tf-idf2): ")

    print("Generating list of 10 most similar gestures to '" + ges_val +
          "' for '" + ty + "' values:")
    if ty == "tf":
        get_sim_ges(ges_val, tf)
        print("Task 4 completed")

    elif ty == "tf-idf":
        idf = t2.idf_values(words, list_set)
        tf_idf = t2.calculate_tf_idf(tf, idf)
        get_sim_ges(ges_val, tf_idf)
        print("Task 4 completed")
Пример #10
0
import Task_2
import Task_1
import Task_3

if __name__ == "__main__":
    h_values = (1, 10)
    sigma = 10
    y_values = (-10, 10)
    sigma_10 = Task_1.give_prior_distribution(h_values, sigma, sigma)
    sigma_10 = {k: v / sum(sigma_10.values()) for k, v in sigma_10.items()}
    print(sum(sigma_10.values()))
    print(sigma_10)
    posterior_2 = Task_2.give_posterior_probability(sigma_10, [(4.5, 2.5)])
    print(posterior_2)
    gen_pred_2 = Task_3.give_general_prediction(y_values, h_values,
                                                posterior_2)
    print(gen_pred_2)
    Task_3.plot_contour(y_values, gen_pred_2,
                        "Generalized Predictions with X = {(4.5,2.5)}")