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()
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)
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)
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'])
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
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")
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)
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)
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()