4.1.8. Parameter¶
-
class
primitiv::Parameter¶ Class to manage a trainable tensor parameter.
Inherits from primitiv::mixins::Nonmovable< Parameter >
Public Functions
-
Parameter()¶ Creates an invalid parameter object.
-
Parameter(const Shape &shape, const std::vector<float> &value, Device *device)¶ Creates a new Parameter object.
- Parameters
shape: The shape of the parameter. The batch size should be 1.value: List of initial values. Order of elements should be the column-major (Fortran) order.device: The device object to manage internal memory.
-
Parameter(const Shape &shape, const std::vector<float> &value, Device &device)¶ Creates a new Parameter object.
- Parameters
shape: The shape of the parameter. The batch size should be 1.value: List of initial values. Order of elements should be the column-major (Fortran) order.device: The device object to manage internal memory.
-
Parameter(const Shape &shape, const std::vector<float> &value)¶ Creates a new Parameter object.
- Parameters
shape: The shape of the parameter. The batch size should be 1.value: List of initial values. Order of elements should be the column-major (Fortran) order.
-
Parameter(const Shape &shape, const Initializer &initializer, Device *device)¶ Creates a new Parameter object.
- Parameters
shape: The shape of the parameter. The batch size should be 1.initializer: An Initializer object.device: The device object to manage internal memory.
-
Parameter(const Shape &shape, const Initializer &initializer, Device &device)¶ Creates a new Parameter object.
- Parameters
shape: The shape of the parameter. The batch size should be 1.initializer: An Initializer object.device: The device object to manage internal memory.
-
Parameter(const Shape &shape, const Initializer &initializer)¶ Creates a new Parameter object.
- Parameters
shape: The shape of the parameter. The batch size should be 1.initializer: An Initializer object.
-
void
init(const Shape &shape, const std::vector<float> &value, Device *device)¶ Initializes the Parameter object.
- Parameters
shape: The shape of the parameter. The batch size should be 1.value: List of initial values. Order of elements should be the column-major (Fortran) order.device: The device object to manage internal memory.
-
void
init(const Shape &shape, const std::vector<float> &value, Device &device)¶ Initializes the Parameter object.
- Parameters
shape: The shape of the parameter. The batch size should be 1.value: List of initial values. Order of elements should be the column-major (Fortran) order.device: The device object to manage internal memory.
-
void
init(const Shape &shape, const std::vector<float> &value)¶ Initializes the Parameter object.
- Parameters
shape: The shape of the parameter. The batch size should be 1.value: List of initial values. Order of elements should be the column-major (Fortran) order.
-
void
init(const Shape &shape, const Initializer &initializer, Device *device)¶ Initializes the Parameter object.
- Parameters
shape: The shape of the parameter. The batch size should be 1.initializer: An Initializer object.device: The device object to manage internal memory.
-
void
init(const Shape &shape, const Initializer &initializer, Device &device)¶ Initializes the Parameter object.
- Parameters
shape: The shape of the parameter. The batch size should be 1.initializer: An Initializer object.device: The device object to manage internal memory.
-
void
init(const Shape &shape, const Initializer &initializer)¶ Initializes the Parameter object.
- Parameters
shape: The shape of the parameter. The batch size should be 1.initializer: An Initializer object.
-
void
load(const std::string &path, bool with_stats, Device *device)¶ Loads parameters from specified file.
- Parameters
path: File path to load parameters.with_stats: Whether or not to load all additional statistics as well as parameter values if the file has them.device: The device object to manage internal memory.
-
void
load(const std::string &path, bool with_stats, Device &device)¶ Loads parameters from specified file.
- Parameters
path: File path to load parameters.with_stats: Whether or not to load all additional statistics as well as parameter values if the file has them.device: The device object to manage internal memory.
-
void
load(const std::string &path, bool with_stats)¶ Loads parameters from specified file.
- Parameters
path: File path to load parameters.with_stats: Whether or not to load all additional statistics as well as parameter values if the file has them.
-
void
load(const std::string &path)¶ Loads parameters from specified file.
- Parameters
path: File path to load parameters.
-
void
save(const std::string &path, bool with_stats) const¶ Saves current parameters into specified file.
- Parameters
path: File path to save parameters.with_stats: Whether or not to save all additional statistics as well as parameter values if the parameter object has them.
-
void
save(const std::string &path) const¶ Saves current parameters into specified file.
- Parameters
path: File path to save parameters.
-
bool
valid() const¶ Returns whether the parameter is valid or not.
- Return
- true or false w.r.t. the parameter is valid or not.
-
void
reset_gradient()¶ Set all gradients to 0.
-
void
add_stats(const std::string &name, const Shape &shape)¶ Adds a new optional statistics tensor.
- Remark
- All elements in the new statistics tensor is initialized by 0.
- Parameters
name: Name of the statistics.shape: Shape of the tensor.
-
bool
has_stats(const std::string &name) const¶ Checks whether the statistics with name
nameexists or not.- Return
- true if the entry exists, false otherwise.
- Parameters
name: Name of the statistics.
-
Device &
device() const¶ Returns the Device object to manage the internal memory.
- Return
- Pointer of the Device object.
-
const Tensor &
value() const¶ Returns the values of the parameter.
- Return
- A tensor representing the parameter tensor.
-
Tensor &
value()¶ Returns the values of the parameter.
- Return
- A tensor representing the parameter tensor.
-
const Tensor &
gradient() const¶ Returns the current gradient of the parameter.
- Return
- A tensor representing the gradient of the value.
-
Tensor &
gradient()¶ Returns the current gradient of the parameter.
- Return
- A tensor representing the gradient of the value.
-