Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ STSP

In and out of transit starspot modeling code

V4.5.1 2015-12-07

Refactoring the elapsed time calculation for timed runs. STSP runs can be timed by
setting the MCMC step number to a negative number, which will be interpreted as the
negative of the maximum number of seconds to run the chains.

V4.5 2015-11-30

Added the functionality for analyzing planets on eccentric orbits.
Expand Down
23 changes: 14 additions & 9 deletions stsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <math.h>
#include <time.h>

#define QUIET 0 //0 -> prints things, 1 -> only prints errors
#define QUIETMCMC 0 //0 -> mcmc prints as it goes, 1-> stays quiet (0 overridden by QUIET)
#define QUIET 1 //0 -> prints things, 1 -> only prints errors
#define QUIETMCMC 1 //0 -> mcmc prints as it goes, 1-> stays quiet (0 overridden by QUIET)
#define ALWAYSPRINTVIS 0
#define WHICHPRINTVIS 1 // what sort of visualization file to output (j-1,g-2)
#define ANYPRINTVIS 0 //0 for speed, overrides other PRINTVIS preferences
Expand Down Expand Up @@ -4226,7 +4226,8 @@ void mcmc(stardata *star,planetdata planet[MAXPLANETS],spotdata spot[MAXSPOTS],i
{
char goodparams,filename[128];
int i,j,k,r,msi,nparam,curstep,potstep,*updated,*naccepted,maxsteps;
long int memused,maxtime,time0,time1,avgtime;
long int memused, run_time_buffer;
double maxtime,time0,time1,avgtime,elapsed_time,elapsed_time_at_next_step;
double **param[2],*chisq[2]; //param[0-1][chain number][parameter number]
double sqrtascale,oosqrtascale,smooascale,z,alpha,rn;
double bestchisq,*bestparam,torig;
Expand Down Expand Up @@ -4491,17 +4492,17 @@ void mcmc(stardata *star,planetdata planet[MAXPLANETS],spotdata spot[MAXSPOTS],i
else
{
maxsteps=TOOBIG;
maxtime=starttime-maxstepsortime; //time limit is passed as negative
maxtime=-maxstepsortime; //time limit is passed as negative
# if !QUIETMCMC && !QUIET
printf("start time: %li maxtime: %li (%li)\n",starttime,maxtime,maxstepsortime*(-1));
# endif
}
avgtime=0;
if(maxtime||ALWAYSAVERAGETIME)
time0=timecheck();

for(msi=0;msi<maxsteps;msi++) //the mcmc loop
{
if(maxtime||ALWAYSAVERAGETIME)
time0=timecheck();

j=0;
for(i=0;i<npop;i++)
j+=naccepted[i];
Expand Down Expand Up @@ -4642,8 +4643,12 @@ void mcmc(stardata *star,planetdata planet[MAXPLANETS],spotdata spot[MAXSPOTS],i
if(maxtime||ALWAYSAVERAGETIME)
{
time1=timecheck();
avgtime=(avgtime*msi+time1-time0)/(msi+1);
if(maxtime&&time1+2*avgtime+300>maxtime)
elapsed_time = time1-time0;
avgtime=elapsed_time/(msi+1);
elapsed_time_at_next_step = avgtime + elapsed_time;
run_time_buffer = 300;

if(elapsed_time_at_next_step > maxtime - run_time_buffer)
maxsteps=0; //make it stop, time is almost up
}
} //end of main mcmc loop
Expand Down