Commit 9b187c0b authored by Heller, William T.'s avatar Heller, William T.
Browse files

Merge branch 'run_time_issue' into 'master'

Run time issue

See merge request !16
parents f30bde74 6648e75c
Loading
Loading
Loading
Loading
+57 −42
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ Oak Ridge National Laboratory, 2020
import numpy as np
import math as m
import copy
import time

import sas_temper.modelconfig as modelconfig
import sas_temper.sas_temper_config as config
@@ -23,33 +24,42 @@ import sas_temper.sas_calc as sas_calc
# modconf is the model to be used and the parameter ranges
# d is the input data to be fit against
def sa_control(fconf, modconf, d):
    res = np.empty(fconf.models, "object")            # the parameters returned from the fitting
    mprof = np.empty(fconf.models, "object")        # the profiles returned from the fitting
    mprof_usm = np.empty(fconf.models, "object")    # the unsmeared profiles returned from the fitting - may be empty
    # this is the number of refinements to do and how many models to use - yes, they are 'magic numbers'
    refines = 5
    refine_models = 10
    
    # set  up the memory
    res = np.empty(refine_models, "object")            # the parameters returned from the fitting
    mprof = np.empty(refine_models, "object")        # the profiles returned from the fitting
    mprof_usm = np.empty(refine_models, "object")    # the unsmeared profiles returned from the fitting - may be empty
    
    localconf = modelconfig.ModelConfig(modconf.name,modconf.category,modconf.params,modconf.sq)
    
    # this is the number of refinements to do - yes, it is a 'magic number'
    refines = 5
    # st_time = time.time()
    
    # the number of refinement iterations to do
    for j in range(0,refines) :
        for i in range(0,fconf.models):
        for i in range(0,refine_models):
            if j is 0:
                res[i],mprof[i],mprof_usm[i] = sa_engine(fconf,modconf,d)
            else:
                res[i],mprof[i],mprof_usm[i] = sa_engine(fconf,localconf,d)
            
        # refine the ranges to start over
        localconf = sa_refine(fconf.models, res)
        localconf = sa_refine(refine_models, res)
    
    best = 1000000000.00
    hit = 0
    for k in range(0, fconf.models):
    for k in range(0, refine_models):
        if res[k].chisq < best:
            hit = k
            best = res[k].chisq
    
    #end_time = time.time()
    #dif_time = end_time-st_time
    #junk = "Time for a single model = " + str(dif_time)
    #print(junk)
    
    return res[hit], mprof[hit], mprof_usm[hit]
    

@@ -90,9 +100,11 @@ def sa_engine(fconf, modconf, d):
    temp = 10.0
    r = 1.0
    schedule = 1
    iters = 1
    hit = False
    while schedule <= fconf.temperatures:
        iters = 1
        
        while iters <= fconf.iterations:
            #define the model to test
            f = define_model(schedule,modconf,temp,r,cur)
            
@@ -127,13 +139,16 @@ def sa_engine(fconf, modconf, d):
            if hit:
                cur = copy.deepcopy(f)
                
        iters += 1
            iters = iters + 1
            
            #noise = "schedule " + str(schedule) + "; iteration " + str(iters)
            #print(noise)
        
        # we drop the temperature, tighten the range and increase schedule
        if iters % fconf.iterations :
        temp = temp*fconf.temp_rate
        r = r*fconf.param_rate
            schedule += 1
        schedule = schedule + 1
        
    
    # as the final step, we estimate the uncertainties with the jacobian
    f = copy.deepcopy(fbest)