AdaGrad implements Serializable { public synchronized INDArray getLearningRates(INDArray gradient) { this.gradient = gradient; INDArray squaredGradient = pow(this.gradient,2); if(this.historicalGradient == null || this.historicalGradient.length() != this.gradient.length()) this.historicalGradient = Nd4j.zeros(this.gradient.rows(), this.gradient.columns()); this.historicalGradient.addi(squaredGradient); numIterations++; INDArray sqrtGradient = sqrt(historicalGradient).addi(fudgeFactor); INDArray div = abs(gradient).divi(sqrtGradient); this.adjustedGradient = div.muli(masterStepSize); return adjustedGradient; } AdaGrad( int rows, int cols, double gamma);  AdaGrad(int[] shape);  AdaGrad( int rows, int cols); synchronized INDArray getLearningRates(INDArray gradient); double getMasterStepSize(); void setMasterStepSize(double masterStepSize); synchronized boolean isDecayLr(); synchronized void setDecayLr(boolean decayLr); public INDArray historicalGradient; public INDArray adjustedGradient; public double fudgeFactor; public INDArray gradient; public int[] shape; }
@Test public void testAdaGrad1() { int rows = 1; int cols = 1; AdaGrad grad = new AdaGrad(rows,cols,1e-3); INDArray W = Nd4j.ones(rows, cols); log.info("Learning rates for 1 " + grad.getLearningRates(W)); }