Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't find online_semg_posture_adaptation.online.covariance #1

Open
MarcTasca opened this issue Mar 26, 2024 · 1 comment
Open

I can't find online_semg_posture_adaptation.online.covariance #1

MarcTasca opened this issue Mar 26, 2024 · 1 comment

Comments

@MarcTasca
Copy link

MarcTasca commented Mar 26, 2024

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 :)

@MarcTasca
Copy link
Author

MarcTasca commented Mar 26, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant