An interesting gamble

May 11th, 2015

The other day I was walking on a street, along which there are a lot of booths where people play games to gamble. I stopped in front of one booth. The host was warm and we started to talk.

“How to play?”, I asked.

“Well, simple.” He explained, “You pay $10 to play once. Then you toss a coin until you get a ‘head’ and the game is over. If you get a ‘head’ in the first toss, then I will pay you $1; if in the 2nd toss, I will pay you $2; 3rd I will pay you $4; … and nth I will pay 2^(n-1) dollars.”

“Interesting!” I then started to calculate if this game is fair to me. I needed to calculate the expected return from this game. If it’s larger than $10, then I win; otherwise I will lose. So what is the expected return?

The probability to get ‘head’ in the first toss is 1/2, 2nd time 1/4 and so on. So the expected return is 1×1/2 + 2×1/4 + 4×1/8 + … = 1/2 + 1/2 + 1/2 + 1/2 + … and the sum is infinity!

My return is infinity! And it’s much larger than $10 dollars. For sure I will play. I might become a millionaire today. I count my money in my wallet and I have $100.

“I am in!”, I told the host.

“Good decision.”, He similed.

Then I started to play. The first game I was unlucky. I got the head in the first toss. But it’s the risk I have to take to become a millionaire. So I keep playing.

Before I knew I already spent all my $100! I only won about $50. But at this point nothing could stop me from becoming a millionaire. So I keep playing until I lost all my money.

I was very disappointed, but I was more confused. The expected return is infinity, but why did I lose money? Did I make a mistake in the calculation?

Author: Xu Cui Categories: fun, life Tags:

How to label each point in MatLab plot?

April 27th, 2015

How to label each data point in a MatLab plot, like the following figure?

label data in MatLab plot

label data in MatLab plot

MatLab code:

x = [1:10];
y = x + rand(1,10);

figure('color','w'); plot(x,y,'o');
a = [1:10]'; b = num2str(a); c = cellstr(b);
dx = 0.1; dy = 0.1;
text(x+dx, y+dy, c);

It also works on 3D plot:

label data 3d

label data 3d

Adopted from http://www.mathworks.com/matlabcentral/answers/97277-how-can-i-apply-data-labels-to-each-point-in-a-scatter-plot-in-matlab-7-0-4-r14sp2

Author: Xu Cui Categories: matlab Tags:

SVM regression on time series, is there a lag?

March 23rd, 2015

It would be nice if we can predict the future. For example, give the following time series, can we predict the next point?

Let’s use SVM regression, which is said to be powerful. We use the immediate past data point as the predictor. We train our model with the first 70% of data. Blue and Black are actual data, and Red and Pink are predicted data.

The prediction in general matches the trend. But if you look closely, you see that the predicted data is always lagging the actual data by one time step. See a zoom in below.

Why does this lag come from?

Let’s plot the predictor and the predicted (i.e. the current data point vs the next data point):

It looks normal to me.

It took me a few hours to think about this. Well, the reason turns out to be simple. It’s because our SVM model is too simple (only taking the last data point as predictor): if a data has a increasing trend, then the SVM model, which only consider the immediate history, will give a high predicted value if the current data value is high, a low value if the current data value is low. As a consequence, the predicted value is actually more similar to the current value - and that gives a lag if compared to the actual data.

To reduce the lag, you can build a more powerful SVM model - say use the past 2 data points as the predictor. It will make a more reliable prediction - if the data is not random. See below comparison: you can easily see the lag is much smaller.

Source code can be downloaded here test_svr. Part of the source code is adapted from http://stackoverflow.com/questions/18300270/lag-in-time-series-regression-using-libsvm

Author: Xu Cui Categories: brain, matlab Tags:

NIRS can’t measure deep brain, … maybe it can!

February 27th, 2015

Is NIRS able to measure signal from deep brain structure, such as amygdala? The short answer is no. NIRS is only able to measure the surface of the brain. This is a serious limitation of NIRS compared to fMRI which is able to measure the entire brain.

However, brain is a highly connected network. Deep brain is not isolated from the surface. So maybe we can infer the deep brain activity based on the surface. And this is exactly what we have done.

In a recent publication titled “Inferring deep-brain activity from cortical activity using functional near-infrared spectroscopy”, we used concurrent fMRI-NIRS technology to measure both deep and surface brain activity and explored the possibility to infer deep brain based on surface brain activity measure by NIRS. The result is very encouraging - we are able to infer deep brain from surface activity (correlation ~0.7).

This paper is published in Biomedical Optics Express with Dr Ning Liu, a NIRS expert, as the first author. You can find the paper at http://www.opticsinfobase.org/boe/fulltext.cfm?uri=boe-6-3-1074&id=312512

Abstract:

