[Swift-commit] r5720 - SwiftApps/SciColSim

jonmon at ci.uchicago.edu jonmon at ci.uchicago.edu
Tue Mar 20 14:11:05 CDT 2012


Author: jonmon
Date: 2012-03-20 14:11:04 -0500 (Tue, 20 Mar 2012)
New Revision: 5720

Modified:
   SwiftApps/SciColSim/annealing.swift
   SwiftApps/SciColSim/optimizer.cpp
   SwiftApps/SciColSim/sumloss.sh
Log:
o committed changes for calculation the timing average
o optimizer.cpp now has working loss limiting code



Modified: SwiftApps/SciColSim/annealing.swift
===================================================================
--- SwiftApps/SciColSim/annealing.swift	2012-03-19 15:01:27 UTC (rev 5719)
+++ SwiftApps/SciColSim/annealing.swift	2012-03-20 19:11:04 UTC (rev 5720)
@@ -11,12 +11,12 @@
 {
     float loss;
     float sdev;
-    float tloss;
+    float tavg;
     float tsdev;
 }
 
 global boolean FIX_VARIABLES = true;
-global int var_fixed[] = [1,1,0,0,0];
+global int var_fixed[] = [0,0,0,0,0];
 global int Nworkers = @toint(@arg("nworkers","4"));
 global int rerunsPerApp= @toint(@arg("rerunsperapp", "100"));
 
@@ -159,16 +159,8 @@
                 }
                 tracef( @strcat( "multi_annealing: AR: ", color( 10,"%f" ), " ", color( 9,"%i" ),"\n" ), try_x[j], j );
 
-                if( (try_x[2] < -1.2) || (try_x[2] > 12.0) )  # FIXME: Temp debugging hack: REMOVE THIS!!!
-                {
-                    mlres[i][j].loss = 140.0;
-                    mlres[i][j].sdev = 0.8;
-                }
-                else
-                {
-                    // Up to here, x[] and dx[] are only set for previous i
-                    mlres[i][j] = multi_loss( T_start, T_end, annealing_cycles, Target_rejection, starting_jump, i, j, try_x, target_innov, evolve_reruns ); // do the N evolve()'s, N=evolve_reruns
-                }
+                mlres[i][j] = multi_loss( T_start, T_end, annealing_cycles, Target_rejection, starting_jump, i, j, try_x, target_innov, evolve_reruns ); // do the N evolve()'s, N=evolve_rerusn
+
                 tracef( "multi_annealing: AR: %f +- %f\n", mlres[i][j].loss, mlres[i][j].sdev );
                 // Beyond this point, x[] and dx[] are being set for this i,j
 
@@ -177,14 +169,14 @@
                 if ( mlres[i][j].loss < ALOT )
                 {
                     fprintf( some_out_filename, "N, %fs, %i, %i, %f, %f, |, %i, %f, [, %f, %f, %f, %f, %f, ], %f\n",
-                             mlres[i][j].tloss, i-1, j, dx[i][j], rejection[i][j], @toint(target_innov), mlres[i][j].loss, try_x[0], try_x[1], try_x[2], try_x[3], try_x[4], mlres[i][j].sdev );  // Note i-1 field: print that way to match with C++ output
+                             mlres[i][j].tavg, i-1, j, dx[i][j], rejection[i][j], @toint(target_innov), mlres[i][j].loss, try_x[0], try_x[1], try_x[2], try_x[3], try_x[4], mlres[i][j].sdev );  // Note i-1 field: print that way to match with C++ output
 
                     // fprintf( "max_dist_swift.txt", color( Red,"multi_annealing: AF: max_dist.txt - tbd\n" ) ); // FIXME: max_dist is global set in evolve()
                 }
                 else // does this ever occur? if so did we want to still do the ratio computation above???
                 {
-                    fprintf( some_out_filename, "A %i %i %f %f | %i, %f, %f, %f, %f, %f, %f, %f\n",
-                             i, j, dx[i][j], rejection[i][j], @toint(target_innov), mlres[i][j].loss, try_x[0], try_x[1], try_x[2], try_x[3], try_x[4], mlres[i][j].sdev );
+                    fprintf( some_out_filename, "A, %fs, %i, %i, %f, %f, |, %i, %f, [, %f, %f, %f, %f, %f, ], %f\n",
+                             mlres[i][j].tavg, i-1, j, dx[i][j], rejection[i][j], @toint(target_innov), mlres[i][j].loss, try_x[0], try_x[1], try_x[2], try_x[3], try_x[4], mlres[i][j].sdev );  // Note i-1 field: print that way to match with C++ output
 
                     //tracef( "multi_annealing: Loss %f > ALOT at [i][j] = [%d][%d]\n", mlres[i][j].loss, i ,j );
                 }
