Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 3 files changed
  • 0 comments
  • 1 contributor
4  Makefile
@@ -60,8 +60,8 @@ install:
60 60
 endif
61 61
 
62 62
 
63  
-sample: $(TARGET_SO) sample.o
64  
-	$(CC) $^ -o $@
  63
+sample: sample.o libdogleg.a
  64
+	$(CC) $(LDLIBS) $^ -o $@
65 65
 
66 66
 sample.o: CFLAGS += -I.
67 67
 
23  dogleg.c
@@ -537,10 +537,27 @@ static int evaluateStep_adjustTrustRegion(const dogleg_operatingPoint_t* before,
537 537
     fprintf(stderr, "expected improvement: %.20f, got improvement %.20f. rho = %.20f\n",
538 538
             expectedImprovement, observedImprovement, rho);
539 539
 
540  
-  if(rho < TRUSTREGION_DECREASE_THRESHOLD)
  540
+
  541
+  // adjust the trust region
  542
+  if( rho < TRUSTREGION_DECREASE_THRESHOLD )
  543
+  {
  544
+    if( DOGLEG_DEBUG )
  545
+      fprintf(stderr, "rho too small. decreasing trust region\n");
  546
+
  547
+    // Our model doesn't fit well. We should reduce the trust region size. If
  548
+    // the trust region size was affecting the attempted step, do this by a
  549
+    // constant factor. Otherwise, drop the trustregion to attempted step size
  550
+    // first
  551
+    if( !before->didStepToEdgeOfTrustRegion )
  552
+      *trustregion = sqrt(before->updateGN_lensq);
  553
+
541 554
     *trustregion *= TRUSTREGION_DECREASE_FACTOR;
  555
+  }
542 556
   else if (rho > TRUSTREGION_INCREASE_THRESHOLD && before->didStepToEdgeOfTrustRegion)
543 557
   {
  558
+    if( DOGLEG_DEBUG )
  559
+      fprintf(stderr, "rho large enough. increasing trust region\n");
  560
+
544 561
     *trustregion *= TRUSTREGION_INCREASE_FACTOR;
545 562
   }
546 563
 
@@ -559,14 +576,14 @@ static int runOptimizer(dogleg_solverContext_t* ctx)
559 576
   {
560 577
     if( DOGLEG_DEBUG )
561 578
     {
562  
-      fprintf(stderr, "step %d\n", stepCount);
563 579
       fprintf(stderr, "\n\n\n");
  580
+      fprintf(stderr, "step %d\n", stepCount);
564 581
     }
565 582
 
566 583
     while(1)
567 584
     {
568 585
       if( DOGLEG_DEBUG )
569  
-        fprintf(stderr, "\n\n");
  586
+        fprintf(stderr, "\n");
570 587
 
571 588
       double expectedImprovement =
572 589
         takeStepFrom(ctx->beforeStep, ctx->afterStep->p, trustregion, ctx);
8  sample.c
@@ -154,9 +154,11 @@ int main(void)
154 154
   int Jnnz = Nmeasurements * Nstate;
155 155
 
156 156
   // first, let's test our gradients. This is just a verification step to make
157  
-  // sure the optimizerCallback() is written correctly. This will generate LOTS
158  
-  // of output. You need to make sure that the reported and observed gradients
159  
-  // match (the relative error is low)
  157
+  // sure the optimizerCallback() is written correctly. Normally, you would do
  158
+  // this as a check when developing your program, but would turn this off in
  159
+  // the final application. This will generate LOTS of output. You need to make
  160
+  // sure that the reported and observed gradients match (the relative error is
  161
+  // low)
160 162
   fprintf(stderr, "have %d variables\n", Nstate);
161 163
   for(int i=0; i<Nstate; i++)
162 164
   {

No commit comments for this range

Something went wrong with that request. Please try again.