4.1.5. Model

class primitiv::Model

Set of parameters and specific algorithms.

Inherits from primitiv::mixins::Nonmovable< Model >

Public Functions

void load(const std::string &path, bool with_stats, Device *device)

Loads all parameters from a file.

Parameters
  • path: Path of the file.
  • with_stats: Whether or not to load all additional statistics.
  • device: Device object to manage parameters.

void load(const std::string &path, bool with_stats, Device &device)

Loads all parameters from a file.

Parameters
  • path: Path of the file.
  • with_stats: Whether or not to load all additional statistics.
  • device: Device object to manage parameters.

void load(const std::string &path, bool with_stats)

Loads all parameters from a file.

Parameters
  • path: Path of the file.
  • with_stats: Whether or not to load all additional statistics.

void load(const std::string &path)

Loads all parameters from a file.

Parameters
  • path: Path of the file.

void save(const std::string &path, bool with_stats) const

Saves all parameters to a file.

Parameters
  • path: Path of the file.
  • with_stats: Whether or not to save all additional statistics.

void save(const std::string &path) const

Saves all parameters to a file.

Parameters
  • path: Path of the file.

void add(const std::string &name, Parameter &param)

Registers a new parameter.

Remark
name should not be overlapped with all registered parameters and submodels.
Parameters
  • name: Name of the parameter.
  • param: Reference to the parameter.

void add(const std::string &name, Model &model)

Registers a new submodel.

Remark
name should not be overlapped with all registered parameters and submodels.
Parameters
  • name: Name of the submodel.
  • model: Reference to the submodel.

const Parameter &get_parameter(const std::string &name) const

Retrieves a parameter with specified name.

Return
Const-reference of the corresponding Parameter object.
Parameters
  • name: Name of the parameter.
Exceptions
  • primitiv::Error: Parameter with name not found.

Parameter &get_parameter(const std::string &name)

Retrieves a parameter with specified name.

Return
Reference of the corresponding Parameter object.
Parameters
  • name: Name of the parameter.
Exceptions
  • primitiv::Error: Parameter with name not found.

const Parameter &get_parameter(const std::vector<std::string> &names) const

Recursively searches a parameter with specified name hierarchy.

Return
Const-reference of the corresponding Parameter object.
Parameters
  • names: Name hierarchy of the parameter.
Exceptions
  • primitiv::Error: Parameter with names not found.

Parameter &get_parameter(const std::vector<std::string> &names)

Recursively searches a parameter with specified name hierarchy.

Return
Const-reference of the corresponding Parameter object.
Parameters
  • names: Name hierarchy of the parameter.
Exceptions
  • primitiv::Error: Parameter with names not found.

const Parameter &get_parameter(const std::initializer_list<std::string> names) const

Recursively searches a parameter with specified name hierarchy.

Return
Const-reference of the corresponding Parameter object.
Parameters
  • names: Name hierarchy of the parameter.
Exceptions
  • primitiv::Error: Parameter with names not found.

Parameter &get_parameter(const std::initializer_list<std::string> names)

Recursively searches a parameter with specified name hierarchy.

Return
Const-reference of the corresponding Parameter object.
Parameters
  • names: Name hierarchy of the parameter.
Exceptions
  • primitiv::Error: Parameter with names not found.

const Model &get_submodel(const std::string &name) const

Retrieves a submodel with specified name.

Return
Const-reference of the corresponding Model object.
Parameters
  • name: Name of the submodel.
Exceptions
  • primitiv::Error: Submodel with name not found.

Model &get_submodel(const std::string &name)

Retrieves a submodel with specified name.

Return
Reference of the corresponding Model object.
Parameters
  • name: Name of the submodel.
Exceptions
  • primitiv::Error: Submodel with name not found.

const Model &get_submodel(const std::vector<std::string> &names) const

Recursively searches a submodel with specified name hierarchy.

Return
Const-reference of the corresponding Model object.
Parameters
  • names: Name hierarchy of the submodel.
Exceptions
  • primitiv::Error: Submodel with names not found.

Model &get_submodel(const std::vector<std::string> &names)

Recursively searches a submodel with specified name hierarchy.

Return
Const-reference of the corresponding Model object.
Parameters
  • names: Name hierarchy of the submodel.
Exceptions
  • primitiv::Error: Submodel with names not found.

const Model &get_submodel(const std::initializer_list<std::string> names) const

Recursively searches a submodel with specified name hierarchy.

Return
Const-reference of the corresponding Model object.
Parameters
  • names: Name hierarchy of the submodel.
Exceptions
  • primitiv::Error: Submodel with names not found.

Model &get_submodel(const std::initializer_list<std::string> names)

Recursively searches a submodel with specified name hierarchy.

Return
Const-reference of the corresponding Model object.
Parameters
  • names: Name hierarchy of the submodel.
Exceptions
  • primitiv::Error: Submodel with names not found.

std::map<std::vector<std::string>, Parameter *> get_all_parameters() const

Retrieves all parameters in the model.

Return
Dictionary of parameters.

std::map<std::vector<std::string>, Parameter *> get_trainable_parameters() const

Retrieves trainable parameters in the model.

Return
Dictionary of parameters.