Skip to content

Commit 33e2c24

Browse files
author
mzhelyez
committed
modified docs
1 parent d3e440c commit 33e2c24

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

doc/differentiation/autodiff_reverse.qbk

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
namespace differentiation {
1616
namespace reverse_mode {
1717

18-
/* autodiff variable of type RealType (numeric types), stores derivatives up to DerivativeOrder*/
18+
/* autodiff variable of type RealType (numeric types), stores derivatives up to DerivativeOrder
19+
* rvar inherits from a generic expression base class
20+
* expression<RealType, DerivativeOrder, rvar<RealType, DerivativeOrder>>
21+
* This is a Curiously Recurring Template Pattern(CRTP)
22+
* The purpose is so that rvar acts as a terminal node in an expression graph, and can be combined
23+
* with other expression-based types (sums, producs, etc..) to form expression graphs.
24+
*/
1925
template<typename RealType, size_t DerivativeOrder = 1>
2026
class rvar : public expression<RealType, DerivativeOrder, rvar<RealType, DerivativeOrder>> {
2127
// inner_t of rvar<RealType, N> = var<RealType, N-1>
@@ -60,6 +66,11 @@
6066
}
6167

6268
// gradient tape holds the computational graph
69+
/*
70+
* The expression graph is stored on a tape. The tape is closely related to the memory manegement
71+
* system in the library. BOOST_MATH_BUFFER_SIZE is set to 65536. It controls the block size of the
72+
* internal memory arena. Its a macro, and can be set at compile time.
73+
*/
6374
template<typename RealType, size_t DerivativeOrder, size_t buffer_size = BOOST_MATH_BUFFER_SIZE>
6475
class gradient_tape {
6576

@@ -316,7 +327,17 @@ The model and loss functions are called. This is just to initialize y_fit and lo
316327
// 5. Gradient Descent Loop
317328
double learning_rate = 1e-3;
318329

319-
The learning rate is a tunable parameter determining the "velocity" with which we descend to a solution.
330+
The learning rate controls how large a step we take in the direction of the
331+
negative gradient each iteration. Intuitively, it sets the "velocity" of
332+
descent toward a minimum.
333+
334+
Too high: the optimization may overshoot minima, oscillate, or even diverge.
335+
Too low: convergence will be very slow and may stall in shallow regions.
336+
337+
In practice, values in the range [1e-4, 1e-1] are common starting points,
338+
with 1e-3 being a typical safe default for many problems. The best choice
339+
depends on the scale of the data, the model, and the curvature of the loss
340+
landscape.
320341

321342
while (loss_v > 0.005) {
322343
tape.zero_grad(); // zero out all the adjoints

0 commit comments

Comments
 (0)