Skip to content
This repository was archived by the owner on Sep 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions ocean/cp/_explainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,13 @@ def explain(
case _:
msg = "Unexpected solver status: " + status
raise RuntimeError(msg)

if not cf_status_ok:
self.cleanup()
return None
else:
self.explanation.query = x
self.cleanup()
return self.explanation
self.explanation.query = x
self.cleanup()
return self.explanation


class MySolCallback(cp.CpSolverSolutionCallback):
Expand Down
7 changes: 3 additions & 4 deletions ocean/cp/_explanation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class Explanation(Mapper[FeatureVar], BaseExplanation):
_epsilon: float = 1e-6
_epsilon: float = float(np.finfo(np.float32).eps)
_x: Array1D = np.zeros((0,), dtype=int)

def vget(self, i: int) -> cp.IntVar:
Expand Down Expand Up @@ -73,7 +73,6 @@ def get(v: FeatureVar) -> Key | Number:
return self.reduce(get)

def format_value(self, f: int, idx: int, levels: list[float]) -> float:
eps = min(self._epsilon, 0.5 * min(np.diff(levels)))
if self.query.shape[0] == 0:
return float(levels[idx] + levels[idx + 1]) / 2
j = 0
Expand All @@ -83,9 +82,9 @@ def format_value(self, f: int, idx: int, levels: list[float]) -> float:
if j == idx:
value = float(query_arr[f])
elif j < idx:
value = float(levels[idx]) + eps
value = float(levels[idx]) + self._epsilon
else:
value = float(levels[idx + 1]) - eps
value = float(levels[idx + 1]) - self._epsilon
return value

@property
Expand Down