Wednesday, November 23, 2011

Some Basic Installation Things about Java

1. Set JAVA alternative:

sudo update-alternatives --config java

2. Set the environment variables for Java:

2.1 type the command:  sudo vim /etc/profile

2.2 Then at the end of the "profile" document, type the following:

#set java environment
export JAVA_HOME=/usr/lib/jvm/java-7-sun

export JRE_HOME=/usr/lib/jvm/java-7-sun/jre

export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH

export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

2.3 Save the file. And type the following command to apply it immediately:
                        source /etc/profile

Wednesday, October 5, 2011

使用Eclipse的几个必须掌握的快捷键 + 改默认编码

转自:http://doggou.iteye.com/blog/211741

eclipse修改默认编码位置:菜单window->preferences->general->workspace->text file encoding

“工若善其事,必先利其器”,感谢Eclipse,她 使我们阅读一个大工程的代码更加容易,在阅读的过程中,我发现掌握几个Eclipse的快捷键会使阅读体验更加流畅,写出来与诸君分享,欢迎补充.


1. Ctrl+左键
这个是大多数人经常用到的,用来查看变量、方法、类的定义

2. Ctrl+O
查看一个类的纲要,列出其方法和成员变量。提示 :再多按一次Ctrl+O ,可以列出该类继承的方法和变量。
助记 :"O"--->"Outline"--->"纲要"

3. Ctrl+T
查看一个类的继承关系树,是自顶向下的,再多按一次Ctrl+T, 会换成自底向上的显示结构。
提示 :选中一个方法名,按Ctrl+T,可以查看到有这个同名方法的父类、子类、接口。
助记 :"T"------->"Tree"----->"层次树"

4.Alt+左右方向键
我们经常会遇到看代码时Ctrl+左键,层层跟踪,然后迷失在代码中的情况,这时只需要按“Alt+左方向键”就可以退回到上次阅读的位置,同理,按“Alt+右方向键”会前进到刚才退回的阅读位置,就像浏览器的前进和后退按钮一样。

5.Ctrl+Alt+H
如果你想知道一个类的方法到底被那些其他的类调用,那么请选中这个方法名,然后按“Ctrl+Alt+H”,Eclipse就会显示出这个方法被哪些方法调用,最终产生一个调用关系树。



Ctrl+D: 删除当前行 


Ctrl+Alt+↓ 复制当前行到下一行(复制增加)
Ctrl+Alt+↑ 复制当前行到上一行(复制增加)
Alt+↓ 当前行和下面一行交互位置(特别实用,可以省去先剪切,再粘贴了)
Alt+↑   当前行和上面一行交互位置(同上)
Alt+← 前一个编辑的页面
Alt+→ 下一个编辑的页面(当然是针对上面那条来说了)
Alt+Enter 显示当前选择资源(工程,or 文件 or文件)的属性
Shift+Enter 在当前行的下一行插入空行(这时鼠标可以在当前行的任一位置,不一定是最后)
Shift+Ctrl+Enter 在当前行插入空行(原理同上条)
Ctrl+Q   定位到最后编辑的地方
Ctrl+L 定位在某行 (对于程序超过100的人就有福音了)
Ctrl+M 最大化当前的Edit或View (再按则反之)
Ctrl+/   注释当前行,再按则取消注释
Ctrl+O   快速显示 OutLine
Ctrl+T   快速显示当前类的继承结构
Ctrl+W 关闭当前Editer
Ctrl+K   参照选中的Word快速定位到下一个
Ctrl+E 快速显示当前Editer的下拉列表(如果当前页面没有显示的用黑体表示)
Ctrl+/(小键盘) 折叠当前类中的所有代码
Ctrl+×(小键盘) 展开当前类中的所有代码
Ctrl+Space 代码助手完成一些代码的插入(但一般和输入法有冲突,可以修改输入法的热键,也可以暂用Alt+/来代替)
Ctrl+Shift+E 显示管理当前打开的所有的View的管理器(可以选择关闭,激活等操作)
Ctrl+J 正向增量查找(按下Ctrl+J后,你所输入的每个字母编辑器都提供快速匹配定位到某个单词,如果没有,则在stutes line中显示没有找到了,查一个单词时,特别实用,这个功能Idea两年前就有了)
Ctrl+Shift+J 反向增量查找(和上条相同,只不过是从后往前查)
Ctrl+Shift+F4 关闭所有打开的Editer
Ctrl+Shift+X   把当前选中的文本全部变味小写
Ctrl+Shift+Y   把当前选中的文本全部变为小写
Ctrl+Shift+F 格式化当前代码
Ctrl+Shift+P 定位到对于的匹配符(譬如{}) (从前面定位后面时,光标要在匹配符里面,后面到前面,则反之)
下面的快捷键是重构里面常用的,本人就自己喜欢且常用的整理一下(注:一般重构的快捷键都是Alt+Shift开头的了)
Alt+Shift+R 重命名 (是我自己最爱用的一个了,尤其是变量和类的Rename,比手工方法能节省很多劳动力)
Alt+Shift+M 抽取方法 (这是重构里面最常用的方法之一了,尤其是对一大堆泥团代码有用)
Alt+Shift+C 修改函数结构(比较实用,有N个函数调用了这个方法,修改一次搞定)
Alt+Shift+L 抽取本地变量( 可以直接把一些魔法数字和字符串抽取成一个变量,尤其是多处调用的时候)
Alt+Shift+F 把Class中的local变量变为field变量 (比较实用的功能)
Alt+Shift+I 合并变量(可能这样说有点不妥Inline)
Alt+Shift+V 移动函数和变量(不怎么常用)
Alt+Shift+Z 重构的后悔药(Undo)
Ctrl+Shift+U 选择选中的文字后非常类似于UE的列表查询
Ctrl+Alt+H 查看一个函数被其他函数调用的关系层次

