LaTeX僞代碼編輯

代碼以及僞代碼在LaTeX中的實現,儘量選擇自帶宏包,以方便有效爲目的。

宏包:\usepackage[ruled]{algorithm2e}

其中參數部分[ruled] 作用是實現代碼的頁面居頂。

\begin{algorithm}%[H]
    \caption{The Cascading Bandits on Mobility Management}
    \label{alg:CascadeBandits}
    %\KwIn{this text}
    %\KwOut{how to write algorithm with \LaTeX2e }

    Initialization: Observe $\omega_0$, and $\forall e \in E : T_0 (e) = 1, \quad \hat \omega _1 (e)\gets \omega_0(e)$\;

    \While{$t \leq T$}{

        Compute UCBs $U_t(e)$ for every BSs according to equation \ref{equ:UCB};

        //Recommend a list of $L$ BSs from the NCL

        Let $a_1^t,a_2^t,\dots,a_L^t$ be $L$ BSs with largest UCBs

        $F_t \gets (a_1^t,a_2^t,\dots,a_L^t)$

        UE check all BSs on the list and get the feedback $C_t$

        //Update statistics

        $\forall e \in F $:$T_t(e)\gets T_{t-1}(e)$

        \ForAll {$k=1,2,\dots,\min \{C_t,L\}$}{

            $e\gets a_k^t$

            $T_t(e) \gets T_t(e)+1$

            $\hat \omega _{T_{t}(e)}(e)\gets \frac{T_{t-1}(e) \hat \omega_{T_{t-1}(e)}(e)+ \mathds 1{C_t =k}}{T_t(e)}$

        $t\gets t+1$
}
}
\end{algorithm}

其中命令 \KwIn \KwOut 表示輸入輸出,

效果如下:

僞代碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章