diff --git a/n3fit/src/n3fit/scaler.py b/n3fit/src/n3fit/scaler.py index f4f5abff72..0a8be1f91c 100644 --- a/n3fit/src/n3fit/scaler.py +++ b/n3fit/src/n3fit/scaler.py @@ -23,6 +23,9 @@ def generate_scaler(input_list: List[np.ndarray], interpolation_points: int = No input_arr = np.sort(input_arr) input_arr_size = input_arr.size + # Define an evenly spaced grid in the domain [0,1] + # force_set_smallest is used to make sure the smallest point included in the scaling is + # 1e-9, to prevent trouble when saving it to the LHAPDF grid force_set_smallest = input_arr.min() > 1e-9 if force_set_smallest: new_xgrid = np.linspace( @@ -31,17 +34,23 @@ def generate_scaler(input_list: List[np.ndarray], interpolation_points: int = No else: new_xgrid = np.linspace(start=0, stop=1.0, endpoint=False, num=input_arr_size) + # When mapping the FK xgrids onto our new grid, we need to consider degeneracies among + # the x-values in the FK grids unique, counts = np.unique(input_arr, return_counts=True) map_to_complete = [] for cumsum_ in np.cumsum(counts): + # Make sure to include the smallest new_xgrid value, such that we have a point at + # x<=1e-9 map_to_complete.append(new_xgrid[cumsum_ - counts[0]]) map_to_complete = np.array(map_to_complete) map_from_complete = unique + # If needed, set feature_scaling(x=1e-9)=0 if force_set_smallest: map_from_complete = np.insert(map_from_complete, 0, 1e-9) map_to_complete = np.insert(map_to_complete, 0, 0.0) + # Select the indices of the points that will be used by the interpolator onein = map_from_complete.size / (int(interpolation_points) - 1) selected_points = [round(i * onein - 1) for i in range(1, int(interpolation_points))] if selected_points[0] != 0: