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

#include <nnet-component.h>

Inheritance diagram for MaxoutComponent:
Collaboration diagram for MaxoutComponent:

Public Member Functions

void Init (int32 input_dim, int32 output_dim)
 
 MaxoutComponent (int32 input_dim, int32 output_dim)
 
 MaxoutComponent ()
 
virtual std::string Type () const
 
virtual void InitFromString (std::string args)
 Initialize, typically from a line of a config file. More...
 
virtual int32 InputDim () const
 Get size of input vectors. More...
 
virtual int32 OutputDim () const
 Get size of output vectors. More...
 
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 > &, 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 bool BackpropNeedsInput () const
 
virtual bool BackpropNeedsOutput () const
 
virtual ComponentCopy () const
 Copy component (deep copy). More...
 
virtual void Read (std::istream &is, bool binary)
 
virtual void Write (std::ostream &os, bool binary) const
 Write component to stream. 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 ()
 

Protected Attributes

int32 input_dim_
 
int32 output_dim_
 

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 411 of file nnet-component.h.

Constructor & Destructor Documentation

MaxoutComponent ( int32  input_dim,
int32  output_dim 
)
inlineexplicit

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

References MaxoutComponent::Init().

414  {
415  Init(input_dim, output_dim);
416  }
void Init(int32 input_dim, int32 output_dim)
MaxoutComponent ( )
inline

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

Referenced by MaxoutComponent::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 452 of file nnet-component.cc.

References CuMatrixBase< Real >::GroupMaxDeriv(), kaldi::kSetZero, CuMatrixBase< Real >::MulRowsGroupMat(), CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and CuMatrix< Real >::Resize().

458  {
459  in_deriv->Resize(in_value.NumRows(), in_value.NumCols(), kSetZero);
460  in_deriv->GroupMaxDeriv(in_value, out_value);
461  in_deriv->MulRowsGroupMat(out_deriv);
462 }
void MulRowsGroupMat(const CuMatrixBase< Real > &src)
divide each row into src.NumCols() groups, and then scale i'th row's jth group of elements by src[i...
Definition: cu-matrix.cc:801
void GroupMaxDeriv(const CuMatrixBase< Real > &input, const CuMatrixBase< Real > &output)
Calculate derivatives for the GroupMax function above, where "input" is the input to the GroupMax fun...
Definition: cu-matrix.cc:859
MatrixIndexT NumCols() const
Definition: cu-matrix.h:196
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 434 of file nnet-component.h.

434 { return true; }
virtual bool BackpropNeedsOutput ( ) const
inlinevirtual

Reimplemented from Component.

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

435 { return true; }
virtual Component* Copy ( ) const
inlinevirtual
std::string Info ( ) const
virtual

Reimplemented from Component.

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

References MaxoutComponent::input_dim_, MaxoutComponent::output_dim_, and MaxoutComponent::Type().

481  {
482  std::stringstream stream;
483  stream << Type() << ", input-dim = " << input_dim_
484  << ", output-dim = " << output_dim_;
485  return stream.str();
486 }
virtual std::string Type() const
void Init ( int32  input_dim,
int32  output_dim 
)

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

References MaxoutComponent::input_dim_, KALDI_ASSERT, and MaxoutComponent::output_dim_.

Referenced by MaxoutComponent::InitFromString(), and MaxoutComponent::MaxoutComponent().

419  {
420  input_dim_ = input_dim;
421  output_dim_ = output_dim;
422  if (input_dim_ == 0)
423  input_dim_ = 10 * output_dim_; // default group size : 10
424  KALDI_ASSERT(input_dim_ > 0 && output_dim_ >= 0);
426 }
#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 428 of file nnet-component.cc.

References MaxoutComponent::Init(), KALDI_ERR, KALDI_LOG, kaldi::nnet2::ParseFromString(), and MaxoutComponent::Type().

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

428  {
429  std::string orig_args(args);
430  int32 input_dim = 0;
431  int32 output_dim = 0;
432  bool ok = ParseFromString("output-dim", &args, &output_dim) &&
433  ParseFromString("input-dim", &args, &input_dim);
434  KALDI_LOG << output_dim << " " << input_dim << " " << ok;
435  if (!ok || !args.empty() || output_dim <= 0)
436  KALDI_ERR << "Invalid initializer for layer of type "
437  << Type() << ": \"" << orig_args << "\"";
438  Init(input_dim, output_dim);
439 }
virtual std::string Type() const
bool ParseFromString(const std::string &name, std::string *string, int32 *param)
Functions used in Init routines.
#define KALDI_ERR
Definition: kaldi-error.h:127
void Init(int32 input_dim, int32 output_dim)
#define KALDI_LOG
Definition: kaldi-error.h:133
virtual int32 InputDim ( ) const
inlinevirtual

Get size of input vectors.

Implements Component.

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

References MaxoutComponent::input_dim_.

420 { return input_dim_; }
virtual int32 OutputDim ( ) const
inlinevirtual

Get size of output vectors.

Implements Component.

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

References MaxoutComponent::output_dim_.

421 { return output_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 442 of file nnet-component.cc.

References ChunkInfo::CheckSize(), CuMatrixBase< Real >::GroupMax(), KALDI_ASSERT, and ChunkInfo::NumChunks().

445  {
446  in_info.CheckSize(in);
447  out_info.CheckSize(*out);
448  KALDI_ASSERT(in_info.NumChunks() == out_info.NumChunks());
449  out->GroupMax(in);
450 }
void GroupMax(const CuMatrixBase< Real > &src)
Apply the function y(i) = (max_{j = i*G}^{(i+1)*G-1} x_j where G = x.NumCols() / y.NumCols() must be an integer.
Definition: cu-matrix.cc:1466
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void Read ( std::istream &  is,
bool  binary 
)
virtual

Implements Component.

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

References kaldi::nnet2::ExpectOneOrTwoTokens(), kaldi::ExpectToken(), MaxoutComponent::input_dim_, MaxoutComponent::output_dim_, and kaldi::ReadBasicType().

464  {
465  ExpectOneOrTwoTokens(is, binary, "<MaxoutComponent>", "<InputDim>");
466  ReadBasicType(is, binary, &input_dim_);
467  ExpectToken(is, binary, "<OutputDim>");
468  ReadBasicType(is, binary, &output_dim_);
469  ExpectToken(is, binary, "</MaxoutComponent>");
470 }
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 418 of file nnet-component.h.

Referenced by MaxoutComponent::Info(), and MaxoutComponent::InitFromString().

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

Write component to stream.

Implements Component.

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

References MaxoutComponent::input_dim_, MaxoutComponent::output_dim_, kaldi::WriteBasicType(), and kaldi::WriteToken().

472  {
473  WriteToken(os, binary, "<MaxoutComponent>");
474  WriteToken(os, binary, "<InputDim>");
475  WriteBasicType(os, binary, input_dim_);
476  WriteToken(os, binary, "<OutputDim>");
477  WriteBasicType(os, binary, output_dim_);
478  WriteToken(os, binary, "</MaxoutComponent>");
479 }
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: