mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
Rename xy to xy_sample
This commit is contained in:
@@ -137,7 +137,7 @@ class Component(ABC):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def xy(
|
def xy_sample(
|
||||||
instance: Any,
|
instance: Any,
|
||||||
training_sample: TrainingSample,
|
training_sample: TrainingSample,
|
||||||
) -> Tuple[Dict, Dict]:
|
) -> Tuple[Dict, Dict]:
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ class ObjectiveValueComponent(Component):
|
|||||||
return ev
|
return ev
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def xy(
|
def xy_sample(
|
||||||
instance: Any,
|
instance: Any,
|
||||||
sample: TrainingSample,
|
sample: TrainingSample,
|
||||||
) -> Tuple[Dict, Dict]:
|
) -> Tuple[Dict, Dict]:
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ class PrimalSolutionComponent(Component):
|
|||||||
return [opt_value < 0.5, opt_value > 0.5]
|
return [opt_value < 0.5, opt_value > 0.5]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def xy(
|
def xy_sample(
|
||||||
instance: Any,
|
instance: Any,
|
||||||
sample: TrainingSample,
|
sample: TrainingSample,
|
||||||
) -> Tuple[Dict, Dict]:
|
) -> Tuple[Dict, Dict]:
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from miplearn.types import TrainingSample
|
|||||||
from tests.fixtures.knapsack import get_test_pyomo_instances
|
from tests.fixtures.knapsack import get_test_pyomo_instances
|
||||||
|
|
||||||
|
|
||||||
def test_xy() -> None:
|
def test_xy_sample() -> None:
|
||||||
instance = cast(Instance, Mock(spec=Instance))
|
instance = cast(Instance, Mock(spec=Instance))
|
||||||
instance.get_instance_features = Mock( # type: ignore
|
instance.get_instance_features = Mock( # type: ignore
|
||||||
return_value=[1.0, 2.0],
|
return_value=[1.0, 2.0],
|
||||||
@@ -33,7 +33,7 @@ def test_xy() -> None:
|
|||||||
"Lower bound": [[1.0]],
|
"Lower bound": [[1.0]],
|
||||||
"Upper bound": [[2.0]],
|
"Upper bound": [[2.0]],
|
||||||
}
|
}
|
||||||
x_actual, y_actual = ObjectiveValueComponent.xy(instance, sample)
|
x_actual, y_actual = ObjectiveValueComponent.xy_sample(instance, sample)
|
||||||
assert x_actual == x_expected
|
assert x_actual == x_expected
|
||||||
assert y_actual == y_expected
|
assert y_actual == y_expected
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from miplearn.instance import Instance
|
|||||||
from miplearn.types import TrainingSample
|
from miplearn.types import TrainingSample
|
||||||
|
|
||||||
|
|
||||||
def test_xy_with_lp_solution() -> None:
|
def test_xy_sample_with_lp_solution() -> None:
|
||||||
comp = PrimalSolutionComponent()
|
comp = PrimalSolutionComponent()
|
||||||
instance = cast(Instance, Mock(spec=Instance))
|
instance = cast(Instance, Mock(spec=Instance))
|
||||||
instance.get_variable_category = Mock( # type: ignore
|
instance.get_variable_category = Mock( # type: ignore
|
||||||
@@ -69,14 +69,14 @@ def test_xy_with_lp_solution() -> None:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
x_actual, y_actual = PrimalSolutionComponent.xy(instance, sample)
|
x_actual, y_actual = PrimalSolutionComponent.xy_sample(instance, sample)
|
||||||
assert len(x_actual.keys()) == 1
|
assert len(x_actual.keys()) == 1
|
||||||
assert len(y_actual.keys()) == 1
|
assert len(y_actual.keys()) == 1
|
||||||
assert_array_equal(x_actual["default"], x_expected["default"])
|
assert_array_equal(x_actual["default"], x_expected["default"])
|
||||||
assert_array_equal(y_actual["default"], y_expected["default"])
|
assert_array_equal(y_actual["default"], y_expected["default"])
|
||||||
|
|
||||||
|
|
||||||
def test_xy_without_lp_solution() -> None:
|
def test_xy_sample_without_lp_solution() -> None:
|
||||||
comp = PrimalSolutionComponent()
|
comp = PrimalSolutionComponent()
|
||||||
instance = cast(Instance, Mock(spec=Instance))
|
instance = cast(Instance, Mock(spec=Instance))
|
||||||
instance.get_variable_category = Mock( # type: ignore
|
instance.get_variable_category = Mock( # type: ignore
|
||||||
@@ -123,7 +123,7 @@ def test_xy_without_lp_solution() -> None:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
x_actual, y_actual = comp.xy(instance, sample)
|
x_actual, y_actual = comp.xy_sample(instance, sample)
|
||||||
assert len(x_actual.keys()) == 1
|
assert len(x_actual.keys()) == 1
|
||||||
assert len(y_actual.keys()) == 1
|
assert len(y_actual.keys()) == 1
|
||||||
assert_array_equal(x_actual["default"], x_expected["default"])
|
assert_array_equal(x_actual["default"], x_expected["default"])
|
||||||
|
|||||||
Reference in New Issue
Block a user