server.py
def do_pruning(gesture_points_X, gesture_points_Y, template_sample_points_X, template_sample_points_Y):
    '''Do pruning on the dictionary of 10000 words.

    In this function, we use the pruning method described in the paper (or any other method you consider it reasonable)
    to narrow down the number of valid words so that the ambiguity can be avoided to some extent.

    :param gesture_points_X: A list of X-axis values of input gesture points, which has 100 values since we have
        sampled 100 points.
    :param gesture_points_Y: A list of Y-axis values of input gesture points, which has 100 values since we have
        sampled 100 points.
    :param template_sample_points_X: 2D list, containing X-axis values of every template (10000 templates in total).
        Each of the elements is a 1D list and has the length of 100.
    :param template_sample_points_Y: 2D list, containing Y-axis values of every template (10000 templates in total).
        Each of the elements is a 1D list and has the length of 100.

    :return:
        valid_words: A list of valid words after pruning.
        valid_probabilities: The corresponding probabilities of valid_words.
        valid_template_sample_points_X: 2D list, the corresponding X-axis values of valid_words. Each of the elements
            is a 1D list and has the length of 100.
        valid_template_sample_points_Y: 2D list, the corresponding Y-axis values of valid_words. Each of the elements
            is a 1D list and has the length of 100.
    '''
    valid_words, valid_template_sample_points_X, valid_template_sample_points_Y = [], [], []
    # TODO: Set your own pruning threshold
    threshold = 30
    # TODO: Do pruning (12 points)

    # Create numpy array for gesture start and end point [[x, y]]
    gesture_start_point = np.array([gesture_points_X[0], gesture_points_Y[0]])
    gesture_end_point = np.array([gesture_points_X[-1], gesture_points_Y[-1]])

    # Number of templates
    num_templates = len(template_sample_points_X)
    # Gather the start points and end points of templates in a numpy matrix [[x1, y1], [x2, y2], ..., [xn, yn]]
    template_start_points = np.array([[template_sample_points_X[i][0], template_sample_points_Y[i][0]] for i in range(num_templates)])
    template_end_points = np.array([[template_sample_points_X[i][-1], template_sample_points_Y[i][-1]] for i in range(num_templates)])

    # Calculate distances between start points of gesture and templates and end points of gesture and templates
    start_distances = euclidean_distances(np.reshape(gesture_start_point, (1, -1)), template_start_points)[0]
    end_distances = euclidean_distances(np.reshape(gesture_end_point, (1, -1)), template_end_points)[0]

    # Get indices whose start + end distances are less than the threshold
    valid_indices = np.where((start_distances + end_distances) < threshold)[0]

    # Gather valid template sample points and valid words using the valid indices
    valid_template_sample_points_X = np.array(template_sample_points_X)[valid_indices]
    valid_template_sample_points_Y = np.array(template_sample_points_Y)[valid_indices]
    valid_words = [words[valid_index] for valid_index in valid_indices]

    return valid_indices, valid_words, valid_template_sample_points_X, valid_template_sample_points_Y
Do pruning on the dictionary of 10000 words.

    In this function, we use the pruning method described in the paper (or any other method you consider it reasonable)
    to narrow down the number of valid words so that the ambiguity can be avoided to some extent.

    :param gesture_points_X: A list of X-axis values of input gesture points, which has 100 values since we have
        sampled 100 points.
    :param gesture_points_Y: A list of Y-axis values of input gesture points, which has 100 values since we have
        sampled 100 points.
    :param template_sample_points_X: 2D list, containing X-axis values of every template (10000 templates in total).
        Each of the elements is a 1D list and has the length of 100.
    :param template_sample_points_Y: 2D list, containing Y-axis values of every template (10000 templates in total).
        Each of the elements is a 1D list and has the length of 100.

    :return:
        valid_words: A list of valid words after pruning.
        valid_probabilities: The corresponding probabilities of valid_words.
        valid_template_sample_points_X: 2D list, the corresponding X-axis values of valid_words. Each of the elements
            is a 1D list and has the length of 100.
        valid_template_sample_points_Y: 2D list, the corresponding Y-axis values of valid_words. Each of the elements
            is a 1D list and has the length of 100.
    
Do pruning on the dictionary of 10000 words.
In this function, we use the pruning method described in the paper (or any other method you consider it reasonable)
to narrow down the number of valid words so that the ambiguity can be avoided to some extent.
Do pruning on the dictionary of 10000 words . In this function we use the pruning method described in the paper ( or any other method you consider it reasonable ) to narrow down the number of valid words so that the ambiguity can be avoided to some extent .
def do_pruning(gesture_points_X, gesture_points_Y, template_sample_points_X, template_sample_points_Y):
    valid_words, valid_template_sample_points_X, valid_template_sample_points_Y = [], [], []
    threshold = 30
    gesture_start_point = np.array([gesture_points_X[0], gesture_points_Y[0]])
    gesture_end_point = np.array([gesture_points_X[-1], gesture_points_Y[-1]])
    num_templates = len(template_sample_points_X)
    template_start_points = np.array([[template_sample_points_X[i][0], template_sample_points_Y[i][0]] for i in range(num_templates)])
    template_end_points = np.array([[template_sample_points_X[i][-1], template_sample_points_Y[i][-1]] for i in range(num_templates)])
    start_distances = euclidean_distances(np.reshape(gesture_start_point, (1, -1)), template_start_points)[0]
    end_distances = euclidean_distances(np.reshape(gesture_end_point, (1, -1)), template_end_points)[0]
    valid_indices = np.where((start_distances + end_distances) < threshold)[0]
    valid_template_sample_points_X = np.array(template_sample_points_X)[valid_indices]
    valid_template_sample_points_Y = np.array(template_sample_points_Y)[valid_indices]
    valid_words = [words[valid_index] for valid_index in valid_indices]
    return valid_indices, valid_words, valid_template_sample_points_X, valid_template_sample_points_Y
