[Swift-commit] r5507 - SwiftApps/SciColSim
wilde at ci.uchicago.edu
wilde at ci.uchicago.edu
Sun Jan 22 19:50:27 CST 2012
Author: wilde
Date: 2012-01-22 19:50:27 -0600 (Sun, 22 Jan 2012)
New Revision: 5507
Modified:
SwiftApps/SciColSim/annealing.swift
SwiftApps/SciColSim/math.swift
SwiftApps/SciColSim/tc
Log:
Initial working version of basic swift annealing loop.
Modified: SwiftApps/SciColSim/annealing.swift
===================================================================
--- SwiftApps/SciColSim/annealing.swift 2012-01-22 03:29:59 UTC (rev 5506)
+++ SwiftApps/SciColSim/annealing.swift 2012-01-23 01:50:27 UTC (rev 5507)
@@ -19,6 +19,7 @@
} else {
nx = x - (random())*dx/(pow(2.0,31.0)-1.0);
}
+ tracef("newx(%f,%f)=%f\n",x,dx,nx);
}
app (file outfile, file loss) evolve (string args[], file graph)
@@ -40,7 +41,7 @@
multi_annealing()
multi_loss()
evolve()
- sumloass()
+ sumloss()
*/
(file bestfile, file maxfile) multi_annealing (
@@ -61,7 +62,8 @@
float x[][], dx[][], curr_loss[], curr_sdev[];
Res mlres[][];
- mlres[0][0] = multi_loss( params0, target_innov, evolve_reruns ); // Only done once, not 5x; serves for all evolve-params ???
+ mlres[0][0] = multi_loss( 0, 0, params0, target_innov, evolve_reruns ); // Only done once, not 5x; serves for all evolve-params ???
+tracef("in multi_annealing: i=%i j=%i ret vals from iniital multi_loss=(%f,%f)\n",0,0,mlres[0][0].loss,mlres[0][0].sdev);
foreach j in [0:NEVOPARAMS-1] {
x[0][j]=params0[j];
@@ -74,9 +76,10 @@
foreach i in [1:annealing_cycles] {
// set new temperature, rejection threshold, and dx values for this cycle
float temperature = T_start*exp( @tofloat(i)*(jlog(T_end)-jlog(T_start))/@tofloat(annealing_cycles));
- tracef("....T =%f\n", temperature);
+ tracef("in multi_annealing: i=%i T=%f\n", i, temperature);
// On each new "major" cycle within the annealing_cycles (other than the first) set new rejection and dx values
if ( i %% cycle == 1 && i > 1 ){
+ tracef("multi_annealing: new cycle at i=%i\n",i);
foreach k in [0:NEVOPARAMS-1] {
float newrejection = rejection[i-1][k] / @tofloat(cycle);
if (newrejection > 0.0){
@@ -90,47 +93,61 @@
trace ("Recomputed rejection: i=%d k=%d dx[i][k]=%f\n", i, k, dx[i][k]);
}
}
+ else { # If not new cycle, set dx from previous dx (i-1)
+ foreach k in [0:NEVOPARAMS-1] {
+ dx[i][k] = dx[i-1][k];
+ }
+ }
foreach j in [0:NEVOPARAMS-1] { // Try a new value for each non-fixed param; then write results and accept or reject
- float try_x[];
+ // float try_x[];
int curr = (i * NEVOPARAMS) + j;
int prev = curr-1;
- if ( FIX_VARIABLES || var_fixed[j]==0) {
- foreach k in [0:NEVOPARAMS] { // Select the evolve params to try
+tracef("in multi_annealing: i=%i j=%i curr=%i prev=%i\n", i, j, curr, prev);
+ if ( /*(!FIX_VARIABLES) || */ (var_fixed[j]==0) ) { # fixed=1,1,0,0,0: FIXME: FIX_VARIABLES flag has faulty logic but OK when TRUE
+ float try_x[];
+ foreach k in [0:NEVOPARAMS-1] { // Select the evolve params to try
if ( k < j ) {
try_x[k] = x[i][k]; // already set x[i][k]
}
else {
if ( k == j ) {
- try_x[k] = newx(x[i][j],dx[i][j]); // permute x[i][j]
+ try_x[k] = newx(x[i-1][j],dx[i-1][j]); // permute x[i-1][j]
}
- else {
+ else { // k > j
try_x[k] = x[i-1][k]; // use x[i-1][k] (from prior cycle)
}
}
+ tracef("in multi_annealing: i=%i j=%i k=%i try_x=%f\n", i, j, k, try_x[k]);
+ tracef("in multi_annealing: i=%i j=%i k=%i\n", i, j, k);
}
-
- mlres[i][j] = multi_loss(try_x, target_innov, evolve_reruns);
-
+ // Up to here, x[] and dx[] are only set for previous i
+tracef("in multi_annealing: i=%i j=%i calling multi_loss\n",i,j);
+#tracef("in multi_annealing: i=%i j=%i calling multi_loss try_x=%q\n",i,j,try_x);
+ mlres[i][j] = multi_loss(i,j,try_x, target_innov, evolve_reruns); # do the N evolve()'s, N=evolve_reruns
+tracef("in multi_annealing: i=%i j=%i ret vals from multi_loss=(%f,%f)\n",i,j,mlres[i][j].loss,mlres[i][j].sdev);
+ // Beyond this point, x[] and dx[] are being set for this i,j
float ratio = min(1.0, exp( -(mlres[i][j].loss-curr_loss[prev]) /temperature));
float r = (random()) / (pow(2.0,31.0)-1.0); // why all the 2^31's ???
float ALOT=100000000000.0; // 100,000,000,000. = 10^11
- if (mlres[i][j].loss < ALOT) { // does this ever occur? if so did we want to still do the ratio computation above???
- trace("filestr.open (best_opt_some.txt, ofstream::app);");
+ if (mlres[i][j].loss < ALOT) {
+ tracef("multi_annealing: Writing: filestr.open (best_opt_some.txt, ofstream::app);\n");
# un[0]->get_target() Res.loss un[0]->get_parameter[0:4] Res.error
# filestr.open ("max_dist.txt", ofstream::app);
}
- else { tracef("Loss %f > ALOT at [i][j] = [%d][%d]\n", mlres[i][j].loss, i ,j); }
- if (r > ratio) { // Reject
+ else { // does this ever occur? if so did we want to still do the ratio computation above???
+ tracef("multi_annealing: Loss %f > ALOT at [i][j] = [%d][%d]\n", mlres[i][j].loss, i ,j);
+ }
+ if (r > ratio) { // Reject new parameter
x[i][j] = x[i-1][j];
- rejection[i][j] = rejection[i][j] + 1.0; // Is this correct? incr rejection?
+ rejection[i][j] = rejection[i-1][j] + 1.0; // Is this correct? incr rejection?
curr_loss[curr] = curr_loss[prev];
curr_sdev[curr] = curr_sdev[prev];
}
- else { // Accept
-trace("Accepting try_x[j],j=",j);
- x[i][j] = try_x[j]; # FIXME: is this right? Just assign the j'th try_x, or the whole try_x param set?
-trace("Accepting try_x[j],x[i][j]=",x[i][j]);
+ else { // Accept new parameter
+tracef("multi_annealing: Accepting try_x[j], i=%i j=%i\n",i,j);
+ x[i][j] = try_x[j];
+tracef("multi_annealing: Accepting try_x[j], i=%i j=%i try_x[j]=%f\n",i,j,try_x[j]);
curr_loss[curr] = mlres[i][j].loss;
curr_sdev[curr] = mlres[i][j].sdev;
}
@@ -144,9 +161,16 @@
}
}
-(Res r) multi_loss( float x[], float target_innov, int evolve_reruns )
+(Res r) multi_loss( int ci, int cj, float x[], float target_innov, int evolve_reruns )
{
file rfile[];
+ tracef("In multi_loss: entered: ci=%i cj=%i target_innov=%f evolve_reruns=%i x=%q\n",ci, cj, target_innov,evolve_reruns,x);
+ tracef("In multi_loss: entered: ci=%i cj=%i target_innov=%f evolve_reruns=%i\n",ci, cj, target_innov,evolve_reruns);
+/* This hangs:
+ foreach f,i in x {
+ tracef("In multi_loss: x[]: ci=%i cj=%i x[%i]=%f\n",ci, cj, i, f);
+ }
+*/
foreach i in [1:evolve_reruns] { // repeats of the evolove() - same as n_reruns
file outfile; // FIXME: map and save in future
string args[] = [ // FIXME: move this to a setargs() function
@@ -155,7 +179,7 @@
// n_epochs n_steps evolve_reruns range
// "40000", "20", @strcat(evolve_reruns), "2",
- "40000", "20", "1", " 2", # Set reruns to 1 for the cpp code; we do the re-runs in Swift for now.
+ "40000", "20", "1", "2", # Set reruns to 1 for the cpp code; we do the re-runs in Swift for now.
// verbose_level
"1",
@@ -171,23 +195,26 @@
file graph <"movie_graph.txt">;
(outfile, rfile[i]) = evolve(args,graph);
+ tracef("in multi_loss: after evolve: i=%i %k %k\n", i, outfile, rfile[i]);
}
file sumfile = sumloss(rfile);
r = readData(sumfile);
-
+ tracef("in multi_loss: returning: ci=%i cj=%i r.loss=%f r.sdev=%f\n",ci,cj,r.loss,r.sdev);
}
optimizer_sweep() // Implements logic of python driver script
{
int minrange=58;
- int maxrange=59;
+ int maxrange=209;
+ //int maxrange=59;
//int maxrange=1009;
//int maxrange=209;
int rangeinc=50;
// fixme: add provision for random priming and random param values when x[i] == -100 (see optimizer.cpp main())
- int nreps=1; # 15
+ //int nreps=1; # 15
+ int nreps=3; # 15
// file bestfile <single_file_mapper; file=@strcat("output/T",target,".R",rep,".best_opt_some")>;
// file maxfile <single_file_mapper; file=@strcat("output/T",target,".R",rep,".max_dist")>;
@@ -204,8 +231,8 @@
evolve_reruns = 2,
starting_jump = 2.3,
params0[] = [0.0, 0.0, 4.0, 50.0, -1.0],
- @tofloat(@strcat(target_innov)), // fixme: would @tofloat(int) work?
- annealing_cycles = 1); // fixme: clarify: annealing repeats, steps, and cycles
+ @tofloat(target_innov),
+ annealing_cycles = 1);
*/
(outfile,lossfile) = multi_annealing(
2.0,
@@ -214,8 +241,8 @@
2,
2.3,
[0.0, 0.0, 4.0, 50.0, -1.0],
- @tofloat(@strcat(target_innov)), // fixme: would @tofloat(int) work?
- 1); // fixme: clarify: annealing repeats, steps, and cycles
+ @tofloat(target_innov),
+ 1);
}
}
}
@@ -236,7 +263,7 @@
multi_annealing()
multi_loss()
evolve()
- sumloass()
+ sumloss()
Example parameter sets:
Modified: SwiftApps/SciColSim/math.swift
===================================================================
--- SwiftApps/SciColSim/math.swift 2012-01-22 03:29:59 UTC (rev 5506)
+++ SwiftApps/SciColSim/math.swift 2012-01-23 01:50:27 UTC (rev 5507)
@@ -38,7 +38,7 @@
else {
result = b;
}
- tracef("min: result=%f\n",result);
+ tracef("math/min: result=%f\n",result);
}
(float result) pow (float x, float y)
Modified: SwiftApps/SciColSim/tc
===================================================================
--- SwiftApps/SciColSim/tc 2012-01-22 03:29:59 UTC (rev 5506)
+++ SwiftApps/SciColSim/tc 2012-01-23 01:50:27 UTC (rev 5507)
@@ -1,13 +1,15 @@
localhost sh /bin/sh null null null
localhost cat /bin/cat null null null
+
pbs cat /bin/cat null null null
mcs cat /bin/cat null null null
localhost catnap /home/wilde/swift/lab/catnap.sh null null GLOBUS::maxwalltime="00:01:00"
+
beagle optimizer /home/wilde/AndreysOptimizer/Optimizer null null GLOBUS::maxwalltime="01:00:00"
beagle optimizersh /home/wilde/AndreysOptimizer/optimizer.sh null null GLOBUS::maxwalltime="02:00:00"
beagle evolve /home/wilde/AndreysOptimizer/evolve.sh null null GLOBUS::maxwalltime="02:00:00"
-localhost evolve /home/wilde/AndreysOptimizer/evolve.sh null null GLOBUS::maxwalltime="02:00:00"
+localhost evolve /home/wilde/AndreysOptimizer/src/evolve.sh null null GLOBUS::maxwalltime="02:00:00"
beagle sumloss /home/wilde/AndreysOptimizer/evolve.sh null null GLOBUS::maxwalltime="02:00:00"
-localhost sumloss /home/wilde/AndreysOptimizer/sumloss.sh null null GLOBUS::maxwalltime="02:00:00"
+localhost sumloss /home/wilde/AndreysOptimizer/src/sumloss.sh null null GLOBUS::maxwalltime="02:00:00"
More information about the Swift-commit
mailing list