個人檔案铁猪头相片部落格清單更多 工具 說明
31 December

山寨口号:“不折腾”

山寨威武!我相信写出这个口号的国务院秘书小文员同志在主席读出来的时候,真得笑到不行了~~~
 
我觉得中国的民族性已经没什么可以置疑的了,就是山寨精神啊!真拿来追的话,可以追溯到明清时候的很多传统,甚至回到史记汉书,都可以找到山寨的本色(比如刘邦同志,那位一生气了就拔着剑乱砍柱子的山寨皇帝),而且,我国文化中最神奇的部分莫过于用源远流长的用一本正经的话来解释山寨行为的传统:
 
王晨称,“胡锦涛总书记在纪念党的十一届三中全会召开30周年大会上发表的重要讲话,既有非常深刻的思想内涵,也有来自群众的一些生动的语言。我也注意到在大会上总书记讲到‘不动摇、不懈怠、不折腾’的时候,全场都发出会心的笑声,表达了大家对胡主席重要讲话的衷心赞同。”

  在说到自己对这句话的理解时,王晨提高了声调,高声说:“我觉得胡锦涛总书记在这样一个严肃的大会上,代表党中央这样一个重要的讲话中,总结 30年的经验、体会,说到‘不折腾’,我个人的理解就是表达了全党、全国人民总结30年的改革开放巨大成就,最根本的就是坚定不移地走中国特色社会主义道路,坚定不移地坚持中国特色社会主义理论体系,就是这样一个道路,不是别的什么道路,就是这样一个理论体系不是别的什么理论,我们中国在下一个30年、下一个50年就一定能够取得更大的成就,就一定能够发展得更好,屹立于世界民族之林。”

  王晨总结称,“不折腾”就是要我们沿着这条道路、这样一个方向继续奋勇前进,确实说出了全国人民的心声、全党的共同意志。

  值得一提的是,翻译在翻译“不折腾”这个词时,直接使用了汉语拼音的直译,引来会场全体记者的笑声。“不折腾”这个词,或许将会成为英语当中的一个专有名词。

蜘蛛精神

这回讨论一个大家电脑上都有的游戏:蜘蛛纸牌。
 
我真可耻,连这个东西都上瘾的不行,最后只好一起戒掉。但是当时上瘾时,总是觉得玩这个游戏的过程和科研很像。。。(此语曾经雷倒过人的。。。你们不是第一个。。。)
 
这玩艺的总体玩法是:挪来挪去,然后可以发大概5-6次牌,有10列,每次发牌会往每一列上加一张牌。目标是通过挪来挪去挪出2副牌4种花色都从K排到1。
 
蜘蛛的难度比曾经风靡一时的空档接龙要高出很多很多。空当接龙我很小的时候就可以随便来上个20-30连胜并且保持胜率在90%以上(貌似最高纪录是55连胜,后来实在打得恶心了就没连下去),而这个蜘蛛却是研究了几年拼死拼活才能把胜率打到80%,而且最高纪录只有11连胜。
 
它的最大特点是可以几乎无限次的悔,空当接龙只能悔一步(挪一次的undo回来),而蜘蛛只要:不发牌,不形成13张牌的一列,就可以无限次的悔下去,如果有足够耐心的话,就可以找到下一次发牌之前差不多最优的情况。
 
这个游戏的难点就在于,你经常会发现,在下一次发牌以后,如果你上一次只是差了一张牌没有挪到最优,也很有可能就死在这一张牌上。。。而且你其实并没有明确的判断什么局势是最优的函数,而只是凭大概的一些方向性的概念来猜怎样放比较好。
 
我之所以觉得和科研像,有三点:1。有很高的控制权(几乎无限次悔,不过有一次我悔了3000多步终于出bug不让我悔到完了)但是没有完全的控制权(不知道真正的最优,不知道怎样摆牌最好),空当接龙因为你可以看见所有的牌,所以可以认为是有完全的控制权的。而蜘蛛的话你大概只能看到表面上的一点点牌,差的很多。2。re-re-re-re-re-search,搜索啊搜索,悔啊悔,搜索啊,悔啊,最后简直必须得把状态空间都走完,就这样我还有20%的局打不成功。3。阴沟翻船,往往因为一个很小的地方没注意到,就完全的死了。。。
 
玩这个游戏的精神我称为蜘蛛精神,其主要特点就是把所有能试的都试一遍(。。。),但是这个试又不是真正的全搜索,因为总是有些地方是你试不了只能听天由命的,人所能做到的就是摆出一副看上去最像能通的样子然后等着上天发下下一波的牌。所以这里头又有眼光的成分,究竟放哪种局面比较好?这要靠眼光。但是,光有眼光,不把所有的可能性都试过,成功的概率是很低的。经常,有时觉得都已经进入了死局,但是一试再试之后发现,有那么一条狭长的小道它通向光明~~~~~~~~~~~~~~~~~就像做科研的时候一样。
26 December

不动摇,不懈怠,不折腾

胡总书记说:只要我们不动摇,不懈怠,不折腾,就一定能实现这一宏伟蓝图~~~
 
不折腾啊~~那看来中国改革真要转变方向啦。
23 December

小bug

上面提到的weave在GCC 4.3下编译通不过,原因是它没有包含<stdlib.h>。

解决方法:在/usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/blitz.h 57行#include <cmath>的
前后添上#include <cstdlib>即可。

