mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
Primal: Refactor stats
This commit is contained in:
@@ -63,31 +63,32 @@ class PrimalSolutionComponent(Component):
|
|||||||
self.threshold_prototype = threshold
|
self.threshold_prototype = threshold
|
||||||
self.classifier_prototype = classifier
|
self.classifier_prototype = classifier
|
||||||
self.stats: Dict[str, float] = {}
|
self.stats: Dict[str, float] = {}
|
||||||
self._n_free = 0
|
|
||||||
self._n_zero = 0
|
|
||||||
self._n_one = 0
|
|
||||||
|
|
||||||
def before_solve_mip(self, solver, instance, model):
|
def before_solve_mip(self, solver, instance, model):
|
||||||
if len(self.thresholds) > 0:
|
if len(self.thresholds) > 0:
|
||||||
logger.info("Predicting primal solution...")
|
logger.info("Predicting MIP solution...")
|
||||||
solution = self.predict(instance.features, instance.training_data[-1])
|
solution = self.predict(
|
||||||
|
instance.features,
|
||||||
|
instance.training_data[-1],
|
||||||
|
)
|
||||||
|
|
||||||
# Collect prediction statistics
|
# Collect prediction statistics
|
||||||
self._n_free = 0
|
self.stats["Primal: Free"] = 0
|
||||||
self._n_zero = 0
|
self.stats["Primal: Zero"] = 0
|
||||||
self._n_one = 0
|
self.stats["Primal: One"] = 0
|
||||||
for (var, var_dict) in solution.items():
|
for (var, var_dict) in solution.items():
|
||||||
for (idx, value) in var_dict.items():
|
for (idx, value) in var_dict.items():
|
||||||
if value is None:
|
if value is None:
|
||||||
self._n_free += 1
|
self.stats["Primal: Free"] += 1
|
||||||
else:
|
else:
|
||||||
if value < 0.5:
|
if value < 0.5:
|
||||||
self._n_zero += 1
|
self.stats["Primal: Zero"] += 1
|
||||||
else:
|
else:
|
||||||
self._n_one += 1
|
self.stats["Primal: One"] += 1
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Predicted: free: {self._n_free}, zero: {self._n_zero}, "
|
f"Predicted: free: {self.stats['Primal: Free']}, "
|
||||||
f"one: {self._n_one}"
|
f"zero: {self.stats['Primal: zero']}, "
|
||||||
|
f"one: {self.stats['Primal: One']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Provide solution to the solver
|
# Provide solution to the solver
|
||||||
@@ -104,9 +105,7 @@ class PrimalSolutionComponent(Component):
|
|||||||
stats: LearningSolveStats,
|
stats: LearningSolveStats,
|
||||||
training_data: TrainingSample,
|
training_data: TrainingSample,
|
||||||
) -> None:
|
) -> None:
|
||||||
stats["Primal: free"] = self._n_free
|
stats.update(self.stats)
|
||||||
stats["Primal: zero"] = self._n_zero
|
|
||||||
stats["Primal: one"] = self._n_one
|
|
||||||
|
|
||||||
def fit_xy(
|
def fit_xy(
|
||||||
self,
|
self,
|
||||||
|
|||||||
Reference in New Issue
Block a user