All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ScaleComponent Class Reference

#include <nnet-component.h>

Inheritance diagram for ScaleComponent:
Collaboration diagram for ScaleComponent:

Public Member Functions

 ScaleComponent (int32 dim, BaseFloat scale)
 
 ScaleComponent (const ScaleComponent &other)
 
 ScaleComponent ()
 
virtual std::string Type () const
 
virtual ComponentCopy () const
 Copy component (deep copy). More...
 
virtual bool BackpropNeedsInput () const
 
virtual bool BackpropNeedsOutput () const
 
virtual void Propagate (const ChunkInfo &in_info, const ChunkInfo &out_info, const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out) const
 Perform forward pass propagation Input->Output. More...
 
virtual void Backprop (const ChunkInfo &in_info, const ChunkInfo &out_info, const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_value, const CuMatrixBase< BaseFloat > &out_deriv, Component *to_update, CuMatrix< BaseFloat > *in_deriv) const
 Perform backward pass propagation of the derivative, and also either update the model (if to_update == this) or update another model or compute the model derivative (otherwise). More...
 
virtual int32 InputDim () const
 Get size of input vectors. More...
 
virtual int32 OutputDim () const
 Get size of output vectors. More...
 
virtual void Read (std::istream &is, bool binary)
 
virtual void Write (std::ostream &os, bool binary) const
 Write component to stream. More...
 
void Init (int32 dim, BaseFloat scale)
 
virtual void InitFromString (std::string args)
 Initialize, typically from a line of a config file. More...
 
virtual std::string Info () const
 
- Public Member Functions inherited from Component
 Component ()
 
virtual int32 Index () const
 Returns the index in the sequence of layers in the neural net; intended only to be used in debugging information. More...
 
virtual void SetIndex (int32 index)
 
virtual std::vector< int32 > Context () const
 Return a vector describing the temporal context this component requires for each frame of output, as a sorted list. More...
 
void Propagate (const ChunkInfo &in_info, const ChunkInfo &out_info, const CuMatrixBase< BaseFloat > &in, CuMatrix< BaseFloat > *out) const
 A non-virtual propagate function that first resizes output if necessary. More...
 
virtual ~Component ()
 

Private Member Functions

ScaleComponentoperator= (const ScaleComponent &other)
 

Private Attributes

int32 dim_
 
BaseFloat scale_
 

Additional Inherited Members

- Static Public Member Functions inherited from Component
static ComponentReadNew (std::istream &is, bool binary)
 Read component from stream. More...
 
static ComponentNewFromString (const std::string &initializer_line)
 Initialize the Component from one line that will contain first the type, e.g. More...
 
static ComponentNewComponentOfType (const std::string &type)
 Return a new Component of the given type e.g. More...
 

Detailed Description

Definition at line 730 of file nnet-component.h.

Constructor & Destructor Documentation

ScaleComponent ( int32  dim,
BaseFloat  scale 
)
inlineexplicit

Definition at line 732 of file nnet-component.h.

ScaleComponent ( const ScaleComponent other)
inlineexplicit

Definition at line 733 of file nnet-component.h.

733  :
734  dim_(other.dim_), scale_(other.scale_) { }
ScaleComponent ( )
inline

Definition at line 735 of file nnet-component.h.

Referenced by ScaleComponent::Copy().

Member Function Documentation

void Backprop ( const ChunkInfo in_info,
const ChunkInfo out_info,
const CuMatrixBase< BaseFloat > &  in_value,
const CuMatrixBase< BaseFloat > &  out_value,
const CuMatrixBase< BaseFloat > &  out_deriv,
Component to_update,
CuMatrix< BaseFloat > *  in_deriv 
) const
virtual

Perform backward pass propagation of the derivative, and also either update the model (if to_update == this) or update another model or compute the model derivative (otherwise).

Note: in_value and out_value are the values of the input and output of the component, and these may be dummy variables if respectively BackpropNeedsInput() or BackpropNeedsOutput() return false for that component (not all components need these).

num_chunks lets us treat the input matrix as contiguous-in-time chunks of equal size; it only matters if splicing is involved.

Implements Component.

Definition at line 845 of file nnet-component.cc.

References CuMatrixBase< Real >::CopyFromMat(), kaldi::kUndefined, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), CuMatrix< Real >::Resize(), CuMatrixBase< Real >::Scale(), and ScaleComponent::scale_.

