Skip to content

Add suport for arbitrary labels in fisher #2

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions pybalu/feature_analysis/jfisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
def jfisher(features, classification, p=None):
m = features.shape[1]

norm = classification.ravel() - classification.min()
max_class = norm.max() + 1

if p is None:
p = np.ones(shape=(max_class, 1)) / max_class

classes = np.unique(classification)
size = classes.shape[0]
p = np.ones(shape=(size, 1)) / size

# Centroid of all samples
features_mean = features.mean(0)

Expand All @@ -20,8 +19,8 @@ def jfisher(features, classification, p=None):
# covariance between classes
cov_b = np.zeros(shape=(m, m))

for k in range(max_class):
ii = (norm == k) # indices from class k
for k in range(size):
ii = (classification.ravel() == classes[k]) # indices from class k
class_features = features[ii,:] # samples of class k
class_mean = class_features.mean(0) # centroid of class k
class_cov = np.cov(class_features, rowvar=False) # covariance of class k
Expand Down
7 changes: 1 addition & 6 deletions pybalu/feature_analysis/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@


def score(features, classification, *, method='fisher', param=None):
if param is None:
dn = classification.max() - classification.min() + 1 # number of classes
p = np.ones((dn, 1)) / dn
else:
p = param

if method == 'mi': # mutual information
raise NotImplementedError()
Expand All @@ -27,7 +22,7 @@ def score(features, classification, *, method='fisher', param=None):

# fisher
elif method == 'fisher':
return jfisher(features, classification, p)
return jfisher(features, classification)

elif method == 'sp100':
return sp100(features, classification)
Expand Down