pub trait LSTMLayerTrait: LSTMLayerTraitConst + LayerTrait {
// Required method
fn as_raw_mut_LSTMLayer(&mut self) -> *mut c_void;
// Provided methods
fn set_weights(
&mut self,
wh: &impl MatTraitConst,
wx: &impl MatTraitConst,
b: &impl MatTraitConst,
) -> Result<()> { ... }
fn set_out_shape(&mut self, out_tail_shape: &MatShape) -> Result<()> { ... }
fn set_out_shape_def(&mut self) -> Result<()> { ... }
fn set_use_timstamps_dim(&mut self, use_: bool) -> Result<()> { ... }
fn set_use_timstamps_dim_def(&mut self) -> Result<()> { ... }
fn set_produce_cell_output(&mut self, produce: bool) -> Result<()> { ... }
fn set_produce_cell_output_def(&mut self) -> Result<()> { ... }
fn input_name_to_index(&mut self, input_name: &str) -> Result<i32> { ... }
fn output_name_to_index(&mut self, output_name: &str) -> Result<i32> { ... }
}
Expand description
Mutable methods for crate::dnn::LSTMLayer
Required Methods§
fn as_raw_mut_LSTMLayer(&mut self) -> *mut c_void
Provided Methods§
Sourcefn set_weights(
&mut self,
wh: &impl MatTraitConst,
wx: &impl MatTraitConst,
b: &impl MatTraitConst,
) -> Result<()>
👎Deprecated: Use LayerParams::blobs instead.
fn set_weights( &mut self, wh: &impl MatTraitConst, wx: &impl MatTraitConst, b: &impl MatTraitConst, ) -> Result<()>
Deprecated: Use LayerParams::blobs instead. Set trained weights for LSTM layer.
LSTM behavior on each step is defined by current input, previous output, previous cell state and learned weights.
Let @f$x_t@f$ be current input, @f$h_t@f$ be current output, @f$c_t@f$ be current state. Than current output and current cell state is computed as follows: @f{eqnarray*}{ h_t &= o_t \odot tanh(c_t), \ c_t &= f_t \odot c_{t-1} + i_t \odot g_t, \ @f} where @f$\odot@f$ is per-element multiply operation and @f$i_t, f_t, o_t, g_t@f$ is internal gates that are computed using learned weights.
Gates are computed as follows: @f{eqnarray*}{ i_t &= sigmoid&(W_{xi} x_t + W_{hi} h_{t-1} + b_i), \ f_t &= sigmoid&(W_{xf} x_t + W_{hf} h_{t-1} + b_f), \ o_t &= sigmoid&(W_{xo} x_t + W_{ho} h_{t-1} + b_o), \ g_t &= tanh &(W_{xg} x_t + W_{hg} h_{t-1} + b_g), \ @f} where @f$W_{x?}@f$, @f$W_{h?}@f$ and @f$b_{?}@f$ are learned weights represented as matrices: @f$W_{x?} \in R^{N_h \times N_x}@f$, @f$W_{h?} \in R^{N_h \times N_h}@f$, @f$b_? \in R^{N_h}@f$.
For simplicity and performance purposes we use @f$ W_x = [W_{xi}; W_{xf}; W_{xo}, W_{xg}] @f$ (i.e. @f$W_x@f$ is vertical concatenation of @f$ W_{x?} @f$), @f$ W_x \in R^{4N_h \times N_x} @f$. The same for @f$ W_h = [W_{hi}; W_{hf}; W_{ho}, W_{hg}], W_h \in R^{4N_h \times N_h} @f$ and for @f$ b = [b_i; b_f, b_o, b_g]@f$, @f$b \in R^{4N_h} @f$.
§Parameters
- Wh: is matrix defining how previous output is transformed to internal gates (i.e. according to above mentioned notation is @f$ W_h @f$)
- Wx: is matrix defining how current input is transformed to internal gates (i.e. according to above mentioned notation is @f$ W_x @f$)
- b: is bias vector (i.e. according to above mentioned notation is @f$ b @f$)
Sourcefn set_out_shape(&mut self, out_tail_shape: &MatShape) -> Result<()>
fn set_out_shape(&mut self, out_tail_shape: &MatShape) -> Result<()>
Specifies shape of output blob which will be [[T
], N
] + @p outTailShape.
@details If this parameter is empty or unset then @p outTailShape = [Wh
.size(0)] will be used,
where Wh
is parameter from setWeights().
§C++ default parameters
- out_tail_shape: MatShape()
Sourcefn set_out_shape_def(&mut self) -> Result<()>
fn set_out_shape_def(&mut self) -> Result<()>
Specifies shape of output blob which will be [[T
], N
] + @p outTailShape.
@details If this parameter is empty or unset then @p outTailShape = [Wh
.size(0)] will be used,
where Wh
is parameter from setWeights().
§Note
This alternative version of LSTMLayerTrait::set_out_shape function uses the following default values for its arguments:
- out_tail_shape: MatShape()
Sourcefn set_use_timstamps_dim(&mut self, use_: bool) -> Result<()>
👎Deprecated: Use flag produce_cell_output
in LayerParams.
fn set_use_timstamps_dim(&mut self, use_: bool) -> Result<()>
produce_cell_output
in LayerParams.Deprecated: Use flag produce_cell_output
in LayerParams.
Specifies either interpret first dimension of input blob as timestamp dimension either as sample.
If flag is set to true then shape of input blob will be interpreted as [T
, N
, [data dims]
] where T
specifies number of timestamps, N
is number of independent streams.
In this case each forward() call will iterate through T
timestamps and update layer’s state T
times.
If flag is set to false then shape of input blob will be interpreted as [N
, [data dims]
].
In this case each forward() call will make one iteration and produce one timestamp with shape [N
, [out dims]
].
§C++ default parameters
- use_: true
Sourcefn set_use_timstamps_dim_def(&mut self) -> Result<()>
👎Deprecated: Use flag produce_cell_output
in LayerParams.
fn set_use_timstamps_dim_def(&mut self) -> Result<()>
produce_cell_output
in LayerParams.Deprecated: Use flag produce_cell_output
in LayerParams.
Specifies either interpret first dimension of input blob as timestamp dimension either as sample.
If flag is set to true then shape of input blob will be interpreted as [T
, N
, [data dims]
] where T
specifies number of timestamps, N
is number of independent streams.
In this case each forward() call will iterate through T
timestamps and update layer’s state T
times.
If flag is set to false then shape of input blob will be interpreted as [N
, [data dims]
].
In this case each forward() call will make one iteration and produce one timestamp with shape [N
, [out dims]
].
§Note
This alternative version of LSTMLayerTrait::set_use_timstamps_dim function uses the following default values for its arguments:
- use_: true
Sourcefn set_produce_cell_output(&mut self, produce: bool) -> Result<()>
👎Deprecated: Use flag use_timestamp_dim
in LayerParams.
fn set_produce_cell_output(&mut self, produce: bool) -> Result<()>
use_timestamp_dim
in LayerParams.Deprecated: Use flag use_timestamp_dim
in LayerParams.
If this flag is set to true then layer will produce @f$ c_t @f$ as second output.
@details Shape of the second output is the same as first output.
§C++ default parameters
- produce: false
Sourcefn set_produce_cell_output_def(&mut self) -> Result<()>
👎Deprecated: Use flag use_timestamp_dim
in LayerParams.
fn set_produce_cell_output_def(&mut self) -> Result<()>
use_timestamp_dim
in LayerParams.Deprecated: Use flag use_timestamp_dim
in LayerParams.
If this flag is set to true then layer will produce @f$ c_t @f$ as second output.
@details Shape of the second output is the same as first output.
§Note
This alternative version of LSTMLayerTrait::set_produce_cell_output function uses the following default values for its arguments:
- produce: false
fn input_name_to_index(&mut self, input_name: &str) -> Result<i32>
fn output_name_to_index(&mut self, output_name: &str) -> Result<i32>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.