def get_s_indices(*files, ratio: (str, list) = None, index_file=None, s_indices: (PATH_TYPE, list) = None, shuffle=True, random_state=None): if s_indices is not None: if isinstance(s_indices, PATH_TYPE): s_indices = [ set(_s_indices) for _s_indices in json_load(s_indices) ] elif ratio is not None: ratio = _ratio_list(ratio) src = zip(*[loading(_file) for _file in files]) indices = [i for i, _ in enumerate(src)] if shuffle: indices = shuffle_indices(indices, random_state) s_indices = _get_s_indices(indices, ratio) else: raise ValueError("ratio or s_indices should be specified") if index_file is not None: with as_out_io(index_file) as wf: json.dump([list(_s_indices) for _s_indices in s_indices], wf) return s_indices
def load_transition_matrix(filepath): meta_data = json_load(filepath) for i in range(len(meta_data)): if isinstance(meta_data[i], dict): converted_dict = {} for k, v_dict in meta_data[i].items(): converted_dict[int(k)] = defaultdict(float) for key, value in v_dict.items(): converted_dict[int(k)][int(key)] = value meta_data[i] = converted_dict return meta_data
def test_utils(tmpdir, xy_path): with pytest.raises(ValueError): get_s_indices(*xy_path) index_file = path_append(tmpdir, "index.json") train_index, test_index = get_s_indices(*xy_path, ratio="1:1", index_file=index_file, shuffle=False) train_index, test_index = get_s_indices( *xy_path, s_indices=[train_index, test_index]) assert list(train_index) == [0, 1, 2, 3, 4] assert list(test_index) == [5, 6, 7, 8, 9] train_index, test_index = json_load(index_file) assert train_index == [0, 1, 2, 3, 4] assert test_index == [5, 6, 7, 8, 9] train_index, test_index = get_s_indices(*xy_path, s_indices=index_file) assert list(train_index) == [0, 1, 2, 3, 4] assert list(test_index) == [5, 6, 7, 8, 9]
def load_configuration(filepath): return json_load(filepath)
def load_learning_order(filepath): return json_load(filepath)
def load_items(filepath): if os.path.exists(filepath): return json_load(filepath) else: return {}
def load_state_to_vector(filepath): return json_load(filepath)
def load_initial_states(filepath): return json_load(filepath)