minor improvements
This commit is contained in:
parent
6353ae7f78
commit
703019c4cd
1 changed files with 123 additions and 214 deletions
11
editor/utils/kldiv.py
Normal file
11
editor/utils/kldiv.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import numpy as np
|
||||
|
||||
|
||||
def kldiv(P: np.ndarray, Q: np.ndarray) -> float:
|
||||
P /= P.sum()
|
||||
Q /= Q.sum()
|
||||
|
||||
P_safe = np.maximum(P, np.finfo(float).eps)
|
||||
Q_safe = np.maximum(Q, np.finfo(float).eps)
|
||||
|
||||
return np.sum(P_safe * np.log(P_safe / Q_safe))
|
||||
Loading…
Reference in a new issue