# How Simpleitk calculate the gain factor and the approximation gradient for stochastic gradient descent?

**URL:** https://discourse.itk.org/t/how-simpleitk-calculate-the-gain-factor-and-the-approximation-gradient-for-stochastic-gradient-descent/3123
**Category:** Engineering
**Created:** [May 27, 2020, 6:33am UTC](https://discourse.itk.org/t/how-simpleitk-calculate-the-gain-factor-and-the-approximation-gradient-for-stochastic-gradient-descent/3123 "2020-05-27T06:33:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Felippe\_Trigueiro\_An](https://discourse.itk.org/user_avatar/discourse.itk.org/felippe_trigueiro_an/32/1015_2.png) [@Felippe\_Trigueiro\_An](https://discourse.itk.org/u/Felippe_Trigueiro_An)
#### Post date: [May 27, 2020, 6:33am UTC](https://discourse.itk.org/t/how-simpleitk-calculate-the-gain-factor-and-the-approximation-gradient-for-stochastic-gradient-descent/3123/1 "2020-05-27T06:33:01Z")

</div>

Hi, I as looking for how to use stochastic gradient descent and I found that it can be done by setting `MetricSamplingStrategyType` as `RANDOM` and that the adaptative gain factor can be done by setting `EstimateLearningRateType` as `EachIteration`.

My problem is that I looked in the [documentation](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1ImageRegistrationMethod.html#ac174f5723bed30eb278ac0d79dc7b93e) and in the simpleitk [papers](https://simpleitk.readthedocs.io/en/master/#how-to-cite) and didn’t find the methods for calculating the gradient and the gain factor. So, does anyone know where I can find this?

Thanks.

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [May 27, 2020, 12:41pm UTC](https://discourse.itk.org/t/how-simpleitk-calculate-the-gain-factor-and-the-approximation-gradient-for-stochastic-gradient-descent/3123/2 "2020-05-27T12:41:19Z")

</div>

Hello @Felippe_Trigueiro_An,

As SimpleITK is a wrapper around ITK, the actual implementation is in the [ITK code](https://github.com/InsightSoftwareConsortium/ITK). The theory behind the ITK registration implementation was described in [this paper](https://www.frontiersin.org/articles/10.3389/fninf.2014.00044/full).
