Skip to content

Commit 45d86ea

Browse files
committed
I added a different refinement method, it checks all bisecting refinements before adding new points. I don't know if it's much better yet
1 parent 469598b commit 45d86ea

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

iterator.py

+34-6
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,41 @@ def error_adaptive_iterative_fit_spectra(
188188
else:
189189
adaptation_spectrum = rms_spectrum
190190

191-
#### we combine the new points with the old at the start of the next pass
192-
new_lamda_list = []
193-
for i in range(len(lamda_list)-1):
194-
if (adaptation_spectrum[i] > adaptation_threshold) or (adaptation_spectrum[i+1] > adaptation_threshold): # should we refine?
191+
192+
refinement_method = 'interpolate_and_check_all'
193+
#### with our adaptation selection method set, we find new points
194+
if refinement_method == 'near_worst':
195+
new_lamda_list = []
196+
for i in range(len(lamda_list)-1):
197+
if (adaptation_spectrum[i] > adaptation_threshold) or (adaptation_spectrum[i+1] > adaptation_threshold): # should we refine?
198+
if (lamda_list[i+1] - lamda_list[i]) > dlamda_min: # if the gap is bigger than the minimum, then it is allowed to refine
199+
new_lamda = (lamda_list[i]+lamda_list[i+1])/2.0
200+
new_lamda_list.append( new_lamda)
201+
202+
elif refinement_method == 'interpolate_and_check_all':
203+
test_lamda_list = []
204+
for i in range(len(lamda_list)-1):
195205
if (lamda_list[i+1] - lamda_list[i]) > dlamda_min: # if the gap is bigger than the minimum, then it is allowed to refine
196-
new_lamda = (lamda_list[i]+lamda_list[i+1])/2.0
197-
new_lamda_list.append( new_lamda)
206+
test_lamda_list.append( (lamda_list[i]+lamda_list[i+1])/2.0 )
207+
208+
if use_reducible_error :
209+
test_error_spectrum, test_irreducible_error_spectrum = reducible_rms_error_spectrum(
210+
lamda_list = test_lamda_list,
211+
nk_f = fit_nk_f,
212+
spectrum_list_generator = spectrum_list_generator,
213+
parameter_list_generator = parameter_list_generator, threads = threads)
214+
else:
215+
test_error_spectrum = rms_error_spectrum(lamda_list = test_lamda_list,
216+
nk_f = fit_nk_f,
217+
spectrum_list_generator = spectrum_list_generator,
218+
parameter_list_generator = parameter_list_generator, threads = threads)
219+
#sorted_indices = argsort(test_error_spectrum)
220+
new_lamda_list = []
221+
for i in range(len(test_lamda_list)):
222+
if (test_error_spectrum[i] > adaptation_threshold) :
223+
new_lamda_list.append( test_lamda_list[i])
224+
225+
#### we combine the new points with the old at the start of the next pass
198226
### this is important to have here for the termination condition
199227
num_new_points = len(new_lamda_list)
200228

0 commit comments

Comments
 (0)