资源调配不均匀

August 15, 2013

最近看《进击的巨人》,里面有个 dilemma 很引起我共鸣。背景:地球突然出现身高10+米的巨人,以人类为食,人类为了自保,修建城墙阻挡巨人。同时训练士兵,成绩好的士兵可以选择留在最安全的地方成为保护国王的宪兵,而其他则必须去进入调查兵团,即前线的士兵,随时牺牲生命。tl;dr:有能力的人明哲保身,能力弱的反而要肩负起最重要的保护人类生命的责任。

我突然觉得跟我在现实生活的一些想法很有共鸣。我身边一些我觉得很有聪明才智的人,没有选择在学术道路上,而是选择安逸的生活;而像我有兴趣在科学道路上有所建树,却总是为自己没有他们的智商而着急。从资源调配角度来说,真是离最优解恰好相反。

这个问题其实跟在 quora 上的一个问题也有点类似。top answer 的大意是,Google 优越的条件吸引了世界上最聪明的一群人,然则大多数人在 google 其实 overqualified,因为 challenging 的东西总是已经被做完,或者说做决策的只能是高层更聪明的人。

当然我本意不是埋怨别人不好好利用它们的聪明才智,每个人都有做出自己选择的权利。我仅仅,只是在着急搞研究进展缓慢,觊觎别人的能力而已…

关于 stty, erase, ^H, ^?

July 31, 2013

引用这位同学的问题,之前自己经常遇到但是没有好好总结。

表现就是,在 terminal 里面,backspace 经常会出现问题,偶尔会看到 ^? 或 ^H 这种东西的出现。

由于历史原因 (追溯到打卡机时代),要删除一个字符,必须先 ASCII BS (0x08, ^H) 回到前一个字母,然后再 ASCII DEL (0x7F, ^?) 删除它。

现代电脑里,backspace 的作用基本上就相当于上述 BS+DEL的功能,而delete真正发送的是"^[[3"。而事实上 backspace 究竟定义为 ^H 还是 ^? 只是一个个人的选择,并且没有标准,所以不同的 terminal emulator 可能会采用不同的值。

我们知道可以用不同的 terminal (emulator) login 到一个机器上。但是不同 terminal 有不同的 key mapping,具体来说,它们 backspace 发送的值可能 *不一样*. 比如 linux console 是模拟 vt220 的,backspace 发送的是 DEL,而 xterm 模拟 vt100,backspace 发送的是 BS。

而 stty 是用来控制 terminal options 的。简单来说,是控制 terminal 怎么理解输入的字符串的。如果 backspace 发送的值与 stty 的设置定义不一样,那么就可能出现问题,最常见的,就是 stty 里 erase (向前删除一个字符) 设置为 ^? 而 backspace 发送的是 ^H. 这时解决方法是:

1. 设置 stty 理解 ^H 为 erase: stty erase ^H,或者
2. 设置 terminal emulator, 使得 backspace 发送 ^? 而不是 ^H。

历史与详细解决方法:http://www.ibb.net/~anne/keyboard.html
历史与参考链接:http://www.quetek.com/dictionary/linux-backspace-delete-config.html
另外一些资料:http://www.hypexr.org/linux_ruboff.php

O show 觀感(& vs Le Reve)

December 24, 2012

看的第二場 Cirque de solei 的 show。之前看過在 Wynn 的 Le Reve。

買的比較靠前排的灰常灰常貴的票。
不過看到舞台的佈置,演員精湛的表演,夢幻的劇情與艷麗的服飾,以及歌手現場的表演,也算覺得值回票價。
特別是看到那麽多演員的雜技與舞蹈,知道培養、訓練這麽一羣人並不容易。
另外設計師的創意也是非常值錢的。
都說 O show 是他們最好的、必看的表演。
不過對比起之前看的 Le Reve,我倒覺得未必。
首先 O show 的舞台就已經被比了下去——是一個傳統的佈置,前面是舞台,後面是觀眾。

