{"action":"created","comment":{"url":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments/67599557","id":67599557,"diff_hunk":"@@ -0,0 +1,145 @@\n+\"\"\"\n+========================================\n+Regression on continuous and event-based data)\n+========================================\n+Neat description. Oooo so cool.\n+\n+rERPs are described in:\n+\n+  Smith, N. J., & Kutas, M. (2015). Regression-based estimation of ERP\n+  waveforms: II. Non-linear effects, overlap correction, and practical\n+  considerations. Psychophysiology, 52(2), 169-189.\n+\n+Estimation of receptive fields and modeling with continuous inputs\n+is described in:\n+\n+  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+\n+  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+# Authors: Chris Holdgraf <choldgraf@gmail.com>\n+#          Jona Sassenhagen <jona.sassenhagen@gmail.de>\n+#\n+#\n+# License: BSD (3-clause)\n+\n+import mne\n+import numpy as np\n+import matplotlib.pyplot as plt\n+from scipy import stats as stt\n+from sklearn.linear_model import Ridge\n+from mne.encoding import EncodingModel, delay_timeseries\n+from mne.encoding import DataSubsetter, EventsBinarizer, DataDelayer\n+from sklearn.pipeline import Pipeline\n+\n+\n+# Helper function to create data\n+def modulate_noise(signal, sfreq, delays, weights, snr=1):\n+    sig_delayed = delay_timeseries(signal[np.newaxis, :], sfreq, delays)\n+    output = np.dot(weights, sig_delayed)\n+    noise = (np.percentile(output, 95) / snr) * np.random.randn(len(output))\n+    return output + noise\n+\n+# -- Creating stimuli --\n+# Define our continuous signal\n+sfreq = 1000.\n+n_sec = 10.\n+freq = 3.\n+amp = 1\n+time = np.linspace(0, n_sec, sfreq * n_sec)\n+stim_cont = amp * np.sin(2 * np.pi * freq * time)\n+\n+# Define events\n+n_events = 20\n+events = np.linspace(0, stim_cont.shape[0] - 1, n_events).astype(int)\n+events = np.vstack([events, np.zeros_like(events), np.ones_like(events)]).T\n+\n+# Define weights we'll use to modulate the signal\n+delays_sig = np.arange(0, -.4, -.01)\n+weights = stt.norm.pdf(delays_sig, -.2, .05)\n+\n+# Now create our stimulus-modulated signal\n+snr = 3\n+sig_cont = modulate_noise(stim_cont, sfreq, delays_sig,\n+                          weights=weights, snr=snr)\n+\n+# And a signal that responds to event onsets\n+binarizer = EventsBinarizer(stim_cont.shape[-1], sfreq=1)\n+stim_events = binarizer.fit_transform(events[:, 0], event_ids=events[:, -1])\n+sig_event = modulate_noise(stim_events[0], sfreq, delays_sig,\n+                           weights=weights, snr=snr)\n+info = mne.create_info(['ch'], sfreq, ch_types=['eeg'])\n+sig_cont = mne.io.RawArray(sig_cont[np.newaxis, :], info)\n+sig_event = mne.io.RawArray(sig_event[np.newaxis, :], info)\n+\n+\n+# -- Preparing model features --\n+# Iterate through our events-based and continuous datasets\n+data_iterator = [(stim_events, sig_event, 'Events'),\n+                 (stim_cont[np.newaxis, :], sig_cont, 'Continuous')]\n+\n+# Define a training / test set of indices\n+ixs = np.arange(sig_cont.n_times)\n+ix_split = int(.8 * ixs.shape[0])\n+tr = ixs[:ix_split]\n+tt = ixs[ix_split:]\n+\n+\n+# -- Define preprocessing pipelines for X/y --\n+# For creating time lags\n+delays_model = delays_sig\n+delayer = DataDelayer(delays=delays_model, sfreq=sig_cont.info['sfreq'])\n+\n+# To subset training data\n+sub_tr = DataSubsetter(tr)\n+sub_tt = DataSubsetter(tt)\n+\n+# Now put them together into pipelines\n+pipe_x = Pipeline([('delays', delayer), ('subset', sub_tr)])\n+pipe_y = Pipeline([('subset', sub_tr)])\n+preproc_x_pred = Pipeline([('delays', delayer), ('subset', sub_tt)])\n+\n+\n+# -- Fit the model, iterating through alphas --\n+alphas = np.logspace(0, 2, 4)\n+f, axs_coef = plt.subplots(2, len(alphas), figsize=(4 * len(alphas), 8),\n+                           sharex=True, sharey=True)\n+f, axs_pred = plt.subplots(2, len(alphas), figsize=(4 * len(alphas), 8),\n+                           sharex=True, sharey=False)","path":"examples/encoding/plot_encoding_model.py","position":112,"original_position":112,"commit_id":"d3b72b2d346c3581140d18ee0f946e266892010f","original_commit_id":"d3b72b2d346c3581140d18ee0f946e266892010f","user":{"login":"kingjr","id":4881164,"avatar_url":"https://avatars.githubusercontent.com/u/4881164?v=3","gravatar_id":"","url":"https://api.github.com/users/kingjr","html_url":"https://github.com/kingjr","followers_url":"https://api.github.com/users/kingjr/followers","following_url":"https://api.github.com/users/kingjr/following{/other_user}","gists_url":"https://api.github.com/users/kingjr/gists{/gist_id}","starred_url":"https://api.github.com/users/kingjr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kingjr/subscriptions","organizations_url":"https://api.github.com/users/kingjr/orgs","repos_url":"https://api.github.com/users/kingjr/repos","events_url":"https://api.github.com/users/kingjr/events{/privacy}","received_events_url":"https://api.github.com/users/kingjr/received_events","type":"User","site_admin":false},"body":"`fig` or `_`","created_at":"2016-06-18T11:16:21Z","updated_at":"2016-06-18T11:16:21Z","html_url":"https://github.com/mne-tools/mne-python/pull/3310#discussion_r67599557","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/67599557"},"html":{"href":"https://github.com/mne-tools/mne-python/pull/3310#discussion_r67599557"},"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-18T11:16:21Z","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":"kingjr"}}