Skip to content

Commit

Permalink
Using the Clarabel solver instead of ECOS after all since it seems mo…
Browse files Browse the repository at this point in the history
…re robust; setting transition_matrix pos=True helps prevent negative results
  • Loading branch information
dmnapolitano committed Dec 6, 2023
1 parent 399daaf commit 6e130ba
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/elexsolver/TransitionMatrixSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ def __get_constraint(coef, strict):
return [cp.sum(coef, axis=1) <= 1.1, cp.sum(coef, axis=1) >= 0.9]

def __solve(self, A, B):
transition_matrix = cp.Variable((A.shape[1], B.shape[1]))
transition_matrix = cp.Variable((A.shape[1], B.shape[1]), pos=True)
loss_function = cp.norm(A @ transition_matrix - B, "fro")
objective = cp.Minimize(loss_function)
constraint = TransitionMatrixSolver.__get_constraint(transition_matrix, self._strict)
problem = cp.Problem(objective, constraint)
# preferring cvxpy's prior default solver, ECOS, over its new default, Clarabel
# because sometimes Clarabel produces negative-valued results for our problem
problem.solve(solver=cp.ECOS)
problem.solve(solver=cp.CLARABEL)
return transition_matrix.value

def fit_predict(self, X, Y):
Expand Down

0 comments on commit 6e130ba

Please sign in to comment.