# Path: lxmls/data.py
# def find(filename):


import sys
import os
import numpy as np
import pytest
import warnings
import lxmls.readers.pos_corpus as pcc
import lxmls.readers.simple_sequence as ssr
import lxmls.sequences.hmm as hmmc
from lxmls import data
    from lxmls.sequences.log_domain import logsum


def test_exercise_9(hmm_with_corpus, train_seq, dev_seq, test_seq):
    hmm_with_corpus.train_supervised(train_seq)

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        viterbi_pred_train = hmm_with_corpus.viterbi_decode_corpus(train_seq)
        posterior_pred_train = hmm_with_corpus.posterior_decode_corpus(train_seq)
        eval_viterbi_train = hmm_with_corpus.evaluate_corpus(train_seq, viterbi_pred_train)
        eval_posterior_train = hmm_with_corpus.evaluate_corpus(train_seq, posterior_pred_train)
        assert abs(eval_posterior_train - 0.9848682232688646) < tolerance
        assert abs(eval_viterbi_train - 0.9846678023850085) < tolerance

        viterbi_pred_test = hmm_with_corpus.viterbi_decode_corpus(test_seq)
        posterior_pred_test = hmm_with_corpus.posterior_decode_corpus(test_seq)
        eval_viterbi_test = hmm_with_corpus.evaluate_corpus(test_seq, viterbi_pred_test)
        eval_posterior_test = hmm_with_corpus.evaluate_corpus(test_seq, posterior_pred_test)
        assert abs(eval_posterior_test - 0.3497722321251733) < tolerance
        assert abs(eval_viterbi_test - 0.5088136264606853) < tolerance

        best_smothing = hmm_with_corpus.pick_best_smoothing(train_seq, dev_seq, [1, 0.1])

        hmm_with_corpus.train_supervised(train_seq, smoothing=best_smothing)
        viterbi_pred_test = hmm_with_corpus.viterbi_decode_corpus(test_seq)
        posterior_pred_test = hmm_with_corpus.posterior_decode_corpus(test_seq)
        eval_viterbi_test = hmm_with_corpus.evaluate_corpus(test_seq, viterbi_pred_test)
        eval_posterior_test = hmm_with_corpus.evaluate_corpus(test_seq, posterior_pred_test)
        assert abs(best_smothing - 0.100) < tolerance
        assert abs(eval_posterior_test - 0.8367993662111309) < tolerance

# Path: lxmls/data.py
# def find(filename):


# Path: tests/test_sequence_models.py
import sys
import os
import numpy as np
import pytest
import warnings
import lxmls.readers.pos_corpus as pcc
import lxmls.readers.simple_sequence as ssr
import lxmls.sequences.hmm as hmmc
from lxmls import data
    from lxmls.sequences.log_domain import logsum



def test_exercise_9(hmm_with_corpus, train_seq, dev_seq, test_seq):
    hmm_with_corpus.train_supervised(train_seq)

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        viterbi_pred_train = hmm_with_corpus.viterbi_decode_corpus(train_seq)
        posterior_pred_train = hmm_with_corpus.posterior_decode_corpus(train_seq)
        eval_viterbi_train = hmm_with_corpus.evaluate_corpus(train_seq, viterbi_pred_train)
        eval_posterior_train = hmm_with_corpus.evaluate_corpus(train_seq, posterior_pred_train)
        assert abs(eval_posterior_train - 0.9848682232688646) < tolerance
        assert abs(eval_viterbi_train - 0.9846678023850085) < tolerance

        viterbi_pred_test = hmm_with_corpus.viterbi_decode_corpus(test_seq)
        posterior_pred_test = hmm_with_corpus.posterior_decode_corpus(test_seq)
        eval_viterbi_test = hmm_with_corpus.evaluate_corpus(test_seq, viterbi_pred_test)
        eval_posterior_test = hmm_with_corpus.evaluate_corpus(test_seq, posterior_pred_test)
        assert abs(eval_posterior_test - 0.3497722321251733) < tolerance
        assert abs(eval_viterbi_test - 0.5088136264606853) < tolerance

        best_smothing = hmm_with_corpus.pick_best_smoothing(train_seq, dev_seq, [1, 0.1])

        hmm_with_corpus.train_supervised(train_seq, smoothing=best_smothing)
        viterbi_pred_test = hmm_with_corpus.viterbi_decode_corpus(test_seq)
        posterior_pred_test = hmm_with_corpus.posterior_decode_corpus(test_seq)
        eval_viterbi_test = hmm_with_corpus.evaluate_corpus(test_seq, viterbi_pred_test)
        eval_posterior_test = hmm_with_corpus.evaluate_corpus(test_seq, posterior_pred_test)
        assert abs(best_smothing - 0.100) < tolerance
        assert abs(eval_posterior_test - 0.8367993662111309) < tolerance

        assert abs(eval_viterbi_test - 0.8265002970885323) < tolerance