@@ -17,6 +17,8 @@ def error_adaptive_iterative_fit_spectra(
17
17
reuse_mode = False ,
18
18
KK_compliant = False ,
19
19
use_free_drude = False ,
20
+ return_drude_params = False ,
21
+ sigma_bar0_guess = 0.0 , lamda_tau_guess = 0.0 , epsilon_f1p_guess = 0.0 ,
20
22
interpolation_type = 'cubic' ,
21
23
no_negative = True ,
22
24
interpolate_to_fine_grid_at_end = True ,
@@ -77,7 +79,7 @@ def error_adaptive_iterative_fit_spectra(
77
79
print ('dlamda_max: ' ,dlamda_max )
78
80
print ('dlamda_min: ' , dlamda_min )
79
81
print ('delta_weight:' , delta_weight )
80
- lamda_tau , sigma_bar0 , epsilon_f1p = 0.0 , 0.0 , 0.0
82
+ lamda_tau , sigma_bar0 , epsilon_f1p = lamda_tau_guess , sigma_bar0_guess , epsilon_f1p_guess
81
83
82
84
# literally jury rigging the conidtion so it starts the loop, ugly, but cleaner than the alternatives
83
85
num_new_points = len (lamda_list )
@@ -120,7 +122,7 @@ def error_adaptive_iterative_fit_spectra(
120
122
# now we use the inputs
121
123
t0 = time ()
122
124
if use_free_drude :
123
- inputs .update (dict ( sigma_bar0_guess = sigma_bar0 , lamda_tau_guess = lamda_tau , epsilon_f1p_guess = epsilon_f1p ))
125
+ inputs .update (dict ( sigma_bar0_guess = sigma_bar0 , lamda_tau_guess = lamda_tau , epsilon_f1p_guess = epsilon_f1p ))
124
126
fit_nk_f , lamda_tau , sigma_bar0 , epsilon_f1p = fit_spectra_nk_sqr_drude_KK_compliant (** inputs )
125
127
else :
126
128
if KK_compliant :
@@ -284,8 +286,10 @@ def error_adaptive_iterative_fit_spectra(
284
286
parameter_list_generator = parameter_list_generator , threads = threads )
285
287
savetxt (data_directory + 'fit_nk_fine.txt' ,array ([lamda_fine , nk .real , nk .imag , array (rms_spectrum_fine )* 100.0 , array (reducible_error_spectrum_fine )* 100.0 ]).T )
286
288
287
-
288
- return fit_nk_f , lamda_list
289
+ if use_free_drude and return_drude_params :
290
+ return fit_nk_f , lamda_list , lamda_tau , sigma_bar0 , epsilon_f1p
291
+ else :
292
+ return fit_nk_f , lamda_list
289
293
290
294
291
295
@@ -305,6 +309,7 @@ def scan_for_scaled_weight_crossover(
305
309
use_free_drude = False ,
306
310
interpolation_type = 'cubic' ,
307
311
no_negative = False ,
312
+ target_ratio = 1.0 ,
308
313
threads = 0 ,
309
314
data_directory = 'TRANK_weight_scan/' , method = 'least_squares' , verbose = True , write_to_file = True ,
310
315
make_plots = True , show_plots = False , rms_file_format = 'rms_vs_weight.pdf' ):
@@ -382,13 +387,13 @@ def RMS(a):
382
387
print ('--> reducible/irreducible ratio %f' % (ratio ))
383
388
384
389
if len (log_data ) > 1 :
385
- if log_data [- 1 ][4 ] < 1.0 and log_data [- 2 ][4 ] > 1.0 : # decreasing case
390
+ if log_data [- 1 ][4 ] < target_ratio and log_data [- 2 ][4 ] > target_ratio : # decreasing case
386
391
cross_over_found = True
387
- if log_data [- 1 ][4 ] > 1.0 and log_data [- 2 ][4 ] < 1.0 : # increasing case
392
+ if log_data [- 1 ][4 ] > target_ratio and log_data [- 2 ][4 ] < target_ratio : # increasing case
388
393
cross_over_found = True
389
394
390
395
if cross_over_found == False : # actually don't need to do this check, but now we only update if we are still searching
391
- if ratio > 1.0 :
396
+ if ratio > target_ratio :
392
397
scaled_weight = scaled_weight * step_multiplier
393
398
else :
394
399
scaled_weight = scaled_weight / step_multiplier
@@ -401,7 +406,7 @@ def RMS(a):
401
406
scaled_weight_data = log_data [0 ]
402
407
#simple linear interpolation is fast, and we dont have to worry about https://en.wikipedia.org/wiki/Runge%27s_phenomenon
403
408
ratio_slope = ( ratio_data [- 1 ] - ratio_data [- 2 ] )/ (scaled_weight_data [- 1 ] - scaled_weight_data [- 2 ])
404
- scaled_weight_crossover = ( 1 - ratio_data [- 2 ]) / ratio_slope + scaled_weight_data [- 2 ]
409
+ scaled_weight_crossover = ( target_ratio - ratio_data [- 2 ]) / ratio_slope + scaled_weight_data [- 2 ]
405
410
406
411
407
412
@@ -419,7 +424,7 @@ def RMS(a):
419
424
420
425
figure ()
421
426
plot (scaled_weight_data ,ratio_data , marker = 'o' )
422
- plot ([scaled_weight_crossover ],[1 ], marker = '+' , label = 'scaled_weight_crossover' )
427
+ plot ([scaled_weight_crossover ],[target_ratio ], marker = '+' , label = 'scaled_weight_crossover' )
423
428
xlabel ('scaled_weight' )
424
429
ylabel ('reducible error:irreducible error ratio' )
425
430
legend ()
0 commit comments