@@ -290,7 +282,7 @@
                  @strcat(t_start), @strcat(t_end), @strcat(annealing_steps), @strcat(t_rejection), @strcat(starting_jump),
 
             //    FREEZE: alpha_i alpha_m beta gamma delta
-                            "1",    "1",  "0",  "0",  "0",
+                            "0",    "0",  "0",  "0",  "0",
 
             //   operation-code:(m,a)    Nworkers           seed
                       "m",            @strcat(Nworkers), @arg("seed", "0" ) ];

Modified: SwiftApps/SciColSim/optimizer.cpp
===================================================================
--- SwiftApps/SciColSim/optimizer.cpp	2012-03-19 15:01:27 UTC (rev 5719)
+++ SwiftApps/SciColSim/optimizer.cpp	2012-03-20 19:11:04 UTC (rev 5720)
@@ -990,25 +990,23 @@
     void evolve_to_target_and_save(int istart, int iend, double* storage, int* counters){
 
         double ALOT=10000.;
+        double ratio = 0.0;
         int check = 0;
 
         reset_world();
 
         for (int k = istart; k < iend; k++){
 
-// Code for getting time to check
-
             for(int i=0; i< N_epochs &&  current_novelty < TargetNovelty; i++){
 
-// Check the walltime limit
-
-                if(current_loss/current_novelty < max_loss_value((int)TargetNovelty)){
+                if(ratio < max_loss_value((int)TargetNovelty)*2){
                     update_world();
                 }
                 else{
-                    check=1;
+                    check = 1;
                     break;
                 }
+                ratio = current_loss/current_novelty;
             }
 
             if( check ){
@@ -1026,28 +1024,27 @@
 
     //==============================================
     double max_loss_value(int tn){
-        /* Poor check */
-        /* Do not check for equality, check for within some error */
-        if( tn == 58. )           return 128.286;
-        else if( tn == 108. )     return 131.866;
-        else if( tn == 158. )     return 135.551;
-        else if( tn == 208. )     return 139.694;
-        else if( tn == 258. )     return 144.163;
-        else if( tn == 308. )     return 148.967;
-        else if( tn == 358. )     return 154.201;
-        else if( tn == 408. )     return 159.962;
-        else if( tn == 458. )     return 166.441;
-        else if( tn == 508. )     return 173.655;
-        else if( tn == 558. )     return 181.921;
-        else if( tn == 608. )     return 191.246;
-        else if( tn == 658. )     return 202.150;
-        else if( tn == 708. )     return 215.197;
-        else if( tn == 758. )     return 202.150;  // Verify with Andrey. Same as TargetNovelty of 658
-        else if( tn == 808. )     return 251.698;
-        else if( tn == 858. )     return 279.201;
-        else if( tn == 908. )     return 320.112;
-        else if( tn == 958. )     return 394.774;
-        else if( tn == 1008. )    return 1052.38;  // Huge number here. Why?
+
+        if( tn == 58 )           return 128.286;
+        else if( tn == 108 )     return 131.866;
+        else if( tn == 158 )     return 135.551;
+        else if( tn == 208 )     return 139.694;
+        else if( tn == 258 )     return 144.163;
+        else if( tn == 308 )     return 148.967;
+        else if( tn == 358 )     return 154.201;
+        else if( tn == 408 )     return 159.962;
+        else if( tn == 458 )     return 166.441;
+        else if( tn == 508 )     return 173.655;
+        else if( tn == 558 )     return 181.921;
+        else if( tn == 608 )     return 191.246;
+        else if( tn == 658 )     return 202.150;
+        else if( tn == 708 )     return 215.197;
+        else if( tn == 758 )     return 202.150;  // Verify with Andrey. Same as TargetNovelty of 658
+        else if( tn == 808 )     return 251.698;
+        else if( tn == 858 )     return 279.201;
+        else if( tn == 908 )     return 320.112;
+        else if( tn == 958 )     return 394.774;
+        else if( tn == 1000 )    return 1052.38;  // Huge number here. Why?
         else                      return 10000.;   /* Pray that this does not occur. Ask Andrey what to do */
     }
 

Modified: SwiftApps/SciColSim/sumloss.sh
===================================================================
--- SwiftApps/SciColSim/sumloss.sh	2012-03-19 15:01:27 UTC (rev 5719)
+++ SwiftApps/SciColSim/sumloss.sh	2012-03-20 19:11:04 UTC (rev 5720)
@@ -1,8 +1,17 @@
 #! /bin/sh
 
+# Calculates the average loss, loss standard deviation, average running time, and average running time standard deviation
+# of a set of loss files all produced by evolve.sh
+
+# loss = average loss
+# sdev = standard deviation of loss
+# tavg = average timing data(name should be changed)
+# tsdev = standard deviation of timing data
+
+# process each file individually and treat each number as a field
 awk '
 
-BEGIN { RS = ""; FS="\n";  loss = 0; loss_sq = 0; tloss = 0; tloss_sq = 0; n = 0; tn = 0; }
+BEGIN { RS = ""; FS="\n";  loss = 0; loss_sq = 0; tavg = 0; tavg_sq = 0; n = 0; tn = 0; }
 
 {
   for(i=1;i<NF;i++)
@@ -11,8 +20,8 @@
       loss_sq += ($i*$i)
       n++
   }
-  tloss += $NF
-  tloss_sq += ($NF*$NF)
+  tavg += $NF
+  tavg_sq += ($NF*$NF)
   tn++
 }
 
@@ -20,56 +29,16 @@
 
   loss /= n;
   loss_sq /= n;
-  tloss /= tn;
-  tloss_sq /= tn;
+  tavg /= tn;
+  tavg_sq /= tn;
 
   x = (loss_sq - (loss*loss))/n
-  y = (tloss_sq - ( tloss*tloss))/tn
+  y = (tavg_sq - ( tavg*tavg))/tn
   sdev = 2.0 * sqrt(x)
   tsdev = 2.0 * sqrt(y)
 
-  printf "loss sdev tloss tsdev\n"
-  printf "%f %f %f %f\n", loss, sdev, tloss, tsdev
+  printf "loss sdev tavg tsdev\n"
+  printf "%f %f %f %f\n", loss, sdev, tavg, tsdev
 } ' $*
 
 # the awk script above implements this c++ logic from optimizer.cpp:
-#
-#    for (int i=0; i<N; i++){
-#        double n = double(N);
-#        Loss += Results[i]/n;
-#        LossSquare += Results[i]*Results[i]/n;
-#
-#        std::cout<<" RESULT: " << Results[i];
-#    }
-#
-#    std::cout<<" \n\n\n";
-#    double x = ((LossSquare - Loss*Loss)/(double)N);
-#    double two_std = 2.*sqrt(x);
-#
-#    std::pair<double,double> Res;
-#    Res.first=Loss;
-#    Res.second=two_std;
-
-
-# Older logic, literal transcription from C++ (didnt handle multiline files correctly):
-
-# awk '
-
-# BEGIN { n = 0; loss = 0; }
-
-# {
-#   loss += $1
-#   loss_sq += ($1*$1)
-#   n++
-# }
-
-# END {
-
-#   loss /= n;
-#   loss_sq /= n;
-
-#   x = (loss_sq - (loss*loss))/n
-#   sdev = 2.0 * sqrt(x)
-#   printf "loss sdev\n"
-#   printf "%f %f\n", loss, sdev
-# } ' $*




More information about the Swift-commit mailing list