| 0 x 0 |

.codes


  • 首页

  • 照片

  • 关于

在GCP上搭建SS服务器

发表于 2017-09-26

GCP账号自行申请

实例创建

  1. 计算引擎-VM实例-创建实例:
    1. 亚太東1区
    2. 小型 g1-small
    3. Ubuntu 16.04 LTS
    4. 允许HTTP/HTTPS流量
  2. VPC网络-外部IP地址:设为静态
  3. VPC网络-防火墙规则:添加入站规则,全部来源全部端口,目标为网络中的所有实例
  4. 计算引擎-VM实例:记录内部IP(10.X.X.X),记录外部IP,SSH下拉菜单在浏览器中直接打开

实例配置

sudo apt-get update
sudo apt-get install python-pip
sudo pip install shadowsocks

服务配置

sudo nano /etc/shadowsocks.json

1
2
3
4
5
6
7
8
9
10
11
12
13
{

"server":"your_internal_ip",

"server_port":your_own_port,

"password":"your_own_password",

"timeout":300,

"method":"your_own_method",

}

*请填入你的内部IP、自定义端口、密码、加密方式

启动服务

sudo ssserver -c /etc/shadowsocks.json -d start

连接服务

  1. 在本机安装适合的客户端。
  2. 填入自定义的端口、密码和加密方式,设置PAC规则或全局代理,启动连接。

homebridge-on-windows-bash

发表于 2017-08-01

KDD Cup 2017 赛题

发表于 2017-04-13

Highway Tollgates Traffic Flow Prediction

Travel Time & Traffic Volume Prediction

Background

Highway tollgates are well known bottlenecks in traffic networks. During rush hours, long queues at tollgates can overwhelm traffic management authorities. Effective preemptive countermeasures are desired to solve this challenge. Such countermeasures include expediting the toll collection process and streamlining future traffic flow. The expedition of toll collection could be simply allocating temporary toll collectors to open more lanes. Future traffic flow could be streamlined by adaptively tweaking traffic signals at upstream intersections. Preemptive countermeasures will only work when the traffic management authorities receive reliable predictions for future traffic flow. For example, if heavy traffic in the next hour is predicted, then traffic regulators could immediately deploy additional toll collectors and/or divert traffic at upstream intersections.
Traffic flow patterns vary due to different stochastic factors, such as weather conditions, holidays, time of the day, etc. The prediction of future traffic flow and ETA (Estimated Time of Arrival) is a known challenge. An unprecedented large amount of traffic data from mobile apps such as Waze (in the US) or Amap (in China) can help us take up that challenge. If the contestants in this proposed KDD CUP could design reliable approaches for future traffic flow and ETA prediction, then the traffic management authorities might be able to capitalize on big data & algorithms for fewer congestions at tollgates.

众所周知,高速公路收费环节是交通网络中的瓶颈。 在高峰时间,在收费站前排起的长队足以压垮交通管理系统。需要预先采取有效的对策来解决这个问题。比如加速收费过程和减少接下来的交通量。让收费站使用更多的车道可以简单的加块收费的过程。通过前一交叉口的信号可以控制未来的交通量。如果有对未来交通流的可靠预测,交通管理系统才能使用先制策略。例如预测到下一小时会有交通高峰,交通管理系统可以部署额外的收费车道以及/或者在前一个交叉路口实行分流。

交通流由于不同的随机因素而有各种模式,如天气、假日、时间段等。未来交通流和ETA(估计到达时间)的预测是已知的难题。来自Waze(美国)或Amap(中国)等移动应用的前所未有的大量流量数据也许可以帮助我们挑战这一难题。如果KDD CUP中的参赛者可以设计用于未来交通流和ETA预测的可靠方法,则交通管理系统可能能够利用大数据和算法来减少在收费站的拥塞。

Tasks

Available datasets are: the road network topology in the target area (Figures 1, 3, and 4, Tables 3 and 4), vehicle trajectories (Table 5), historical traffic volume at tollgates (Table 6), and weather data (Table 7). The contest consists of two tasks with the details below.

可用的数据集是:目标区域中的道路网络拓扑(图1,3和4,表3和4)、车辆轨迹(表5)、所有收费站历史交通量(表6)和天气数据(表7 )。 比赛包括两个任务,详情如下。

Task 1: To estimate the average travel time from designated intersections to tollgates

