{"action":"created","comment":{"url":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments/67598769","id":67598769,"diff_hunk":"@@ -0,0 +1,154 @@\n+import numpy as np\n+from sklearn.base import BaseEstimator\n+from scipy import linalg\n+from ..externals.six import string_types\n+\n+\n+class EncodingModel(object):\n+    def __init__(self, est=None, delays=[0.], preproc_x=None, preproc_y=None):\n+        \"\"\"Fit a STRF model.\n+\n+        Fit an encoding model using time lags and a custom estimator.\n+        Compatible either with continuous or events-based input\n+        stimuli. It creates time lags for the input matrix, performs\n+        preprocessing according to any transformers in the pipeline in `est`,\n+        and then fits a model with the final estimator in `est`.\n+\n+        Parameters\n+        ----------\n+        est : instance of sklearn-style estimator\n+            The estimator to use for fitting. This is any object that contains\n+            a `fit` and `predict` method, which takes inputs of the form\n+            (X, y), and which creates a `.coef_` attribute upon fitting.\n+        delays : array, shape (n_delays,)\n+            The delays to include when creating time lags. The input array X\n+            will end up having shape (n_feats * n_delays, n_times)\n+        preproc_x : instance of sklearn-style pipeline | None\n+            An object for preprocessing / transforming input data before the\n+            call to `est`. If None, no preprocessing will occur.\n+        preproc_y : instance of sklearn-style pipeline | None\n+            An object for preprocessing / transforming the output data before\n+            the call to `est`. If None, no preprocessing will occur.\n+\n+        References\n+        ----------\n+        .. [1] Smith, N. J., & Kutas, M. (2015). Regression-based estimation of\n+               ERP waveforms: II. Non-linear effects, overlap correction, and\n+               practical considerations. Psychophysiology, 52(2), 169-189.\n+        .. [2] Theunissen, F. E. et al. Estimating spatio-temporal receptive\n+               fields of auditory and visual neurons from their responses to\n+               natural stimuli. Network 12, 289-316 (2001).\n+        .. [3] Willmore, B. & Smyth, D. Methods for first-order kernel\n+               estimation: simple-cell receptive fields from responses to\n+               natural scenes. Network 14, 553-77 (2003).\n+        \"\"\"\n+        self.delays = np.asarray(delays)\n+        self.n_delays = len(self.delays)\n+        self.est = _check_estimator(est)\n+        self.preproc_y = _check_preproc(preproc_y)\n+        self.preproc_x = _check_preproc(preproc_x)\n+\n+    def fit(self, X, y=None):\n+        \"\"\"Fit the model.\n+\n+        Fits a receptive field model. Model results are stored as attributes.\n+\n+        Parameters\n+        ----------\n+        raw : instance of MNE Raw\n+            The data on which we want to fit a regression model.\n+        events : array, shape (n_events, 3)\n+            An MNE events array specifying indices for event onsets\n+        event_id : dictionary | None\n+            A dictionary of (event_name: event_int) pairs, corresponding to the\n+            mapping from event name strings to the 3rd column of events.\n+        continuous : array, shape (n_feats, n_times)\n+            Continuous input features in the regression.\n+        continuous_names : array, shape (n_feats,) | None\n+            Names for the input continuous variables.\n+        picks : array, shape (n_picks,) | None\n+            Indices for channels to use in model fitting. If None, all channels\n+            will be fit.\n+\n+        Attributes\n+        ----------\n+        coefs_ : array, shape (n_channels, n_features)\n+            The coefficients fit on each row of X\n+        coef_names : array, shape (n_features,)\n+            A list of coefficient names, useful for keeping track of time lags\n+        \"\"\"\n+        if y is None:\n+            raise ValueError('Must supply an output variable `y`')\n+        if X.shape[-1] != y.shape[-1]:\n+            raise ValueError('X and y must have last dimension same length.')\n+        n_chs, n_times = y.shape\n+\n+        # Prepare the input feature matrix\n+        if self.preproc_x is not None:\n+            X = self.preproc_x.fit_transform(X)\n+        if self.preproc_y is not None:\n+            y = self.preproc_y.fit_transform(y)\n+        n_features = X.shape[0]\n+\n+        # Fit the model and assign coefficients\n+        self.coef_ = np.zeros([n_chs, n_features])\n+        for ii in range(n_chs):","path":"mne/encoding/model.py","position":95,"original_position":95,"commit_id":"d3b72b2d346c3581140d18ee0f946e266892010f","original_commit_id":"d3b72b2d346c3581140d18ee0f946e266892010f","user":{"login":"jona-sassenhagen","id":4321826,"avatar_url":"https://avatars.githubusercontent.com/u/4321826?v=3","gravatar_id":"","url":"https://api.github.com/users/jona-sassenhagen","html_url":"https://github.com/jona-sassenhagen","followers_url":"https://api.github.com/users/jona-sassenhagen/followers","following_url":"https://api.github.com/users/jona-sassenhagen/following{/other_user}","gists_url":"https://api.github.com/users/jona-sassenhagen/gists{/gist_id}","starred_url":"https://api.github.com/users/jona-sassenhagen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jona-sassenhagen/subscriptions","organizations_url":"https://api.github.com/users/jona-sassenhagen/orgs","repos_url":"https://api.github.com/users/jona-sassenhagen/repos","events_url":"https://api.github.com/users/jona-sassenhagen/events{/privacy}","received_events_url":"https://api.github.com/users/jona-sassenhagen/received_events","type":"User","site_admin":false},"body":"With Ridge, you can fit all channels simultaneously. This is a massive slowdown compared to that isn't it?","created_at":"2016-06-18T10:15:15Z","updated_at":"2016-06-18T10:15:15Z","html_url":"https://github.com/mne-tools/mne-python/pull/3310#discussion_r67598769","pull_request_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/3310","_links":{"self":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments/67598769"},"html":{"href":"https://github.com/mne-tools/mne-python/pull/3310#discussion_r67598769"},"pull_request":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/3310"}}},"pull_request":{"url":"https://api.github.com/repos/mne-tools/mne-python/pulls/3310","id":74009397,"html_url":"https://github.com/mne-tools/mne-python/pull/3310","diff_url":"https://github.com/mne-tools/mne-python/pull/3310.diff","patch_url":"https://github.com/mne-tools/mne-python/pull/3310.patch","issue_url":"https://api.github.com/repos/mne-tools/mne-python/issues/3310","number":3310,"state":"open","locked":false,"title":"WIP: sklearn-style encoding, and support for continuous input","user":{"login":"choldgraf","id":1839645,"avatar_url":"https://avatars.githubusercontent.com/u/1839645?v=3","gravatar_id":"","url":"https://api.github.com/users/choldgraf","html_url":"https://github.com/choldgraf","followers_url":"https://api.github.com/users/choldgraf/followers","following_url":"https://api.github.com/users/choldgraf/following{/other_user}","gists_url":"https://api.github.com/users/choldgraf/gists{/gist_id}","starred_url":"https://api.github.com/users/choldgraf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/choldgraf/subscriptions","organizations_url":"https://api.github.com/users/choldgraf/orgs","repos_url":"https://api.github.com/users/choldgraf/repos","events_url":"https://api.github.com/users/choldgraf/events{/privacy}","received_events_url":"https://api.github.com/users/choldgraf/received_events","type":"User","site_admin":false},"body":"Hey all - this is is a WIP change to port the `linear_regression_raw` code into a more scikit-learn friendly interface. The hope is that this will be more modular and easier to use with cross-validation routines. It also allows support for both continuous and events-based inputs for the regression.\r\n\r\nI haven't changed much of @jona-sassenhagen's code so we can make comparisons, but I can start to do this if the `EncodingModel` class is on the right track. I also wrote a simple example but this should also be improved as well.\r\n\r\nMy hope is that this can be a somewhat incremental PR, and not implement the full preprocessing pipelines / feature extractions / cross validation that people eventually want, so that this doesn't take forever. But agreeing on a general API and making this code function and useful would be a good first step.\r\n\r\n@jona-sassenhagen and @kingjr probably have lots of opinions :)","created_at":"2016-06-16T01:20:58Z","updated_at":"2016-06-18T10:15:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f0b08057d52ee2a7b3510722840889134bf5817d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/3310/commits","review_comments_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/3310/comments","review_comment_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mne-tools/mne-python/issues/3310/comments","statuses_url":"https://api.github.com/repos/mne-tools/mne-python/statuses/d3b72b2d346c3581140d18ee0f946e266892010f","head":{"label":"choldgraf:continuous_encoding","ref":"continuous_encoding","sha":"d3b72b2d346c3581140d18ee0f946e266892010f","user":{"login":"choldgraf","id":1839645,"avatar_url":"https://avatars.githubusercontent.com/u/1839645?v=3","gravatar_id":"","url":"https://api.github.com/users/choldgraf","html_url":"https://github.com/choldgraf","followers_url":"https://api.github.com/users/choldgraf/followers","following_url":"https://api.github.com/users/choldgraf/following{/other_user}","gists_url":"https://api.github.com/users/choldgraf/gists{/gist_id}","starred_url":"https://api.github.com/users/choldgraf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/choldgraf/subscriptions","organizations_url":"https://api.github.com/users/choldgraf/orgs","repos_url":"https://api.github.com/users/choldgraf/repos","events_url":"https://api.github.com/users/choldgraf/events{/privacy}","received_events_url":"https://api.github.com/users/choldgraf/received_events","type":"User","site_admin":false},"repo":{"id":29602471,"name":"mne-python","full_name":"choldgraf/mne-python","owner":{"login":"choldgraf","id":1839645,"avatar_url":"https://avatars.githubusercontent.com/u/1839645?v=3","gravatar_id":"","url":"https://api.github.com/users/choldgraf","html_url":"https://github.com/choldgraf","followers_url":"https://api.github.com/users/choldgraf/followers","following_url":"https://api.github.com/users/choldgraf/following{/other_user}","gists_url":"https://api.github.com/users/choldgraf/gists{/gist_id}","starred_url":"https://api.github.com/users/choldgraf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/choldgraf/subscriptions","organizations_url":"https://api.github.com/users/choldgraf/orgs","repos_url":"https://api.github.com/users/choldgraf/repos","events_url":"https://api.github.com/users/choldgraf/events{/privacy}","received_events_url":"https://api.github.com/users/choldgraf/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/choldgraf/mne-python","description":"MNE : Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python","fork":true,"url":"https://api.github.com/repos/choldgraf/mne-python","forks_url":"https://api.github.com/repos/choldgraf/mne-python/forks","keys_url":"https://api.github.com/repos/choldgraf/mne-python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/choldgraf/mne-python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/choldgraf/mne-python/teams","hooks_url":"https://api.github.com/repos/choldgraf/mne-python/hooks","issue_events_url":"https://api.github.com/repos/choldgraf/mne-python/issues/events{/number}","events_url":"https://api.github.com/repos/choldgraf/mne-python/events","assignees_url":"https://api.github.com/repos/choldgraf/mne-python/assignees{/user}","branches_url":"https://api.github.com/repos/choldgraf/mne-python/branches{/branch}","tags_url":"https://api.github.com/repos/choldgraf/mne-python/tags","blobs_url":"https://api.github.com/repos/choldgraf/mne-python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/choldgraf/mne-python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/choldgraf/mne-python/git/refs{/sha}","trees_url":"https://api.github.com/repos/choldgraf/mne-python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/choldgraf/mne-python/statuses/{sha}","languages_url":"https://api.github.com/repos/choldgraf/mne-python/languages","stargazers_url":"https://api.github.com/repos/choldgraf/mne-python/stargazers","contributors_url":"https://api.github.com/repos/choldgraf/mne-python/contributors","subscribers_url":"https://api.github.com/repos/choldgraf/mne-python/subscribers","subscription_url":"https://api.github.com/repos/choldgraf/mne-python/subscription","commits_url":"https://api.github.com/repos/choldgraf/mne-python/commits{/sha}","git_commits_url":"https://api.github.com/repos/choldgraf/mne-python/git/commits{/sha}","comments_url":"https://api.github.com/repos/choldgraf/mne-python/comments{/number}","issue_comment_url":"https://api.github.com/repos/choldgraf/mne-python/issues/comments{/number}","contents_url":"https://api.github.com/repos/choldgraf/mne-python/contents/{+path}","compare_url":"https://api.github.com/repos/choldgraf/mne-python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/choldgraf/mne-python/merges","archive_url":"https://api.github.com/repos/choldgraf/mne-python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/choldgraf/mne-python/downloads","issues_url":"https://api.github.com/repos/choldgraf/mne-python/issues{/number}","pulls_url":"https://api.github.com/repos/choldgraf/mne-python/pulls{/number}","milestones_url":"https://api.github.com/repos/choldgraf/mne-python/milestones{/number}","notifications_url":"https://api.github.com/repos/choldgraf/mne-python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/choldgraf/mne-python/labels{/name}","releases_url":"https://api.github.com/repos/choldgraf/mne-python/releases{/id}","deployments_url":"https://api.github.com/repos/choldgraf/mne-python/deployments","created_at":"2015-01-21T17:41:37Z","updated_at":"2015-01-21T17:41:40Z","pushed_at":"2016-06-16T21:45:37Z","git_url":"git://github.com/choldgraf/mne-python.git","ssh_url":"git@github.com:choldgraf/mne-python.git","clone_url":"https://github.com/choldgraf/mne-python.git","svn_url":"https://github.com/choldgraf/mne-python","homepage":"http://martinos.org/mne/","size":86417,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mne-tools:master","ref":"master","sha":"f248db95eb90601ff34eda3a29e227f496f10913","user":{"login":"mne-tools","id":583875,"avatar_url":"https://avatars.githubusercontent.com/u/583875?v=3","gravatar_id":"","url":"https://api.github.com/users/mne-tools","html_url":"https://github.com/mne-tools","followers_url":"https://api.github.com/users/mne-tools/followers","following_url":"https://api.github.com/users/mne-tools/following{/other_user}","gists_url":"https://api.github.com/users/mne-tools/gists{/gist_id}","starred_url":"https://api.github.com/users/mne-tools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mne-tools/subscriptions","organizations_url":"https://api.github.com/users/mne-tools/orgs","repos_url":"https://api.github.com/users/mne-tools/repos","events_url":"https://api.github.com/users/mne-tools/events{/privacy}","received_events_url":"https://api.github.com/users/mne-tools/received_events","type":"Organization","site_admin":false},"repo":{"id":1301584,"name":"mne-python","full_name":"mne-tools/mne-python","owner":{"login":"mne-tools","id":583875,"avatar_url":"https://avatars.githubusercontent.com/u/583875?v=3","gravatar_id":"","url":"https://api.github.com/users/mne-tools","html_url":"https://github.com/mne-tools","followers_url":"https://api.github.com/users/mne-tools/followers","following_url":"https://api.github.com/users/mne-tools/following{/other_user}","gists_url":"https://api.github.com/users/mne-tools/gists{/gist_id}","starred_url":"https://api.github.com/users/mne-tools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mne-tools/subscriptions","organizations_url":"https://api.github.com/users/mne-tools/orgs","repos_url":"https://api.github.com/users/mne-tools/repos","events_url":"https://api.github.com/users/mne-tools/events{/privacy}","received_events_url":"https://api.github.com/users/mne-tools/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mne-tools/mne-python","description":"MNE : Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python","fork":false,"url":"https://api.github.com/repos/mne-tools/mne-python","forks_url":"https://api.github.com/repos/mne-tools/mne-python/forks","keys_url":"https://api.github.com/repos/mne-tools/mne-python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mne-tools/mne-python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mne-tools/mne-python/teams","hooks_url":"https://api.github.com/repos/mne-tools/mne-python/hooks","issue_events_url":"https://api.github.com/repos/mne-tools/mne-python/issues/events{/number}","events_url":"https://api.github.com/repos/mne-tools/mne-python/events","assignees_url":"https://api.github.com/repos/mne-tools/mne-python/assignees{/user}","branches_url":"https://api.github.com/repos/mne-tools/mne-python/branches{/branch}","tags_url":"https://api.github.com/repos/mne-tools/mne-python/tags","blobs_url":"https://api.github.com/repos/mne-tools/mne-python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mne-tools/mne-python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mne-tools/mne-python/git/refs{/sha}","trees_url":"https://api.github.com/repos/mne-tools/mne-python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mne-tools/mne-python/statuses/{sha}","languages_url":"https://api.github.com/repos/mne-tools/mne-python/languages","stargazers_url":"https://api.github.com/repos/mne-tools/mne-python/stargazers","contributors_url":"https://api.github.com/repos/mne-tools/mne-python/contributors","subscribers_url":"https://api.github.com/repos/mne-tools/mne-python/subscribers","subscription_url":"https://api.github.com/repos/mne-tools/mne-python/subscription","commits_url":"https://api.github.com/repos/mne-tools/mne-python/commits{/sha}","git_commits_url":"https://api.github.com/repos/mne-tools/mne-python/git/commits{/sha}","comments_url":"https://api.github.com/repos/mne-tools/mne-python/comments{/number}","issue_comment_url":"https://api.github.com/repos/mne-tools/mne-python/issues/comments{/number}","contents_url":"https://api.github.com/repos/mne-tools/mne-python/contents/{+path}","compare_url":"https://api.github.com/repos/mne-tools/mne-python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mne-tools/mne-python/merges","archive_url":"https://api.github.com/repos/mne-tools/mne-python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mne-tools/mne-python/downloads","issues_url":"https://api.github.com/repos/mne-tools/mne-python/issues{/number}","pulls_url":"https://api.github.com/repos/mne-tools/mne-python/pulls{/number}","milestones_url":"https://api.github.com/repos/mne-tools/mne-python/milestones{/number}","notifications_url":"https://api.github.com/repos/mne-tools/mne-python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mne-tools/mne-python/labels{/name}","releases_url":"https://api.github.com/repos/mne-tools/mne-python/releases{/id}","deployments_url":"https://api.github.com/repos/mne-tools/mne-python/deployments","created_at":"2011-01-28T03:31:13Z","updated_at":"2016-06-18T03:19:35Z","pushed_at":"2016-06-18T07:29:31Z","git_url":"git://github.com/mne-tools/mne-python.git","ssh_url":"git@github.com:mne-tools/mne-python.git","clone_url":"https://github.com/mne-tools/mne-python.git","svn_url":"https://github.com/mne-tools/mne-python","homepage":"http://martinos.org/mne/","size":178472,"stargazers_count":206,"watchers_count":206,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":196,"mirror_url":null,"open_issues_count":205,"forks":196,"open_issues":205,"watchers":206,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/3310"},"html":{"href":"https://github.com/mne-tools/mne-python/pull/3310"},"issue":{"href":"https://api.github.com/repos/mne-tools/mne-python/issues/3310"},"comments":{"href":"https://api.github.com/repos/mne-tools/mne-python/issues/3310/comments"},"review_comments":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/3310/comments"},"review_comment":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/3310/commits"},"statuses":{"href":"https://api.github.com/repos/mne-tools/mne-python/statuses/d3b72b2d346c3581140d18ee0f946e266892010f"}}}}
{"actor":{"display_login":"jona-sassenhagen"}}