Run long computations remotely with screen

This post assumes you use UNIX-like operating system on your computer.

At some point I needed to run some extensive computations on a remote computer from my laptop. The problem was that this would take a long time and I would like to log out from the remote terminal and only log in later to see if the results were ready. If that is also your problem, then screen is the software for you.

screen is useful to detach and reattach your terminals and to have multiple terminals when you’re logged in remotely.

If you don’t have it installed type:

 sudo apt-get install screen

 screen # start screen R # Run something, e.g. R statistical software. <Ctrl+a c> # That creates a new screen terminal. R # Run another thing, R again in this case. <Ctrl+a d> # That detaches screen from your session and sends it into the background. 

Now that you have detached your screens you can log out, go to another computer and log in again.

 screen -r # your screen terminals will be reattached.

You can press <Ctrl+a n> or <Ctrl+a p> to cycle through your terminals. Type exit to terminate this screen session including all its terminals.

To scroll up and down you need to be in copy mode first, press <Ctrl+a [> to enter in copy mode and Esc to exit copy mode.

Auto-logistic model

Consider a two dimensional lattice, each node ${(i,j)}$ of which has a random variable ${X_{i,j}}$ associated with it. One definition of nearest-neighbor models which might be applied to describe the interactions between the variables ${X_{i,j}}$ in this situation is through conditional probabilities of the form

$\displaystyle P\{x_{i,j}| \text{all other values} \} \equiv P\{x_{i,j}|x_{i-1, j}, x_{i+1, j}, x_{i, j-1}, x_{i, j+1}\} \ \ \ \ \ (1)$

Although (1) provides a intuitive representation, it has some drawbacks. For instance, there is no direct method of evaluating the joint probability distribution on the lattice, and the functional form of the conditional probability on the right-hand side of (1) is subject to severe consistency conditions.

Assuming that the model is spatially homogeneous, and that we have binary data Besag (1972) have shown that we may write

$\displaystyle p(x_{i,j}|x_{i-1, j}, x_{i+1, j}, x_{i, j-1}, x_{i, j+1}) = \frac {\exp\{x[\alpha + \beta_1(x_{i-1, j} + x_{i+1, j}) + \beta_2(x_{i, j-1} + x_{i, j+1})]\}} {1 + \exp\{\alpha + \beta_1(x_{i-1, j} + x_{i+1, j}) + \beta_2(x_{i, j-1} + x_{i, j+1})\}}$

where ${\alpha}$, ${\beta_1}$ and ${\beta_2}$ are arbitrary real numbers. The similarity of the above model with the logistic regression model led it to be called an auto-logistic model.

If a boundary of zeros ${\bold{x}_\bold{B} = 0}$ surrounds the inner array of the lattice ${\bold{x}_{\bold{I}}}$, then

$\displaystyle P\{\bold{x}_\bold{I}|\bold{x}_\bold{B} = 0\} = \frac{\exp\{\sum (\alpha + \beta_1 x_{i-1, j} + \beta_2x_{i, j-1})x_{i,j}\}}{C(\alpha, \beta_1, \beta_2)}$

where the summation extends over all ${(i,j) \in I}$ and ${C(\alpha, \beta_1, \beta_2)}$ is a normalizing function, dependent also upon the dimensions of the array.

The above results are valid for any shape of closed boundary. Notice that with this result we get a valid functional form for the conditional probability in Eq. (1), but we still don’t have a direct method of evaluating the joint probability distribution on the lattice.

Reference:

Besag, J.E., 1972. Nearest-neighbor systems and the auto-logistic model for binary data. Journal of the Royal Statistical Society. Series B (Methodological), 75-83