For every 20-minute time window, please estimate the average travel time of vehicles for a specific route (shown in Figure 1).**

  • a. Routes from Intersection A to Tollgates 2 & 3;
  • b. Routes from Intersection B to Tollgates 1 & 3;
  • c. Routes from Intersection C to Tollages 1 & 3.
    Note: the ETA of a 20-minute time window for a given route is the average travel time of all vehicle trajectories that enter the route in that time window. Each 20-minute time window is defined as a right half-open interval, e.g., [2016-09-18 23:40:00, 2016-09-19 00:00:00).

Submission Format (see Table 1)
The data types used in all tables in this document are int, float, string, date and datetime. The date and datetime comply with the formats “yyyy-MM-dd” and “yyyy-MM-dd HH:mm:ss”. The time_window field consists of two datetime types separated by a comma without any blank, e.g., “2016-09-18 08:40:00,2016-09-18 09:00:00”.

Field Type Description
intersection_id string intersection ID
tollgate_id string tollgate ID
time_window string e.g., [2016-09-18 08:40:00,2016-09-18 09:00:00)
avg_travel_time float average travel time (seconds)

Table 1. Travel Time from Intersections to Tollgates

Task 2: To predict average tollgate traffic volume

For every 20-minute time window, please predict the entry and exit traffic volumes at tollgates 1, 2 and 3 (Figures 1 and 2). Note that tollgate 2 only allows traffic entering the highway while others allow traffic both ways (entry and exit). Therefore, we need to predict the volume for 5 tollgate-direction pairs in total.

Submission Format (see Table 2)

Field Type Description
tollgate_id string tollgate ID
time_window string e.g., [2016-09-18 08:40:00,2016-09-18 09:00:00)
direction string 0: entry, 1: exit
volume int total volume

Table 2. Traffic Volume at Tollgates

Training & Testing Datasets:

At the beginning of the contest, traffic predictions for specific rush hours from Oct. 18th to Oct. 24th are to be made by the contestants. On May 25 there will be a data swap, after which the participants need to predict traffic during rush hours from Oct. 25th to Oct. 31st.

在比赛开始时,参赛者将对10月18日至10月24日的特定高峰时间的交通情况进行预测。 5月25日将进行数据更替,之后参与者需要预测10月25日至10月31日高峰时段的交通情况。

Contestants are to predict the ensuing traffic during the red time slots shown in Figure 2, i.e., 08:00 - 10:00 and 17:00 - 19:00, at 20-minute intervals.

Figure 2. Time Windows for Traffic Prediction

For travel time prediction, the initial training set contains data gathered from July. 19th to Oct. 17th. For volume prediction, the initial training set contains data gathered from Sep. 19th to Oct. 17th. After the data swap on May 25, additional training data from Oct. 18th to Oct. 24th will be added for both prediction tasks.
In the testing datasets, contestants are provided with traffic data during the green time slots shown in Figure 2, i.e., 06:00 - 08:00 and 15:00 - 17:00. Contestants can use that information as a leading indicator of traffic in the next two hours, which is to be predicted.
Note: Contestants are not restricted to use only the previous 2-hour data in prediction. However, each prediction is restricted to use only the traffic data before the predicted time window. For example, contestants are NOT allowed use the traffic data from Oct. 20th to predict the traffic on Oct. 19th.

Evaluation Metrics

We choose Mean Absolute Percentage Error (MAPE) to evaluate the result.
Task 1: Let drt and prt be the actual and predicted average travel time for route r during time window t. The MAPE for travel time prediction is defined as:

R and T are the number of routes and number of to-predict time windows in the testing period respectively.

Task 2: Let C be the number of tollgate-direction pairs (as aforementioned: 1-entry, 1-exit, 2-entry, 3-entry and 3-exit), T be the number of time windows in the testing period, and fct and pct be the actual and predicted traffic volume for a specific tollgate-direction pair c during time window t. The MAPE for traffic volume prediction is defined as:
$$
MAPE=\frac{1}{c} \sum_{c=1}^c\left(\frac{1}{T} \sum_{t=1}^T\Biggm\lvert\frac{f_{ct}-p_{ct}}{f_{ct}} \Biggm\rvert\right)
$$

Data Description

