Skip to content

Commit

Permalink
Adding a check to make sure we have enough units
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnapolitano committed Oct 16, 2023
1 parent 3aa0f5b commit a67304f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/elexsolver/TransitionSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ def _check_percentages(self, A: np.ndarray):

def _check_and_rescale(self, A: np.ndarray):
"""
Rescale columns (units) so that they sum to 1 (100%).
After ensuring that A is (things x units), make sure we have enough units.
If that's the case, rescale columns (units) so that they sum to 1 (100%).
"""
if A.shape[1] <= A.shape[0] or (A.shape[1] // 2) <= A.shape[0]:
raise ValueError(f"Not enough units ({A.shape[1]}) relative to the number of things ({A.shape[0]}).")

if not np.all(A.sum(axis=0) == 1):
LOG.warn("Each column (unit) needs to sum to 1. Rescaling...")
LOG.warn("Each unit needs to sum to 1. Rescaling...")
if isinstance(A, np.ndarray):
for j in range(0, A.shape[1]):
A[:, j] /= A[:, j].sum()
Expand Down

0 comments on commit a67304f

Please sign in to comment.