Google Translate

2014年11月6日星期四

MinGW w64 在Windows下的安装方法

1. 安装msys2

2. path: C:\msys64\usr\bin;
             C:\msys64\mingw64\bin

3. pacman -Syu


4. pacman -S git

    pacman -S make
    pacman -S mingw-w64-x86_64-gcc
    pacman -S mingw-w64-x86_64-gdb

2014年10月16日星期四

安装boost

Windows, In cmd:
1. Build bjam.exe

cd ###\boost_1_56_0\tools\build\src\engine\

build.bat gcc

And bjam.exe is ready in ###\boost_1_56_0\tools\build\src\engine\bin.ntx86\

copy bjam.exe to  ###\boost_1_56_0\

2. Build

bjam install --toolset=gcc --prefix="C:/Boost_1_56_0"




Linux: (??)

./build.sh

bjam install --toolset=gcc

2014年8月25日星期一

HMM实现 [<转载>]

C语言版:
1、 HTK(Hidden Markov Model Toolkit):
        HTK是英国剑桥大学开发的一套基于C语言的隐马尔科夫模型工具箱,主要应用于语音识别、语音合成的研究,也被用在其他领域,如字符识别和DNA排序等。HTK是重量级的HMM版本。
        HTK主页:http://htk.eng.cam.ac.uk/
2、 GHMM Library:
        The General Hidden Markov Model library (GHMM) is a freely available LGPL-ed C library implementing efficient data structures and algorithms for basic and extended HMMs.
        GHMM主页:http://www.ghmm.org/
3、 UMDHMM(Hidden Markov Model Toolkit):
        Hidden Markov Model (HMM) Software: Implementation of Forward-Backward, Viterbi, and Baum-Welch algorithms.
        这款属于轻量级的C语言HMM版本。
C++版:
        以上两个是C++版本的,但是实现的是离散型的HMM。
Java版:
        Jahmm Java Library (general-purpose Java library):
        Jahmm (pronounced “jam”), is a Java implementation of Hidden Markov Model (HMM) related algorithms. It’s been designed to be easy to use (e.g. simple things are simple to program) and general purpose.
        Jahmm主页:http://code.google.com/p/jahmm/
Python版:
Malab版:
        Hidden Markov Model (HMM) Toolbox for Matlab:
        This toolbox supports inference and learning for HMMs with discrete outputs (dhmm’s), Gaussian outputs (ghmm’s), or mixtures of Gaussians output (mhmm’s).
Common Lisp版:
        CL-HMM Library (HMM Library for Common Lisp):
        Simple Hidden Markov Model library for ANSI Common Lisp. Main structures and basic algorithms implemented. Performance speed comparable to C code. It’s licensed under LGPL.
Haskell版:
        The hmm package (A Haskell library for working with Hidden Markov Models):
        A simple library for working with Hidden Markov Models. Should be usable even by people who are not familiar with HMMs. Includes implementations of Viterbi’s algorithm and the forward algorithm.
        Haskell-HMM主页:http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hmm
        注:Haskell是一种纯函数式编程语言,它的命名源自美国数学家Haskell Brooks Curry,他在数学逻辑方面上的工作使得函数式编程语言有了广泛的基础。
CDHMM C++版:
        连续HMM的C++实现:http://download.csdn.net/detail/luxiaoxun/4417043
        注:这是网上找的,里面实现有个连续的HMM-GMM的实现,代码写的很好,有些地方需要根据自己的需求改动。

2014年8月2日星期六

zz 如何在DSM系统上安装迅雷离线!!

迅雷远程经过一段时间的完善,到目前一切都变得相当简单了。

一、准备文件

下载迅雷官方远程固件 Xware
此处插入固件下载地址 http://g.xunlei.com/forum-51-1.html
最新版查看地址:http://luyou.xunlei.com/forum-51-1.html

二、上传文件

  • 在 DSM 的"控制面板","终端机和SNMP"中,勾选"启动SSH功能"
  • 用 Putty SSH 登录到 DSM,(用户名:root,密码同 admin 帐号密码),切勿用 admin 登录,貌似会有问题。
  • 新建一个目录,用于存放迅雷远程固件 Xware,放到 DSM 官方程序的指定文件夹/volume1/@appstore/下,命令如下:
mkdir /volume1/@appstore/Thunder
  • 将解压后的 Xware 固件文件拷贝到 Thunder 目录,可以先把文件拷贝到共享文件夹,然后通过再 Putty 中运行如下命令,我是先把固件文件拷贝到一个叫 file 的共享文件夹。
cp /volume1/file/* /volume1/@appstore/Thunder
  • 设置 Thunder 文件夹权限,命令如下:
chmod -R 777 /volume1/@appstore/Thunder

三、安装固件

  • 运行固件安装命令:
/volume1/@appstore/Thunder/portal
在出现的回显中,有类似如下的语句:
THE ACTIVE CODE IS:XXXXXX
其中 XXXXXX 就是需要的激活码,先复制
  • 打开迅雷远程网页http://yuancheng.xunlei.com,选择NAS,然后填入刚才复制的激活码。
  • 迅雷默认会在本地创建路径为 /volume1/TDDOWNLOAD 的文件夹,用于存放下载文件,但是默认该文件夹不会显示,需要在 DSM 的共享文件夹中,赋予该文件夹 admin 帐号可读写的权限,因为之前是用 root 运行的迅雷,文件夹权限只赋予了 root。设置完成后,TDDOWNLOAD就可以正常显示出来了。
  • 可根据需要,在迅雷远程网页中可以配置设备的下载路径,不过最好不要设置成 /volume1/download,设置成 download 以后,偶尔download 这个共享文件夹的权限会消失,必须修复 admin 的共享文件夹权限。

四、设置任务计划

在 DSM 中添加任务计划,设置为每个小时运行一次,所有者选择root(若选admin,迅雷将不能正常启动)
/volume1/@appstore/Thunder/portal

2014年7月13日星期日

茶与咖啡因

茶的咖啡因含量大约是茶叶干重的2%左右(一般不超过5%) 红茶含量相对高,绿茶相对低。

加拿大政府推荐每日咖啡因摄入不超过400mg.

咖啡因主要由肝脏代谢,半衰期大约为3-4小时。当然因人而异。

咖啡因的提神效果也是因各人的咖啡因耐受性而异。

Personally, 多喝绿茶少喝红茶吧~~

2014年6月30日星期一

简明中国古代史 编年 (转载)

中国古代史,始于大约170万年前的元谋人,止于1840年的鸦片战争前,是中国原始社会、奴隶社会和封建社会的历史。
  中国近代史的时间为,从1840年鸦片战争到1949年中华人民共和国成立前,这也是中国半殖民地半封建社会的历史。中国近代史分为前后两个阶段,从1840年鸦片战争到1919年“五四”运动前夕,是旧民主主义革命阶段;从1919年“五四”运动到1949年中华人民共和国成立前夕,是新民主主义革命阶段。
  1949年10月1日中华人民共和国的成立,标志着中国进入了社会主义革命和建设时期。
    夏……………………………约公元前2070——约公元前1600
    商………………………………约公元前1600——公元前1046
    周………………………………… 公元前1046——公元前221
      ——西周…………………… 公元前1046——公元前771
      ——东周……………………………公元前770——前256
      ——春秋……………………………公元前770——前476
      ——战国……………………………公元前475——前221
    秦…………………………………………公元前221——前206
    汉………………………………………公元前202——公元220
      ——西汉………………………………公元前202—公元8
      ——东汉………………………………… 公元25——220
    三国……………………………………………公元220——280
      ——魏……………………………………公元220——265
      ——蜀……………………………………公元221——263
      ——吴……………………………………公元222——280
    晋………………………………………………公元265——420
      ——西晋…………………………………公元265——316
      ——东晋…………………………………公元317——420
    十六国…………………………………………公元304——439
    南北朝…………………………………………公元386——589
      ——北朝…………………………………公元386——581
      ——南朝…………………………………公元420——589
    隋………………………………………………公元581——618
    唐………………………………………………公元618——907
    五代十国………………………………………公元907——979
    宋…………………………………………… 公元960——1276
      ——北宋……………………………… 公元960——1127
      ——南宋………………………………公元1127——1276
    辽…………………………………………… 公元916——1125
    西夏…………………………………………公元1038——1227
    金……………………………………………公元1115——1234
    元……………………………………………公元1271——1368
    明……………………………………………公元1368——1644
    清……………………………………………公元1644——1911
    中华民国……………………………………公元1912——1949
    中华人民共和国………………………… 1949年10月1日成立
中国古代史,始于大约170万年前的元谋人,止于1840年的鸦片战争前,是中国原始社会、奴隶社会和封建社会的历史。

2014年6月13日星期五

Binary trees -- traversal, insertion, deletion, and balancing.

这一章比较纠结,可浅可深。既然是伪技术总结,就只提一提要点就好了。

1. Traversal

i) Breadth First: The key is to use a queue to maintain the traversal...two steps as follow.
a) Enqueue root.
b) while (queue != null)
        {
         qPointer = Dequeue;
         visit qPointer;
         Enqueue left and right children of the qPointer.
}

ii) Depth First: Inorder, Preorder and Post order.
L - Left sub tree; R- Right sub-tree; V = visit (access) the node;

Easy in using recursion,
Inorder = LVR.
Preorder = VLR.
Postorder = LRV.

A bit complicated in using non-recursive methods.
a) by maintaining a stack, traversal can be implemented using iterations.
b) using a threaded tree can avoid the stack.
c) Morris's algorithm can avoid both a) and b) to traversal a tree through tree transformation. (complicated...)

In general, recursive methods has better readable code with marginal cost of performance. However, for certain cases, e.g., ultimate performance to be achieve or suffering stack overflow, non-recursive methods or Morris's algorithms has to apply!!

2. Insertion in threaded tree and deletions.

i) insertion.
the key points are using two pointers, prev and p. Consider element el to be inserted. Keep going until these three stop criterion.

a) if (el < p -> el) prev = p and p go left (p = p -> left) until p == nullptr;
b) if (el > p -> el and thread indicator == 0) prev = p and go right until p == nullptr;
c) if (el > p -> el and thread indicator == 1) stop;

How to insert:
a) if (el < prev -> el) insertion is the left child of prev, successor of the child is prev.
b) else if (prev -> successor) means parent of the insertion is not the rightmost node, so, prev -> right = insertion. make parent's successor the insertion's successor.
c) else prev -> right = insertion. (prev is the rightmost node, just insert new node to the right side.)

This is important and very easy to make mistakes when assigning the successor indicator....


ii) deletion.
By merging or copying we could delete a node that has sub-trees on both of its left and right side.

Merging increases the tree depth significantly while copying method has to consider the balancing issue in those problems of many deletion and insertion operations.

3. Balancing
AVL and black-red trees are similar. Specifically, black-red tree is the underlying implementation of (sorted) map and set in STL in C++!!

Eizo ev2336w VS Asus PA238q in panels, colour and flicker free

My PA238q was bought in 2012 and today comes the Eizo ev2336w.

There are resources online suggesting that ev2336w is native 8bit PLS panel with 10bit LUT whilst PA238q is 6-bit E-IPS and 8/10 LUT. Nevertheless with a side-by-side comparison of these two monitors, PA238q outperforms ev2336w in the colour test using the following picture. Both monitor setting in the default sRGB mode (ev2336w with display port & pa238q with hdmi), PA238q can distinguish the leftmost colours while ev2336w can only do 1 step worse -- the most left two blocks are displayed in one colour...


Ideally, I was expecting ev2336w provide as least equivalent colour performance to my old PA238q, but I have to be a little disappointed. Nevertheless, ev2336w provides much better colour than iiyama x2783HSB, which adopts the latest amva+ panel (I am returning it....). Based on this results, my personal intention will be that pa238q is native 8bit and 10bit LUT (pB238q is for sure degrade to 6bit e-ips...) and ev2336w is possibly native 6bit panel and 8bit LUT. Both have impressively colour deviations. ASUS officially guarantees delta E < 5 and Eizo is Eizo.

Speaking to the flicker free, it is my motivation to buy ev2336w in the first place. Eizo used DC to control brightness from range 20%-100% and PMW from 0-20%. PA238q uses PMW all the time but high (some said > 2khz) the frequency to avoid possible screen flickering when brightness is low. Both methods seems great in practice. However, pa238q will generate high frequency pitch when brightness is less than 90% in my case, by which I can only use less contrast to make my eyes less tired rather than by directly reducing the brightness.

In all, both monitors are fantastic! They are trading off the quality of panel and the quality of the product overall. Ideally, one for coding and the other phtoshopping.:-)

2014年6月4日星期三

Data structure 之 Linked List

Key summaries of linked list chapter from Drozdek's Data Structures and Algorithms in C++.

Lists mainly consists of 2 classes, one for node and list for the other. Nodes comprise elements to store and pointers to be linked while List is maintaining the "Head", "Tail" and functions for interface and implementation(e.g., insert, search, etc.).

1. Fundamental lists: singly and doubly linked list.

Nodes of singly linked list has one pointer pointing to the next while doubly linked list contains two pointers. Examples follow by the end of the text.

2. Skip lists and self organising lists.

Skip list is overwhelmingly better in searching with the complexity of lg(n).

self organising lists consist of:
i) move-to-front. (one been searched jumps to the head or tail)
ii) transpose.(one been searched float-up or sink-down by one position)
iii) count    (descent by the frequency been searched)
iv) ordering  (by certain criterion, e.g., alphabetical)

In terms of efficiency (approximately and regardless of the cost on pointers):

i) == iii) > ii)
i) == iii) > iv)

3. "Two one-dimensional arrays of linked lists" to establish compact index which saves storage space.


#1. class declarations for singly and doubly linked lists.
class IntSingleList
{
public:
    IntSingleList() : info(0), next(nullptr) {}
    IntSingleList(int in, IntSingleList* pn = nullptr) : info(in), next(pn) {}

int info = 0;
IntSingleList* next;
};

class IntSLList
{
public:
    IntSLList() : head(nullptr), tail(nullptr){}
    ~IntSLList();
    int isEmpty()
    {
        return head == nullptr;
    }

    void addToHead(int);
    void addToTail(int);
    int deleteFromHead();
    int deleteFromTail();
    void deleteNode(int);
    bool isInList(int) const;

private:
    IntSLLNode* head = nullptr, *tail = nullptr;

};

#2. Example of skip list.

//---------------------------
//skipList.h
const int maxLevel = 4;
template<typename T>
class skipListNode
{
public:
    skipListNode() = default;
    skipListNode(const T& k, skipListNode *nt = nullptr) : key(k), next(nt){}
    T key;
    skipListNode *next = nullptr;

};
template<typename T>
class skipList
{
public:
    skipList() = default;
    bool isEmpty() const;
    void choosePowers();
    int chooseLevel();
    T* skipListSearch(const T&);
    void skipListInsert(const T&);

private:
    typedef skipList<T> *nodePtr;
    nodePtr root[maxLevel] = {nullptr};
    int powers[maxLevel] = {0};
};
//----------------------------------
//skipList.cpp

template<class T>
bool skipList<T>::isEmpty() const
{
    return root[0] == nullptr;
}

template<class T>
void skipList<T>::choosePowers()
{
    powers[maxLevel - 1] = (2 << (maxLevel-1)) - 1; // 2 ^ maxLevel - 1
    for (int i = maxLevel - 2, j = 0; i >= 0; --i, ++j)
        powers[i] = powers[i+1] - (2 << j); // 2 ^ (j+1)
}

template<class T>
int skipList<T>::chooseLevel()
{
    std::default_random_engine e;
    int i, r = e() % powers[maxLevel-1] + 1;
    for (int i = 1; i < maxLevel; ++i)
        if (r < powers[i])
        return i-1;
    return i-1;
}

template<class T>
T* skipList<T>::skipListSearch(const T& key)
{
    if (isEmpty())
        return nullptr;
    nodePtr prev = nullptr, curr = nullptr;
    int lvl = 0;
    for (lvl = maxLevel - 1; lvl >= 0 && !root[lvl]; --lvl);    //find the highest non-null level;
    prev = curr = root[lvl];
    while(true)
    {
        if(key == curr->key)
            return &curr->key;
        else if (key < curr->key)
        {
            if (!lvl)
                return 0;
            else if (curr == root[lvl])
                curr = root[--lvl];
            else curr = *(prev->next + --lvl);
        }
        else
        {
            prev = curr;
            if (*(curr->next + lvl) != 0)
                curr = *(curr->next + lvl);
            else
            {
                for (lvl--; lvl >=0 && *(curr->next + lvl) == 0; --lvl);
                if (lvl >= 0)
                    curr = *(curr->next + lvl);
                else return 0;
            }
        }
    }
}

template<class T>
void skipList<T>::skipListInsert(const T& key)
{
    nodePtr curr[maxLevel], prev[maxLevel], newNode;
    int lvl, i;
    curr[maxLevel-1] = root[maxLevel-1];
    prev[maxLevel-1] = 0;
    for (lvl = maxLevel - 1; lvl >= 0; --lvl)
    {
        while (curr[lvl] && curr[lvl]->key < key)
        {
            prev[lvl] = curr[lvl];
            curr[lvl] = *(curr[lvl]->next + lvl);
        }
        if (curr[lvl] && curr[lvl]->key == key)
            return;
        if (lvl > 0)
            if (!prev[lvl])
        {
            curr[lvl-1] = root[lvl-1];
            prev[lvl-1] = 0;
        }
        else
        {
            curr[lvl-1] = *(prev[lvl]->next + lvl-1);
            prev[lvl-1] = prev[lvl];
        }
    }
    lvl = chooseLevel();
    newNode = new skipListNode<T>;
    newNode->next = new nodePtr[sizeof(nodePtr) * (lvl+1)];
    newNode->key = key;
    for (i = 0; i <= lvl; ++i)
    {
        *(newNode->next + i) = curr[i];
        if (prev[i] == 0)
            root[i] = newNode;
        else *(prev[i]->next + i) = newNode;
    }
}

2014年5月28日星期三

C++ 类的继承 -- private

基类指针(or ref)可以指向 所有 的子类 (e.g., overriding),除了private 子类的所有子类 。意味着 private class 可用于隔断上下层的类的访问。

e.g., void memfcn (Base &b) { b = *this;} in class drv_from_Drv3


class Base
{
public:
    double dBPublic = 0.1;
protected:
    double dBProtect = 0.2;
private:
    double dBPrivate = 0.3;
};

class Drv1 : public Base
{
public:
    double dpubdrvPublic = 1.1;
    void memfcn(Base &b) {b = *this;}
protected:
    double dpubdrvProtect = 1.2;
private:
    double dpubdrvPrivate = 1.3;
};

class Drv2 : protected Base
{
public:
    double dprodrvPublic = 2.1;
    void memfcn(Base &b) {b = *this;}
protected:
    double dprodrvProtect = 2.2;
private:
    double dprodrvPrivate = 2.3;

};

class Drv3 : private Base
{
public:
    double dpridrvPublic = 2.1;
    void memfcn(Base &b) {b = *this;}
protected:
    double dpridrvProtect = 2.2;
private:
    double dpridrvPrivate = 2.3;

};

class drv_from_Drv1 : public Drv1
{
public:
    double dpubdrvPublic = 3.1;
    void memfcn(Base &b) {b = *this;}
protected:
    double dpubdrvProtect = 3.2;
private:
    double dpubdrvPrivate = 3.3;
};

class drv_from_Drv2 : public Drv2
{
public:
    double dpubdrvPublic = 4.1;
    void memfcn(Base &b) {b = *this;}
protected:
    double dpubdrvProtect = 4.2;
private:
    double dpubdrvPrivate = 4.3;
};

class drv_from_Drv3 : public Drv3
{
public:
    double dpubdrvPublic = 5.1;
    void memfcn(Base &b) {b = *this;} //编译报错.
//原因: Drv3 is private, all the member that Drv3 inherit from Base are private.


protected:
    double dpubdrvProtect = 5.2;
private:
    double dpubdrvPrivate = 5.3;
};