Skip to content

Commit

Permalink
- Fixed BLDA:
Browse files Browse the repository at this point in the history
	- pos/neg classes in fit
	- predict
 On branch master
 Your branch is up to date with 'origin/master'.

 Changes to be committed:
	modified:   baseline/erp/blda.py
  • Loading branch information
okbalefthanded committed Jun 26, 2022
1 parent e05048c commit dbedb2c
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions baseline/erp/blda.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ def fit(self, X, y=None):

y = y.astype(np.float32)
y = y.T
n_posexamples = np.sum(y==1)
n_negexamples = np.sum(y==-1)
classes = np.unique(y)
if -1 in classes:
self.neg_class = -1.
n_posexamples = np.sum(y==self.pos_class)
n_negexamples = np.sum(y==self.neg_class)
n_examples = n_posexamples + n_negexamples
y[y==1] = n_examples / n_posexamples
y[y==-1] = -n_examples / n_negexamples
y[y==self.pos_class] = n_examples / n_posexamples
y[y==self.neg_class] = -n_examples / n_negexamples

# n_posexamples = np.sum(y==1)
# n_negexamples = np.sum(y==-1)
# n_examples = n_posexamples + n_negexamples
# y[y==1] = n_examples / n_posexamples
# y[y==-1] = -n_examples / n_negexamples

# add feature that is constantly one (bias term)
if X.shape[0] == n_instances:
X = X.T
Expand Down Expand Up @@ -99,7 +109,13 @@ def decision_function(self,X):
return np.dot(X.T, self.w)

def predict(self, X, y=None):
return self.decision_function(X)
scores = self.decision_function(X) # self.score(X).squeeze()
predictions = np.zeros(len(scores))
predictions[scores > 0.] = 1.
if self.neg_class == -1:
predictions[scores <= 0.] = -1
return predictions
# return self.decision_function(X)

def score(self,X, y=None):
pass
Expand Down

0 comments on commit dbedb2c

Please sign in to comment.