而 Le reve 是圓形的舞台,所以無論哪個角度都能很清楚地看到,並且不同角度有不同觀感。
我個人的感覺是,看 le reve 時感覺『眼睛不夠用』,似乎看哪裏都會 miss 掉別的細節。
而 O show 則一覽無餘,基本上可以看清每個演員的動作。
出場時, O show 是用觀眾過橋,從觀眾席裏『拉』了一個觀眾下去。
而 Le reve 是演員們從四面八方沿著觀眾席衝下舞台,非常地震撼!
最後,它們的定位也不一樣。

(以下劇透)
O show 可以說是奇幻+雜技+滑稽+冒險。
講的是一個男孩撿到神秘女孩的絲巾,尋覓這位女孩的故事。
感覺比較適合大人帶小孩那種家庭觀看。
而 Le reve 渾身透著文藝味,可以說是夢幻+雜技+文藝+哲學。
講的是一個女孩遇到愛人示愛但是卻猶豫,經歷了許多奇幻的經歷解開心扉的故事。
比較適合文藝青年和二逼青年觀看。
總的來說,我喜歡 le reve 遠勝於 O。當然也許是因為 O 被宣傳得太厲害使得我有落差。

不過 anyway,兩個 show 都各有千秋。 O show 裏面有挺多的笑點,兩個小丑的表演還是很逗笑的。
O 裏面的雜技似乎比 Le reve 要更『驚險』一點(其實不大記得 le reve 了)。
比較有印象的是裏面著火的人以及用頭倒立盪千秋的人。
Le reve 圓形的舞台,前排的觀眾真的是會『濕身』的。
而且由於演員們會在過道、樓梯上也一同表演,觀眾的『代入感』會更強(而 O show 大部分時間是在舞台上)。

總結:如果你是一羣人想開心地看一場表演,那就去看 O。
如果是男女朋友或者自己,能靜下心思考看似『荒誕』、『夢幻』的表演裏面導演埋下的含義,那麽去看 Le Reve.

最後兩個亂談:
1. 有人覺得 O show 跟少年Pi有那麽一絲相似麽?那個拿著紅絲巾尋覓『女神』的著裝有中東風格的少年,水上秀,以及裏面的奇幻歷程,都讓我非常有既視感。
2. 那個駝著背的長腿叔叔,感覺超級超級像死亡筆記裏的死神流克(Ryuk)!

My workflow of copying and pasting content between Mac and iOS device

November 14, 2012

I’ve always wanted to dumping contents from Mac to my iOS. For example, I subscribe to websites that reports Free for Limited Time apps everyday. Whenever I want to download, I have to download it to iTunes first, then sync to my iOS, or turn on the iCloud to allow simultaneous download, which is kinda cumbersome in my opinion.

One solution is Pastebot. Pastebot is good, but I always think that it’s overpriced ($3.99, iPhone only), and you need to install server in your Mac. It’s functionality is also rather limited.

My solution is to use droplr. It’s pretty handy in all aspects. You capture the screen, drag a link, image, text or whatever file type to the menu bar icon, they get uploaded and the link is copied to your paste board immediately when upload is finished.

Drag to the menu bar icon

Uploading

转载:中年夫妻「相看兩相厭」?

September 19, 2012

轉載自親子天下雜誌

原文:

有些中年夫妻結婚許久,卻各自活在自己的世界,沒去理解對方應對問題的方式。這時,一個小小的溝通不良,就足以讓彼此覺得「真是夠了」…

quote

June 30, 2012

“为你流过两滴眼泪就心软啦,你为她也流过泪寒过心,早还给她了。况且这点眼泪对于她对你的残忍,算个p。 ”

Compressed Sensing

May 11, 2012

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.

Fixing X11 failure in Mac OS X Lion

April 18, 2012

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.

三分鐘熱度?

December 23, 2011

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

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

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

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

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

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

Applescript to export your iPhoto albums according to the hierachy

December 8, 2011

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!