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

Rearrange the matrix columns according to the indices in copy_from_indices_. More...

#include <nnet-various.h>

Inheritance diagram for CopyComponent:
Collaboration diagram for CopyComponent:

Public Member Functions

 CopyComponent (int32 dim_in, int32 dim_out)
 
 ~CopyComponent ()
 
ComponentCopy () const
 Copy component (deep copy),. More...
 
ComponentType GetType () const
 Get Type Identification of the component,. More...
 
void InitData (std::istream &is)
 Virtual interface for initialization and I/O,. More...
 
void ReadData (std::istream &is, bool binary)
 Reads the component content. More...
 
void WriteData (std::ostream &os, bool binary) const
 Writes the component content. More...
 
std::string Info () const
 Print some additional info (after <ComponentName> and the dims),. More...
 
void PropagateFnc (const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out)
 Abstract interface for propagation/backpropagation. More...
 
void BackpropagateFnc (const CuMatrixBase< BaseFloat > &in, const CuMatrixBase< BaseFloat > &out, const CuMatrixBase< BaseFloat > &out_diff, CuMatrixBase< BaseFloat > *in_diff)
 Backward pass transformation (to be implemented by descending class...) More...
 
- Public Member Functions inherited from Component
 Component (int32 input_dim, int32 output_dim)
 Generic interface of a component,. More...
 
virtual ~Component ()
 
virtual bool IsUpdatable () const
 Check if componeny has 'Updatable' interface (trainable components),. More...
 
virtual bool IsMultistream () const
 Check if component has 'Recurrent' interface (trainable and recurrent),. More...
 
int32 InputDim () const
 Get the dimension of the input,. More...
 
int32 OutputDim () const
 Get the dimension of the output,. More...
 
void Propagate (const CuMatrixBase< BaseFloat > &in, CuMatrix< BaseFloat > *out)
 Perform forward-pass propagation 'in' -> 'out',. More...
 
void Backpropagate (const CuMatrixBase< BaseFloat > &in, const CuMatrixBase< BaseFloat > &out, const CuMatrixBase< BaseFloat > &out_diff, CuMatrix< BaseFloat > *in_diff)
 Perform backward-pass propagation 'out_diff' -> 'in_diff'. More...
 
void Write (std::ostream &os, bool binary) const
 Write the component to a stream,. More...
 
virtual std::string InfoGradient () const
 Print some additional info about gradient (after <...> and dims),. More...
 

Protected Attributes

CuArray< int32 > copy_from_indices_
 
- Protected Attributes inherited from Component
int32 input_dim_
 Data members,. More...
 
int32 output_dim_
 Dimension of the output of the Component,. More...
 

Additional Inherited Members

- Public Types inherited from Component
enum  ComponentType {
  kUnknown = 0x0, kUpdatableComponent = 0x0100, kAffineTransform, kLinearTransform,
  kConvolutionalComponent, kConvolutional2DComponent, kLstmProjected, kBlstmProjected,
  kRecurrentComponent, kActivationFunction = 0x0200, kSoftmax, kHiddenSoftmax,
  kBlockSoftmax, kSigmoid, kTanh, kParametricRelu,
  kDropout, kLengthNormComponent, kTranform = 0x0400, kRbm,
  kSplice, kCopy, kTranspose, kBlockLinearity,
  kAddShift, kRescale, kKlHmm = 0x0800, kSentenceAveragingComponent,
  kSimpleSentenceAveragingComponent, kAveragePoolingComponent, kAveragePooling2DComponent, kMaxPoolingComponent,
  kMaxPooling2DComponent, kFramePoolingComponent, kParallelComponent, kMultiBasisComponent
}
 Component type identification mechanism,. More...
 
- Static Public Member Functions inherited from Component
static const char * TypeToMarker (ComponentType t)
 Converts component type to marker,. More...
 
static ComponentType MarkerToType (const std::string &s)
 Converts marker to component type (case insensitive),. More...
 
static ComponentInit (const std::string &conf_line)
 Initialize component from a line in config file,. More...
 
static ComponentRead (std::istream &is, bool binary)
 Read the component from a stream (static method),. More...
 
- Static Public Attributes inherited from Component
static const struct key_value kMarkerMap []
 The table with pairs of Component types and markers (defined in nnet-component.cc),. More...
 

Detailed Description