The road network (Figure 1) here used is a directed graph formed by interconnected road links (Figure 3). A route (Figure 4) in the network is represented by a sequence of links. For every road link, its vehicle traffic comes from one or more “incoming road links” and goes into one or more “outgoing road links”. Table 3 and Figure 3 describe road links.

Vehicles traveling from road intersections to highway tollgates have limited route options. For each intersection-tollgate pair, we selected only the most important one into Table 4. For example, Figure 4 illustrates the route with 9 consecutive road links from Intersection B to tollgate 1.

Table 5 introduces the time-stamped records of actual vehicles along the routes from road intersections to highway tollgates.

Table 5 introduces the time-stamped records of actual vehicles along the routes from road intersections to highway tollgates.

在Hexo博客中正确显示LaTex排版

发表于 2017-04-03

Intro.

Hexo的主题配置文件默认不支持LaTex,且Markdown语法和LaTex语法存在一定冲突。

在Hexo中启用LaTex支持

在主题配置文件_config.yml中找到Third Party Services Settings,修改false为ture。

1
2
3
mathjax:
enable: ture
cdn: //cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML

解决Markdown和LaTex的语法冲突

举例:

下划线_在Markdown语法中是斜体标记,然而在LaTex中用来标记下标,转HTML文件中优先按Markdown语法处理,导致MathJax无法得到正确的LaTex语句。

解决方法:

在Hexo安装文件夹中找到/node_modules/marked/lib/中的marked.js,打开。

1.将

