描点画图

Posted on Wed 20 September 2017 in Computer

等距描点画图

\begin{align} \Delta l&=\sqrt{\Delta x^2+\Delta y^2}=C\\ \Rightarrow \Delta x&=\frac{\Delta l}{\sqrt{1+y'^2}} \end{align}

等角描点画图

\begin{align} \theta&=\arctan\frac{\Delta y}{\Delta x}\\ \delta\theta&=C\\ \Rightarrow \Delta x&=\delta\theta\Big/\frac{y''}{1+y'^2} \end …


Continue reading

Network Programming

Posted on Mon 18 September 2017 in Computer

IP(Internet Protocal) Address

  • Generally, it is stored(Big endian) in a struct in_addr rather than a scalar value.

    struct in_addr {
      unsigned int s_addr; /* Network byte order (big-endian) */
    };
    
  • To convert endianess between local machine word and in_addr struct, we need functions

    #include <netinet/in.h>
    //Returns: value in network byte …

Continue reading

健壮性拟合

Posted on Mon 11 September 2017 in ProbStat

大概等于Hough变换。

Sub Quadratic Loss Function

$$L_k(x)=\frac{x^2}{1+|x|^{2-k}}, \quad 0\leq k\leq 2$$

$$\lim_{x\to0} L_k(x)=x^2,\quad \lim_{x\to\infty} L_k(x)=x^k$$

At $|x|^{2-k}\ll 1$, it is $x^2$. That is $|x|<e^{-C/(2-k …


Continue reading

分钱问题

Posted on Wed 09 August 2017 in ProbStat

设总钱数为$M$,总人数为$N$,第$i$个人的钱数为$m_i$。

我们需要随机抽满足以下约束的格点$(m_1,\ldots, m_N)$: $$\sum_{i=1}^N m_i = M, m_i\ge 0$$

$m_i$为第$i$个人的钱数,

  • 求第$i$个人的钱数$m_i$取值的概率分布
  • 求对某固定钱数$m$,抽到这个钱数的人的数量$n_m=\sum (m_i = m)$

每个人的钱数分布

首先,定义归一化钱数$x_i=m_i/M$。如果我们取极限近似,假设钱数足够大即$M\gg n$,那么$x_i …


Continue reading

Processing the capillary force video

Posted on Tue 30 May 2017 in Computer

Frames Export

Get frame rate information

videoname=T-L\ _\ 1-50\ tip-tip.avi
ffmpeg -i $videoname 2>&1 |grep -o '[0-9]\+ fps'

The output is 30 fps

ffmpeg -i $videoname -r 30 output_%04d.png

Edges Detection

The Canny edge detector is used in this step.

In [1]:
from capillary …

Continue reading

Covariant Linear Fit

Posted on Mon 29 May 2017 in Computer

Aim

Minimize $$\sum_i \mathrm{distance}^2(\vec r_i, \mathrm{line})=\sum_i (\vec r_i\cdot \hat n-\rho)^2$$ for line $\vec r\cdot \hat n-\rho=0$. It is equivalent to

  • The principle axis with least moment of inertia
  • The eigenvector with largest eigenval for the covariance matrix

When is …


Continue reading

Convert str(array) back to numpy array

Posted on Sun 21 May 2017 in Physics

If we print a numpy array, which actually use str(), we will find it almost irreversible.

In [5]:
l=arange(16).reshape(4,4)
print('l is printed as:\n', l)
l is printed as:
 [[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]
 [12 13 14 …

Continue reading

又双叒叕——汉字的堆叠

Posted on Tue 16 May 2017 in ProbStat

你可能会有这样的问题:类似“又双叒叕”这样子的汉字有多少?本文就是对此问题的分析。

数据来源

原始数据来源于参考维基百科条目二叠字三叠字四叠字

格式化后的的数据,参见源文件

本页面含有Unihan新版用字。有关字符可能会错误显示,详见Unicode扩展汉字。

数据分析

使用pandas进行数据表连接查询,可以找到同时具有多种叠字的字。

In [1]:
import pandas as pd
from functools import reduce
In [2]:
data=[pd.read_table('%d.txt'%i) for i in range(2, 5)]
In [3]:
def merge_out(x …

Continue reading

带负权有向无环图的最短路径

Posted on Mon 15 May 2017 in Computer

最短路径

正权图

用广度优先,先到达的点一定是最短路径。因此不需要考虑后续更新问题

带负权

由于先到达的某条路可能被后面带负权的路所代替,需要考虑后续更新问题。为了防止某节点的最短路径更新导致的后续步骤重算,任何节点必须等待他的依赖做完,此时给出的路径才是真正的最短路径。这个过程需要使用拓扑排序(考虑依赖的任务排序)来实现。

每次某个事情做完的时候,计算假设走该路径它的后继到达所需要的时间。如果该时间更短的话,给它的后继节点更新时间并记录该路径。

拓扑排序

初始时有一系列任务待处理,构成一个任务树。这些任务有的不需要依赖(入度为零)即可以完成,称为树叶;另一些是出度为零的树根;其他的称为树干。每次剪除任意一个枝叶,此次剪除可能产生新的枝叶,加入枝叶队列。以此不断循环。

此方法应用于一个任意有向/无向图可以剪除所有树枝,剩余的皆是非平凡的,或者连接环路的


Continue reading

Reduced density matrix and partial trace

Posted on Wed 03 May 2017 in Physics

The reduced matrix is defined as the partial trace of the density matrix. In linear algebra and functional analysis, the partial trace is a generalization of the trace. Whereas the trace is a scalar valued function on operators, the partial trace is an operator-valued function. The partial trace has applications in quantum information and decoherence which is relevant for quantum measurement and thereby to the decoherent approaches to interpretations of quantum mechanics, including consistent histories and the relative state interpretation.


Continue reading