<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hi Brian,<br>
      <br>
      I did read this code, but if I understand correctly,
      ModifyGradientByScales does the equivalent of the first scaling
      that was already done in the old itkRegularStepGradientOptimizer.<br>
      <br>
      However the whole point of my post is that it would make sense (I
      think!) to apply the scales *again* after adjusting the gradient
      for step size (or "learning rate"), which doesn't seem to be done
      in this code either.<br>
      <br>
      Note that in itkGradientDescentOptimizerv4, the gradient isn't
      normalized, so I don't think my change is needed. But if you
      implemented a RegularStepGradientOptimizerv4, I think re-applying
      the scales after scaling the gradient would be a good thing.<br>
      <br>
      joel<br>
      <br>
      <br>
      On 05/07/2013 06:07 PM, brian avants wrote:<br>
    </div>
    <blockquote
cite="mid:CABWzF4Wm_Gb_UGCYzHcr05TShGjuVwOU22miYg5SS4EM4R+g_w@mail.gmail.com"
      type="cite">
      <div dir="ltr">yes - there is something you are missing. &nbsp; read
        the code below:&nbsp;
        <div><br>
        </div>
        <div>
          <div style="font-family:arial,sans-serif;font-size:13px">&nbsp; /*
            Begin threaded gradient modification.</div>
          <div style="font-family:arial,sans-serif;font-size:13px">
            &nbsp; &nbsp;* Scale by gradient scales, then estimate the learning</div>
          <div style="font-family:arial,sans-serif;font-size:13px">&nbsp; &nbsp;*
            rate if options are set to (using the scaled gradient),</div>
          <div style="font-family:arial,sans-serif;font-size:13px">
            &nbsp; &nbsp;* then modify by learning rate. The m_Gradient variable</div>
          <div style="font-family:arial,sans-serif;font-size:13px">&nbsp; &nbsp;*
            is modified in-place. */</div>
          <div style="font-family:arial,sans-serif;font-size:13px">&nbsp;
            this-&gt;ModifyGradientByScales();</div>
          <div style="font-family:arial,sans-serif;font-size:13px">&nbsp;
            this-&gt;EstimateLearningRate();</div>
          <div style="font-family:arial,sans-serif;font-size:13px">&nbsp;
            this-&gt;ModifyGradientByLearningRate();</div>
        </div>
        <div><br>
        </div>
        <div>the call to &nbsp;<span
            style="font-family:arial,sans-serif;font-size:13px">&nbsp;
            this-&gt;ModifyGradientByScales()</span><span
            style="font-family:arial,sans-serif;font-size:13px">; &nbsp;
            changes the gradient according the scales, as the name
            suggests. &nbsp; the v4 optimizers all behave in this general
            manner although this is taken from the gradient descent
            class.</span></div>
        <div><br>
        </div>
        <div>so - the transform expects that the update was already
          modified by the scales so that the only thing the transform
          needs to do ( if anything at all) is multiply by a scalar</div>
        <div><br>
        </div>
        <div>also, you are looking at the base class which is only used
          if the derived class did not implement
          UpdateTransformParameters. &nbsp;for instance, the
          GaussianDisplacementField transform will also smooth the
          parameters when this function is called.</div>
        <div><br>
        </div>
        <div>is this clear enough?</div>
        <div><br>
        </div>
      </div>
      <div class="gmail_extra"><br clear="all">
        <div>
          <div><br>
          </div>
          brian<br>
          <div><br>
          </div>
          <div><br>
          </div>
        </div>
        <br>
        <br>
        <div class="gmail_quote">On Tue, May 7, 2013 at 11:59 AM, Jo&euml;l
          Schaerer <span dir="ltr">&lt;<a moz-do-not-send="true"
              href="mailto:joel.schaerer@gmail.com" target="_blank">joel.schaerer@gmail.com</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div text="#000000" bgcolor="#FFFFFF">
              <div>I spent a while looking at the v4 optimization
                framework. I can follow your reasoning until
                UpdateTransformParameters is called on the transform.
                However, at this state, the old scaling is still done:<br>
                <br>
                itkTransform.hxx:<br>
                &nbsp; if( factor == 1.0 )<br>
                &nbsp;&nbsp;&nbsp; {<br>
                &nbsp;&nbsp;&nbsp; for( NumberOfParametersType k = 0; k &lt;
                numberOfParameters; k++ )<br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;m_Parameters[k] += update[k];<br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
                &nbsp;&nbsp;&nbsp; }<br>
                &nbsp; else<br>
                &nbsp;&nbsp;&nbsp; {<br>
                &nbsp;&nbsp;&nbsp; for( NumberOfParametersType k = 0; k &lt;
                numberOfParameters; k++ )<br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;m_Parameters[k] += update[k] * factor;<br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
                &nbsp;&nbsp;&nbsp; }<br>
                <br>
                which makes sense, since parameters scales are an
                optimizer concept that transforms know nothing about.<br>
                <br>
                So (if I understand correctly), the code has been
                shuffled around quite a bit, but the behavior is still
                the same.<br>
                <br>
                Is there something I'm missing?<br>
                <br>
                joel
                <div>
                  <div class="h5"><br>
                    <br>
                    <br>
                    On 07/05/2013 16:40, brian avants wrote:<br>
                  </div>
                </div>
              </div>
              <div>
                <div class="h5">
                  <blockquote type="cite">
                    <div dir="ltr">also - to take away a bit of the
                      "mystery" surrounding v4 optimization, let's see
                      how the gradient descent AdvanceOneStep function
                      works:
                      <div><br>
                      </div>
                      <div>
                        <div>void</div>
                        <div>GradientDescentOptimizerv4</div>
                        <div>::AdvanceOneStep()</div>
                        <div>{</div>
                        <div>&nbsp; itkDebugMacro("AdvanceOneStep");</div>
                        <div><br>
                        </div>
                        <div>&nbsp; /* Begin threaded gradient modification.</div>
                        <div>&nbsp; &nbsp;* Scale by gradient scales, then
                          estimate the learning</div>
                        <div>&nbsp; &nbsp;* rate if options are set to (using the
                          scaled gradient),</div>
                        <div>&nbsp; &nbsp;* then modify by learning rate. The
                          m_Gradient variable</div>
                        <div>&nbsp; &nbsp;* is modified in-place. */</div>
                        <div>&nbsp; this-&gt;ModifyGradientByScales();</div>
                        <div>&nbsp; this-&gt;EstimateLearningRate();</div>
                        <div>&nbsp; this-&gt;ModifyGradientByLearningRate();</div>
                        <div><br>
                        </div>
                        <div>&nbsp; try</div>
                        <div>&nbsp; &nbsp; {</div>
                        <div>&nbsp; &nbsp; /* Pass graident to transform and let
                          it do its own updating */</div>
                        <div>&nbsp; &nbsp;
                          this-&gt;m_Metric-&gt;UpdateTransformParameters(
                          this-&gt;m_Gradient );</div>
                        <div>&nbsp; &nbsp; }</div>
                        <div>&nbsp; catch ( ExceptionObject &amp; )</div>
                        <div>&nbsp; &nbsp; {</div>
                        <div>&nbsp; &nbsp; this-&gt;m_StopCondition =
                          UPDATE_PARAMETERS_ERROR;</div>
                        <div>&nbsp; &nbsp; this-&gt;m_StopConditionDescription
                          &lt;&lt; "UpdateTransformParameters error";</div>
                        <div>&nbsp; &nbsp; this-&gt;StopOptimization();</div>
                        <div><br>
                        </div>
                        <div>&nbsp; &nbsp; // Pass exception to caller</div>
                        <div>&nbsp; &nbsp; throw;</div>
                        <div>&nbsp; &nbsp; }</div>
                        <div><br>
                        </div>
                        <div>&nbsp; this-&gt;InvokeEvent( IterationEvent() );</div>
                        <div>}</div>
                        <div><br>
                        </div>
                        <div><br>
                        </div>
                        <div>i hope this does not look too convoluted.
                          &nbsp;then&nbsp;the base metric class does this:</div>
                        <div><br>
                        </div>
                        <div>
                          <div>template&lt;unsigned int TFixedDimension,
                            unsigned int TMovingDimension, class
                            TVirtualImage&gt;</div>
                          <div>void</div>
                          <div>ObjectToObjectMetric&lt;TFixedDimension,
                            TMovingDimension, TVirtualImage&gt;</div>
                          <div>::UpdateTransformParameters( const
                            DerivativeType &amp; derivative,
                            ParametersValueType factor )</div>
                          <div>{</div>
                          <div>&nbsp; /* Rely on
                            transform::UpdateTransformParameters to
                            verify proper</div>
                          <div>&nbsp; &nbsp;* size of derivative */</div>
                          <div>&nbsp;
                            this-&gt;m_MovingTransform-&gt;UpdateTransformParameters(
                            derivative, factor );</div>
                          <div>}</div>
                        </div>
                        <div><br>
                        </div>
                        <div><br>
                        </div>
                        <div>so the transform parameters should be
                          updated in a way that is consistent with:&nbsp;</div>
                      </div>
                      <div><br>
                      </div>
                      <div><span
                          style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px">newPosition[j]

                          = currentPosition[j] + transformedGradient[j]
                          * factor / scales[j];</span><br
                          style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px">
                      </div>
                      <div><span
                          style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px"><br>
                        </span></div>
                      <div><font color="#500050" face="arial,
                          sans-serif">factor defaults to 1 .... &nbsp;anyway,
                          as you can infer from the above discussion,
                          even the basic gradient descent optimizer can
                          be used to take " regular steps " &nbsp;if you
                          want.</font></div>
                      <div><br>
                      </div>
                    </div>
                    <div class="gmail_extra"><br clear="all">
                      <div>
                        <div><br>
                        </div>
                        brian<br>
                        <div><br>
                        </div>
                        <div><br>
                        </div>
                      </div>
                      <br>
                      <br>
                      <div class="gmail_quote">On Tue, May 7, 2013 at
                        10:23 AM, brian avants <span dir="ltr">&lt;<a
                            moz-do-not-send="true"
                            href="mailto:stnava@gmail.com"
                            target="_blank">stnava@gmail.com</a>&gt;</span>
                        wrote:<br>
                        <blockquote class="gmail_quote" style="margin:0
                          0 0 .8ex;border-left:1px #ccc
                          solid;padding-left:1ex">
                          <div dir="ltr">brad
                            <div><br>
                            </div>
                            <div>did this issue ever go up on jira? &nbsp;i
                              do remember discussing with you at a
                              meeting. &nbsp; our solution is in the v4
                              optimizers.</div>
                            <div><br>
                            </div>
                            <div>the trivial additive parameter update
                              doesnt work in more general cases e.g.
                              when you need to compose parameters with
                              parameter updates.&nbsp;</div>
                            <div><br>
                            </div>
                            <div>to resolve this limitation, the v4
                              optimizers pass the update step to the
                              transformations&nbsp;</div>
                            <div><br>
                            </div>
                            <div>this implements the idea that &nbsp;" the
                              transforms know how to update themselves
                              "&nbsp;</div>
                            <div><br>
                            </div>
                            <div>there are several other differences, as
                              nick pointed out, that reduce the need for
                              users to experiment with scales .</div>
                            <div><br>
                            </div>
                            <div>for basic scenarios like that being
                              discussed by joel, i prefer the conjugate
                              gradient optimizer with line search.&nbsp;</div>
                            <div><br>
                            </div>
                            <div>
                              <div>itkConjugateGradientLineSearchOptimizerv4.h</div>
                              <div><br>
                              </div>
                              <div>when combined with the scale
                                estimators, this leads to registration
                                algorithms with very few parameters to
                                tune. &nbsp; 1 parameter if you dont consider
                                multi-resolution.</div>
                              <span><font color="#888888"> </font></span></div>
                          </div>
                          <div class="gmail_extra"><span><font
                                color="#888888"><br clear="all">
                                <div>
                                  <div><br>
                                  </div>
                                  brian<br>
                                  <div><br>
                                  </div>
                                  <div><br>
                                  </div>
                                </div>
                              </font></span>
                            <div>
                              <div> <br>
                                <br>
                                <div class="gmail_quote">On Tue, May 7,
                                  2013 at 9:27 AM, Nick Tustison <span
                                    dir="ltr">&lt;<a
                                      moz-do-not-send="true"
                                      href="mailto:ntustison@gmail.com"
                                      target="_blank">ntustison@gmail.com</a>&gt;</span>
                                  wrote:<br>
                                  <blockquote class="gmail_quote"
                                    style="margin:0 0 0
                                    .8ex;border-left:1px #ccc
                                    solid;padding-left:1ex"> Hi Brad,<br>
                                    <br>
                                    I certainly don't disagree with
                                    Joel's findings. &nbsp;It seems like a<br>
                                    good fix which should be put up on
                                    gerrit. &nbsp;There were several<br>
                                    components that we kept in upgrading
                                    the registration framework.<br>
                                    The optimizers weren't one of them.<br>
                                    <br>
                                    Also, could you elaborate a bit more
                                    on the "convoluted" aspects<br>
                                    of parameter advancement? &nbsp;There's
                                    probably a reason for it and<br>
                                    we could explain why.<br>
                                    <span><font color="#888888"><br>
                                        Nick<br>
                                      </font></span>
                                    <div>
                                      <div><br>
                                        <br>
                                      </div>
                                    </div>
                                  </blockquote>
                                </div>
                              </div>
                            </div>
                          </div>
                        </blockquote>
                      </div>
                      <br>
                    </div>
                  </blockquote>
                  <br>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>