class MXNet::Gluon::Parameter

Overview

A Container holding parameters (weights) of Blocks.

Parameter holds a copy of the parameter on each Context after it is initialized with #init. If grad_req is not :null, it also holds a gradient array on each Context.

Direct Known Subclasses

Defined in:

mxnet/gluon/parameter.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(name, shape = nil, dtype = nil, init = nil, allow_deferred_init = false, grad_req = :write) #

Creates a new instance.

Parameters

  • name (String) Name of this parameter.
  • shape (Int | Array(Int), optional) Shape of this parameter. By default, shape is inferred.
  • dtype (Symbol, default :float32) Data type of this parameter.
  • init (Initializer, optional) The initializer to use.
  • allow_deferred_init (Bool, default = false) Is deferred initialization allowed.
  • grad_req (Symbol, default :write)
    • :write: updated is written to the gradient
    • :add: update is added to the existing gradient.
    • :null: gradient is not supported on this parameter

[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


[View source]
def data(ctx = nil) #

Returns a copy of this parameter on one context. Must have been initialized on this context before.

Parameters

  • ctx (Context, optional) Desired context.

[View source]
def dtype : Symbol? #

[View source]
def dtype=(dtype) #

[View source]
def grad(ctx = nil) #

Returns a gradient buffer for this parameter on one context. Must have been initialized on this context before.

Parameters

  • ctx (Context, optional) Desired context.

[View source]
def init(init = nil, ctx = nil, default_init = :uniform, force_reinit = false) #

Initializes parameter and gradient arrays. Only used with NDArray API.

Parameters

  • init (Initializer, default = nil) The initializer to use. Overrides both init, set when this instance was created, and default_init in this call.
  • ctx (Context | Array(Context), default = nil) Initialize Parameter on given Contexts. A copy will be created for each context. Note: copies are independent arrays. The programmer is responsible for keeping values consistent when updating. Normally Trainer does this for you.
  • default_init (Initializer, default = :uniform) Default initializer.
  • force_reinit (Bool, default = false) Whether to force re-initialization if parameter is already initialized.
weight = MXNet::Gluon::Parameter.new('weight', shape: [2, 2])
weight.init(ctx: MXNet.cpu)
weight.data # => [[0.0068339, 0.0129982],...
weight.grad # => [[0, 0],...

[View source]
def list_ctx #

Returns a list of contexts this parameter is initialized on.


[View source]
def list_data #

Returns copies of this parameter on all contexts, in the same order as creation.


[View source]
def list_grad #

Returns gradient buffers on all contexts, in the same order as creation.


[View source]
def name : String #

[View source]
def set_data(data) #

Sets this parameter's value on all contexts.


[View source]
def shape : Array(Int32)? #

[View source]
def shape=(shape) #

[View source]
def to_s(io) #

Writes this object to an IO.


[View source]
def trainer : MXNet::Gluon::Trainer? #

[View source]
def trainer=(trainer) #

[View source]
def var #

Returns a symbol representing this parameter.


[View source]
def zero_grad #

Sets gradient buffer to zero on all contexts.


[View source]