def do_pruning ( gesture_points_X , gesture_points_Y , template_sample_points_X , template_sample_points_Y ) : valid_words , valid_template_sample_points_X , valid_template_sample_points_Y = [ ] , [ ] , [ ] threshold = 30 gesture_start_point = np . array ( [ gesture_points_X [ 0 ] , gesture_points_Y [ 0 ] ] ) gesture_end_point = np . array ( [ gesture_points_X [ - 1 ] , gesture_points_Y [ - 1 ] ] ) num_templates = len ( template_sample_points_X ) template_start_points = np . array ( [ [ template_sample_points_X [ i ] [ 0 ] , template_sample_points_Y [ i ] [ 0 ] ] for i in range ( num_templates ) ] ) template_end_points = np . array ( [ [ template_sample_points_X [ i ] [ - 1 ] , template_sample_points_Y [ i ] [ - 1 ] ] for i in range ( num_templates ) ] ) start_distances = euclidean_distances ( np . reshape ( gesture_start_point , ( 1 , - 1 ) ) , template_start_points ) [ 0 ] end_distances = euclidean_distances ( np . reshape ( gesture_end_point , ( 1 , - 1 ) ) , template_end_points ) [ 0 ] valid_indices = np . where ( ( start_distances + end_distances ) < threshold ) [ 0 ] valid_template_sample_points_X = np . array ( template_sample_points_X ) [ valid_indices ] valid_template_sample_points_Y = np . array ( template_sample_points_Y ) [ valid_indices ] valid_words = [ words [ valid_index ] for valid_index in valid_indices ] return valid_indices , valid_words , valid_template_sample_points_X , valid_template_sample_points_Y
Do pruning on the dictionary of 10000 words.
Do pruning on the dictionary of 10000 words .
'''Do pruning on the dictionary of 10000 words.

    In this function, we use the pruning method described in the paper (or any other method you consider it reasonable)
    to narrow down the number of valid words so that the ambiguity can be avoided to some extent.

    :param gesture_points_X: A list of X-axis values of input gesture points, which has 100 values since we have
        sampled 100 points.
    :param gesture_points_Y: A list of Y-axis values of input gesture points, which has 100 values since we have
        sampled 100 points.
    :param template_sample_points_X: 2D list, containing X-axis values of every template (10000 templates in total).
        Each of the elements is a 1D list and has the length of 100.
    :param template_sample_points_Y: 2D list, containing Y-axis values of every template (10000 templates in total).
        Each of the elements is a 1D list and has the length of 100.

    :return:
        valid_words: A list of valid words after pruning.
        valid_probabilities: The corresponding probabilities of valid_words.
        valid_template_sample_points_X: 2D list, the corresponding X-axis values of valid_words. Each of the elements
            is a 1D list and has the length of 100.
        valid_template_sample_points_Y: 2D list, the corresponding Y-axis values of valid_words. Each of the elements
            is a 1D list and has the length of 100.
    ''' # TODO: Set your own pruning threshold # TODO: Do pruning (12 points) # Create numpy array for gesture start and end point [[x, y]] # Number of templates # Gather the start points and end points of templates in a numpy matrix [[x1, y1], [x2, y2], ..., [xn, yn]] # Calculate distances between start points of gesture and templates and end points of gesture and templates # Get indices whose start + end distances are less than the threshold # Gather valid template sample points and valid words using the valid indices
A list of valid words after pruning.
valid_probabilities: The corresponding probabilities of valid_words.
valid_template_sample_points_X: 2D list, the corresponding X-axis values of valid_words. Each of the elements
is a 1D list and has the length of 100.
valid_template_sample_points_Y: 2D list, the corresponding Y-axis values of valid_words. Each of the elements
is a 1D list and has the length of 100.
A list of valid words after pruning . valid_probabilities : The corresponding probabilities of valid_words . valid_template_sample_points_X : 2D list the corresponding X - axis values of valid_words . Each of the elements is a 1D list and has the length of 100 . valid_template_sample_points_Y : 2D list the corresponding Y - axis values of valid_words . Each of the elements is a 1D list and has the length of 100 .
gesture_points_X
A list of X-axis values of input gesture points, which has 100 values since we have
sampled 100 points.
A list of X - axis values of input gesture points which has 100 values since we have sampled 100 points .
gesture_points_Y
A list of Y-axis values of input gesture points, which has 100 values since we have
sampled 100 points.
A list of Y - axis values of input gesture points which has 100 values since we have sampled 100 points .
template_sample_points_X
2D list, containing X-axis values of every template (10000 templates in total).
Each of the elements is a 1D list and has the length of 100.
2D list containing X - axis values of every template ( 10000 templates in total ) . Each of the elements is a 1D list and has the length of 100 .
template_sample_points_Y
2D list, containing Y-axis values of every template (10000 templates in total).
Each of the elements is a 1D list and has the length of 100.
2D list containing Y - axis values of every template ( 10000 templates in total ) . Each of the elements is a 1D list and has the length of 100 .