esfit and maxTime

General forum for EasySpin: questions, how to's, etc.
Locked
arden13
User
Posts: 14
Joined: Thu Jul 24, 2014 3:46 pm

esfit and maxTime

Post by arden13 »

I am having problems getting esfit to recognize or use the maxTime parameter. I've tried setting it to a reasonable value (20min or so) and to very small values (1min) just to see if I typed it incorrectly or capitalized something incorrectly. Is there something I'm doing wrong?

Code: Select all

Sys.S=1/2;
Sys.gStrain=[.01 .01 .01];
Sys.g=[2.00 2.00 2.06];
Sys.A=[40 50 50; 40 50 50];
Sys.Nucs = '59Co,59Co';

Vary.g=[0.1 0.1 0.1];
Vary.A=[10 10 10];
Vary.gStrain=[0.005 0.005 0.005];

Exp.mwFreq=9.3756;
Exp.Range=[200 399.8];
Exp.nPoints=1000;
Exp.ModAmp=0.8;

pepOpt.Verbosity=1;

FitOpt.Method='simplex fcn';
FitOpt.maxTime = 10;

bestSys = esfit('pepper',Data,Sys,Vary,Exp,pepOpt,FitOpt);


also: FIRST
Stefan Stoll
EasySpin Creator
Posts: 1041
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: esfit and maxTime

Post by Stefan Stoll »

You are trying to fit N=9 parameters simultaneously. In the simplex algorithm, esfit first computes N+1=10 spectra with slightly different parameter sets within your range to set up what's called the initial simplex. During these setup simulations, esfit does not check FitOpt.maxTime. Only after that, esfit compares elapsed time to FitOpt.maxTime and stops if over.

So it seems your 10 initial simulations take longer than the FitOpt.maxTime you set.
Matt Krzyaniak
EasySpin Guru
Posts: 153
Joined: Tue Jul 22, 2014 11:01 am
Location: Northwestern University

Re: esfit and maxTime

Post by Matt Krzyaniak »

Another suggestion would be to parse how long pepper actually takes to run a single simulation through the use of tic and toc.

Code: Select all

tic;
pepper(Sys,Exp);
toc
With that in hand you can get a better idea of how long you need to make FitOpt.maxTime.
Morgan Bye
EasySpin Guru
Posts: 18
Joined: Thu Jul 24, 2014 9:44 am
Location: BC Cancer, Canada
Contact:

Re: esfit and maxTime

Post by Morgan Bye »

Matt Krzyaniak wrote:Another suggestion would be to parse how long pepper actually takes to run a single simulation through the use of tic and toc.

Code: Select all

tic;
pepper(Sys,Exp);
toc
With that in hand you can get a better idea of how long you need to make FitOpt.maxTime.
I'd perhaps take this one step further and remove the timing control from ES altogether. Whilst I typically stay away from "while" commands as they can be nightmares to debug, you could

Code: Select all

tic;
while tic < [a time in seconds]
    pepper(Sys,Exp);
end
toc
arden13
User
Posts: 14
Joined: Thu Jul 24, 2014 3:46 pm

Re: esfit and maxTime

Post by arden13 »

Morgan Bye wrote:
Matt Krzyaniak wrote:Another suggestion would be to parse how long pepper actually takes to run a single simulation through the use of tic and toc.

Code: Select all

tic;
pepper(Sys,Exp);
toc
With that in hand you can get a better idea of how long you need to make FitOpt.maxTime.
I'd perhaps take this one step further and remove the timing control from ES altogether. Whilst I typically stay away from "while" commands as they can be nightmares to debug, you could

Code: Select all

tic;
while tic < [a time in seconds]
    pepper(Sys,Exp);
end
toc
My pepper simulations generally don't take all that long, a minute or two at most; I am more concerned about limiting the time of esfit when I don't simulate it with the UI. If I utilize a while command and it runs for however many seconds, will I still receive a system structure out when it finishes or will it just halt the operation altogether?
Matt Krzyaniak
EasySpin Guru
Posts: 153
Joined: Tue Jul 22, 2014 11:01 am
Location: Northwestern University

Re: esfit and maxTime

Post by Matt Krzyaniak »

Why would you want to limit the time of esfit? By prematurely stopping an optimization you're not likely to be at a parameter space minimum(on the way but not there yet). Perhaps a better method would be to decrease the step tolerance or function tolerance for coarse optimizations in parameter space.
Morgan Bye
EasySpin Guru
Posts: 18
Joined: Thu Jul 24, 2014 9:44 am
Location: BC Cancer, Canada
Contact:

Re: esfit and maxTime

Post by Morgan Bye »

You are correct, by moving the time control out of ES and into the while loop, when that time limit is reached any command that is running will be killed.

So you are likely only wanting to be use my solution has a last-resort method - ie. you know your simulations take 1-2 mins and you have a lot queued to run overnight, so you set the kill time at 5 mins.

As Matt says, if you want to reduce time then the step tolerance is a much better thing to adjust.

In the past, I've always hunted for rough parameters first and then piped the results into a second round of fitting with finer parameters. I recall I even made a quick and dirty GUI for it.... ah yes... here:
http://morganbye.net/eprtoolbox/easyrefiner/

But I haven't used it since esfit got the GUI so it probably wont work with new ES releases.
arden13
User
Posts: 14
Joined: Thu Jul 24, 2014 3:46 pm

Re: esfit and maxTime

Post by arden13 »

Matt Krzyaniak wrote:Why would you want to limit the time of esfit? By prematurely stopping an optimization you're not likely to be at a parameter space minimum(on the way but not there yet). Perhaps a better method would be to decrease the step tolerance or function tolerance for coarse optimizations in parameter space.
Morgan Bye wrote:You are correct, by moving the time control out of ES and into the while loop, when that time limit is reached any command that is running will be killed.

So you are likely only wanting to be use my solution has a last-resort method - ie. you know your simulations take 1-2 mins and you have a lot queued to run overnight, so you set the kill time at 5 mins.

As Matt says, if you want to reduce time then the step tolerance is a much better thing to adjust.

In the past, I've always hunted for rough parameters first and then piped the results into a second round of fitting with finer parameters. I recall I even made a quick and dirty GUI for it.... ah yes... here:
http://morganbye.net/eprtoolbox/easyrefiner/

But I haven't used it since esfit got the GUI so it probably wont work with new ES releases.
Thanks, I started doing coarser step sizes and it seems to have sped things up quite a bit. I still am not entirely sure how the FitOpt.TolStep parameter works specifically though. For example if I have my Vary structure and FitOpt set as follows:

Code: Select all

Vary.g=[0.1 0.1 0.1];

FitOpt.TolStep=1e-02;
I would figure that esfit would then vary each of the g values in 0.01 increments only. However esfit seems to still take steps as small as 0.0001. Did I misspell something or how does TolStep work?
Stefan Stoll
EasySpin Creator
Posts: 1041
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: esfit and maxTime

Post by Stefan Stoll »

That's an inaccuracy in the documentation. The termination tolerance for Levenberg/Marquardt is FitOpt.TolStep, but for the simplex it is FitOpt.TolEdgeLength: When the edge length of the N+1-dimensional simplex falls below that number, the algorithm will terminate.

I'll fix the documentation.
Locked