UVA 100: The 3n+1 Problem

First Submit: Time Limit Exceeded!

Reason:  I was thinking about building up the whole table from 1 to max(startInt, endInt) in advance. However, this process take too much time, and most of the entries in the table cannot be used during the computation.

Second Submit: Wrong Answer!

Reason:  I forgot to set the result variable back to 0 at the end of each running instance.

Third Submit: Accept!

Source code:

#include <iostream>
using namespace std;

const int size = 1000001;

int table[size] = {0};

int calcCycleLength(int n) {
    if (n < size && table[n])
        return table[n];

    if (n & 1) { // n is odd.
        if (n < size) {
            table[n] = 2 + calcCycleLength( (3 * n + 1) >> 1 );
            return table[n];
        } else {
            return 2 + calcCycleLength( (3 * n + 1) >> 1 );
        }
    } else { // n is even.
        if (n < size) {
            table[n] = 1 + calcCycleLength( n >> 1 );
            return table[n];
        } else {
            return 1 + calcCycleLength( n >> 1 );
        }
    }
}

int main() {
    int startInt, endInt;
    int result = 0, temp;

    table[1] = 1;

    cin >> startInt >> endInt;
    while (!cin.eof()) {

        if (startInt > endInt) {
            int i;

            for (i = endInt; i <= startInt; ++i) {
                temp = calcCycleLength(i);
                if (temp > result)
                    result = temp;
            }

        } else {
            int i;
            for (i = startInt; i <= endInt; ++i) {
                temp = calcCycleLength(i);
                if (temp > result)
                    result = temp;
            }
        }

        cout << startInt << " " << endInt << " " << result << endl;

        result = 0;

        cin >> startInt >> endInt;
    }

    return 0;
}

Tuesday, September 13, 2011

Report for LLVM Project

I get the SVN version of LLVM.

There are two kinds of LLVM: LLVM source code, and LLVM GCC front end. What I'm trying is LLVM source code.

In Ubuntu, it has some bug if associated with dragonegg module:

https://bugs.launchpad.net/ubuntu/+source/dragonegg/+bug/787800

The above is the bug report, and the solution is in #3.

Bug happened when I used llvm to compile toy.cpp:


