Skip to content

Sequential Domain Reduction does not respect global bounds #394

Closed

Description

@raghavchandra123

Describe the bug
the minimum window width is imposed after the global bounds trim rather than before which I think means that if a minimum window is wide enough then it can escape global bounds. This applies to the trim method of the SequentialDomainReductionTransformer.

To Reproduce
For example:

def _trim(new_bounds: np.array, global_bounds: np.array) -> np.array:
	min_window = 1
        for i, variable in enumerate(new_bounds):
            if variable[0] < global_bounds[i, 0]:
                variable[0] = global_bounds[i, 0]
            if variable[1] > global_bounds[i, 1]:
                variable[1] = global_bounds[i, 1]
        for i, entry in enumerate(new_bounds):
            if entry[0] > entry[1]:
                new_bounds[i, 0] = entry[1]
                new_bounds[i, 1] = entry[0]
            window_width = abs(entry[0] - entry[1])
            if window_width < 1:
                new_bounds[i, 0] -= (min_window - window_width) / 2.0
                new_bounds[i, 1] += (min_window - window_width) / 2.0

        return new_bounds
new_bounds = np.concatenate((np.ones((5,1))*0.1,np.ones((5,1))),axis=1)
global_bounds = np.concatenate((np.ones((5,1))*-1,np.ones((5,1))),axis=1)*0.5
print(new_bounds)
print(global_bounds)
print(_trim(new_bounds,global_bounds))
prints:
 [[0.1 1. ]
 [0.1 1. ]
 [0.1 1. ]
 [0.1 1. ]
 [0.1 1. ]]
[[-0.5  0.5]
 [-0.5  0.5]
 [-0.5  0.5]
 [-0.5  0.5]
 [-0.5  0.5]]
[[-0.2  0.8]
 [-0.2  0.8]
 [-0.2  0.8]
 [-0.2  0.8]
 [-0.2  0.8]]

where the first array is new_bounds before trim, second is global bounds and third is the trimmed version which is outside global bounds

Expected behavior
I think the global bounds check and minimum window should be combined in a way to respect both, e.g. for the example above it should return the new_bounds as -0.5 and 0.5.

Screenshots

Activity

  1. t-muser commented on Feb 16, 2023

    @t-muser
    Member

    Hey @raghavchandra123,

    thanks for reporting this. Would you be willing to submit a PR to make this change? I would be happy to review it!

  2. t-muser commented on Mar 20, 2023

    @t-muser
    Member

    @bwheelz36 I think this can be closed now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions