時序

如何找到最小化幾次序列之間距離的係數

  • July 17, 2017

我有 3 個時間序列 X1、X2、X3。我想找到將它們之間的距離最小化的係數 (c1, c2),如下所示:

$$ MIN\sum\sqrt{(X1-(c1X2+c2X3))^2} $$ 約束是:

$$ -1< c1,c2 < 1 $$ 我怎樣才能在 R 中做到這一點?

定義 $ |.|_1 $ 作為 $ L_1 $ 規範。我將使用粗體字母來表示向量,我正在使用 $ \mathbf{y} = \mathbf{x}_1 $ . 你的問題是:

$$ \begin{equation} \begin{array}{*2{>{\displaystyle}r}} \mbox{minimize (over $c_1, c_2$)} & | \mathbf{y} - c_1 \mathbf{x}_2 - c_2 \mathbf{x}_3 |_1 \ \mbox{subject to} & -1 \leq c_1 \leq 1\ & -1 \leq c_2 \leq 1 \end{array} \end{equation} $$ 或者讓矩陣 $ X = \begin{bmatrix} \mathbf{x}_2 & \mathbf{x}_3 \end{bmatrix} $ . 這個問題可以更簡潔地寫成:

$$ \begin{equation} \begin{array}{*2{>{\displaystyle}r}} \mbox{minimize (over $\mathbf{c}$)} & | X \mathbf{c} - \mathbf{y} |_1 \ \mbox{subject to} & \mathbf{c} \preceq \mathbf{1} \ & -\mathbf{c} \preceq \mathbf{1} \end{array} \end{equation} $$ 最小化 $ L_1 $ 受仿射約束的範數是一個凸優化問題。有很多方法可以解決這個問題,而且由於它只有兩個變數,所以解決起來很簡單。任何通用優化庫都可以毫無問題地解決這個問題。

以下是您可以做的事情的簡短列表。這不是一份詳盡的清單。

選項 1:使用CVX解決此問題:

我只是提到這一點,因為我很清楚。有多種方法可以從 R 呼叫 CVX,但可能不方便。如果您在 MATLAB 或 Python 中,您可以執行以下操作:

%% initialize code (currently matlab code)
n = 200;
y = randn(n, 1);  
X = randn(n, 2);

%% CVX CODE
cvx_begin
variables c(2);
minimize(norm(y - X * c, 1))
subject to:
-1 &lt;= c
c &lt;= 1
cvx_end

選項 2:將問題重寫為線性程序。

通過引入向量 $ \mathbf{s} \in \mathbb{R}^n $ , 這 $ L_1 $ 範數最小化問題可以寫成線性規劃

$$ \begin{equation} \begin{array}{*2{>{\displaystyle}r}} \mbox{minimize (over $\mathbf{c}, \mathbf{s}$)} & \mathbf{1}’\mathbf{s} \ \mbox{subject to} & \mathbf{c} \preceq \mathbf{1} \ & -\mathbf{c} \preceq \mathbf{1} \ & X\mathbf{c} - \mathbf{y} \preceq \mathbf{s} \ & -X\mathbf{c} + \mathbf{y} \preceq \mathbf{s} \end{array} \end{equation} $$ R 中有許多線性程序的求解器

引用自:https://quant.stackexchange.com/questions/35143