----------------------------------------------------------------------------------------------
toy.cpp: In member function ‘virtual llvm::Value* CallExprAST::Codegen()’:
toy.cpp:401:75: error: no matching function for call to ‘llvm::IRBuilder<>::CreateCall(llvm::Function*&, std::vector<llvm::Value*, std::allocator<llvm::Value*> >::iterator, std::vector<llvm::Value*, std::allocator<llvm::Value*> >::iterator, const char [8])’
/usr/local/include/llvm/Support/IRBuilder.h:1119:13: note: candidates are: llvm::CallInst* llvm::IRBuilder<preserveNames, T, Inserter>::CreateCall(llvm::Value*, const llvm::Twine&) [with bool preserveNames = true, T = llvm::ConstantFolder, Inserter = llvm::IRBuilderDefaultInserter<true>]
/usr/local/include/llvm/Support/IRBuilder.h:1122:13: note:                 llvm::CallInst* llvm::IRBuilder<preserveNames, T, Inserter>::CreateCall(llvm::Value*, llvm::Value*, const llvm::Twine&) [with bool preserveNames = true, T = llvm::ConstantFolder, Inserter = llvm::IRBuilderDefaultInserter<true>]
/usr/local/include/llvm/Support/IRBuilder.h:1146:13: note:                 llvm::CallInst* llvm::IRBuilder<preserveNames, T, Inserter>::CreateCall(llvm::Value*, llvm::ArrayRef<llvm::Value*>, const llvm::Twine&) [with bool preserveNames = true, T = llvm::ConstantFolder, Inserter = llvm::IRBuilderDefaultInserter<true>]
toy.cpp: In member function ‘llvm::Function* PrototypeAST::Codegen()’:
toy.cpp:409:54: error: no matching function for call to ‘llvm::FunctionType::get(llvm::Type*, std::vector<const llvm::Type*>&, bool)’
/usr/local/include/llvm/DerivedTypes.h:105:24: note: candidates are: static llvm::FunctionType* llvm::FunctionType::get(llvm::Type*, llvm::ArrayRef<llvm::Type*>, bool)
/usr/local/include/llvm/DerivedTypes.h:110:24: note:                 static llvm::FunctionType* llvm::FunctionType::get(llvm::Type*, bool)
--------------------------------------------------------------------------------------------------

Tuesday, June 7, 2011

Log for June 7th, 2011

In code.l, the path of parsing the class body is:

<Body>"class"  =>   <ClassName>   => <ClassVar>  =>  <Body>

And the function definition or declaration is dealt with in <Body>.


Timestamp: 16:14
--------------------------------------------------------

Monday, June 6, 2011

Log for June 6th, 2011

Today, I applied for New Mexico Non-Driver ID, and went to Motor Vehicle Division with Jim. The materials I brought were Passport, SSN card, latest Bank Statement, and Apartment Rental Agreement. The process was very successful and no exception happened.

Then about the book The History of Western Philosophy, I finished reading Plato's theory of ideas. This is the main part of Plato's book Republic, and here he tried to define the concept "philosophy", "knowledge", "reason", and "understand". Philosophy means the love of wisdom. In Plato's thought, wisdom is different from the things we can perceive. In the sense of metaphysic, say, there are many particular cats, and we call them all "cat". However, there should exist one perfect cat, which was created by God, to designate all attributes of a cat. Then what we can see in reality are all imperfect cats. Similarly, the beautiful things are quite vary, but the beauty behind them remains the same. A person who likes different beautiful music, books, flowers, etc. is just the one who love for beautiful things, but doesn't realize the beauty itself. In Plato's theory, all facts and knowledge are eternal, infallible, and immutable. And most of us humans, in a parable, are prisoners in the dark crime. We face the wall, and there is a fire behind us. What we are able to see are just shadows which has been made by the fire. But the philosophers are the group of persons who can break through the prison and are able to see the real things through the sunshine. And the guardians from this group are the persons who are brave to return to the prison, and make the rest people realize their situation and be accompany with them to break the prison and see the facts instead of the illusions.

For Meta-Math project, now I come across two bugs. One is for the following situation:

class SomeClass {
       private:
               int x;
       public:
              int getX(void);
};

int SomeClass::getX(void) {
         return x;
}

Doxygen cannot parse "int getX(void);" correctly. Actually, the bug is that when it deals with this case, then the current member object is NULL. But if working well, it should be the function's name "getX" or "SomeClass::getX".

The other bug is that Doxygen is not able to add the related MetaReference record for the member function invocations like:

a::c();
a.c();
a->c();
(*a)->c();
(*a).c();

This is what I should fix after the first bug.

Next, I shall test whether Doxygen works well for the nested class definiton case. Like,

Class Class1 {
         Class Class2 {
                   ...
         };
         ...
};

Thursday, April 14, 2011

Mission for April 14th

1. 詩經·檜風·匪風
2. Implemented Set, P_queue, Stack ADTs in C++

Meta-Math For Today:

1.  A way to defining customized command:

In the ``ALIASES" section of the configure file, create the command by ``name=value" format.

E.g.: If we want to create a command "@Unit" such that "@Unit{Meter}" can refer to "<unit>Meter</unit>" in the resulting XML file, we can define our customized command as follows:

ALIASES     +=     Unit{1}=<unit>\1</unit>

2. The "@param" and "@retval" commands in Doxygen can specify the name of the target variables.

Wednesday, April 13, 2011

Summary for April 13th

Achievement:

1. Implemented the moving rules for 8 puzzle problem in C++.
2. Solve one problem in HW3 CS 500.
3. Learn 詩經·檜風之素冠,隰有萇楚.
4. Practice Taiji and Kendo.

Improvement:

I should have finished C++ implementation for 8 puzzle and sliding tile problems. Besides, I should have spent hours on Meta-Math project. For most of this semester, I didn't pay enough attention on it, so there's no concrete progress on this project, which makes me upset and ashamed. Though Prof. Kniss said nothing about it, I still have to work more diligently on it.

It's near the final of the semester, and there are many works should be finished by then. I should work harder so as to finish them perfectly.

顽张ってね!

Sunday, March 6, 2011

Some thoughts about NP Problems

Due to the book "Nature of Computation", consider a problem A, if there exists a witness w such that (x, w) is a yes-instance of B, where B is a decision problem in P regarding pairs (x, w), and x is a yes-instance of A, and where |w| = poly(|x|), then this problem A can be classified as a member of the set NP.

So consider the Minimum Spanning Tree (aka. MST) problem, given a spanning tree T, and we are requested to check whether it is the solution for the graph G. Though T can be regarded as the witness w and |w| = poly(|V| + |E|). However, because we don't know the sum of weights of the MST of G in advance, then we have two methods to check this instance.

The first one is to use either Prim's or Kruskal's Algorithm to generate a MST of G and compare its sum of weights with that of T. If they are equal, then this instance is a yes-instance.

The second method may seem a little bit more complicated. We can take advantage of Lemma 3.1. Namely, during each iteration we choose one edge of T and add it in the set T' which is initially empty. Then we check the edges connecting T'.V and (G - T').V. If this edge is the lightest one among those across these two subsets, then we continue this iteration. If not, we just terminate the algorithm and say that T is not a yes-instance. If all the edges in T are checked and there's no termination, we can end the algorithm and say that T is a yes-instance of this problem.

Comparing the above two methods, I'll buy the first one. 

Thursday, January 6, 2011

Thoughts about Machine Learning

In the book "All of Statistics", the author believed that Machine Learning should be called Statistical Inference in order to reveal its core thoughts. However, I've found that Machine Learning should be much more than that. It contains many thoughts in Neural Science and Clustering, besides Bayesian Inference and Hypothesis Test.

Nowadays, Machine Learning is becoming more and more popular, -- not only among scientists of Computer Science and Statistics, but almost everyone in the fields of Natural and Social Science. I don't know whether scholars in Art, Humanities or History are interested in Machine Learning. But I hope not.

I don't whether it is a good news that it becomes so popular. More and more smart persons are working on it, but I see no theoretical breakthrough hitherto. And I don't want to join this revelry.

I know that statistics can be used as a concrete tool to resolve many real-world problems perfectly. I will learn it well. But I don't believe that it can be the Messiah for science, especially for Artificial Intelligence.

My purpose of studying science is to know deeply about western philosophy. I like the feeling that I can help promote the world, but I don't want to be an engineer. I want to be a teacher -- not a teacher in high school or primary school, but a teacher of both Oriental and Western cultures and philosophies.

Thus, I cannot be crazy about Machine Learning. I will step towards the kernel of Artificial Intelligence without any stop. For ML, I regard it as a concrete tool, but not a comprehensive theory which can help me reach the philosophy hiding behind it.