Saturday, May 12, 2012

Compressed Sensing

Compressed sensing is an interesting and hot topic recently. I wrote an report on it for my optimization course. I want to summarize it in a more succinct way in a blog post.

Overview

Consider an underdetermined linear system Ax = b, where A is a nxN matrix and n << N, x in R^N. If A is not degenerate (or has rank n), then there will be infinitely many solutions to this system. However, if we know the solution x is sparse, i.e., the number of non-zeros is only a few, then the solution is unique and under a certain condition we may find it exactly.

Application Background

Many application can be formulated in the above way. For example, in signal processing, to recover the signal x, one must have enough samples to do so. According to Nyquist-Shannon sampling theorem, the sampling rate must be no less than half of the frequency. The matrix A is usually called measurement matrix, which corresponds to the measurement, or sensing in our context. However, in compressed sensing we can still recover the signal even when the samples are not enough. This may seem contradicting, but it is not. The sampling theorem does not make any assumption to the signal, but we does – the signal is sparse.

Another example is image 'sensing'. When we are taking images using a digital camera, we must capture all of the pixels. If the resolution is high, the resulting image file will be very large, and people may want to compress it. The modern approach in image compression is wavelet transform, which is used in JPEG2000 standard. An image can be viewed as a 2D signal, and can be represented using a set of wavelets and coefficients. This is similar to Fourier transform, where the signal can be represented by a set of sinusoids and coefficients. The wavelet or sinusoids are called 'basis'. Interestingly, we may always find a basis such that only a few components in it are significant, while others are not. The compressions relies on such an idea, we may safely discard the unimportant components but keep those important components. This will not hurt the image quality too much, and human-eyes cannot see the difference. Intuitively, we can plot the coefficient of the components, and we will see some 'sparks' in the plot, while the others are very small magnitude that is close to zero. We threshold those small magnitude and keep only those sparks. This is roughly how the image compression works. Nevertheless, if we are to abandon lots of information anyway, why not just only capture the important ones from the very beginning?

Key Discoveries of CS

The following summarizes the keys:

  • If the solution x is sparse enough and matrix A satisfies 'Restricted Isometry Property' (RIP), then x is unique.
  • RIP itself is hard to check, but if we obtain A using some random process, it is almost always guaranteed (or, with high probability, with high confident).
  • We can formulate an optimization to find the solution: minimize ||x||_0 s.t. Ax=b, where ||x||_0 is the l0-norm of x. Note that the norm is not a true 'norm', but just counting the number of non-zeros in x. However, l0-norm is clearly not continuous, not differentiable and not convex, the minimization is combinatorially hard, or, NP-hard.
  • We can convexify the problem. Instead of minimizing l0-norm, we minimize l1-norm, which can be recast as linear program and solved efficiently.
  • When A satisfies some property, the l1-minimization has the exact solution as l0-minimization.

Disclaimer

The above description is based on the paper I read and my interpretation. Some description may not be very accurate or rigorous in math.

Thursday, April 19, 2012

Fixing X11 failure in Mac OS X Lion



Sometimes when I start octave, it will start X11 automatically, which triggers the command:

    priviledge_startx -d

But somehow X11 keeps crashing and restarting, which is very annoying.
From the system console, one line of message shows:

    4/18/12 11:31:43.142 AM org.x.startx: _XSERVTransmkdir: ERROR: Owner of /tmp/.X11-unix must be set to root

Checked the folder /tmp/.X11-unix, and found that the owner is the current user. chmod the directory to set the owner to root resolve the issue.

Monday, February 13, 2012

低音下行

一些歌曲的伴奏里面都使用了低音下行。

我所听过的最早的也是最经典的应该就是 Led Zeppelin 的 Stairway to Heaven 的 intro 了。前三小节分别是
D-#C-C-B-bB ,乍看之下非常不和谐的半音过渡。但是却完美地把那种忧郁的味道诠释了出来。不得不佩服 Jimmy Page
编曲的强大。

相对地, 国内很多歌曲似乎都 copy 了这个套路。 比如超载的 《梦缠绕的时候》, 其实和弦组成几乎一样, 也是一个经典的 D-#C-C-B-bB 半音下行。

另一个例子是筠子/汪峰的《青春》, intro里也使用了类似的技法, 不过不是半音。

古典音乐里面也有不少低音下行的例子。比如 Bach 的 Air 的一些吉他编曲。


在回忆更多的例子.

Ozzy Osbourne《Mama I'm Coming Home》1=E

Friday, December 23, 2011

三分鐘熱度?

今晚與一眾人玩三國殺,水平很菜,玩得一般。主要是興趣不大,一直沒有研究,連哪個武將作甚都記不住。

按道理來說,這種 board game 是比較合我胃口的:做工精美,人物豐富,老少咸宜。但不知怎的就是提不起興趣去玩好。

忽然一驚,以前的自己對這種東西可是很著迷的,睡覺想,上課想,但現在,竟然不 fancy 了。

突然覺得以前大人所說的三分鐘熱度,不是什麼壞東西。世上的東西那麼多,值得研究的千千萬,可以學習的萬萬千。三分鐘熱度,說明你能對一樣東西提起興趣;三分鐘熱度,不至於讓你以生之有涯,去花在學之無涯。最重要的,還是保持對萬事萬物的好奇之心,自己覺得喜歡的,大可不必在意旁人的眼光,而自己決定是否要花時間在上面。沉迷於一樣東西的感覺也是很好很妙的,它可以讓你廢寢忘食,它可以讓你如痴如醉。即使時間很短,但事半功倍,往往效率很高地能在很短時間內達到業餘的水平。最後,把自己的才智與時間花在有興趣的東西上,豈不妙哉?

三分鐘熱度,可以保持人的敏感性。這樣才能多嘗試不同事物,最終找到不是"三分鐘熱度"而是三年,三十年熱度的東西的幾率也就大大增加了,興趣也就自然廣泛。

希望我繼續多一點三分鐘熱度。

Friday, December 9, 2011

Applescript to export your iPhoto albums according to the hierachy



iPhoto has one thing that drives me nuts: one cannot export photos in folder/album while keeping the hierarchy!

This is very useful when your want to export them to some external device, say, a digital photo frame.

I did some search and found that people are using some cumbersome trick, i.e., to batch rename the photos with prefix of the event, export, and then move the photos with the same prefix into folders with the prefixes. This is not so elegant because people may want to give meaningful name the photos and this will certainly destroy it.

So I wrote this little script to make life easier. Extract it and drag to  ~/Library/Services. This will add it as an service of iPhoto. Now you can just select an album and choose 

    'iPhoto -> Service -> Export Album'

then select a folder to export to. Enjoy!