@@ -583,31 +583,61 @@ def _append_optimize_op(self, block, param_and_grad):
583
583
584
584
585
585
class AdadeltaOptimizer (Optimizer ):
586
- """Simple Adadelta optimizer with average squared grad state and
586
+ """
587
+ **Adadelta Optimizer**
588
+ Simple Adadelta optimizer with average squared grad state and
587
589
average squared update state.
590
+ The details of adadelta please refer to this
591
+ `ADADELTA: AN ADAPTIVE LEARNING RATE METHOD
592
+ <http://www.matthewzeiler.com/pubs/googleTR2012/googleTR2012.pdf>`_.
593
+
594
+ .. math::
595
+
596
+ E(g_t^2) &= \\ rho * E(g_{t-1}^2) + (1-\\ rho) * g^2 \\ \\
597
+ learning\\ _rate &= sqrt( ( E(dx_{t-1}^2) + \\ epsilon ) / ( \\
598
+ E(g_t^2) + \\ epsilon ) ) \\ \\
599
+ E(dx_t^2) &= \\ rho * E(dx_{t-1}^2) + (1-\\ rho) * (-g*learning\\ _rate)^2
600
+
601
+ Args:
602
+ learning_rate(float): global leraning rate
603
+ rho(float): rho in equation
604
+ epsilon(float): epsilon in equation
605
+
606
+ Examples:
607
+ .. code-block:: python
608
+
609
+ optimizer = fluid.optimizer.Adadelta(
610
+ learning_rate=0.0003, epsilon=1.0e-6, rho=0.95)
611
+ _, params_grads = optimizer.minimize(cost)
588
612
"""
613
+
589
614
_avg_squared_grad_acc_str = "_avg_squared_grad"
590
615
_avg_squared_update_acc_str = "_avg_squared_update"
591
616
592
617
def __init__ (self , learning_rate , epsilon = 1.0e-6 , rho = 0.95 , ** kwargs ):
593
- assert learning_rate is not None
594
- assert epsilon is not None
595
- assert rho is not None
618
+ if learning_rate is None :
619
+ raise ValueError ("learning_rate is not set." )
620
+ if epsilon is None :
621
+ raise ValueError ("epsilon is not set." )
622
+ if rho is None :
623
+ raise ValueError ("rho is not set." )
596
624
super (AdadeltaOptimizer , self ).__init__ (
597
625
learning_rate = learning_rate , ** kwargs )
598
626
self .type = "adadelta"
599
627
self ._epsilon = epsilon
600
628
self ._rho = rho
601
629
602
630
def _create_accumulators (self , block , parameters ):
603
- assert isinstance (block , framework .Block )
631
+ if not isinstance (block , framework .Block ):
632
+ raise TypeError ("block is not instance of framework.Block." )
604
633
605
634
for p in parameters :
606
635
self ._add_accumulator (self ._avg_squared_grad_acc_str , p )
607
636
self ._add_accumulator (self ._avg_squared_update_acc_str , p )
608
637
609
638
def _append_optimize_op (self , block , param_and_grad ):
610
- assert isinstance (block , framework .Block )
639
+ if not isinstance (block , framework .Block ):
640
+ raise TypeError ("block is not instance of framework.Block." )
611
641
612
642
avg_squared_grad_acc = self ._get_accumulator (
613
643
self ._avg_squared_grad_acc_str , param_and_grad [0 ])
0 commit comments