[matlab] performance for-loops vs. vectorization vs. bsxfun

From time to time I explain my students certain concepts. To archive those and as an extended memory, I share them here. We also recently had some discussion on vectorization in our research group. e.g. in python and matlab. With the second link claiming for-loops in matlab are performing much better than before.   Goal Show that for-loops are still quite slow in matlab. Compare bsxfun against vectorized arithmetic expansion in matlab against bsxfun The contenders good old for-loop: Easy to understand, can be found everywhere, slow arithmetic expansion: medium difficulty, should be general used, fast bsxfun: somewhat difficult to…

Scientific Poster Templates

I got asked for the design of my academic posters. Indeed I have templates in landscape and portrait and I’m happy to share them. In addition I can recommend the blog better-posters which has regularily features and link-roundups on poster-design related things. In my newest poster (landscape below) I tried to move as much text to the side, so that people can still understand the poster, but it does not obscure the content. I also really like the 15s summary, an easy way to see whether you will like the poster, or you can simply move on. Maybe it even needs to…

Layman Paper Summary: Humans treat unreliable filled-in percepts as more real than veridical ones

We recently published an article (free to read): “Humans treat unreliable filled-in percepts as more real than veridical ones”. Inspired by Selim Onat and many others, I try to to explain the main findings in plain language. First let me give you some background: To make sense of the world around us, we must combine information from multiple sources while taking into account how reliable they are. When crossing the street, for example, we usually rely more on input from our eyes than our ears. However we can reassess our reliability estimate: on a foggy day with poor visibility, we…

EEGlab: Gracefully overwrite the default colormap

EEGlab has ‘jet’ as the default colormap. But jet is pretty terrible   You see structure where there is none (e.g. rings in the third example).   The problem: Eeglabs sets the default colormap to ‘jet’, thus overwriting a system wide default set e.g. by “` set(0,’DefaultFigureColormap’,parula); “` It does so by calling “`icadefs.m “` in various functions (e.g. topoplot, erpimage) and defining: “` DEFAULT_COLORMAP = ‘jet’ “` We want to overwrite the one line, but keep it forward compatible i.e. we do not want to copy the whole icadefs file, but just replace the single line whenever icadefs is…

Simple Filter Generation

I sometimes explain concepts to my students. Then I forget the code and the next time round, I have to redo it. Take this post as an extended memory-post. In this case I showed what filter-ringing artefacts could look like. This is especially important for EEG preprocessing where filtering is a standard procedure. A good introduction to filtering can be found in this slides by andreas widmann or this paper by andreas widmann Impulse with noise I simulated as simple impulse response with some additional noise. The idea is to show the student that big spikes in the EEG-data could result…

Logistic Regression: Will it rain in Osnabrück tomorrow?

TLDR; 52% of days it rained (Precipitation>0) Is it sunny? 2x as likely that it is sunny tomorrow as well. Is it rainy? 2.3x as likely that it is rainy tomorrow as well Predicting rainfall using logistic regression I’m playing around with some analyses for an upcoming course. This follows loosely the example of “Advanced Data Analysis from an Elemental Point of View” Chapter 12.7 It is a somewhat naive analysis. Further improvements are discussed at the end. library(ggplot2) library(plyr) We load the data and change some of the German variables # I downloaded the data from here: # http://www.dwd.de/DE/leistungen/klimadatendeutschland/klimadatendeutschland.html…

How to use bimodal priors for bayesian data analysis in STAN

I tried adding a bi-modal prior in STAN for a homework exercise on Bayesian Data Analysis. At first, I thought this could work: “`STAN model{ mu ~ normal(-0.5,0.3) + normal(0.5,0.3); } “` But it doesn’t. I had to dig deeper and I thought I could simply add multiple times to the log-posterior due to a sideremark of Bob Carpenter: “`STAN target += normal_lpdf(mu|.5,0.3); target += normal_lpdf(mu|-.5,0.3); “` Which also does not work. Finally, the solution is akin to the mixture model in the STAN manual: “`STAN target += log_sum_exp(normal_lpdf(mu|.5,0.3),normal_lpdf(mu|-.5,0.3)); “` This results in beautiful bi-modal priors: I did not find…

Scatterplots, regression lines and the first principal component

I made some graphs that show the relation between X1~X2 (X2 predicts X1), X2~X1 (X1 predicts X2) and the first principal component (direction with highest variance, also called total least squares). The line you fit with a principal component is not the same line as in a regression (either predicting X2 by X1 [X2~X1] or X1 by X2 [X1~X2]. This is quite well known (see references below). With regression one predicts X2 based on X1 (X2~X1 in R-Formula writing) or vice versa. With principal component (or total least squares) one tries to quantify the relation between the two. To completely…

EEG: Contours in multiple topoplots

The problem It is commonly accepted that axes of plots should align if data needs to be compared between subplots. But the default way on how multiple topoplots are plotted violates this principle. While usually the limits of the colormap are kept constant for all colormaps, the contours rarely are. This default plot looks similar to this one: The solution It is simple, keep the contours constant! In eeglab this is done using the topoplot function with the argument ‘numcontours’, linspace(-scale,scale,n_contours) or similar. You can also use my new plotting script available here on github So if we would keep…

Multitaper Time vs Frequency Resolution

Goal Give a graphical representation of multitaper time frequency parameters. Background Frequency Resolution and sFFT In M/EEG analysis we are often interested in oscillations. One tool to analyse oscillations is by using time-frequency methods. In principle they work by segmenting the signal of interest in small windows and calculating a spectrum for each window. A tutorial can be found on the fieldtrip page. There exists a time-frequency tradeof: $\delta f = \frac{1}{T}$ with T the timewindow (in s) and $\delta f$ the frequency resolution. The percentage-difference of two neighbouring frequency resolution gets smaller the higher the frequency goes, e.g. a…

5 of 7
1234567