Skip to content

Conversation

@larsoner
Copy link
Member

@larsoner larsoner commented Sep 8, 2017

This code:

  • Fixes some fill_value logic for the delaying
  • Cleans up the logic for delaying
  • Fixes / improves the logic for Laplacian, simultaneously making it easier in the future to do Laplacian of arbitrary neighbors (instead of just grid_to_graph)
  • Fixes a bug with TDR having to do with edge effects in the autocorrelation matrix terms.

@larsoner larsoner added this to the 0.15 milestone Sep 8, 2017
@larsoner larsoner mentioned this pull request Sep 8, 2017
@larsoner
Copy link
Member Author

larsoner commented Sep 8, 2017

I realize now why this "bug" never showed up. We have # X is now shape (n_times, n_epochs, n_feats, n_delays) when using _delay_and_reshape in the code ReceptiveField code. So it won't really be exposed by using ReceptiveField.

In any case, I need to still fix the TDR bug.

@larsoner
Copy link
Member Author

larsoner commented Sep 9, 2017

Found and fixed a bug in the Laplacian calculations and updated the tutorial. Also made it easier if, in the future, we want to supply an arbitrary connectivity/adjacency matrix (instead of assuming grid_to_graph-like structure like we do now)

@larsoner
Copy link
Member Author

larsoner commented Sep 9, 2017

Updated tutorial here (yes I know I need to fix the xlim in the STRF plots and the text placement in the bottom panel of the last figure)

@agramfort
Copy link
Member

+1 to fix xlim

@codecov-io
Copy link

codecov-io commented Sep 9, 2017

Codecov Report

Merging #4543 into master will decrease coverage by 0.21%.
The diff coverage is 95.65%.

@@            Coverage Diff             @@
##           master    #4543      +/-   ##
==========================================
- Coverage    80.9%   80.68%   -0.22%     
==========================================
  Files         349      349              
  Lines       65441    65568     +127     
  Branches    10158    10171      +13     
==========================================
- Hits        52945    52904      -41     
- Misses       9566     9709     +143     
- Partials     2930     2955      +25

@larsoner larsoner changed the title WIP: fill_value in ReceptiveField MRG: fill_value in ReceptiveField Sep 11, 2017
@larsoner
Copy link
Member Author

Okay this is ready for review/merge from my end. Should have it for 0.15 as it contains a couple small but important bug fixes.

@agramfort
Copy link
Member

+1 for MRG when CIs are green. Thx a lot @larsoner for hunting these bugs !

@larsoner
Copy link
Member Author

@choldgraf @nbara any interest in reviewing?

for ii, (rf_lap, rf, i_alpha) in enumerate(zip(models_lap, models, alphas)):
ax = plt.subplot2grid([3, len(alphas)], [0, ii], 1, 1)
ax.pcolormesh(times, rf_lap.feature_names, rf_lap.coef_[0], **kwargs)
ax.set(xticks=[], yticks=[])
Copy link
Contributor

@nbara nbara Sep 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

white spaces are still visible in example, so I'm assuming this needs to be
ax.set(xticks=[], yticks=[], xlim=times[[0, -1]])

@nbara
Copy link
Contributor

nbara commented Sep 11, 2017

Woah this is quite the code cleanup! It's looking really nice!

I didn't spot anything else, but I'll let @choldgraf give the +1 as he would know better than me anyway.

@larsoner
Copy link
Member Author

Glad the code is readable enough, it was a nightmare to figure out why they weren't giving equivalent results!

@larsoner
Copy link
Member Author

Updated example with fixed bounds here

Copy link
Contributor

@choldgraf choldgraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoah! This is way more complex than I was expecting. I kinda feel like you solved multiple problems in this PR other than just the mean_value issue, no? Either way, this looks like a great improvement...a few small comments

'download_section_examples': False,
'thumbnail_size': (160, 112),
}
'min_reported_time': 1.,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we using sphinx-gallery master?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes :)

fill_mean=self.fit_intercept)
X = _reshape_for_est(X)
# Concat times + epochs
if y is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just confirming that you want y is not None to be inside the if statement, since before it was outside the if statement

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, TimeDelayingRidge is now epochs-aware

Parameters
----------
X : array, shape (n_times[, n_epochs], n_features)
X : array, shape (n_times[, n_epochs][, n_features])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking to require at the least (n_times, n_features) to avoid confusion about what the extra dimension means. E.g., if we allow for just (n_times, n_epochs) AND (n_times, n_features), how do we know which the user wants if they give a 2D input?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code does already actually, I'll update the docstring

delayed : array, shape(n_times[, n_epochs][, n_features], n_delays)
The delayed data. It has the same shape as X, with an extra dimension
created at ``newaxis`` that corresponds to each delay.
appended to the end.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this seems like a better way of doing it, I agree.

# all negative
smin, smax = -2, -1
X_del = _delay_time_series(X, smin, smax, 1.)
X_del.shape = (X.shape[0], -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance you could add some comments here so that it'll be easier for somebody else to debug?

x_xt = _compute_corrs(X, np.zeros((X.shape[0], 1)), -smax, -smin + 1)[0]
assert_allclose(x_xt, expected)

# even worse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and, e.g., what you mean by "slightly harder" and "even worse"?


def _compute_corrs(X, y, smin, smax):
"""Compute the auto- and cross-correlations."""
"""Compute auto- and cross-correlations."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this relates to #3884

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, and the changes here actually make it easier to use either pipeline interchangeably if we want to do so at some point

Parameters
----------
X : array, shape (n_samples, n_features)
X : array, shape (n_samples[, n_epochs], n_features)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a docstring discrepancy between here and _delay_time_series...that OK?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(referring to [n_features])

@larsoner
Copy link
Member Author

@choldgraf comments addressed, let me know if you're happy (or just hit "approve")

Copy link
Contributor

@choldgraf choldgraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(pending travis being happy)

@agramfort agramfort merged commit cf9ff8b into mne-tools:master Sep 12, 2017
@agramfort
Copy link
Member

thx @larsoner

@larsoner larsoner deleted the mean_rf branch September 12, 2017 13:32
@nbara nbara mentioned this pull request Sep 12, 2017
4 tasks
@choldgraf
Copy link
Contributor

seriously, this was a way better PR than I would have put together :-)

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

Successfully merging this pull request may close these issues.

5 participants