Rearrange the matrix columns according to the indices in copy_from_indices_.

Definition at line 146 of file nnet-various.h.

Constructor & Destructor Documentation

CopyComponent ( int32  dim_in,
int32  dim_out 
)
inline

Definition at line 148 of file nnet-various.h.

Referenced by CopyComponent::Copy().

148  :
149  Component(dim_in, dim_out)
150  { }
Component(int32 input_dim, int32 output_dim)
Generic interface of a component,.
~CopyComponent ( )
inline

Definition at line 152 of file nnet-various.h.

153  { }

Member Function Documentation

void BackpropagateFnc ( const CuMatrixBase< BaseFloat > &  in,
const CuMatrixBase< BaseFloat > &  out,
const CuMatrixBase< BaseFloat > &  out_diff,
CuMatrixBase< BaseFloat > *  in_diff 
)
inlinevirtual

Backward pass transformation (to be implemented by descending class...)

Implements Component.

Definition at line 221 of file nnet-various.h.

References CopyComponent::GetType(), KALDI_WARN, CuMatrixBase< Real >::SetZero(), and Component::TypeToMarker().

224  {
225  static bool warning_displayed = false;
226  if (!warning_displayed) {
228  << __func__ << "() Not implemented!";
229 
230  warning_displayed = true;
231  }
232  in_diff->SetZero();
233  }
static const char * TypeToMarker(ComponentType t)
Converts component type to marker,.
void SetZero()
Math operations, some calling kernels.
Definition: cu-matrix.cc:474
#define KALDI_WARN
Definition: kaldi-error.h:130
ComponentType GetType() const
Get Type Identification of the component,.
Definition: nnet-various.h:156
Component* Copy ( ) const
inlinevirtual

Copy component (deep copy),.

Implements Component.

Definition at line 155 of file nnet-various.h.

References CopyComponent::CopyComponent().

155 { return new CopyComponent(*this); }
CopyComponent(int32 dim_in, int32 dim_out)
Definition: nnet-various.h:148
ComponentType GetType ( ) const
inlinevirtual

Get Type Identification of the component,.

Implements Component.

Definition at line 156 of file nnet-various.h.

References Component::kCopy.

Referenced by CopyComponent::BackpropagateFnc().

std::string Info ( ) const
inlinevirtual

Print some additional info (after <ComponentName> and the dims),.

Reimplemented from Component.

Definition at line 211 of file nnet-various.h.

References CopyComponent::copy_from_indices_, CuArray< T >::Max(), CuArray< T >::Min(), and kaldi::nnet1::ToString().

211  {
212  return std::string("\n min ") + ToString(copy_from_indices_.Min()) +
213  ", max " + ToString(copy_from_indices_.Max());
214  }
std::string ToString(const T &t)
Convert basic type to a string (please don't overuse),.
Definition: nnet-utils.h:52
T Min() const
Get minimum value (for now implemented on CPU, reimplement if slow).
Definition: cu-array-inl.h:205
CuArray< int32 > copy_from_indices_
Definition: nnet-various.h:236
T Max() const
Get minimum value (for now implemented on CPU, reimplement if slow).
Definition: cu-array-inl.h:223
void InitData ( std::istream &  is)
inlinevirtual

Virtual interface for initialization and I/O,.

Initialize internal data of a component

Reimplemented from Component.

Definition at line 158 of file nnet-various.h.

References CuArray< T >::Add(), kaldi::nnet1::BuildIntegerVector(), CopyComponent::copy_from_indices_, CuArray< T >::Dim(), Component::InputDim(), KALDI_ASSERT, KALDI_ERR, CuArray< T >::Max(), CuArray< T >::Min(), Component::OutputDim(), CuArray< T >::Read(), kaldi::ReadToken(), and kaldi::SplitStringToIntegers().

158  {
159  // define options,
160  std::vector<std::vector<int32> > build_vector;
161  // parse config,
162  std::string token;
163  while (is >> std::ws, !is.eof()) {
164  ReadToken(is, false, &token);
165  if (token == "<ReadVector>") {
166  copy_from_indices_.Read(is, false);
167  } else if (token == "<BuildVector>") {
168  // <BuildVector> 1:1:1000 1:1:1000 1 2 3 1:10 </BuildVector>
169  // 'matlab-line' indexing, read the colon-separated-lists:
170  while (is >> std::ws, !is.eof()) {
171  std::string colon_sep_list_or_end;
172  ReadToken(is, false, &colon_sep_list_or_end);
173  if (colon_sep_list_or_end == "</BuildVector>") break;
174  std::vector<int32> v;
175  SplitStringToIntegers(colon_sep_list_or_end, ":", false, &v);
176  build_vector.push_back(v);
177  }
178  } else {
179  KALDI_ERR << "Unknown token " << token << ", a typo in config?"
180  << " (ReadVector|BuildVector)";
181  }
182  }
183 
184  if (build_vector.size() > 0) {
185  // build the vector, using <BuildVector> ... </BuildVector> inputs,
186  BuildIntegerVector(build_vector, &copy_from_indices_);
187  }
188 
189  // decrease by 1,
191 
192  // check range,
195  // check dim,
197  }
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
Definition: text-utils.h:68
T Min() const
Get minimum value (for now implemented on CPU, reimplement if slow).
Definition: cu-array-inl.h:205
int32 OutputDim() const
Get the dimension of the output,.
void ReadToken(std::istream &is, bool binary, std::string *str)
ReadToken gets the next token and puts it in str (exception on failure).
Definition: io-funcs.cc:154
void Read(std::istream &is, bool binary)
I/O.
Definition: cu-array-inl.h:241
void BuildIntegerVector(const std::vector< std::vector< int32 > > &in, std::vector< int32 > *out)
Build 'integer vector' out of vector of 'matlab-like' representation: 'b, b:e, b:s:e'.
Definition: nnet-utils.h:239
#define KALDI_ERR
Definition: kaldi-error.h:127
void Add(const T &value)
Add a constant value.
Definition: cu-array-inl.h:195
CuArray< int32 > copy_from_indices_
Definition: nnet-various.h:236
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
MatrixIndexT Dim() const
Return the vector dimension.
Definition: cu-array.h:62
T Max() const
Get minimum value (for now implemented on CPU, reimplement if slow).
Definition: cu-array-inl.h:223
int32 InputDim() const
Get the dimension of the input,.
void PropagateFnc ( const CuMatrixBase< BaseFloat > &  in,
CuMatrixBase< BaseFloat > *  out 
)
inlinevirtual

Abstract interface for propagation/backpropagation.

Forward pass transformation (to be implemented by descending class...)

Implements Component.

Definition at line 216 of file nnet-various.h.

References kaldi::cu::Copy(), and CopyComponent::copy_from_indices_.

217  {
218  cu::Copy(in, copy_from_indices_,out);
219  }
CuArray< int32 > copy_from_indices_
Definition: nnet-various.h:236
void Copy(const CuMatrixBase< Real > &src, const CuArray< int32 > &copy_from_indices, CuMatrixBase< Real > *tgt)
Copies elements from src into tgt as given by copy_from_indices.
Definition: cu-math.cc:173
void ReadData ( std::istream &  is,
bool  binary 
)
inlinevirtual

Reads the component content.

Reimplemented from Component.

Definition at line 199 of file nnet-various.h.

References CuArray< T >::Add(), CopyComponent::copy_from_indices_, CuArray< T >::Dim(), KALDI_ASSERT, Component::OutputDim(), and CuArray< T >::Read().

199  {
200  copy_from_indices_.Read(is, binary);
202  copy_from_indices_.Add(-1); // -1 from each element,
203  }
int32 OutputDim() const
Get the dimension of the output,.
void Read(std::istream &is, bool binary)
I/O.
Definition: cu-array-inl.h:241
void Add(const T &value)
Add a constant value.
Definition: cu-array-inl.h:195
CuArray< int32 > copy_from_indices_
Definition: nnet-various.h:236
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
MatrixIndexT Dim() const
Return the vector dimension.
Definition: cu-array.h:62
void WriteData ( std::ostream &  os,
bool  binary 
) const
inlinevirtual

Writes the component content.

Reimplemented from Component.

Definition at line 205 of file nnet-various.h.

References CuArray< T >::Add(), CopyComponent::copy_from_indices_, and CuArray< T >::Write().

205  {
206  CuArray<int32> tmp(copy_from_indices_);
207  tmp.Add(1); // +1 to each element,
208  tmp.Write(os, binary);
209  }
CuArray< int32 > copy_from_indices_
Definition: nnet-various.h:236

Member Data Documentation


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