1
escape: /^\\([\\`*{}\[\]()# +\-.!_>])/,

替换为

1
escape: /^\\([`*\[\]()#+\-._>])/,

取消对\\,\{,\},\!的转义。

2.将

1
em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

替换为

1
em:/^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

取消对_等的识别。

注意: 这样无法使用_作为 斜体 标记,可以使用*。

部署测试

$$
\int\!\!\!\int_D dx\,dy \\
\int_D dx
$$

LaTex 数学表示示例

发表于 2017-04-03

Intro.

记录数学符号、公式等LaTex格式,不间断更新。

涉及《Covenx Optimization/凸优化》、《矩阵论》、《随机过程》、《数理逻辑》。

数字符号

重音

\bar{a}
$$
\bar{a}
$$
\acute{a}
$$
\acute{a}
$$
\check{a}
$$
\check{a}
$$
\grave{a}
$$
\grave{a}
$$
\dot{a}
$$
\dot{a}
$$
\ddot{a}
$$
\ddot{a}
$$
\hat{a}
$$
\hat{a}
$$
\widehat{A}
$$
\widehat{A}
$$
\tilde{a}
$$
\tilde{a}
$$
\widetilde{A}
$$
\widetilde{A}
$$
\breve{a}
$$
\breve{a}
$$
\vec{a}
$$
\vec{a}
$$

希腊字母

Alphabet LaTex Code Alphabet LaTex Code Alphabet LaTex Code
α \alpha
β \beta
γ \gamma Γ \Gamma
δ \delta Δ \Delta
ɛ \epsilon ε \varepsilon
ζ \zeta
η \eta
θ \theta Θ \Theta ϑ \vartheta
ι \iota
κ \kappa
λ \lambda Λ \Lambda
μ \mu
ν \nu
ξ \xi Ξ \Xi
o o
π \pi ϖ \varpi
ρ \rho ϱ \varrho
σ \sigma Σ \Sigma ς \varsigma
τ \tau
υ \upsilon Υ \Upsilon
φ \phi Φ \Phi ϕ \varphi
χ \chi
ψ \psi Ψ \Psi
ω \omega Ω \Omega

……

基本表达式

凸优化

例2.1 线性方程组的解集

$$
\begin{align}
A( \theta x_1 + (1 - \theta x_2) ) &= \theta Ax_1 + (1 - \theta) Ax_2 \\
&= \theta b + (1 - \theta) b \\
&= b
\end{align}
$$

1
2
3
4
5
\begin{align}
A( \theta x_1 + (1 - \theta x_2) ) &= \theta Ax_1 + (1 - \theta) Ax_2 \\
&= \theta b + (1 - \theta) b \\
&= b
\end{align}

例2.2 R3中处于(x1, x2)平面的一个正方形

$$
C = \lbrace x \in \mathbf{R}^3 \vert -1\leqslant x_1 \leqslant 1,\ -1\leqslant x_2\leqslant1,\ x_3=0 \rbrace
$$

1
C = \lbrace x \in \mathbf{R}^3 \vert -1\le x_1 \le 1,\ -1\le x_2\le1,\ x_3=0 \rbrace

例2.3 二阶锥是由Euclid范数定义的范数锥

$$
\begin{align}
C&=\lbrace (x,t)\in\mathbf{R}^{n+1}\mid \Vert x \Vert_2 \leqslant t \rbrace \\
&=\left\{
\left[\begin{matrix} x \\ t\end{matrix} \right]
\Biggm \vert \Biggm.
\left[\begin{matrix}x \\ t\end{matrix} \right]^T
\left[ \begin{matrix} I&0 \\ 0&-1\end{matrix} \right]
\left[\begin{matrix} x \\ t\end{matrix} \right]
\leqslant0,\ t\geqslant0
\right\}
\end{align}
$$

1
2
3
4
5
6
7
8
9
10
11
\begin{align}
C&=\lbrace (x,t)\in\mathbf{R}^{n+1}\mid \Vert x \Vert_2 \le t \rbrace \\
&=\left\{
\left[\begin{matrix} x \\ t\end{matrix} \right]
\Biggm \vert \Biggm.
\left[\begin{matrix}x \\ t\end{matrix} \right]^T
\left[ \begin{matrix} I&0 \\ 0&-1\end{matrix} \right]
\left[\begin{matrix} x \\ t\end{matrix} \right]
\le0,\ t\ge0
\right\}
\end{align}

例2.4 非负象限

$$
\mathbf{R}^n_+=\{ x \in \mathbf{R}^n \ \vert\ x_i\geqslant0,\ i=1, \cdots ,n\}=\{x\in\mathbf{R}^n\vert x \succeq 0 \}
$$

例2.5 常见单纯形

单位单纯形

$$
x \succeq0, \qquad \mathbf{1}^T\leqslant1.
$$

概率单纯形

$$
x \succeq0, \qquad \mathbf{1}^T =1.
$$

例2.6 S2上的半正定锥

$$
X=\left[\begin{matrix}x &y \\ y &z \end{matrix} \right]\in \mathbf{S}^2_+ \iff x\geqslant0,\ z\geqslant0,\ xz\geqslant y^2.
$$

例2.7 半正定锥Sn+

$$
\bigcap_{x\not=0}\{X\in\mathbf{S}^n\vert z^TXz\geqslant0 \}.
$$

例2.8 集合

$$
S=\{x\in\mathbf{R}^m\vert \lvert p(t)\rvert\leqslant1\mbox{对于}\lvert t\rvert\leqslant\left. \pi \middle / 3 \right\}
$$

例2.9 多面体

$$
\{x\vert Ax\preceq b, Cx=d\}=\{x\vert f(x)\in\mathbf{R}^m_+\times\{0\}\}.
$$

例2.10 线性矩阵不等式的解

$$
A(x)=x_1A_1+\cdots+x_nA_n\preceq B
$$

例2.11 双曲锥

$$
\{x\vert x^TPx\leqslant(c^Tx)^2,c^Tx\geqslant0\}
$$

例2.12 椭球

$$
\mathcal{E}=\{x\vert (x-x_c)^Tp^{-1}(x-x_c)\leqslant1\}
$$

例2.13 条件概率

$$
f_{ij}=\mathbf{prob}(u=i\vert v=j)=\frac{p_{ij}}{\sum_\limits{k=1}^np_{kj}}
$$

例2.14 非负象限及分量不等式

$$
K=\mathbf{R}^n_+\qquad x\preceq_Ky \iff x_i\leqslant y_i, i=1,\cdots,n
$$

例2.15 半正定锥和矩阵不等式

$$
X\preceq_KY\iff Y-X\mbox{ 为半正定锥}
$$

例2.16 [0,1]上的非负多项式锥

$$
K=\{c\in\mathbf{R}^n\vert c_1+c_2t+\cdots+c_nt^{n-1}\geqslant0 \mbox{ 对于}t\in[0,1]\}
$$

例2.18 对称矩阵集合中的最小元和极小元

$$
\mathcal{E}_A=\{x\vert x^TA^{-1}x\leqslant1\}
$$

例2.19 子空间的对偶锥

$$
V^\perp =\{y\vert y^Tv=0,\forall x\in K\}
$$

例2.23 非负象限的对偶锥是其本身

$$
y^Tx\geqslant 0, \forall x \succeq0 \iff y\succeq0.
$$

例2.24 半正定锥生自对偶的

$$
\mathbf{tr}(XY)\geqslant 0,\forall X \succeq0 \iff y\succeq0.
$$

例2.25 范数维的对偶

$$
K^\ast=\{(u,v)\in\mathbf{R}^{n+1}\vert \Vert u\Vert_\ast\leqslant v\}
$$

例3.1 凸集的示性函数

$$
\begin{eqnarray}\tilde {I}_C(x)=
\begin{cases}
0 &x\in C\cr \infty&x\notin C \end{cases}
\end{eqnarray}
$$

例3.2 二次函数的凸性

$$
f(x)=(1/2)x^TPx+q^Tx+r
$$

例3.3 几何平均 算术平均

$$
G(x)=\left(\prod^n_{i=1}x_i\right)^{1/n},\qquad A(x)=\frac1n\sum^n_{i=1}x_i
$$

例3.4 矩阵分式函数

$$
f(x,Y)=x^TY^{-1}x
$$

例3.5 分片线性函数

$$
f(x)=\max\{a^T_1x+b_1,\cdots,a^T_Lx+b_L\}
$$

例3.6 最大r个分量之和

$$
f(x)=\sum_{i=1}^r=\max\{x_{i_1}+\cdots+x_{i_r}\vert1\leqslant i_1<i_2<\cdots<i_r\leqslant n\}.
$$

例3.7 集合的支撑函数

$$
S_C(x)=\sup\{x^Ty \ \vert\ y\in C\}
$$

例3.8 到集合中最远点的距离

$$
f(x)=\sup_{y\in C}\Vert x-y\Vert
$$

例3.9 以权为变量的最小二乘费用函数

$$
g(w)=\inf_x\sum_{i=1}^nw_i(a^T_ix-b_i)^2
$$

例3.10 对称矩阵的最大矩阵值

$$
f(X)=\sup\{y^TXy \ \vert\ \Vert y\Vert_2=1\}
$$

例3.11 矩阵范数

$$
f(X)=\sup\{u^TXv\vert \Vert u\Vert_2=1,\Vert v\Vert_2=1\},
$$

$$
\Vert X\Vert_{a,b}=\sup_{v\not=0}{\frac{\Vert X_v\Vert_a}{\Vert v\Vert_b}}.
$$

例3.15 Schur补

$$
f(x,y)=x^TAx+2x^TBy+y^TCy,
$$

$$
\left[\begin{matrix}A &B \\ B^T &C \end{matrix} \right]\succeq0.
$$

例3.16 到某一集合的距离

$$
\mathbf{dist}(x,S)=\inf_\limits{y\in S}\Vert{x-y}\Vert.
$$

Mac上文件夹的软连接命令

发表于 2017-03-28

Intro.

为iOS设备的备份文件夹Backup默认在Library/Application Support/MobileSync的位置,随着设备容量的变大,其备份文件也不适合再占据本地SSD空间,但是iTunes并没有提供更改默认备份文件夹位置的选项。

ln命令

ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同不的链接,这个命令最常用的参数是 -s,具体用法是:ln –s 源文件 目标文件。

当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在某个固定的目录,放上该文件,然后在 其它的目录下用ln命令链接(link)它就可以,不必重复的占用磁盘空间。
-s 是代号(symbolic)的意思

故使用ln命令行,迁移默认备份文件夹的实际存储位置到外置硬盘。

ln -s /Volumes/Zeus+/Mobile/iOS/Backup /Users/tianyuax/Library/Application\ Support/MobileSync

注意:

  1. ln的链接分软链接和硬链接两种,软链接会生成文件的镜像,不占用磁盘空间,硬链接没有参数-s, 会生成和源文件大小相同的文件。
  2. 对于有空格的路径,需要加入转义字符\

Outro.

对于iOS设备在大版本升级的不可预知性,以及iCloud备份的恢复的网络阻碍,在外置硬盘保留设备的完整备份(勾选加密)是很有必要的,同时避免Time Machine的重复备份。

12
tianyuax

tianyuax

0x0.codes

20 日志
© 2016 - 2019 0x0