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

How to calculate tied covariance matrix #19

Open
lumliolum opened this issue Apr 19, 2023 · 0 comments
Open

How to calculate tied covariance matrix #19

lumliolum opened this issue Apr 19, 2023 · 0 comments

Comments

@lumliolum
Copy link

lumliolum commented Apr 19, 2023

As per the formulae given in the paper

image

which is equalivalent to calculate the covaraince matrix for each class and then take the weighted average to get the tied covariance matrix. But in the code,

precision = []
for k in range(num_output):
X = 0
for i in range(num_classes):
if i == 0:
X = list_features[k][i] - sample_class_mean[k][i]
else:
X = torch.cat((X, list_features[k][i] - sample_class_mean[k][i]), 0)
# find inverse
group_lasso.fit(X.cpu().numpy())
temp_precision = group_lasso.precision_
temp_precision = torch.from_numpy(temp_precision).float().cuda()
precision.append(temp_precision)

you are using sklearn.covariance.EmpiricalCovariance for all of the data (see line 117 X) but as per formulae you calculate the covariance for each class and then take the average. So I feel that we should apply sklearn.covariance.EmpiricalCovariance per class and then take the sum.

Thanks,

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