线性代数:矩阵&矩阵计算

矩阵本身的理解:

  •  矩阵本身包含基变换,每一列都是从V到W的空间变换:https://www.zhihu.com/question/22218306/answer/88697757

 

单位矩阵(I)

初等矩阵:I经过三种不同的变化

酉矩阵:n阶复方阵U的n个列向量是U空间的一个标准正交基,则U是酉矩阵(Unitary Matrix)。显然酉矩阵是正交矩阵往复数域上的推广。酉矩阵又称为幺正矩阵。充要条件是:方阵U的共扼转置乘以U等于单位阵,则U是酉矩阵。

共轭转置:在实数域,等价于转置;在复数域,是转置后对每个元素取复共轭。

正交矩阵:实数域的酉矩阵

 

对称矩阵 对称矩阵(Symmetric Matrices)是指元素以主对角线为对称轴对应相等的矩阵。 在线性代数中,对称矩阵是一个方形矩阵,其转置矩阵和自身相等。

若尔当标准型:

 

协方差矩阵

正定矩阵,半正定矩阵:

特征值分解

奇异值分解

行列式

相似矩阵

 

矩阵乘法直观理解

– 公交车模型(基变换 or 运动):https://www.zhihu.com/question/21351965

 

 

ref: https://zh.wikipedia.org/wiki/%E7%9F%A9%E9%98%B5%E5%88%86%E8%A7%A3

矩阵乘法理解
Av:
– 向量空间角度:以A (mxn, m行n列),每列为空间基A[:0], A[:1], …, A[:n],v(n维向量)则是对n个基进行线性组合
– 线性变换角度:以A每一行为向量A[0:], A[1:], …, A[m:], 则每一个向量都是对v的一个操作

-错误理解:换空间基:以A每一行为向量,构成一组空间基,则A[i:]v 是v在A[i:]这个基上的投影长度:这是错误的

特例:
MB:
– 视A每列为一组基,如果B是对角矩阵,则AB是对这组基分别进行扩大和缩小,另外形成一个空间
– 线性变换:M有m组操作(行),B有k个输入(列),所以结果应该是对每一个操作,每一个输入都有一个结构,构成mxk结果

正交矩阵

特征值分解的运动方式理解:https://www.zhihu.com/question/21874816/answer/181864044

特征值:wiki
特征向量:wiki

QR分解:wiki
特征分解:wiki
奇异值分解:wiki

ref:

– 知乎:如果直观理解线性代数

– https://yjango.gitbooks.io/superorganism/content/xian_xing_dai_shu.html

Determining Optical Flow

paper link: http://www.caam.rice.edu/~zhang/caam699/opt-flow/horn81.pdf
这篇1981年发表的文章是CV中众多optical flow文章的起始工作,我花了三天时间自习阅读该文章,亦可称的上是我读CV文章的起源。

文章贡献:
提出一种计算光流的方法

文章思路:
一个点的亮度信息E(x,y,t)不足以计算光流,因为光流是二维的向量,亮度只有一维。文章通过一系列假设的条件,引入两个约束:
– 一个点的亮度在时间维度不变:E对x,y,t的偏倒之和为0
– 一个刚体内部相邻点光流平滑过渡:u, v对x,y 偏倒之和最小

具体方案
– 以上两个约束虽然可以求解,但是计算量很大
– 使用迭代的方法来求解有效降低计算量

后续
后续光流又提出很多算法,参考:http://blog.csdn.net/zouxy09/article/details/8683859

ubuntu setup

init Ubuntu OS
zh#选择最好的源
#add source list
#sudo gedit /etc/apt/sources.list
#ibus 源
#deb http://ppa.launchpad.net/ubuntu-x-swat/xserver-no-backfill/ubuntu jaunty main
#deb-src http://ppa.launchpad.net/ubuntu-x-swat/xserver-no-backfill/ubuntu jaunty main

#sudo apt-get install perl

#install openwebmail
#gedit /etc/apt/sources.list
#deb ftp://debian.tnc.edu.tw/pub1 b2d/
#sudo apt-get update
#sudo apt-get install openwebmail

#vnc
sudo apt-get install vnc-common vnc4server xvnc4viewer
#设置系统-》首选项-》安全-》允许远程&不需要确认
.vnc/xstartup 最后一行替换为 “gnome-session &”

sudo apt-get install openssh-server

#各种解码器,汉化包
#之前一定要在#System->Language Support->Chinese选上

#给apt设置代料 – In Tsinghua
#export http_proxy=http://netarch246:netarch@202.112.49.246:8080

#禁用pango
#sudo gedit /etc/environment
#MOZ_DISABLE_PANGO=”1″

#新建用户
#sudo adduser test1
#添加到某个组
#sudo gpasswd -a <账号> <组名>
#eg: sudo gpaswd -a admin test1

#要加入这几个组:adm (使用sudo) dialout (拨号) cdrom (使用光驱) plugdev (使用U盘等) lpadmin (使用打印机) admin (使用sudo) sambashare (使用samba共享) users (默认组)

#sudo gpasswd -a test1 adm

# 添加sudo用户
#还不属于别的组
#sudo usermod -G admin username
#已经属于别的组
#sudo usermod -a -G admin username

#安装ns2&nam 所需的软件包,需要重新编译nam,并将其nam执行文件移到bin目录下,并且需要安装g++

sudo apt-get install -f libxt-dev libxt6 libsm-dev libsm6 libice-dev libice6 libxmu-dev
#sudo apt-get install g++

#Trash place
$HOME/.local/share/Trash/

#firefox flash plugin
#http://get.adobe.com/flashplayer/thankyou/?installer=Flash_Player_10_for_Linux_(.deb)

#ibus
#sudo aptitude install ibus ibus-gtk
#在Ubuntu Tweak中启用iBus 1.2的源。
#在Ubuntu Tweak中安装ibus-pinyin。
#im-switch -c

#sudo aptitude remove ttf-mscorefonts-installer

#downthemAll, GooglePreview

#gftp 乱码
#sudo locale-gen zh_CN.GBK
#sudo gedit /usr/bin/gftp在#!/bin/sh之后加上export LANG=zh_CN.GBK
#在系统——首选项——主菜单里面找到gftp的菜单项,右键属性后发现其启动命令是gftp-gtk %u,果然与终端启动的命令不同
#于是我把这个启动命令改成gftp。然后重新从应用程序——互联网——gftp启动,果然问题解决了。

#让gedit默认打开编码为2312
#gconf-editor–>app–>gedit2–>preferences–>encodings 记入编码GB2312,
################################before install################################

#flash:
#sudo wget http://ubuntu:ubuntuftp@ftp.ubuntu.org.cn/home/dbzhang800/wiki/install_flash_player_10_linux.deb

#music player
sudo apt-get install audacious

#BT down software
#deluge

#LAMP: apache2 mysql php
sudo apt-get install apache2 mysql-server php5 php5-mysql php5-gd phpmyadmin
#php5-gd:phpmyadim

#tweak tool
sudo aptitude ubuntu-tweak

sudo apt-get install amule
sudo apt-get install vim

sudo apt-get install sqlite3

sudo apt-get install chmsee

sudo apt-get install wireshark

sudo apt-get install emacs

#文档生成工具
#sudo apt-get install doxygen

#sudo apt-get install qterm

#decoder
#sudo apt-get install ubuntu-restricted-extras

#压缩,解压
sudo apt-get install rar unrar
#解压缩
#tar -zxvf xxx.tar.gz
#压缩 tar -zcvf xxx.tar.gz aaa

#QQ
#sudo apt-get install eva
#sudo apt-get install scim-qtimm

#beryl,桌面效果软件
#sudo apt-get install beryl-core beryl-plugins beryl-plugins-data emerald beryl-settings beryl-manager beryl beryl-dev emerald-themes

sudo apt-get install conky
#这个软件有点高深~它的用途是,在桌面上显示自己配置好的一些系统信息,比如时间日期,IP,网络状况,内存和CPU的使用情况,硬盘容量这些内容,进行监控,查看。
#软件配置好,运行后,会定时的自动更新系统信息,让你第一时间更加了解系统当前的工作状态。

#安装pdf阅读,并解决中文乱码乱码问题
sudo ap-get
install xpdf
sudo apt-get install xpdf-chinese-simplified xpdf-chinese-traditional poppler-data

sudo apt-get install subversion

#选择java
#sudo apt-get install sun-java6-jre
#sudo apt-get install sun-java6-jdk

#安装python和django
sudo apt-get install python
sudo apt-cache search django
sudo apt-get install python-django
wget -q http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py
sudo easy_install mysql-python

#安装vnc
#sudo apt-get install vnc4server
#sudo apt-get install vnc4-common xvnc4viewer

#主题美化 gcursor:鼠标主题管理 gnome-art:gnome主题,需要联网 drapes:自动更换壁纸 screenlets:桌面小面板程序
sudo apt-get install gcursor gnome-art drapes ubuntustudio-look screenlets

#右键菜单
sudo apt-get install nautilus-open-terminal
#root权限打开文件夹
sudo apt-get install nautilus-gksu

sudo apt-get install eclipse-cdt eclipse eclipse-pydev

#c文档
sudo apt-get install manpages-dev
sudo apt-get install manpages-posix-dev
sudo apt-get install binutils-doc cpp-doc gcc-4.1-doc gcc-doc glibc-doc libstdc++6-4.1-doc stl-manual cpp-4.1-doc manpages manpages-dev

#vbox安装
sudo apt-get install virtualbox
#sudo mount -t vboxsf Documents /mnt/Documents

#sudo apt-get install sourcenav
#./snavigator
###################################after install###################################

sudo apt-get clean
sudo apt-get autoclean
sudo apt-get remove
sudo apt-get autoremove

#set java config
#sudo update-alternatives-config java

卡尔曼滤波

ref: http://blog.csdn.net/lanbing510/article/details/40936343
ref: https://www.zhihu.com/question/22422121

ref: http://bilgin.esme.org/BitsAndBytes/KalmanFilterforDummies
When I started doing my homework for Optimal Filtering for Signal Processing class, I said to myself :”How hard can it be?”. Soon I realized that it was a fatal mistake.

The whole thing was like a nightmare. Nothing made sense. The equations were composed of some ridiculously complex superscripted and subscripted variables combined with transposed matrices and untransposed some other stuff, which are totally unknowable to most of us.

And then, instead of aiming for the homework, I decided first fully concentrating on Kalman Filter itself. This article is the result of my couple of day’s work and reflects the slow learning curves of a “mathematically challenged” person.

If you’re humble enough to admit that you don’t understand this stuff completely, you’ll find this material very enlightening.

So, enjoy it!

Kalman Filter – too complicated?
Kalman Filter
too complicated?

A Quick Insight
As I mentioned earlier, it’s nearly impossible to grasp the full meaning of Kalman Filter by starting from definitions and complicated equations (at least for us mere mortals).

For most cases, the state matrices drop out and we obtain the below equation, which is much easier to start with.

Kalman Filter – quick insight
Remember, the k’s on the subscript are states. Here we can treat it as discrete time intervals, such as k=1 means 1ms, k=2 means 2ms.

Our purpose is to find Estimate of X at state k, the estimate of the signal x. And we wish to find it for each consequent k’s.

Also here, Measurement value is the measurement value. Keep in mind that, we are not perfectly sure of these values. Otherwise, we won’t be needing to do all these. And Kalman gain is called “Kalman Gain” (which is the key point of all these), and Estimate of x on the previous state is the estimate of the signal on the previous state.

The only unknown component in this equation is the Kalman gain Kalman gain. Because, we have the measurement values, and we already have the previous estimated signal. You should calculate this Kalman Gain for each consequent state. This is not easy of course, but we have all the tools to do it.

On the other hand, let’s assume Kalman gain be 0.5, what do we get? It’s a simple averaging! In other words, we should find smarter Kalman gain coefficients at each state. The bottom line is :


Kalman filter finds the most optimum averaging factor for each consequent state. Also somehow remembers a little bit about the past states.

Isn’t this amazing?

Step-by-Step Guide
Here’s a simple step-by-step guide for a quick start to Kalman filtering.

STEP 1 – Build a Model
It’s the most important step. First of all, you must be sure that, Kalman filtering conditions fit to your problem.

As we remember the two equations of Kalman Filter is as follows:

Kalman – equation 1
Kalman – equation 2
It means that each xk (our signal values) may be evaluated by using a linear stochastic equation (the first one). Any xk is a linear combination of its previous value plus a control signal k and a process noise (which may be hard to conceptualize). Remember that, most of the time, there’s no control signal uk.

The second equation tells that any measurement value (which we are not sure its accuracy) is a linear combination of the signal value and the measurement noise. They are both considered to be Gaussian.

The process noise and measurement noise are statistically independent.

The entities A, B and H are in general form matrices. But in most of our signal processing problems, we use models such that these entities are just numeric values. Also as an additional ease, while these values may change between states, most of the time, we can assume that they’re constant.

If we are pretty sure that our system fits into this model (most of the systems do by the way), the only thing left is to estimate the mean and standard deviation of the noise functions Wk-1 and vk. We know that, in real life, no signal is pure Gaussian, but we may assume it with some approximation.

This is not a big problem, because we’ll see that the Kalman Filtering Algorithm tries to converge into correct estimations, even if the Gaussian noise parameters are poorly estimated.

The only thing to keep in mind is : “The better you estimate the noise parameters, the better estimates you get.”

STEP 2 – Start the Process
If you succeeded to fit your model into Kalman Filter, then the next step is to determine the necessary parameters and your initial values.

We have two distinct set of equations : Time Update (prediction) and Measurement Update (correction). Both equation sets are applied at each kth state.

Time Update
(prediction) Measurement Update
(correction)
Kalman Filter – Time Update Equations Kalman Filter – Measurement Update Equations
We made the modeling in STEP1, so we know the matrices A, B and H. Most probably, they will be numerical constants. And even most probably, they’ll be equal to 1.

I suggest you to re-write these equations and see how simplified will these equations become. (if you’re lazy enough not to do it, I’ll do it for you in the Example below).

The most remaining painful thing is to determine R and Q. R is rather simple to find out, because, in general, we’re quite sure about the noise in the environment. But finding out Q is not so obvious. And at this stage, I can’t give you a specific method.

To start the process, we need to know the estimate of x0, and P0.

STEP 3 – Iterate
After we gathered all the information we need and started the process, now we can iterate through the estimates. Keep in mind that the previous estimates will be the input for the current state.

Kalman Filter – Iteration Process
Here, Prior estimate is the prior estimate which in a way, means the rough estimate before the measurement update correction. And also Prior error covariance is the prior error covariance. We use these prior values in our Measurement Update equations.

In Measurement Update equations, we really find Estimate of x at time k which is the estimate of x at time k (the very thing we wish to find). Also, we find which is necessary for the k+1 (future) estimate, together with Estimate of x at k .

The Kalman Gain (Kalman Gain) we evaluate is not needed for the next iteration step, it’s a hidden, mysterious and the most important part of this set of equations.

The values we evaluate at Measurement Update stage are also called posterior values. Which also makes sense.

A Simple Example
Now let’s try to estimate a scalar random constant, such as a “voltage reading” from a source. So let’s assume that it has a constant value of aV (volts), but of course we some noisy readings above and below a volts. And we assume that the standard deviation of the measurement noise is 0.1 V.

Now let’s build our model:
Kalman Filter – Example Equation 1Kalman Filter – Example Equation 2

As I promised earlier, we reduced the equations to a very simple form.
Above all, we have a 1 dimensional signal problem, so every entity in our model is a numerical value, not a matrix.
We have no such control signal uk, and it’s out of the game
As the signal is a constant value, the constant A is just 1, because we already know that the next value will be same as the previous one. We are lucky that we have a constant value in this example, but even if it were any other linear nature, again we could easily assume that the value A will be 1.
The value H = 1, because we know that the measurement is composed of the state value and some noise. You’ll rarely encounter real life cases that H is different from 1.
And finally, let’s assume that we have the following measurement values:

TIME (ms) 1 2 3 4 5 6 7 8 9 10
VALUE (V) 0.39 0.50 0.48 0.29 0.25 0.32 0.34 0.48 0.41 0.45
OK, we should start from somewhere, such as k=0. We should find or assume some initial state. Here, we throw out some initial values. Let’s assume estimate of X0 = 0, and P0 = 1. Then why didn’t we choose P0 = 0 for example? It’s simple. If we chose that way, this would mean that there’s no noise in the environment, and this assumption would lead all the consequent Estimate of X at state k to be zero (remaining as the initial state). So we choose P0 something other that zero.

Let’s write the Time Update and Measurement Update equations.

Time Update
(prediction) Measurement Update
(correction)
Kalman Filter – Time Update Equations for Example Kalman Filter – Measurement Update Equations for Example
Now, let’s calculate the Estimate of X at state k values for each iteration.

k Estimate of x on the previous state Prior error covariance Time Update Measurement Update Estimate of X at state k
1 0.390 0 1 Prior estimate = Estimate of x on the previous state = 0
Prior error covariance = = 1 Kalman gain = 1 / (1 0.1)
= 0.909
Estimate of X at state k = 0.909 . (0.390 – 0)
= 0.35
= (1 – 0.909) . 1
= 0.091 0.355 0.091
2 0.500 0.355 0.091 Prior estimate = 0.355
Prior error covariance = 0.091 Kalman gain = 0.091 / (0.091 0.1)
= 0.476
Estimate of X at state k = 0.355 . 0.476 . (0.500 – 0.355)
= 0.424
= (1 – 0.476) . 0.091
= 0.048 0.424 0.048
3 0.480 0.424 0.048 0.442 0.032
4 0.290 0.442 0.032 0.405 0.024
5 0.250 0.405 0.024 0.375 0.020
6 0.320 0.375 0.020 0.365 0.016
7 0.340 0.365 0.016 0.362 0.014
8 0.480 0.362 0.014 0.377 0.012
9 0.410 0.377 0.012 0.380 0.011
10 0.450 0.380 0.011 0.387 0.010
Here, I displayed the first 2 state iterations in detail, the others follow the same pattern. I’ve completed the other numerical values via a computer algorithm, which is the appropriate solution. If you try to write it as an algorithm, you’ll discover that Kalman Filter is very easy to implement.

The chart here (right) shows that the Kalman Filter algorithm converges to the true voltage value. Here, I displayed the first 10 iterations and we clearly see the signs of convergence. In 50 or so iterations, it’ll converge even better.

To enable the convergence in fewer steps, you should

Model the system more elegantly
Estimate the noise more precisely
OK. We’re done. The only thing to do is collecting the Estimate of X at state k values we’ve calculated. That’s it!

Kalman Filter – Convergence over iterations: The Kalman Filter algorithm converges to the truth over a few iterations
Convergence over iterations
The Kalman Filter algorithm converges to the truth over a few iterations

References
[1] Greg Welch, Gary Bishop, “An Introduction to the Kalman Filter”, University of North Carolina at Chapel Hill Department of Computer Science, 2001
[2] M.S.Grewal, A.P. Andrews, “Kalman Filtering – Theory and Practice Using MATLAB”, Wiley, 2001

高斯白噪声

ref: http://www.cnblogs.com/YoungHit/archive/2012/03/09/2388230.html

 本文科普一下高斯白噪声(white Gaussian noise,WGN)。

  百度百科上解释为“高斯白噪声,幅度分布服从高斯分布,功率谱密度服从均匀分布”,听起来有些晦涩难懂,下面结合例子通俗而详细地介绍一下。

  白噪声,如同白光一样,是所有颜色的光叠加而成,不同颜色的光本质区别是的它们的频率各不相同(如红色光波长长而频率低,相应的,紫色光波长短而频率高)。白噪声在功率谱上(若以频率为横轴,信号幅度的平方为功率)趋近为常值,即噪声频率丰富,在整个频谱上都有成分,即从低频到高频,低频指的是信号不变或缓慢变化,高频指的是信号突变。

  由傅里叶变换性质可知,时域有限,频域无限;频域有限,时域无限。那么频域无限的信号变换到时域上,对应于冲击函数的整数倍(由公式也可推得:)。即说明在时间轴的某点上,噪声孤立,与其它点的噪声无关,也就是说,该点噪声幅值可以任意,不受前后点噪声幅值影响。简而言之,任意时刻出现的噪声幅值都是随机的(这句话实际上说的就是功率谱密度服从均与分布的意思,不同的是,前者从时域角度描述,而后者是从频域角度描述)。这里要指出功率谱密度(Power Spectral Density,PSD)的概念,它从频域角度出发,定义了信号的功率是如何随频率分布的,即以频率为横轴,功率为纵轴。

  既然白噪声信号是“随机”的,那么反过来,什么叫做“相关”呢?顾名思义,相关就是某一时刻的噪声点不孤立,和其它时刻的噪声幅值有关。其实相关的情况有很多种,比如此时刻的噪声幅值比上一时刻的大,而下一时刻的噪声幅值比此时刻的还大,即信号的幅值在时间轴上按从小到大的顺序排列。除此之外,幅值从大到小,或幅值一大一小等都叫做“相关”,而非“随机”的。

  解释完了“白噪声”,再来谈谈“高斯分布”。高斯分布,又名正态分布(normal distribution)。概率密度函数曲线的形状又两个参数决定:平均值和方差。简单来说,平均值决定曲线对称中线,方差决定曲线的胖瘦,即贴近中线的程度。概率密度定义了信号出现的频率是如何随着其幅值变化的,即以信号幅值为横轴,以出现的频率为纵轴。因此,从概率密度角度来说,高斯白噪声的幅度分布服从高斯分布

  描述了“白噪声”和“高斯噪声”两个含义,那么,回到文章开头的解释:高斯白噪声,幅度分布服从高斯分布,功率谱密度服从均匀分布。它的意义就很明确了,上半句是从空域(幅值)角度描述“高斯噪声”,而下半句是从频域角度描述“白噪声”。

  下面以matlab程序演示,感性认识一下高斯白噪声。

程序1(高斯白噪声):

  由上图可以看出,高斯白噪声的功率谱密度服从均匀分布。

  若对噪声进行由小到大排序,则使其从随机噪声变为相关噪声,则功率谱密度就不再是均匀分布了。

程序2(非高斯白噪声):

  下面让我们从高斯白噪声的统计信息和幅值分布看一下它的特点。

程序3(高斯白噪声):

  直方图的纵轴为频次,而概率密度的纵轴为频率,但是两者大致的分布曲线确是一样的,因此,这幅图解释了高斯白噪声的幅度分布服从高斯分布。

latex tutorial

#embed all fonts
pdftops file.pdf
ps2pdf14 -dPDFSETTINGS=/prepress -dEmbedAllFonts=true file.ps file.pdf

 

debug: cannot loaded simhei.ttf
put simhei into /usr/local/texlive/texmf-local/fonts/truetype
and then re-generate ls-R directory useing: sudo mktexlsr

fc-cache -fc: scan files
fc-list :lang=zh-cn #list all chinese font

 

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8
%!TEX main=../main.tex
\documentclass[11pt]{article}
\usepackage[a4paper,margin=0.75in]{geometry}
\usepackage{amsmath}
\usepackage{subfig}
\usepackage{epsfig}
\usepackage{graphicx}
\graphicspath{{figures/}}
\usepackage{epstopdf}
\epstopdfsetup{suffix=}
\usepackage{booktabs}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}
\usepackage{CJK}

 

\newcommand{\myvskip}[0]{\vskip 1cm}
\begin{document}
\begin{CJK}{UTF8}{gbsn}

 

\title{Brief Article}
\author{The Author 蒋小可 }
%\date{}
\maketitle

 

 

\section{标签}
Hello World, 蒋小可

 

%多行等号对齐长公式
%\usepackage{amsmath}
\begin{equation}
\begin{split}
BitsSent &= (\Delta + p) * n \\
&= (\Delta + P) * \frac{1}{(1-\Omega)^{\Delta + P}}
\end{split}
\end{equation}

 

%大括号多种情况公式
\begin{equation} H =
\begin{cases}
h & \textrm{if p = 0} \\
\frac{1-(1-p)^h}{p} & \textrm{ if $p \neq 0 $}
\end{cases}
\end{equation}
or
\begin{displaymath}
\bar{H} = \left\{ \begin{array}{ll}
h & \textrm{if p = 0 } \\
\frac{1-(1-p)^h}{p} & \textrm{ if $p \neq 0 $}
\end{array} \right.
\end{displaymath}

 

%该环境对多行公式每行都加自动编号,如果相对某行不加编号,可在换行之前添加命令\nonumber
\begin{eqnarray}
a & b & c\\
x & y & z\\
\end{eqnarray}

 

%插入图片
\begin{figure}[htbp]
\begin{center}
\includegraphics[width=3.2in]{a}
\caption{Invalid Payload Ratio}
\label{fig:invalid-payload-ratio}
\end{center}
\end{figure}

 

% location of
% h Place the float here, i.e., approximately at the same point it occurs in the source text (however, not exactly at the spot)
% t Position at the top of the page.
% b Position at the bottom of the page.
% p Put on a special page for floats only.
% ! Override internal parameters LaTeX uses for determining “good” float positions.
% H Places the float at precisely the location in the LaTeX code. Requires the float package,[1] e.g., \usepackage{float}. This is somewhat equivalent to h!.

 

%一行多个图片
%\usepackage{subfig}
\begin{figure*}[t]
\centering
\subfloat[Node Failure] {\label{fig:nodedown}
\includegraphics[width=0.5\textwidth]{a}}
\subfloat[Link Failure] {\label{fig:linkfail}
\includegraphics[width=0.5\textwidth]{b}}
\myvskip
\end{figure*}

 

%多行多个
%\usepackage{subfig}
\begin{figure*}[t]
\centering
\subfloat[Node Failure] {\label{fig:nodedown}
\includegraphics[width=0.33\textwidth]{a}}
\subfloat[Link Failure] {\label{fig:linkfail}
\includegraphics[width=0.33\textwidth]{a}}
\subfloat[Bandwidth] {\label{fig:bandwidth}
\includegraphics[width=0.33\textwidth]{a}}

 

\subfloat[Packet Loss] {\label{fig:loss}
\includegraphics[width=0.33\textwidth]{b}}
\subfloat[Latency] {\label{fig:latency}
\includegraphics[width=0.33\textwidth]{b}}
\subfloat[Jitter] {\label{fig:jitter}
\includegraphics[width=0.33\textwidth]{b}}
\caption{QoS and Reliability}
\label{fig:qos}
\end{figure*}

 

%表格样式
%\usepackage{booktabs}
\begin{table}[htbp]
\caption{Terminology}
\begin{center}
\begin{tabular}{cl}
\toprule[1.5pt]
Variable & Meaning \\
\midrule[1pt]
$\Delta$ & overhead of signature \\
$S$ & File Size \\
$B$ & Bandwidth\\
$\Omega$ & Packet Loss rate of 1KB Packet\\
$p$ & Payload Size (by 1KB)\\
$\rho$ & Packet Loss rate of Packet with Size $\Delta+p$\\
n & Time of Transmission to delivery a Chunk\\
\bottomrule[1.5pt]
\end{tabular}
\end{center}
\label{default}
\end{table}%

 

%\usepackage{booktabs}
\begin{table}[htbp]
\caption{Terminology}
\begin{center}
\begin{tabular}{cl}
\toprule[1.5pt]
A & B \\
\midrule[1pt]
C & D \\
X & Y\\
\bottomrule[1.5pt]
\end{tabular}
\end{center}
\label{default}
\end{table}

 

%蒋小可
\end{CJK}
\end{document}

linux

Diff:
echo “side-by-side display”
diff -y a.txt b.txt

echo “ignore case”
diff -yi a.txt b.txt

echo “ignore whitespace”
diff -yiw a.txt b.txt

echo “supress same line”
diff -yiw –suppress-common-line a.txt b.txt

内核版本
uname -r

ubuntu 版本号与名字
cat /etc/issue

 

useradd -m -G adm,root shock
-m 创建主目录
adduser shock sudo
把用户shock添加到sudo组
or visudo
add: shock ALL=(ALL) ALL (after root ALL=(ALL) ALL)

rsync -aXS /var/lib/docker/. /data/docker/ 同步文件

#! /bin/sh
get file dir:
sh file: LOCAL_DIR=$(cd $(dirname $0); pwd) (这个值不因为当前执行目录的改变而改变)
conf file: set $LOCAL_DIR = $(cd $(dirname $0); pwd)
rsync -e ‘ssh -p 30000’ -avl –delete –stats –progress –exclude ‘sources’ –exclude ‘public_html/database.txt’ demo@123.45.67.890:/home/demo /backup/

 

find . -type f -exec sed -i.orig ‘s/\t/ /g’ {} +

KEYWORD=iperf3
CMD=”iperf3 -s -p 5201 -d >> iperf3daemon.log 2>&1″
CMD2=”echo more than 1 ${KEYWORD} found”
/bin/sleep 10
/usr/bin/killall ${KEYWORD}
/bin/sleep 1
/usr/bin/killall -9 ${KEYWORD}
/bin/sleep 1
if [ `ps -C ${KEYWORD} | wc -l` -ge “1” ] ; then
if [ `ps -C ${KEYWORD} | wc -l` -gt “1” ] ; then
if [ `ps -C ${KEYWORD} | wc -l` = “1” ] ; then
${CMD}
else
${CMD2}
fi

 

pkill -f xxx.py

find . -type f -exec ls -l {} \;
find ./ -name “*.mp4” -exec ffprobe {} 2>&1 \;|grep h264|wc -l

ps aux | grep ffmpeg | awk ‘{print $2}’ | xargs kill -9

 

last command:
arrow up
!!
!-1
Ctrl-P

history to list all histor comands, then “!10” to execute the command with index 10
!ps to run the history command starting with “ps”

inherit the last parameters from last command:
vim !!:$
or specify the index (from 1) of parameter
vim !!:1

 

make with 8 threads:
make -j8

#auto-start app for ubuntu
sudo update-rc.d -f slapd remove

#check file size
du -sh FILE

# check the status of specific port, lsof stands for ls open files
sudo lsof -i:80
lsof -u shock
lsof -c /bin/vim # show all files opened by vim

# check status of all port
sudo lsof -Pn

# check all the connection
netstat -an

# check connection to specific IP
sudo lsof -Pn|grep IP
netstat -P (linux) or netstat -o (windows)

# copy
cp tmp.txt{,.bak}

# set hidden flag
chflags hidden FILE
chflags nohidden FILE

 

清单 7. 查找大于 10MB 的所有文件

$ find / -size +10000k –xdev –exec ls –lh {}\;

 

# find file with name
find ./ -name “*.cc”
find ./ -name “*.cc” -exec ls {} \; (\; is required at the end of the command line)

 

# grep recursively
grep “WORD” -r ./

grep -c “John” ./ (count number)
grep -v “John” ./ (does not contain John)

“:” as delimiter, keyword is the colum 3 as a integer (index start from 0)
sort -t: -u -k 3n /etc/passwrd
sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n /etc/hosts
# rank the output from shell
cat t.tmp | grep “^17” | sort -k 3 (ordered by colum 3) -n (odered by numberic) -u (no duplicate)

 

ls -l | awk ‘$6 == “Dec”‘
ls -l | awk ‘$5 = 686′

cut -d: -f 1,3 /etc/passwd
cut -d: -f 1-3 /etc/passwd (first 1-8 chars)

sed -i -e “s;/mysite/v2/user/;/user/;g” *.html

 

echo “side-by-side display”
diff -y a.txt b.txt

echo “ignore case”
diff -yi a.txt b.txt

echo “ignore whitespace”
diff -yiw a.txt b.txt

echo “supress same line”
diff -yiw –suppress-common-line a.txt b.txt

 

tar cvf a.tar ./a/
tar xvf a.tar
zip a.zip ./a/
unzip a.zip

# set python with port
port select –list python
port select -set python python 27

# shell hint message, in /etc/bashrc
PS1=’\h:\W \u\$’
PS2=”continue-> ”

#check the user of the directory or file
fuser -v .
fuser -vm tunnel.sh
ps auxf # show the process tree
ps U shock uxf

 

vmstat 1 100 #show system performance

nohup CMD & #run the command after logout
or nohup sh CMD > custom-out.log &

uname -a #show system info
df
du
# create account
sudo useradd -s /bin/bash -mr <USERNAME>
sudo adduser <USERNAME> sudo

type which whereis locate

 

grep -E ‘aaa|bbbb’

crontab时间格式范例
1-3表示123
1-9/2表示13579
crontab范例
每五分钟执行 */5 * * * *

每小时执行 0 * * * *

每天执行 0 0 * * *

每周执行 0 0 * * 0

每月执行 0 0 1 * *

每年执行 0 0 1 1 *SRC=/data/wwwroot/web/ #代码发布服务器目录

DST=/data/wwwroot/web/ #目标服务器目录
IP=”192.168.20.7″ #目标服务器IP,多个以空格隔开
USER=www
INOTIFY_EXCLUDE=”–fromfile /data/conf/shell/inotify_exclude.list”
RSYNC_EXCLUDE=”–include-from=/data/conf/shell/rsync_include.list –exclude-from=/data/conf/shell/rsync_exclude.list”

#su – $USER
inotifywait -mrq –exclude “(.swp|.inc|.svn|.rar|.tar.gz|.gz|.txt|.zip|.bak)” -e modify,delete,create,close_write,attrib $INOTIFY_EXCLUDE | while read D E F
do
for i in $IP
do
/usr/bin/rsync -e ‘ssh -p 5000’ -ahqzt $RSYNC_EXCLUDE –delete $SRC $USER@$i:$DST
done
done

 

inotify_exclude.list:
/tmp/inotify-test-dir
@/tmp/inotify-test-dir/cache

 

shell command:
#! /bin/sh
FILE_PATH=file.txt
DIR_PATH=dir
STR=0

if type python 2>/dev/null;
then
echo “yes”
else
echo “no”
fi

if [ -a ${FILE_PATH} ] ; then
echo “file: ${FILE_PATH} exists”
else
echo “file: ${FILE_PATH} does not exist”
fi

if [ -d ${DIR_PATH} ] ; then
echo “file: ${DIR_PATH} exists”
else
echo “file: ${DIR_PATH} does not exist”
fi

 

if [ “${STR}”x != “0”x ] ;
then
echo “not 0”
else
echo “be 0”
fi

 

ls

if [ ! $? -eq 0 ]; then
echo “last command executed successfully”
fi

function func_cmp() {
if [ $1 -eq 0 ] ; then
echo “equal 0”
else
echo “not equal 0″
fi
}

function func_add() {
a1=1
a2=10
a3=100
a4=-1
r1=$[$a1+-1]
r2=$[$a2+$a2]
r3=$[$a3+$a4]

echo $r1, $r2, $r3
}

function split_str() {
echo $1
tail -n 2 $1 | while read LINE
do
echo $LINE
done

OLD_IFS=”$IFS”
IFS=” ”
arr=($LINE)
IFS=”$OLD_IFS”
}

compiling: gcc/make/ldd

ldd:
/etc/ld.so.conf.d
pkg-config: locate pkgconfig for managed lib

check the gcc include path:
echo | cpp -Wp,-v
or short cpp -v
or gcc -xc -v – (for c), gcc -xc++ -v – (for c++)

 

ldconfig is used to find the shared library when executing a program
ldconfig search the /etc/ld.so.conf which then defines the searching path
LD_LIBRARY_PATH is used to specify the search path

add addtional include path:
export C_INCLUDE_PATH=/opt/local/include
export CPLUS_INCLUDE_PATH=/opt/local/include
add addtional library path
export LIBRARY_PATH=/opt/local/lib
搜索的先后顺序是:
1.编译目标代码时指定的动态库搜索路径;
2.环境变量LD_LIBRARY_PATH指定的动态库搜索路径;
3.配置文件/etc/ld.so.conf中指定的动态库搜索路径;
4.默认的动态库搜索路径/lib;

5.默认的动态库搜索路径/usr/lib。

 

CPATH
C_INCLUDE_PATH
CPLUS_INCLUDE_PATH
OBJC_INCLUDE_PATH

find the which header files are included:
gcc -M main.cpp -I/opt/local/include

ignore the system header files:
gcc -M main.cpp
or gcc -H main.cpp

linux:
sudo ldconfig (will refresh the ldconfig’s cache)
ldconfig -p: list all managed lib (/etc/ld.so.conf)
ldconfig -n /opt/dummy/lib #add new lib to ldconfig links, may not permantly

 

ldd APP: to show its linked lib
if ldd APP found “not found XX”, this may cause by ldconfig, which is called by ldd

pkg-config –cflags –libs libass

echo $PKG_CONFIG_PATH together with /usr/lib/pkgconfig, /usr/share/pkgconfig, /usr/local/lib/pkgconfig and /usr/local/share/pkgconfig
gcc program.c $(pkg-config –cflags –libs gnomeui)

CMake Module path
/usr/share/cmake-3.5/Modules

 

find the head file:
echo ‘#include <stdbool.h>’ | cpp -H
or: locate stdbool.h

locate
sudo updatedb to refresh locate cache

mac osx
otool -L APP # ldd’s equipvalent
or dyldinfo -dylibs APP

 

查看.a文件都包含了那些文件
ar -t xxx.a
查看.so文件接口
nm -D xxx.so

查看库支持的CPU体系结构
readelf -h libxslt.a/so

 

ffmepg:
–extra-libs=’/usr/local/lib/libTransform360.a -lstdc++ -L/usr/local/lib’

git tutorial

linux: git config credential.helper ‘cache –timeout=3600000’
windows: git config credential.helper winstore
git config –global credential.helper wincred
https://github.com/anurse/git-credential-winstore/downloads
git config –global credential.helper store
it config –unset credential.helper

git config -l

http://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server

git ls-files -o -i –exclude-standard

git review:
git push gerrit HEAD:refs/for/master

git commit –amend –author “Shock Jiang <shock.jiang@gmail.com>”

#remove file in the repository but keep local copy
git rm –cached shock-rsp/abc

git push remote localbranch:remotebranch
git push -f remote localbranch:remotebranch

git reset –hard remote/branch

 

git diff HEAD~1
git diff HEAD~1 main.tex

#check pull/push
git remote -v

 

#remove file from last commit
git reset HEAD~1 — FILE
git checkout FILE
git commit –amend
git rm doc/\*.txt #recursive remove all *.txt under doc

git branch -vv
git push -u origin new_branch
git branch -u origin/foo foo
git branch –set-upstream my_branch origin/my_branch

#replace origin with new url
git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git
git push -u origin master
git remote set-url origin http://git.oschina.net/shockjiang/shock-data

remove a branch:
git branch -D <name-of-branch>
git branch -D -r origin/<name-of-branch>
git push origin :<name-of-branch>

#on server’s computer
#===================
$ sudo adduser git
$ su git
$ cd
$ mkdir .ssh && chmod 700 .ssh
$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

#on server’s computer
$ mkdir project.git

git 一部分
mkdir gitSparse
cd gitSparse/
git init
git remote add -f origin https://github.com/bestswifter/MySampleCode.git
ls
git config core.sparsecheckout true
echo “CornerRadius” >> .git/info/sparse-checkout
cat ./.git/info/sparse-checkout
git pull origin master
$ cd project.git
$ git init –bare

 

on client’s computer
====================
$ cd myproject
$ git init
$ git add .
$ git commit -m ‘initial commit’
$ git remote add origin git@gitserver:/opt/git/project.git
$ git push origin master

 

push code to a remote server (with public IP) from local:
You could push the changes to the web server, instead of trying to pull them:

Set up a repos on the web server:

cd /somedir
git init –bare
Push to that repos from your dev machine:

git remote add web user@web:/somedir
git push web master

vim turtorial

set expandtab
set tabstop=4
set shiftwidth=4
set autoindent
set smartindent
set nu

:retab to allow the converting

 

移动光标 hjkl 左上下右; 对应emacs 中的 Ctrl-b Ctrl-p Ctrl-n Ctrl-f

O: 向上插入一行并跳转

move the current line to top/middle/bottom of the screen:
z-t: top
z-z or z-. : middle
z-b: bottom

列模式
ctrl-v 进入列模式, Shift-Ctrl-A eclipse with mouse to select text
移动光标,选择对应的修改区域
r-进入修改模式 I-进入行首编辑模式 A-进入行末插入模式-
ESC 退出列模式

Shift-j: merge/join two line

针对粘贴时候太多缩进的问题,粘贴之前: set paste
完成之后: set nopaste

全文替换
:1, $s / old / new / g
我们知道%等价于1,$,所以上行命令也可以这样写:
:% s / old / new / g