예제 #1
0
def test_assert_exception_to_many_terms():
    x = Symbol('x')
    basis_functions = [x,exp,log,sin] #Pay attention as the order is indeed important, for testing we put it in alphabetical order (apart from x)
    fun_generator = DatasetCreator(basis_functions,max_linear_terms=5, random_terms=False)
    with pytest.raises(IndexError):
        for i in range(10):
            fun_generator.generate_fun()
예제 #2
0
def test_get_back(constats_enabled):
    x = Symbol('x')
    basis_functions = [
        x, exp, log, sin
    ]  #Pay attention as the order is indeed important, for testing we put it in alphabetical order (apart from x)
    for i in range(10):
        fun_generator = DatasetCreator(basis_functions,
                                       max_linear_terms=4,
                                       constants_enabled=constats_enabled)
        simpy_output, dictionary, dictionary_clean = fun_generator.generate_fun(
        )
        separated_dict = tokenization.extract_terms(dictionary_clean)
        numberized_dict, mapping = tokenization.numberize_terms(separated_dict)
        final_seq = tokenization.flatten_seq(numberized_dict, mapping=mapping)
        ori_fun = lambdify(x, simpy_output, 'numpy')
        try:
            get_back = lambdify(x, tokenization.get_string(final_seq), 'numpy')
        except:
            pdb.set_trace()
        input_x = np.arange(-3, 3, 0.1)
        if not constats_enabled:
            ori_y = np.nan_to_num(
                fun_generator.handling_nan_evaluation(input_x, ori_fun))
            new_y = np.nan_to_num(
                fun_generator.handling_nan_evaluation(input_x, get_back))
            assert np.all(ori_y == new_y)
예제 #3
0
def test_generate_X_and_Y():
    x = Symbol('x')
    basis_functions = [x,exp,log,sin] #Pay attention as the order is indeed important, for testing we put it in alphabetical order (apart from x)
    fun_generator = DatasetCreator(basis_functions,max_linear_terms=4)
    string, _, _ =  fun_generator.generate_fun()
    support = np.arange(1,20)
    y = fun_generator.evaluate_function(support,string)
예제 #4
0
def test_separator():
    x = Symbol('x')
    basis_functions = [
        x, exp, log, sin
    ]  #Pay attention as the order is indeed important, for testing we put it in alphabetical order (apart from x)
    fun_generator = DatasetCreator(basis_functions, max_linear_terms=4)
    string, dictionary, _ = fun_generator.generate_fun()
    separated_dict = tokenization.extract_terms(dictionary)
    print(separated_dict['Single'])
예제 #5
0
def test_no_terms_are_zoo():
    for i in range(100):
        x = Symbol('x')
        basis_functions = [x,exp,log,sin] #Pay attention as the order is indeed important, for testing we put it in alphabetical order (apart from x)
        fun_generator = DatasetCreator(basis_functions,max_linear_terms=4)
        string, dictionary, _ =  fun_generator.generate_fun()
        for terms in dictionary.values():
            for term in terms:
                assert term != zoo
예제 #6
0
def test_final():
    x = Symbol('x')
    basis_functions = [
        x, exp, log, sin
    ]  #Pay attention as the order is indeed important, for testing we put it in alphabetical order (apart from x)
    fun_generator = DatasetCreator(basis_functions, max_linear_terms=4)
    string, dictionary, _ = fun_generator.generate_fun()
    separated_dict = tokenization.extract_terms(dictionary)
    numberized_dict, mapping = tokenization.numberize_terms(separated_dict)
    final_seq = tokenization.flatten_seq(numberized_dict, mapping=mapping)
    print(final_seq)
    print("hello")
예제 #7
0
def test_forecast_len():
    x = Symbol('x')
    basis_functions = [x,exp,log,sin] #Pay attention as the order is indeed important, for testing we put it in alphabetical order (apart from x)
    fun_generator = DatasetCreator(basis_functions,max_linear_terms=4)
    string, dictionary =  fun_generator.generate_fun()
    utils.forecast_len(dictionary)
예제 #8
0
def test_domain_calculator():
    x = Symbol('x')
    basis_functions = [x,exp,log,sin] #Pay attention as the order is indeed important, for testing we put it in alphabetical order (apart from x)
    fun_generator = DatasetCreator(basis_functions,max_linear_terms=4)
    string, dictionary, _ =  fun_generator.generate_fun()
    fun_generator.compute_admissible_domain(string)
예제 #9
0
def test_single_function_generation(constats_enabled):
    x = Symbol('x')
    basis_functions = [x,exp,log,sin] #Pay attention as the order is indeed important, for testing we put it in alphabetical order (apart from x)
    fun_generator = DatasetCreator(basis_functions,max_linear_terms=4, constants_enabled=constats_enabled,max_compositions=4)
    string, dictionary, dictionary_cleaned =  fun_generator.generate_fun()