851  {
852 
853  in_deriv->Resize(out_deriv.NumRows(), out_deriv.NumCols(),
854  kUndefined);
855  in_deriv->CopyFromMat(out_deriv);
856  in_deriv->Scale(scale_);
857 }
void Scale(Real value)
Definition: cu-matrix.cc:608
MatrixIndexT NumCols() const
Definition: cu-matrix.h:196
void CopyFromMat(const MatrixBase< OtherReal > &src, MatrixTransposeType trans=kNoTrans)
Definition: cu-matrix.cc:337
void Resize(MatrixIndexT rows, MatrixIndexT cols, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Allocate the memory.
Definition: cu-matrix.cc:47
MatrixIndexT NumRows() const
Dimensions.
Definition: cu-matrix.h:195
virtual bool BackpropNeedsInput ( ) const
inlinevirtual

Reimplemented from Component.

Definition at line 738 of file nnet-component.h.

738 { return false; }
virtual bool BackpropNeedsOutput ( ) const
inlinevirtual

Reimplemented from Component.

Definition at line 739 of file nnet-component.h.

739 { return false; }
virtual Component* Copy ( ) const
inlinevirtual

Copy component (deep copy).

Implements Component.

Definition at line 737 of file nnet-component.h.

References ScaleComponent::ScaleComponent().

737 { return new ScaleComponent(*this); }
std::string Info ( ) const
virtual

Reimplemented from Component.

Definition at line 894 of file nnet-component.cc.

References ScaleComponent::dim_, ScaleComponent::scale_, and ScaleComponent::Type().

894  {
895  std::stringstream stream;
896  stream << Type() << ", dim=" << dim_ << ", scale=" << scale_;
897  return stream.str();
898 }
virtual std::string Type() const
void Init ( int32  dim,
BaseFloat  scale 
)

Definition at line 859 of file nnet-component.cc.

References ScaleComponent::dim_, KALDI_ASSERT, and ScaleComponent::scale_.

Referenced by ScaleComponent::InitFromString(), and kaldi::nnet2::UnitTestScaleComponent().

859  {
860  dim_ = dim;
861  scale_ = scale;
862  KALDI_ASSERT(dim_ > 0);
863  KALDI_ASSERT(scale_ != 0.0);
864 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void InitFromString ( std::string  args)
virtual

Initialize, typically from a line of a config file.

The "args" will contain any parameters that need to be passed to the Component, e.g. dimensions.

Implements Component.

Definition at line 866 of file nnet-component.cc.

References ScaleComponent::Init(), KALDI_ERR, and kaldi::nnet2::ParseFromString().

Referenced by kaldi::nnet2::UnitTestScaleComponent().

866  {
867  std::string orig_args(args);
868  int32 dim;
869  BaseFloat scale;
870  if (!ParseFromString("dim", &args, &dim))
871  KALDI_ERR << "Dimension not specified for ScaleComponent in config file";
872  if (!ParseFromString("scale", &args, &scale))
873  KALDI_ERR << "Scale not specified for ScaleComponent in config file";
874  Init(dim, scale);
875 }
bool ParseFromString(const std::string &name, std::string *string, int32 *param)
Functions used in Init routines.
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ERR
Definition: kaldi-error.h:127
void Init(int32 dim, BaseFloat scale)
virtual int32 InputDim ( ) const
inlinevirtual

Get size of input vectors.

Implements Component.

Definition at line 753 of file nnet-component.h.

References ScaleComponent::dim_.

753 { return dim_; }
ScaleComponent& operator= ( const ScaleComponent other)
private
virtual int32 OutputDim ( ) const
inlinevirtual

Get size of output vectors.

Implements Component.

Definition at line 754 of file nnet-component.h.

References ScaleComponent::dim_.

754 { return dim_; }
void Propagate ( const ChunkInfo in_info,
const ChunkInfo out_info,
const CuMatrixBase< BaseFloat > &  in,
CuMatrixBase< BaseFloat > *  out 
) const
virtual

Perform forward pass propagation Input->Output.

Each row is one frame or training example. Interpreted as "num_chunks" equally sized chunks of frames; this only matters for layers that do things like context splicing. Typically this variable will either be 1 (when we're processing a single contiguous chunk of data) or will be the same as in.NumFrames(), but other values are possible if some layers do splicing.

Implements Component.

Definition at line 837 of file nnet-component.cc.

References CuMatrixBase< Real >::CopyFromMat(), CuMatrixBase< Real >::Scale(), and ScaleComponent::scale_.

840  {
841  out->CopyFromMat(in);
842  out->Scale(scale_);
843 }
void Scale(Real value)
Definition: cu-matrix.cc:608
void CopyFromMat(const MatrixBase< OtherReal > &src, MatrixTransposeType trans=kNoTrans)
Definition: cu-matrix.cc:337
void Read ( std::istream &  is,
bool  binary 
)
virtual

Implements Component.

Definition at line 886 of file nnet-component.cc.

References ScaleComponent::dim_, kaldi::nnet2::ExpectOneOrTwoTokens(), kaldi::ExpectToken(), kaldi::ReadBasicType(), and ScaleComponent::scale_.

886  {
887  ExpectOneOrTwoTokens(is, binary, "<ScaleComponent>", "<Dim>");
888  ReadBasicType(is, binary, &dim_);
889  ExpectToken(is, binary, "<Scale>");
890  ReadBasicType(is, binary, &scale_);
891  ExpectToken(is, binary, "</ScaleComponent>");
892 }
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:55
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
Definition: io-funcs.cc:188
static void ExpectOneOrTwoTokens(std::istream &is, bool binary, const std::string &token1, const std::string &token2)
virtual std::string Type ( ) const
inlinevirtual

Implements Component.

Definition at line 736 of file nnet-component.h.

Referenced by ScaleComponent::Info().

736 { return "ScaleComponent"; }
void Write ( std::ostream &  os,
bool  binary 
) const
virtual

Write component to stream.

Implements Component.

Definition at line 877 of file nnet-component.cc.

References ScaleComponent::dim_, ScaleComponent::scale_, kaldi::WriteBasicType(), and kaldi::WriteToken().

877  {
878  WriteToken(os, binary, "<ScaleComponent>");
879  WriteToken(os, binary, "<Dim>");
880  WriteBasicType(os, binary, dim_);
881  WriteToken(os, binary, "<Scale>");
882  WriteBasicType(os, binary, scale_);
883  WriteToken(os, binary, "</ScaleComponent>");
884 }
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
Definition: io-funcs.cc:134
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:34

Member Data Documentation


The documentation for this class was generated from the following files: