mlpack
|
Classes | |
class | restore_value |
Functions | |
def | process_params_out (model, params, return_str=False) |
def | process_params_in (model, params_dic) |
def | np_to_arma (obj) |
def | arma_to_np (obj) |
def | scrub (obj, bad_key, values, full_paths, ref_path) |
def | value_resolver (pairs) |
def | insert_in_dic (dic, path, key, val) |
preprocess_json_params.py: utility functions for json paramter preprocessing (see set_cpp_param() and get_cpp_param() methods in print_class_defn.hpp) The "process_params_out" and "process_params_in" utilities are used to handle interconversion between the output json from cereal and python dictionary. mlpack is free software; you may redistribute it and/or modify it under the terms of the 3-clause BSD license. You should have received a copy of the 3-clause BSD license along with mlpack. If not, see http://www.opensource.org/licenses/BSD-3-Clause for more information.
def mlpack.preprocess_json_params.arma_to_np | ( | obj | ) |
This function replaces the JSON representation of armadillo vector to numpy array in the given dictionary.
def mlpack.preprocess_json_params.insert_in_dic | ( | dic, | |
path, | |||
key, | |||
val | |||
) |
This function inserts a particluar key-value pair in a dictionray after following a particular path.
def mlpack.preprocess_json_params.np_to_arma | ( | obj | ) |
This function replaces a numpy array to json representation of armadillo vector. This is reverse of "arma_to_np(obj)".
def mlpack.preprocess_json_params.process_params_in | ( | model, | |
params_dic | |||
) |
This function takes in a model and the parameters dictionary, and returns a string that can be ingested back into the model.
def mlpack.preprocess_json_params.process_params_out | ( | model, | |
params, | |||
return_str = False |
|||
) |
This method processes the parameters obtained from the model. params: 1) model - the model to process params. 2) params - json parameters of the model (which we get through cereal). 3) return_str (bool) - if True then a pretty string version of the params is returned.
def mlpack.preprocess_json_params.scrub | ( | obj, | |
bad_key, | |||
values, | |||
full_paths, | |||
ref_path | |||
) |
This function removes a certain key-value pair from the given dictionary. params: 1) obj (dict) - dictionary to traverse. 2) bad_key (str) - key to remove. 3) values (list) - list of values of all occurrences of bad_key (this will be used to insert bad_key back into dictionary). 4) full_paths (list) - this is a list that contains full path to all occurrences of bad_key (used to insert bad_key back into dictionary). 5) ref_path (list) - this for keeping track of the current path in the dictionary.
def mlpack.preprocess_json_params.value_resolver | ( | pairs | ) |
This function converts multiple "elem" occurences to a list when used with json.loads(). Eg: str({ vec_state: 1, n_rows: 2, n_cols: 1, elem: 1, elem: 2 }) will be converted to dict({ vec_state: 1, n_rows: 2, n_cols: 1, elem: [1,2] }) This is done to handle same keys in the json while converting to python dictionary.