Class XavierInitializer
- All Implemented Interfaces:
Initializer
XavierInitializer is an Initializer that performs "Xavier" initialization for
parameters. This initializer is designed to keep the scale of gradients roughly the same in all
layers. It was originally defined in the paper Understanding the difficulty of
training deep feedforward neural networks.
XavierInitializer is specified by the type of random distribution(XavierInitializer.RandomType),
the factor type(XavierInitializer.FactorType), and the magnitude of the scale. By default, XavierInitializer.RandomType is UNIFORM and XavierInitializer.FactorType is AVG. The initializer fills the
weights with random numbers in the range of \([-c, c]\), where \(c = \sqrt{\frac{3.}{0.5 *
(n_{in} + n_{out})}}\) where \(n_{in}\) is the number of neurons feeding into weights, and
\(n_{out}\) is the number of neurons the result is fed to.
If XavierInitializer.RandomType is UNIFORM and XavierInitializer.FactorType is IN, then \(c =
\sqrt{\frac{3.}{n_{in}}}\). Similarly when XavierInitializer.FactorType is OUT, then \(c =
\sqrt{\frac{3.}{n_{out}}}\).
If XavierInitializer.RandomType is GAUSSIAN and XavierInitializer.FactorType is AVG, the
initializer fills the weights with numbers from normal distribution with a standard deviation of
\(\sqrt{\frac{3.}{0.5 * (n_{in} + n_{out})}}\).
Another common setting of the XavierInitializer is defined in the paper Delving Deep into Rectifiers: Surpassing Human-Level
Performance on ImageNet Classification. These settings better handle non-linearity when
preserving the variance across layers in a neural network. It can be initialized with new
XavierInitializer(RandomType.GAUSSIAN, FactorType.IN, 2)).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnum for different types of factor type.static enumEnum for different types of random distributions. -
Field Summary
Fields inherited from interface ai.djl.training.initializer.Initializer
ONES, ZEROS -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance ofXavierInitializer.XavierInitializer(XavierInitializer.RandomType randomType, XavierInitializer.FactorType factorType, float magnitude) Initializes a Xavier initializer. -
Method Summary
-
Constructor Details
-
XavierInitializer
public XavierInitializer(XavierInitializer.RandomType randomType, XavierInitializer.FactorType factorType, float magnitude) Initializes a Xavier initializer.- Parameters:
randomType- the random generator type, can be GAUSSIAN or UNIFORMfactorType- the factor type, can be one of AVG, IN, or OUTmagnitude- the scale of the random number
-
XavierInitializer
public XavierInitializer()Creates a new instance ofXavierInitializer.
-
-
Method Details
-
initialize
Initializes a singleNDArray.- Specified by:
initializein interfaceInitializer- Parameters:
manager- theNDManagerto create the newNDArrayinshape- theShapefor the new NDArraydataType- theDataTypefor the new NDArray- Returns:
- the
NDArrayinitialized with the manager and shape
-