Skip to content

Commit e37d7b9

Browse files
committed
merge bic results with original
1 parent 3c16b87 commit e37d7b9

File tree

3 files changed

+113
-343
lines changed

3 files changed

+113
-343
lines changed

fmri/analyze_fmri.ipynb

Lines changed: 109 additions & 330 deletions
Large diffs are not rendered by default.

fmri/run.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,24 @@
2525
import random
2626

2727
class RidgeBICRegressor():
28-
def __init__(self, fit_intercept=True, normalize=False):
29-
# self.alpha_range = alpha_range
30-
self.alphas = np.logspace(3, 6, 20).round().astype(int)
31-
# self.n_alphas = n_alphas
32-
self.fit_intercept = fit_intercept
33-
self.normalize = normalize
34-
self.alpha_ = None
35-
self.model_ = None
28+
def __init__(self):
29+
self.alphas = np.logspace(-1, 1, 20).round()
3630

3731
def fit(self, X, y):
3832
n, d = X.shape
39-
# alpha_min, alpha_max = self.alpha_range
40-
# alphas = np.logspace(np.log10(alpha_min), np.log10(alpha_max), self.n_alphas)
41-
4233
bic_scores = []
4334
models = []
4435

4536
ols = LinearRegression()
4637
denom = np.std(y - ols.fit(X, y).predict(X)) / (n - d)
4738

4839
for alpha in tqdm(self.alphas):
49-
model = Ridge(alpha=alpha, fit_intercept=self.fit_intercept, normalize=self.normalize)
40+
model = Ridge(alpha=alpha, fit_intercept=False, normalize=False)
5041
model.fit(X, y)
5142
models.append(model)
5243

5344
# key lines
54-
n_feats = np.trace(X @ npl.pinv(X.T @ X + alpha * np.eye(d)) @ X.T)
45+
n_feats = np.trace(X @ npl.inv(X.T @ X + alpha * np.eye(d)) @ X.T)
5546
rss = np.sum((model.predict(X) - y) ** 2) / denom
5647
bic = n * np.log(rss / n) + n_feats * np.log(n)
5748
bic_scores.append(bic)
20.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)