Functional near-infrared spectroscopy (fNIRS) is an increasingly popular technology for studying brain function because it is non-invasive, non-irradiating and relatively inexpensive. Further, fNIRS potentially allows measurement of hemodynamic activity with high temporal resolution (milliseconds) and in naturalistic settings. However, in comparison with other imaging modalities, namely fMRI, fNIRS has a significant drawback: limited sensitivity to hemodynamic changes in deep-brain regions. To overcome this limitation, we developed a computational method to infer deep-brain activity using fNIRS measurements of cortical activity. Using simultaneous fNIRS and fMRI, we measured brain activity in 17 participants as they completed three cognitive tasks. A support vector regression (SVR) learning algorithm was used to predict activity in twelve deep-brain regions using information from surface fNIRS measurements. We compared these predictions against actual fMRI-measured activity using Pearson’s correlation to quantify prediction performance. To provide a benchmark for comparison, we also used fMRI measurements of cortical activity to infer deep-brain activity. When using fMRI-measured activity from the entire cortex, we were able to predict deep-brain activity in the fusiform cortex with an average correlation coefficient of 0.80 and in all deep-brain regions with an average correlation coefficient of 0.67. The top 15% of predictions using fNIRS signal achieved an accuracy of 0.7. To our knowledge, this study is the first to investigate the feasibility of using cortical activity to infer deep-brain activity. This new method has the potential to extend fNIRS applications in cognitive and clinical neuroscience research.

Author: Xu Cui Categories: brain, nirs Tags:

How to download emails in Gmail?

February 20th, 2015
  1. Log in to your gmail
  2. On the top-right corner, you will find your own icon, click it. A pop up window will show
  3. Click “Account”
  4. You will see a page with a lot of options. Scroll down and find Account tools, then click “Download data”
  5. Select Mail and download your emails in mbox format. The file can be opened with any text editor (e.g. Notepad ++).
Author: Xu Cui Categories: life Tags:

Using a smartphone to measure head motion in a NIRS experiment

February 14th, 2015

Sensitivity of fNIRS measurement to head motion: An applied use of smartphones in the lab

Sensitivity of fNIRS measurement to head motion: An applied use of smartphones in the lab

Is it possible to use a smartphone to measure head motion in a NIRS study? Is it reliable? After all, smartphones are so popular right now and everybody has it. It would make head motion measurement much more convenient than a traditional stand-alone accelerometer if the answers to the above questions are yes.

The good news is, the answers are YES!

In our recently published paper, we demonstrated that a NIRS researcher can easily attach a smartphone to a participant’s head, measure the motion data (3-D), export and analyze the data, and integrate with NIRS measurement.

The title of the paper is “Sensitivity of fNIRS measurement to head motion: An applied use of smartphones in the lab“. The full-text can be found here.

Abstract

Background

Powerful computing capabilities in small, easy to use hand-held devices have made smart technologies such as smartphones and tablets ubiquitous in today’s society. The capabilities of these devices provide scientists with many tools that can be used to improve the scientific method.

Method

Here, we demonstrate how smartphones may be used to quantify the sensitivity of functional near-infrared spectroscopy (fNIRS) signal to head motion. By attaching a smartphone to participants’ heads during the fNIRS scan, we were able to capture data describing the degree of head motion.

Results

Our results demonstrate that data recorded from an off-the-shelf smartphone accelerometer may be used to identify correlations between head-movement and fNIRS signal change. Furthermore, our results identify correlations between the magnitudes of head-movement and signal artifact, as well as a relationship between the direction of head movement and the location of the resulting signal noise.

Conclusions

These data provide a valuable proof-of-concept for the use of off-the-shelf smart technologies in neuroimaging applications.

Keywords

  • Near-infrared spectroscopy;
  • fNIRS;
  • smartphone;
  • technology;
  • neuroimaging;
  • accelerometer
Author: Xu Cui Categories: brain, nirs Tags:

How to split a PDF file for free?

February 13th, 2015

I have a PDF file which contains many pages. For some reason I need to send only page 3 and 5 to a friend. How can I create a PDF which contains only page 3 and 5?

It turns out using Google Chrome is very easy (and free)! I simply open the big PDF in Chrome (drag-n-drop the file to Chrome) and then print the file to a new PDF with only page 3 and 5.

Below is a video tutorial.

Author: Xu Cui Categories: life Tags:

How long is fMRI or NIRS signal delayed?

December 8th, 2014

We know the hemodynamic signal measured by fMRI (or NIRS) is delayed respective to the onset of stimuli. But how long is the delay? Many people think it takes about 2s for the signal to arise. Actually the delay varies from region to region. As shown in this figure, signal in motor cortex (including SMA) arises very quickly (no delay); but the signal in visual cortex arises slow (2s delay).

fmri or nirs signal onset delay

The figure above is adapted from Cui et al, PLoS Biology (2009) Ready…Go: Amplitude of the fMRI Signal Encodes Expectation of Cue Arrival Time

Author: Xu Cui Categories: fmri, nirs Tags:

Driver Detective

August 25th, 2014

I had been using a Lenovo Edge laptop, and one day it died. The operation system (windows 7) was corrupted. After installing a new Windows 7, I found the computer is impossible to use - it does not find the wireless adapter and the screen resolution is low. I did a lot of google but Lenovo apparently has a lot of special hardware and it’s hard to find the correct drivers. I almost gave up.

I then tried an external USB wireless adapter from another computer and it works. So I was going to purchase an external USB wireless adapter. Then I did another search to fix the screen resolution and at this time I found Driver Detective, a program which claimed to be able to fix all driver issues. I hesitated for a few minutes when I found out the program is not free (about 30 dollars). But eventually I convinced myself to pay. To my joy, it fixed all problems, including the wireless adapter driver. So I do not need to buy an USB wireless driver anymore.

Author: Xu Cui Categories: life Tags:

Apply a Formula to an Entire Column in Excel

June 9th, 2014

Two Ways to Apply a Formula to an Entire Column in Excel

This small trick can be handy if you have a lot of rows. The most commonly used method - dragging down - will be too time consuming in this case.

Author: Xu Cui Categories: life Tags: