AMSGrad constructor

AMSGrad(
  1. List<Tensor> parameters, {
  2. required double learningRate,
  3. double beta1 = 0.9,
  4. double beta2 = 0.999,
  5. double epsilon = 1e-8,
})

Implementation

AMSGrad(
    super.parameters, {
      required super.learningRate,
      this.beta1 = 0.9,
      this.beta2 = 0.999,
      this.epsilon = 1e-8,
    }) {
  _m = {};
  _v = {};
  _vHat = {};
  for (Tensor param in parameters) {
    if (param.value is Vector) {
      int size = (param.value as Vector).length;
      _m[param] = List<double>.filled(size, 0.0);
      _v[param] = List<double>.filled(size, 0.0);
      _vHat[param] = List<double>.filled(size, 0.0);
    } else if (param.value is Matrix) {
      Matrix mMatrix = [];
      Matrix vMatrix = [];
      Matrix vHatMatrix = [];
      int numRows = (param.value as Matrix).length;
      int numCols = numRows > 0 ? (param.value as Matrix)[0].length : 0;
      for (int i = 0; i < numRows; i++) {
        mMatrix.add(List<double>.filled(numCols, 0.0));
        vMatrix.add(List<double>.filled(numCols, 0.0));
        vHatMatrix.add(List<double>.filled(numCols, 0.0));
      }
      _m[param] = mMatrix;
      _v[param] = vMatrix;
      _vHat[param] = vHatMatrix;
    }
  }
}