Skip to content

Commit

Permalink
Fix log product formula for NCH (#336)
Browse files Browse the repository at this point in the history
* Update distance.py

* Update pyriemann_qiskit/utils/distance.py

Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>

* Update distance.py

---------

Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>
  • Loading branch information
gcattan and qbarthelemy authored Dec 21, 2024
1 parent 95c0ed1 commit 00dea70
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pyriemann_qiskit/utils/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ def weights_logeuclid_to_convex_hull(A, B, optimizer=ClassicalOptimizer()):
n_matrices, _, _ = A.shape
matrices = range(n_matrices)

def log_prod(m1, m2):
return np.nansum(logm(m1).flatten() * logm(m2).flatten())
def trace_prod_log(m1, m2):
return np.trace(logm(m1) @ logm(m2))

prob = Model()
optimizer = get_global_optimizer(optimizer)
w = optimizer.get_weights(prob, matrices)

wtLogAtLogAw = prob.sum(
w[i] * w[j] * log_prod(A[i], A[j]) for i in matrices for j in matrices
w[i] * w[j] * trace_prod_log(A[i], A[j]) for i in matrices for j in matrices
)
wLogBLogA = prob.sum(w[i] * log_prod(B, A[i]) for i in matrices)
wLogBLogA = prob.sum(w[i] * trace_prod_log(B, A[i]) for i in matrices)
objective = wtLogAtLogAw - 2 * wLogBLogA

prob.set_objective("min", objective)
Expand Down

0 comments on commit 00dea70

Please sign in to comment.