TransWikia.com

Writing multiline equation inside algorithmic pseudocode environment

TeX - LaTeX Asked by David Ireland on August 13, 2021

I have the following code which produces the algorithm in the image.

documentclass{article}
usepackage{algorithm}
usepackage{algorithmicx}
usepackage{algpseudocode}
begin{document}
    begin{algorithm}[h]
        caption{Q-learning}
        begin{algorithmic}[1]
            Require Set of good nodes $V^g$, $score(u) ; forall u in V^g, mbox{ number of episodes } E, mbox{ budget size } b$, $epsilon$
            Ensure Learned parameters $Theta_Q$
            State Initialise replay buffer $M = emptyset$
            For{Episode $e leftarrow 1 mbox{ to } E$}
                State $S_t leftarrow emptyset,; C_t leftarrow V^g$
                For{Step $t leftarrow 1 mbox{ to } b$}
                    State 
                    begin{equation}
                        v_t leftarrow 
                        begin{cases}
                            mbox{A node chosen uniformly at random from } C_t & mbox{w.p. } epsilon 
                            argmax_{v in C_t} Q(S_t, v) & mbox{w.p. } 1-epsilon
                        end{cases}
                    end{equation}
                EndFor
            EndFor
        end{algorithmic}
    end{algorithm}
end{document}

image for question

I would like line 5 to be less centred in the middle of the page and more in-line with where it would be under the for loop if it was a normal piece of text. Can I do this using the equation/cases environment or do I need to create it some other way?

Sorry if I have any imports missing for the equation etc. as it may be in my preamble

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP