def __init__(self, tool, module, parameters=None, settings=None): self.instructions = tool.instructions self.name = tool.name if module: self.path = os.path.join('./tools', tool.path, tool.modules[module] + '.json') else: self.path = os.path.join('./tools', tool.path, tool.name + '.json') self.parameters = Parameters(self.path) self.user_settings = Parameters('./user_defaults.json') self.cmd = '' self.update() self.qsub_file = None
def test_check_the_progress(self): query_weights_optimizer = QueryWeightsOptimizer(Parameters()) res = query_weights_optimizer.check_the_progress([0.7, 0.6, 0.5, 0.4], 4) self.assertFalse(res) res = query_weights_optimizer.check_the_progress([0.2, 0.6, 0.5, 0.4], 4) self.assertTrue(res) res = query_weights_optimizer.check_the_progress([0.2, 0.6, 0.5, 0.4], 3) self.assertFalse(res) res = query_weights_optimizer.check_the_progress([0.7, 0.6, 0.5, 0.4], 5) self.assertTrue(res) res = query_weights_optimizer.check_the_progress([0.7, 0.6, 0.5, 0.5], 2) self.assertTrue(res) self.assertRaises(ValueError, query_weights_optimizer.check_the_progress, [0.7, 0.6, 0.5, 0.4], 1) self.assertRaises(ValueError, query_weights_optimizer.check_the_progress, [0.7, 0.6, 0.5, 0.4], 2.5)
def setUp(self): self.parameters = Parameters() self.parameters.params["repo_dir"] = '../../index/test_files/index' self.parameters.params["type_weights"]["exp_embed"] = 0.05 self.parameters.params["type_weights"]["exp_top_docs"] = 0 self.parameters.params['feature_parameters'] = {} self.parameters.params['feature_parameters'][ 'OrderedBigramWeights'] = { "od_expression_norm_count": { "window_size": 4 }, "od_expression_norm_document_count": { "window_size": 4 }, "td_od_expression_norm_count": { "window_size": 17, "n_top_docs": 10, }, "td_od_expression_norm_document_count": { "window_size": 17, "n_top_docs": 10, }, } self.parameters.params['features_weights'] = {} self.parameters.params['features_weights']['OrderedBigramWeights'] = { "od_expression_norm_count": 0.33, "od_expression_norm_document_count": 0.33, "bigrams_cosine_similarity_with_orig": 0.33, "td_od_expression_norm_count": 0.33, "td_od_expression_norm_document_count": 0.33, }
def setUp(self): self.parameters = Parameters() self.parameters.params["repo_dir"] = '../../index/test_files/index' self.parameters.params["type_weights"] = { "exp_embed": 0.05, "exp_top_docs": 0 } self.parameters.params['feature_parameters'] = {} self.parameters.params['feature_parameters']['UnigramWeights'] = { "norm_term_count": {}, "norm_document_count": {}, "unigrams_cosine_similarity_with_orig": {}, "td_norm_unigram_count": { "n_top_docs": 10 }, "td_norm_unigram_document_count": { "n_top_docs": 10 }, } self.parameters.params['features_weights'] = {} self.parameters.params['features_weights']['UnigramWeights'] = { "norm_term_count": 0.33, "norm_document_count": 0.33, "unigrams_cosine_similarity_with_orig": 0.33, "td_norm_unigram_count": 0.33, "td_norm_unigram_document_count": 0.33, }
def test_1d_y_dirichlet(self): length_y = 20 # m nx = 1 ny = 20 h_l = 5 h_r = 10 K = 1 q0 = 1 show_plot = False grid = StaggeredGrid(size=[1, length_y], dimensions=[nx, ny]) dirichlet_cell_bc = [grid.idx_cell_dofs_ymin, grid.idx_cell_dofs_ymax] dirichlet_flux_bc = [grid.idx_flux_dofs_ymin, grid.idx_flux_dofs_ymax] g = self.analytical_solution_1d_dirichlet( [grid.loc_cell_y[0], grid.loc_cell_y[-1]], length_y, K, q0, h_l, h_r) param = Parameters(dir_cell=dirichlet_cell_bc, dir_flux=dirichlet_flux_bc) fs = np.full((grid.n_cell_dofs_total, ), q0) numerical_solution = self.solve(grid, param, K, fs, g) analytical_solution = self.analytical_solution_1d_dirichlet( grid.loc_cell_y, length_y, K, q0, h_l, h_r) if show_plot: Visualization.plot_two_data(x1=grid.loc_cell_y, y1=numerical_solution, x2=grid.loc_cell_y, y2=analytical_solution, xlabel="Coordinate") np.testing.assert_almost_equal(numerical_solution, analytical_solution)
def setUp(self): self.parameters = Parameters() self.parameters.params["repo_dir"] = '../index/test_files/index' self.parameters.params["lda"] = { "file_name": '../configs/lda/ap8889.txt', "number_topics": 50 }
def setUp(self): self.parameters = Parameters() self.parameters.params["repo_dir"] = '../index/test_files/index' self.topdocs_ = features.topdocs.Topdocs(self.parameters) self.feature_parameters = { "OrderedBigramWeights": { "td_od_expression_norm_count": { "window_size": 1, "n_top_docs": 15 }, "td_od_expression_norm_document_count": { "window_size": 1, "n_top_docs": 15 } }, "UnigramWeights": { "td_norm_unigram_count": { "n_top_docs": 15 }, "td_norm_unigram_document_count": { "n_top_docs": 15 } }, "UnorderedBigramWeights": { "td_uw_expression_norm_count": { "window_size": 2, "n_top_docs": 15 }, "td_uw_expression_norm_document_count": { "window_size": 2, "n_top_docs": 15 } } } self.topdocs_.init_top_docs_run_query("a")
def setUp(self): self.parameters = Parameters() self.parameters.params["word2vec"] = { "upper_threshold": 0.8, "lower_threshold": 0.6, "n_max": 5 } self.parameters.params["repo_dir"] = '../index/test_files/index' self.embedding_space = EmbeddingSpace(self.parameters) self.embedding_space.initialize()
def setUp(self): self.parameters = Parameters() self.parameters.params["repo_dir"] = '../index/test_files/index' self.features = features.features.Features(self.parameters) self.feature_parameters = { "uw_expression_norm_count": { "window_size": 17 }, "uw_expression_norm_document_count": { "window_size": 4 } }
class TestParameters(TestCase): def setUp(self): self.parameters = Parameters() self.parameters.params_file = "test_files/parameters.json" def test_write_to_parameters_file(self): params_ = { "norm_term_count": { "abc": float(np.int64(0.2)) }, "norm_document_count": { "edc": 12 }, "unigrams_cosine_similarity_with_orig": { "def": 1.2 }, } self.parameters.params = params_ self.parameters.write_to_parameters_file(self.parameters.params_file) self.parameters.read_from_params_file() print(type(self.parameters.params["norm_term_count"]["abc"]), file=sys.stderr) self.assertEqual(params_, self.parameters.params)
def test_1d_y_neumann(self): length_y = 20 # m nx = 1 ny = 20 h_l = 5 q_r = np.array([1]) K = 1 rhs = 1 show_plot = False grid = StaggeredGrid(size=[1, length_y], dimensions=[nx, ny]) # set boundary conditions dirichlet_cell_bc = grid.idx_cell_dofs_ymin dirichlet_flux_bc = grid.idx_flux_dofs_ymin neumann_cell_bc = grid.idx_cell_dofs_ymax neumann_flux_bc = grid.idx_flux_dofs_ymax g = self.analytical_solution_1d_neumann([grid.loc_cell_y[0]], length_y, K, rhs, h_l, q_r, neumann_left=False) param = Parameters( dir_cell=dirichlet_cell_bc, dir_flux=dirichlet_flux_bc, neu_cell=neumann_cell_bc, neu_flux=neumann_flux_bc, flux_bc=-q_r) # this is negative since neumann is right side fs = np.full((grid.n_cell_dofs_total, ), rhs) numerical_solution = self.solve(grid, param, K, fs, g) analytical_solution = self.analytical_solution_1d_neumann( grid.loc_cell_y, length_y, K, rhs, h_l, q_r, neumann_left=False) if show_plot: Visualization.plot_two_data(x1=grid.loc_cell_y, y1=numerical_solution, x2=grid.loc_cell_y, y2=analytical_solution, xlabel="y") np.testing.assert_almost_equal(numerical_solution, analytical_solution)
def setUp(self): self.parameters = Parameters() self.parameters.params["repo_dir"] = '../index/test_files/index' self.features = features.collection.Collection(self.parameters) self.feature_parameters = { "uw_expression_count": { "window_size": 17 }, "od_expression_count": { "window_size": 4 }, "uw_expression_document_count": { "window_size": 4 }, "od_expression_document_count": { "window_size": 4 }, }
def test_1d_x_neumann(self): length_x = 20 # m nx = 20 ny = 1 h_r = 5 q_l = np.array([1]) K = 1 rhs = 1 show_plot = False grid = StaggeredGrid(size=[length_x, 1], dimensions=[nx, ny]) # set boundary conditions dirichlet_cell_bc = grid.idx_cell_dofs_xmax dirichlet_flux_bc = grid.idx_flux_dofs_xmax neumann_cell_bc = grid.idx_cell_dofs_xmin neumann_flux_bc = grid.idx_flux_dofs_xmin g = self.analytical_solution_1d_neumann([grid.loc_cell_x[-1]], length_x, K, rhs, h_r, q_l, neumann_left=True) param = Parameters(dir_cell=dirichlet_cell_bc, dir_flux=dirichlet_flux_bc, neu_cell=neumann_cell_bc, neu_flux=neumann_flux_bc, flux_bc=q_l) fs = np.full((grid.n_cell_dofs_total, ), rhs) numerical_solution = self.solve(grid, param, K, fs, g) analytical_solution = self.analytical_solution_1d_neumann( grid.loc_cell_x, length_x, K, rhs, h_r, q_l, neumann_left=True) if show_plot: Visualization.plot_two_data(x1=grid.loc_cell_x, y1=numerical_solution, x2=grid.loc_cell_x, y2=analytical_solution, xlabel="x") np.testing.assert_almost_equal(numerical_solution, analytical_solution)
def setUp(self): self.parameters = Parameters() self.parameters.params["repo_dir"] = '../index/test_files/index' self.original = Original(self.parameters)
def setUp(self): self.parameters = Parameters() self.parameters.params["repo_dir"] = '../index/test_files/index' self.index_ = Index(self.parameters)
def setUp(self): self.parameters = Parameters() self.parameters.params["query_files"] = { "old_indri_query_file": "test_files/indri_query.cfg" } self.parameters.params["cross_validation"] = { "number_of_folds": 3, "testing_fold": 1 } self.parameters.params["repo_dir"] = '../index/test_files/index' self.parameters.params["word2vec"] = {} self.parameters.params["word2vec"]["threshold"] = 0.6 self.parameters.params["window_size"] = {} self.parameters.params["window_size"]["#od"] = 4 self.parameters.params["window_size"]["#uw"] = 17 self.parameters.params['feature_parameters'] = {} self.parameters.params['feature_parameters']['UnigramWeights'] = { "norm_term_count": {}, "norm_document_count": {}, "unigrams_cosine_similarity_with_orig": {} } self.parameters.params['feature_parameters'][ 'UnorderedBigramWeights'] = { "uw_expression_norm_count": { "window_size": 17 }, "uw_expression_norm_document_count": { "window_size": 17 } } self.parameters.params['feature_parameters'][ 'OrderedBigramWeights'] = { "od_expression_norm_count": { "window_size": 17 }, "od_expression_norm_document_count": { "window_size": 17 } } self.parameters.params['features_weights'] = {} self.parameters.params['features_weights']['UnigramWeights'] = { "norm_term_count": 0.33, "norm_document_count": 0.33, "unigrams_cosine_similarity_with_orig": 0.33 } self.parameters.params['features_weights'][ 'UnorderedBigramWeights'] = { "uw_expression_norm_count": 0.33, "uw_expression_norm_document_count": 0.33, "bigrams_cosine_similarity_with_orig": 0.33 } self.parameters.params['features_weights']['OrderedBigramWeights'] = { "od_expression_norm_count": 0.33, "od_expression_norm_document_count": 0.33, "bigrams_cosine_similarity_with_orig": 0.33 } self.parameters.params["word2vec"] = {"threshold": 0.6, "n_max": 5} self.parameters.params["sdm_field_weights"] = { "u": 0.9, "o": 0.05, "w": 0.05 } self.query_weights_optimizer = QueryWeightsOptimizer(self.parameters)
class Job: """ Object Job stores information about a tool and implement methods to work with a tool. """ def __init__(self, tool, module, parameters=None, settings=None): self.instructions = tool.instructions self.name = tool.name if module: self.path = os.path.join('./tools', tool.path, tool.modules[module] + '.json') else: self.path = os.path.join('./tools', tool.path, tool.name + '.json') self.parameters = Parameters(self.path) self.user_settings = Parameters('./user_defaults.json') self.cmd = '' self.update() self.qsub_file = None def update(self): """ Generate / regenerate the cmd string from parameters """ self.cmd = '' for p in self.parameters.list: parameter = getattr(self.parameters, p) self.cmd += self.write_parameter(parameter) def run(self): """ Run command and capture output for verification. """ result = subprocess.Popen(self.cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while True: line = result.stdout.readline() if not line: break def create_qsub_file(self, file_p='./denovo_map.sh'): """ Generate a shell file with the command in the format required to submit a job on an HPC platform. """ try: is_file_o(file_p) file_f = open(file_p, 'w') for name in self.user_settings.list: setting = getattr(self.user_settings, name) to_write = self.write_setting(setting) if to_write: file_f.write(to_write) for instruction in self.instructions: file_f.write(instruction + '\n') file_f.write('\n' + self.cmd) self.qsub_file = file_p except ValueError: print('** Error: could not generate qsub file.') def submit(self): """ Submit a shell file with the command as a job on an HPC platform. """ try: if not self.qsub_file: self.create_qsub_file() qsub_cmd = 'qsub ' + self.qsub_file result = subprocess.Popen(qsub_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if not result: return None except ValueError: print('** Error: qsub file not found. Did you generate a shell' + ' file before submitting?') def set_parameters(self, arg): if (isinstance(arg, dict)): self.parameters.set_from_dictionary(arg) elif (isinstance(arg, str)): self.parameters.set_from_json(arg) self.update() def set_user_settings(self, arg): if (isinstance(arg, dict)): self.user_settings.set_from_dictionary(arg) elif (isinstance(arg, str)): self.user_settings.set_from_json(arg) self.update() def write_parameter(self, parameter): cmd = '' if parameter.value: if parameter.flag: cmd += parameter.flag + ' ' if parameter.type != BOOL: cmd += str(parameter.value) + ' ' elif parameter.required and parameter.default: print('* Warning: no user-defined value for parameter ' + parameter.name + '. Setting value to default: ' + parameter.default + '.') if parameter.flag: cmd += parameter.flag + ' ' if parameter.type != BOOL: cmd += str(parameter.default) + ' ' return cmd def write_setting(self, setting): cmd = '#' if setting.value: if setting.value == 'SHELL': cmd += setting.value if setting.flag: cmd += '$ ' + setting.flag + ' ' cmd += str(setting.value) + ' ' cmd = cmd.rstrip(' ') + '\n' elif setting.required: if setting.value == 'SHELL': cmd += setting.value if setting.flag: cmd += '$ ' + setting.flag + ' ' cmd += str(setting.default) + ' ' cmd = cmd.rstrip(' ') + '\n' else: cmd = '' return cmd
def setUp(self): self.parameters = Parameters() self.parameters.params["repo_dir"] = '../index/test_files/index' self.parameters.params['feature_parameters'] = {} self.parameters.params['feature_parameters']['UnorderedBigramWeights'] = { "uw_expression_norm_count": { "window_size": 17 }, "uw_expression_norm_document_count": { "window_size": 17 }, "td_uw_expression_norm_count": { "window_size": 17, "n_top_docs": 10, }, "td_uw_expression_norm_document_count": { "window_size": 17, "n_top_docs": 10, }, 'bigrams_cosine_similarity_with_orig': {} } self.parameters.params['feature_parameters']['OrderedBigramWeights'] = { "od_expression_norm_count": { "window_size": 17 }, "od_expression_norm_document_count": { "window_size": 17 }, "td_od_expression_norm_count": { "window_size": 17, "n_top_docs": 10, }, "td_od_expression_norm_document_count": { "window_size": 17, "n_top_docs": 10, } } self.parameters.params['features_weights'] = {} self.parameters.params['features_weights']['UnorderedBigramWeights'] = { "uw_expression_norm_count": 0.33, "uw_expression_norm_document_count": 0.33, "bigrams_cosine_similarity_with_orig": 0.33, 'td_uw_expression_norm_document_count': 0.1, "td_uw_expression_norm_count": 0.1 } self.parameters.params['features_weights']['OrderedBigramWeights'] = { "od_expression_norm_count": 0.33, "od_expression_norm_document_count": 0.33, "bigrams_cosine_similarity_with_orig": 0.33 } self.parameters.params['feature_parameters']['UnigramWeights'] = { "norm_term_count": { }, "norm_document_count": { }, "unigrams_cosine_similarity_with_orig": { }, "td_norm_unigram_count": { "n_top_docs": 17 }, "td_norm_unigram_document_count": { "n_top_docs": 17 } } self.parameters.params['features_weights']['UnigramWeights'] = { "norm_term_count": 0.33, "norm_document_count": 0.33, "unigrams_cosine_similarity_with_orig": 0.33, "td_norm_unigram_count": 0.05, "td_norm_unigram_document_count": 0.1 } self.parameters.params["window_size"] = {} self.parameters.params["window_size"]["#od"] = 4 self.parameters.params["window_size"]["#uw"] = 17 self.parameters.params["type_weights"] = {"orig": 1, "exp_embed": 0.05, "exp_top_docs": 0.05} self.all_unigrams = {'orig': [('two', [('two', 1)]), ('stand', [('stand', 1)]), ('hands', [('hands', 1)])], 'exp_embed': [('two', [('pair', 0.5850129127502441), ('one', 0.576961874961853)]), ('stand', [('sit', 0.5178298950195312), ('come', 0.3913347125053406)]), ('hands', [('arm', 0.446733295917511), ('ears', 0.410521537065506)])]} self.all_bigrams = {'orig_orig': [(('two', 'stand'), [(('two', 1), ('stand', 1))]), (('stand', 'hands'), [(('stand', 1), ('hands', 1))])], 'orig_exp_embed': [(('two', 'stand'), [(('two', 1), ('sit', 0.5178298950195312)), (('two', 1), ('come', 0.3913347125053406))]), ( ('stand', 'hands'), [(('stand', 1), ('arm', 0.446733295917511)), (('stand', 1), ('ears', 0.410521537065506))])], 'exp_embed_exp_embed': [(('two', 'stand'), [(('pair', 0.5850129127502441), ('sit', 0.5178298950195312)), (('pair', 0.5850129127502441), ('come', 0.3913347125053406)), (('one', 0.576961874961853), ('sit', 0.5178298950195312)), (('one', 0.576961874961853), ('come', 0.3913347125053406))]), ( ('stand', 'hands'), [(('sit', 0.5178298950195312), ('arm', 0.446733295917511)), (('sit', 0.5178298950195312), ('ears', 0.410521537065506)), (('come', 0.3913347125053406), ('arm', 0.446733295917511)), (('come', 0.3913347125053406), ('ears', 0.410521537065506))])]}
return sol if __name__ == '__main__': # Peclet number pe = 10 # define grids and corresponding operators grid = StaggeredGrid(size=[1, 1], dimensions=[100, 1]) D, G, I = op.build_discrete_operators(grid) # Steady state problem # Set boundary conditions dirichlet_cell_bc = [grid.idx_cell_dofs_xmin, grid.idx_cell_dofs_xmax] dirichlet_flux_bc = [grid.idx_flux_dofs_xmin, grid.idx_flux_dofs_xmax] param = Parameters(dir_cell=dirichlet_cell_bc, dir_flux=dirichlet_flux_bc) g = analytical_solution_steady( np.array([grid.loc_cell_x[0], grid.loc_cell_x[-1]]), pe) q = np.ones(grid.n_flux_dofs_total) A = op.flux_upwind(q, grid) L = D * (pe * A - G) fs = np.zeros(grid.n_cell_dofs_total) B, N, fn = op.build_boundary_operators(grid, param, I) num_sol_steady = solve_linear_boundary_value_problem(L, fs + fn, B, g, N) ana_sol_steady = analytical_solution_steady(grid.loc_cell_x, pe) plt.plot(grid.loc_cell_x, num_sol_steady, '.', label="Numerical") plt.plot(grid.loc_cell_x, ana_sol_steady, label="Analytical") plt.title("Pe = " + str(pe))
def test_build_boundary_operators(self): # 1D grid = StaggeredGrid(size=[3, 1], dimensions=[3, 1]) _, _, I = Operators.build_discrete_operators(grid) # No boundary conditions param = Parameters() B, N, fn = Operators.build_boundary_operators(grid, param, I) B_ans = csr_matrix((len(param.dof_dirichlet), grid.n_cell_dofs_total)) N_ans = I.copy() fn_ans = np.zeros(grid.n_cell_dofs_total) np.testing.assert_array_almost_equal(B.toarray(), B_ans.toarray()) np.testing.assert_array_almost_equal(N.toarray(), N_ans.toarray()) np.testing.assert_array_almost_equal(fn, fn_ans) # Dirithlet and zero Neumann param = Parameters(dir_cell=[0], dir_flux=[0]) B, N, fn = Operators.build_boundary_operators(grid, param, I) B_ans = csr_matrix((len(param.dof_dirichlet), grid.n_cell_dofs_total)) N_ans = csr_matrix((grid.n_cell_dofs_total, grid.n_cell_dofs_total - len(param.dof_dirichlet))) fn_ans = np.zeros(grid.n_cell_dofs_total) B_ans[0, 0] = 1. N_ans[1, 0] = 1. N_ans[2, 1] = 1. np.testing.assert_array_almost_equal(B.toarray(), B_ans.toarray()) np.testing.assert_array_almost_equal(N.toarray(), N_ans.toarray()) np.testing.assert_array_almost_equal(fn, fn_ans) # Non-zero Neumann param = Parameters(neu_cell=[0], neu_flux=[0], flux_bc=[100]) B, N, fn = Operators.build_boundary_operators(grid, param, I) B_ans = csr_matrix((len(param.dof_dirichlet), grid.n_cell_dofs_total)) N_ans = I.copy() fn_ans = np.zeros(grid.n_cell_dofs_total) fn_ans[param.dof_neumann] = 100 np.testing.assert_array_almost_equal(B.toarray(), B_ans.toarray()) np.testing.assert_array_almost_equal(N.toarray(), N_ans.toarray()) np.testing.assert_array_almost_equal(fn, fn_ans) # 2D grid = StaggeredGrid(size=[3, 3], dimensions=[3, 3]) _, _, I = Operators.build_discrete_operators(grid) # No boundary conditions param = Parameters() B, N, fn = Operators.build_boundary_operators(grid, param, I) B_ans = csr_matrix((len(param.dof_dirichlet), grid.n_cell_dofs_total)) N_ans = I.copy() fn_ans = np.zeros(grid.n_cell_dofs_total) np.testing.assert_array_almost_equal(B.toarray(), B_ans.toarray()) np.testing.assert_array_almost_equal(N.toarray(), N_ans.toarray()) np.testing.assert_array_almost_equal(fn, fn_ans) # Dirithlet and zero Neumann dir_cell = [grid.idx_cell_dofs_xmin, grid.idx_cell_dofs_ymax] dir_flux = [grid.idx_flux_dofs_xmin, grid.idx_flux_dofs_ymax] param = Parameters(dir_cell=dir_cell, dir_flux=dir_flux) B, N, fn = Operators.build_boundary_operators(grid, param, I) B_ans = csr_matrix( (len(param.unique_dof_dirichelt), grid.n_cell_dofs_total)) N_ans = csr_matrix( (grid.n_cell_dofs_total, grid.n_cell_dofs_total - len(param.unique_dof_dirichelt))) fn_ans = np.zeros(grid.n_cell_dofs_total) B_ans[0, 0] = 1. B_ans[1, 1] = 1. B_ans[2, 2] = 1. B_ans[3, 5] = 1. B_ans[4, 8] = 1. N_ans[3, 0] = 1. N_ans[4, 1] = 1. N_ans[6, 2] = 1. N_ans[7, 3] = 1. np.testing.assert_array_almost_equal(B.toarray(), B_ans.toarray()) np.testing.assert_array_almost_equal(N.toarray(), N_ans.toarray()) np.testing.assert_array_almost_equal(fn, fn_ans) # Non-zero Neumann neu_cell = [grid.idx_cell_dofs_xmax, grid.idx_cell_dofs_ymin] neu_flux = [grid.idx_flux_dofs_xmax, grid.idx_flux_dofs_ymin] flux_bc = np.full((len(np.unique(neu_flux)), ), 100) flux_bc[:2] = -50 param = Parameters(neu_cell=neu_cell, neu_flux=neu_flux, flux_bc=flux_bc) B, N, fn = Operators.build_boundary_operators(grid, param, I) B_ans = csr_matrix( (len(param.unique_dof_dirichelt), grid.n_cell_dofs_total)) N_ans = I.copy() fn_ans = np.zeros(grid.n_cell_dofs_total) fn_ans[0] = 100 fn_ans[3] = 100 fn_ans[6] = 50 fn_ans[7] = -50 fn_ans[8] = 100 np.testing.assert_array_almost_equal(B.toarray(), B_ans.toarray()) np.testing.assert_array_almost_equal(N.toarray(), N_ans.toarray()) np.testing.assert_array_almost_equal(fn, fn_ans)
def setUp(self): self.parameters = Parameters() self.parameters.params_file = "test_files/parameters.json"
def show_parameters(self, sql_connection): self.parameters = Parameters(self.parametersUi, sql_connection) self.parameters.back_pressed.connect(self.show_sql) self.sqlUi.hide() self.parametersUi.show()
def setUp(self): self.parameters = Parameters() pass
from parameters.parameters import Parameters from solvers.solve_lbvp import solve_linear_boundary_value_problem from visualization.visualization_utils import Visualization if __name__ == '__main__': # define grids and corresponding operators grid = StaggeredGrid(size=[1, 1], dimensions=[10, 10]) D, G, I = op.build_discrete_operators(grid) Kd = 1. nt = 1 ct = 1e-6 # Initial condition p = np.full((grid.n_cell_dofs_total, ), 100) # Set boundary conditions param = Parameters() g = np.array([]) q = np.zeros(grid.n_cell_dofs_total) q[0] = 1 q[-1] = -1 dt = 0.1 L = I + dt / ct * D * Kd * G # fs = np.zeros(grid.n_cell_dofs_total) B, N, fn = op.build_boundary_operators(grid, param, I) for i in range(nt): fs = q * dt / ct + p p = solve_linear_boundary_value_problem(L, fs + fn, B, g, N)
self.check_indri_run_query_exception(run_file_name) evals = self.run_trec_eval_1(trec_eval_bin, run_file_name, qrels_file_name) eval_file_name = self.gen_configs_file_name(query_cfg_file, "evals", ".dsv") self.write_evals_to_files(evals, eval_file_name) self.evals_file_to_dict(eval_file_name) return self.evals_d[measure]['all'] def get_all_measures(self): return self.evals_d @staticmethod def gen_configs_file_name(query_cfg_file, configs_dir, ext): dir_q, file_name = os.path.split(query_cfg_file) dir_c, dir_q = os.path.split(dir_q) dir_r = os.path.join(dir_c, configs_dir) if not os.path.exists(dir_r): raise ValueError("file " + dir_r + " does NOT exist.") file_name_r = os.path.splitext(file_name)[0] + ext return os.path.join(dir_r, file_name_r) if __name__ == "__main__": parameters_ = Parameters() parameters_.read_from_params_file() eval_res = QueriesEvaluator(parameters_).run() print(eval_res)
def setUp(self): self.parameters = Parameters() self.parameters.params["repo_dir"] = '../index/test_files/index' self.parameters.params["word2vec"] = {} self.parameters.params["word2vec"]["threshold"] = 0.6 self.parameters.params["window_size"] = {} self.parameters.params["window_size"]["#od"] = 4 self.parameters.params["window_size"]["#uw"] = 17 self.parameters.params['feature_parameters'] = {} self.parameters.params['feature_parameters']['UnigramWeights'] = { "norm_term_count": {}, "norm_document_count": {}, "unigrams_cosine_similarity_with_orig": {} } self.parameters.params['feature_parameters'][ 'UnorderedBigramWeights'] = { "uw_expression_norm_count": { "window_size": 17 }, "uw_expression_norm_document_count": { "window_size": 17 } } self.parameters.params['feature_parameters'][ 'OrderedBigramWeights'] = { "od_expression_norm_count": { "window_size": 17 }, "od_expression_norm_document_count": { "window_size": 17 } } self.parameters.params['features_weights'] = {} self.parameters.params['features_weights']['UnigramWeights'] = { "norm_term_count": 0.33, "norm_document_count": 0.33, "unigrams_cosine_similarity_with_orig": 0.33 } self.parameters.params['features_weights'][ 'UnorderedBigramWeights'] = { "uw_expression_norm_count": 0.33, "uw_expression_norm_document_count": 0.33, "bigrams_cosine_similarity_with_orig": 0.33 } self.parameters.params['features_weights']['OrderedBigramWeights'] = { "od_expression_norm_count": 0.33, "od_expression_norm_document_count": 0.33, "bigrams_cosine_similarity_with_orig": 0.33 } self.parameters.params["word2vec"] = {"threshold": 0.6, "n_max": 5} self.parameters.params["type_weights"] = { "orig": 1, "exp_embed": 0.065, "exp_top_docs": 0, "orig_orig": 1, "orig_exp_embed": 0.065, "exp_embed_exp_embed": 0.010, "orig_exp_top_docs": 0, "exp_top_docs_exp_top_docs": 0 } self.all_unigrams = { 'orig': [('two', [('two', 1)]), ('stand', [('stand', 1)]), ('hands', [('hands', 1)])], 'exp_embed': [('two', [('pair', 0.5850129127502441), ('one', 0.576961874961853)]), ('stand', [('sit', 0.5178298950195312), ('come', 0.3913347125053406)]), ('hands', [('arm', 0.446733295917511), ('ears', 0.410521537065506)])] } self.all_bigrams = { 'orig_orig': [(('two', 'stand'), [(('two', 1), ('stand', 1))]), (('stand', 'hands'), [(('stand', 1), ('hands', 1))])], 'orig_exp_embed': [(('two', 'stand'), [(('two', 1), ('sit', 0.5178298950195312)), (('two', 1), ('come', 0.3913347125053406))]), (('stand', 'hands'), [(('stand', 1), ('arm', 0.446733295917511)), (('stand', 1), ('ears', 0.410521537065506)) ])], 'exp_embed_exp_embed': [(('two', 'stand'), [(('pair', 0.5850129127502441), ('sit', 0.5178298950195312)), (('pair', 0.5850129127502441), ('come', 0.3913347125053406)), (('one', 0.576961874961853), ('sit', 0.5178298950195312)), (('one', 0.576961874961853), ('come', 0.3913347125053406))]), (('stand', 'hands'), [(('sit', 0.5178298950195312), ('arm', 0.446733295917511)), (('sit', 0.5178298950195312), ('ears', 0.410521537065506)), (('come', 0.3913347125053406), ('arm', 0.446733295917511)), (('come', 0.3913347125053406), ('ears', 0.410521537065506))])] } self.all_fields = { 'u': '#weight(\n 1#weight(\n 0.90000000000000002220#combine(two)\n 0.59999999999999997780#combine(stand)\n 0.10000000000000000555#combine(hands)\n )\n 0.065#weight(\n 0.90000000000000002220#combine(pair)\n 0.10000000000000000555#combine(one)\n 0.59999999999999997780#combine(sit)\n 0.29999999999999998890#combine(come)\n 0.10000000000000000555#combine(arm)\n 0.10000000000000000555#combine(ears)\n )\n )\n', 'o': '#weight(\n 1#weight(\n 0.59999999999999997780#od(two stand)\n 0.20000000000000001110#od(stand hands)\n )\n 0.065#weight(\n 0.29999999999999998890#od(two sit)\n 0.40000000000000002220#od(two come)\n 0.10000000000000000555#od(stand arm)\n 0.10000000000000000555#od(stand ears)\n )\n 0.01#weight(\n 0.50000000000000000000#od(pair sit)\n 0.50000000000000000000#od(pair come)\n 0.50000000000000000000#od(one sit)\n 0.50000000000000000000#od(one come)\n 0.50000000000000000000#od(sit arm)\n 0.50000000000000000000#od(sit ears)\n 0.50000000000000000000#od(come arm)\n 0.50000000000000000000#od(come ears)\n )\n )\n', 'w': '#weight(\n 1#weight(\n 0.59999999999999997780#uw(two stand)\n 0.20000000000000001110#uw(stand hands)\n )\n 0.065#weight(\n 0.29999999999999998890#uw(two sit)\n 0.40000000000000002220#uw(two come)\n 0.10000000000000000555#uw(stand arm)\n 0.10000000000000000555#uw(stand ears)\n )\n 0.01#weight(\n 0.50000000000000000000#uw(pair sit)\n 0.50000000000000000000#uw(pair come)\n 0.50000000000000000000#uw(one sit)\n 0.50000000000000000000#uw(one come)\n 0.50000000000000000000#uw(sit arm)\n 0.50000000000000000000#uw(sit ears)\n 0.50000000000000000000#uw(come arm)\n 0.50000000000000000000#uw(come ears)\n )\n )\n' }