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_compare_speed_with_constants(constats_enabled): for i in range(100): support = np.arange(0.1,3.1,0.1) x = Symbol('x') basis_functions = [x,sin,log,exp] creator_object = DatasetCreator(basis_functions,max_linear_terms=1, max_binomial_terms=1, max_compositions=1, max_N_terms=1,division_on=False, constants_enabled=constats_enabled, random_terms=True) numerical, dictionary = creator_object.generate_batch(support,1)
def test_luca_dataset_creator(constats_enabled): support = np.arange(0.1,3.1,0.1) x = Symbol('x') basis_functions = [x,sin,log,exp] creator_object = DatasetCreator(basis_functions,max_linear_terms=2, max_binomial_terms=1, max_compositions=1, max_N_terms=0,division_on=False, constants_enabled=constats_enabled, random_terms=False) res = creator_object.generate_set(support,25) print(res)
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_generate_batch(X_noise,Y_noise): 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=1, max_compositions=2) number_to_generate = 1 support = np.arange(-20,20,0.1) inp, out, real_dict = fun_generator.generate_batch(support, number_to_generate, X_noise=X_noise, Y_noise=Y_noise, return_real_dict=True) print(out) print(real_dict)
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_batch(): try: 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) support = np.arange(-3, 3, 0.1) string, dictionary = fun_generator.generate_batch(support, 20) result = tokenization.pipeline(dictionary) except: pdb.set_trace()
def test_check_for_plus(): support = np.arange(0.1, 3.1, 0.1) 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=1, max_binomial_terms=1, max_compositions=1, max_N_terms=0, division_on=False) string, dictionary = fun_generator.generate_batch(support, 1) res = tokenization.get_string(tokenization.pipeline(dictionary)[0]) if res: assert res[-1] != "+"
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()
def test_assert_assertion(): x = Symbol 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) with pytest.raises(TypeError): fun_generator = DatasetCreator(basis_functions)