9/30/2012

南懷瑾先生

南懷瑾先生有不少言論著作 他讀過相當多有關於佛釋道禪易等的古籍  也似乎練就一些養生之術  從他的著作 個人感覺他是以說書的方式在說一本書或講一個道理  也有他個人獨到的見解  有些可能與一般的見解有所歧異  不過大致上 還是有相通之處

雖說他修行已有相當長的一段時間 但他還是很自謙的說明一些修行時容易疏忽之處或要注意的誤點  我並不是很了解他對於一些輪迴之說或各種道理 到底是以解釋的方式來做解釋 還是以悟道後的方式來做解釋  無論如何  南懷瑾先生已離開這人世 也許這時他又有另一番體會了吧 也許他不會那麼意外吧

Outsourcing and Economy

What has outsourcing done to our economy?  One of the intentions to outsource the productions or services to other countries is cost cutting.  But the unfavorite consequences is that the original production labors or service labors are unemployed.  The unemployment could be temporary or permanent, it depends on how the worker's effort to get back to the job market.

As the worker is unemployed, it comes the unemployment benefits for a certain period of time.  After that if the worker still cannot find an employment, he might apply for some kind of welfare if he is in trouble of surviving.

So what's the macro economic view of the outsourcing?  As we know, money cannot come from nowhere and go nowhere.  The original payment to the worker is decomposed to: 1. the payment to the new worker(outsourcee) 2. the social benefits to the unemployed worker 3. the new extra profit to the outsourcer.  As item 1 and 3 are quite straight forward, where does the item 2 come from?  Don't forget that our society is a humane society.  We don't let our people die in hunger.

Wait a second, who pays the item 2 after all?  The benefit is paid and shared by all the tax payers, not just from the outsourcer.  So when a worker loses his job due to the outsourcing, not only his income is compromised, the other employed workers also have to share the pain.  The outsourcer share some pain too, but he also gets his extra profit.

Well, the other workers might get some benefits from the outsourcing due to the goods might be cheaper, or he gets hired to do the outsourcing work.  Really?  How do you verify this?  An easy way to check is that just asking yourself if you can buy more goods with your income.  If yes, it means outsourcing is making you richer and living better, because you get benefits from it.  If no, it means outsourcing is making you poorer, and you actually pay for it.

If outsourcing is actually making average people poorer in a developed society, how to fix it?  A simple idea might come from the concept of self sustainable society.  In a self sustainable society, they try to make their goods by themselves.

For example, if the company Xpple sells N Xphones in our society, Xpple should at least make N Xphones in our society.  Xpple is free to make money on the other M Xphones that are sold to other societies by making those M Xphones anywhere Xpple wants.  That's fair, isn't it.

Well, people might argue this approach does not work, is not good, or what so ever.  The key concept is to make our society sustainable.   A society with high inequality will not sustain quite well after all.

Is X related to Y?

As we are investors and speculators, we always want to forecast the future, so we would like to find correlations between Xs and Y.  Xs are any kind of historical data that could come from macro-economic indicators, weather reports, fundamental analysis, technical indicators, and almost anything that you can think of.  Y is what we want to forecast, most are like stock prices, prices of commodities, or market indices.

So what we usually do is to find the "correlation" between X and Y, defined as corr(X,Y).  Basically we can find all the corr(Xi,Y).  So if corr(Xi,Y) is closer to 1 or -1, we might think there is some kind of correlation between X and Y, assuming you have enough samples of data points.  What if corr(Xi,Y) is almost zero?  Is there no correlation at all? or no relationships at all?

When we exam all the corr(Xi,Y), we tempt to pick those value closer to 1 or -1, and use those Xi to do more advanced analysis.  We used to neglect the Xi, whose corr(Xi,Y) is close to zero.  Is this approach valid?

Let's take a look at a simple example, although corr(Xi,Y) is close to zero, actually Xi is "correlated" to Y, or the causation does exist.

Let's say, Y=XOR(X1,X2), X1 and X2 are random numbers of -1 and 1 with probability prob(-1)=prob(1)=0.5.  corr(X1,Y) and corr(X2,Y) are both zero.  But the relationship between (X1,X2) and Y does exist.

Most people who know XOR know how this trick works, but in real life, it's hard to imagine how this could be applied to data analysis.

A weird thing could happen is like that, when we try to find all the possible Xs:=X to forecast Y, and we define Y as f(X), f could be any kind of function, and we calculate corr( f(X),Y).  We want to find the best f, such that f makes corr(f(X),Y) close to 1.  So we can use f(X) to do some forecast.  As we know, X might not be complete, there might be some Xu not observed, or ignored due to corr(Xu,Y) is close to zero.  And corr(fu(X),Y) might be close to zero for some fu, either.  But actually Y=XOR(Xu,fu(X)).  If we ignore Xu or fu, there is no chance to find this relationship.

It means we have to pay attentions to those Xu and fu, even corr(Xu,Y) or corr(fu(X),Y) is close to zero.  So having no correlation(individually) could mean having correlation(communally)?

How many Xu and fu are there to check?


A Simple Compiler - finding the resource first

Do you want to build a simple compiler?

I always wanted to build a simple compiler when I was in the university, though my major was not CS.  I have tried some simple projects since then, such as using C style programming to implement LISP AI projects.  So basically I had to implement most of the LISP basic functions in C, and modify the original LISP codes to more C-like function calls.  It's not that difficult to do so, just it took a while to figure out the correct memory management schemes.


The other project I have tried to do is using C# to implement Prolog-like logic programming.  There is a Japanese education site that gives most of the details about the implementation.  Its starting chapter is Prolog in Python, if you are not familiar with Prolog, you'd better start from there.


So what if you want to build a compiler or interpreter for a language like VB or C, or other object oriented programming languages.  Most of the textbooks are quite complicated, it talks a lot about the details of the theory of a compiler.  But if you just want to start from a simple one and DIY, basically you don't want to know too much about the details.


I found there is an easy start with a Jack compiler that is mentioned in the book, The Elements of Computer Systems, its mainly in chapter 9, 10, & 11.  An education site for the study plan is here.  Some people have implemented it using java or C#.


If you are interested in Open Source, you may take a look at this book, flex & bison.  So what is flex and what is bison?  These are two great tools to help you build your compiler.  Basically you only have to define the grammar of your language, and they can do the lexical analysis and do the parse for you.  So your work can be focused on the code generation part.


So a basic compiler can be done by 3 workers: tokenizer, parser, and code generator.