Open MarcTasca opened 5 months ago
This is my implementation.
My covariance.py:
def update_cov(
x: np.ndarray[np.float32],
mean: np.ndarray[np.float32],
ncov: np.ndarray[np.float32],
count: int
) -> Tuple[
np.ndarray[np.float32],
np.ndarray[np.float32],
int]:
"""
Update the mean and covariance online.
Args:
x: np.ndarray[np.float32]: the new sample
mean: np.ndarray[np.float32]: the current mean
ncov: np.ndarray[np.float32]: the current covariance
count: int: the current number of samples
Returns:
np.ndarray[np.float32]: the updated mean
np.ndarray[np.float32]: the updated covariance
int: the updated number of samples
"""
# update mean and cov online
mean = mean + (x - mean) / count
ncov = ncov + np.outer(x - mean, x - mean)
# return them
return mean, ncov, count
In online_semg_posture_adaptation.online.pca.oja_sga_session I added:
scale = np.sqrt(np.diag(ncov) / (idx_sample + 1))
Scale[scale == 0] = 1
If I don't do so, all W result to be filled with nan values.
Is that similar to your implementation?
Dear authors,
I am writing my thesis at PoliTo. First of all, thank you a lot for making this repository public. I would love to know the implementation of covariance, which should be in online_semg_posture_adaptation/online, but I can't find it. In particular, in online_semg_posture_adaptation/online/pca.py there is the function oja_sga_session( ... ), in here it is called, at line 158 the function cov.update_cov( ... ):
mean, ncov, _ = cov.update_cov(x[:, idx_sample], mean, ncov, idx_sample + 1)
This should be imported in the file pca.py at line 27:
from online_semg_posture_adaptation.online import covariance as cov
.I can't find it. Thank you a lot and best regards :)