Performance Python

http://www.scipy.org/PerformancePython

可以非常容易的把C++嵌入到Python里,速度远超MATLAB,直逼纯C++!代码简单至如下:
from scipy.weave import converters
def inlineTimeStep(self, dt=0.0):
"""Takes a time step using inlined C code -- this version uses
blitz arrays."""
g = self.grid
nx, ny = g.u.shape
dx2, dy2 = g.dx**2, g.dy**2
dnr_inv = 0.5/(dx2 + dy2)
u = g.u

code = """
#line 120 "laplace.py" (This is only useful for debugging)
double tmp, err, diff;
err = 0.0;
for (int i=1; i<nx-1; ++i) {
for (int j=1; j<ny-1; ++j) {
tmp = u(i,j);
u(i,j) = ((u(i-1,j) + u(i+1,j))*dy2 +
(u(i,j-1) + u(i,j+1))*dx2)*dnr_inv;
diff = u(i,j) - tmp;
err += diff*diff;
}
}
return_val = sqrt(err);
"""
# compiler keyword only needed on windows with MSVC installed
err = weave.inline(code,
['u', 'dx2', 'dy2', 'dnr_inv', 'nx', 'ny'],
type_converters=converters.blitz,
compiler = 'gcc')
return err

Here are some timing results for a 500x500 grid for 100 iterations. Note that we also have a comparison of results of using the slow Python version along with Psyco. (以上列的那段代码是下面表里的inline)

Type of solution

Time taken (sec)

Python (estimate)

1500.0

Python + Psyco (estimate)

1138.0

Python + NumPy Expression

29.3

Blitz

9.5

Inline

4.3

Fast Inline

2.3

Python/Fortran

2.9

Pyrex

2.5

Matlab (estimate)

29.0

Octave (estimate)

60.0

Pure C++

2.16


天哪, this kind of thing is a programmer's dream!

19 December

伤感

却不想说理由。反正小伤感而已,一会儿就过去的。

焰火音乐里的Larejouissance都不够了么?或者先来一段Liebesleid释放一下情绪?居然听的泪在眼眶内打转?接下来是Romance in F。

听琴音的感觉,就是脑子中的神经随着琴弦的震颤而震颤,随着琴弦的揉动而揉动。

记得当初下决心重新学琴,一个原因就是因为总是以为自己“听不懂”真正的古典音乐。现在,解决了这个问题,而且知道了以前本来也不是那么“听不懂”。音乐,无分古典和现代,能够让它和自己以同样的频率律动,就是懂了。如果需要非常细腻的律动频率,那么就适合听浪漫的曲子,如果需要非常强力的律动频率,那么就适合听强力的曲子。

随着Romance in F的结束,我也平静了。最后,需要让自己高兴起来,Gossec的Gavotte非常适合这个目的,so, let's go!
9 December

zz论坛上读到的一段MATLAB:Scipy comparison,深得我心啊

Comparing MATLAB’s stability with Scipy is not a fair comparison since MATLAB has had 20 more years to fix its bugs. Many years ago when I was an avid MATLAB user, I contributed some bug reports to MathWorks that caused me some headaches. But most of my headaches with MATLAB have nothing to do with bugs. First, its a horribly designed language created by electrical engineers who should have taken a course in language design prior to writing the language. Second, it promotes bad programming style; some users write clean code but most just learn enough to quickly hack together a filter that no one else can read. Third, its hard to spread computation across machines due to licensing limitations, causing needless tension among colleagues who are all fighting for licenses. People end up cutting experiments and moving on so less science gets done. Fourth, it is harder to collaborate with others because your collaborators must purchase MATLAB licenses to use your code. Fifth, it is primarily an interactive environment rather than a batch environment, encouraging experimentation and statistical analysis which is not reproducible. Sixth, it is difficult to work with any data structure other than a matrix (e.g. a graph, hash map, tree, lists, heaps). This is frustrating when needing to write algorithms requiring richer data structures.

Have you ever tried writing a large application in MATLAB? Are you familiar with MATLAB’s object oriented interface? It is unusable. Modifying a data member causes the object to be copied prior to modification. At some point, prototype code needs to make its way into a larger application. While most people intend to rewrite their prototype code in C or C++, it is often too costly to do so they end up writing their application in the same language as their prototype code, i.e. MATLAB.

You should not be surprised if there is symbol overlap in packages. It would be very difficult for two projects to maintain mutual exclusion in their namespaces. In general, it is bad programming practice to import everything. It should only be done at the python prompt, not in programs.

With regard to memory management, I was unable to handle large data sets with MATLAB. When Scipy came into the picture, I could handle much larger data sets. Also, I can pass very large arrays into functions and modify their contents without any copying. This is particularly helpful when dealing with a memory footprint that approaches the 2GB limit.

You raise a good point about complex data. However, MATLAB has its data type headaches as well. For example, if I have an int8 array (say an image), not all arithmetic operators are supported in MATLAB. Images often need to be converted to a double prior to doing arithmetic on them. That’s annoying, especially when you’re working with large images. I can do most arithmetic operations on int8 arrays in Scipy.

Often, the semantics of Python/Scipy can be quite different from MATLAB. This causes some frustration when migrating from MATLAB but this is temporary. Eventually, I believe the committed learner should find the Python/Scipy framework to be much more flexible.