Una hormiga se coloca en la esquina de un cubo y no puede moverse. Una araña comienza a partir de la esquina opuesta, y pueden moverse a lo largo de los bordes del cubo en cualquier dirección con igual probabilidad . En promedio, ¿cuántos pasos necesitará la araña para llegar a la hormiga?
(Esto no es tarea, fue una pregunta de entrevista).
probability
random-walk
Elizabeth Susan Joseph
fuente
fuente
self-study
etiqueta y seguir las pautas en su etiqueta wiki . Edite esta pregunta eRespuestas:
Sugiero modelar el problema como una cadena de Markov donde cada estado representa la distancia entre la araña y la hormiga. En este caso tenemos 4 estados posiblesSyo ya que las distancias yo puede ser { 0 , 1 , 2 , 3 } .
Cuando la araña está en la esquina opuesta del cubo, está a una distancia de 3 pasos de la hormiga. Está en el estadoS3 .
La construcción de la matriz de transiciónPAGS .
Si dibujamos un cubo, vemos que cuando estamos en el estado , cada movimiento reduce la distancia entre la araña y la hormiga a 2 pasos. Entonces, cuando estamos en el estado S 3, pasamos al estadoS3 S3 con probabilidad 1.S2
Cuando estamos en el estado , podemos volver al estado S 3 utilizando el borde al que llegamos desde allí o podemos disminuir la distancia a solo un paso si elegimos otros dos bordes. Entonces, cuando estamos en el estado S 2 podemos pasar al estado S 1 con probabilidad 2/3 y al estado S 3 con probabilidad 1/3.S2 S3 S2 S1 S3
Cuando estamos en el estado , podemos ir al estado S 0 usando uno de los tres bordes posibles. Si usamos los otros dos, volvemos al estado S 2 . Entonces, cuando estamos en el estado S 1 podemos pasar al estado S 0S1 S0 0 S2 S1 S0 0 con probabilidad 1/3 y al estado con probabilidad 2/3.S2
Cuando llegamos al estado , nos quedamos allí ya que es nuestro objetivo. S 0 es un estado absorbente.S0 0 S0 0
This is an absorbing Markov chain with three transient states (S3 , S2 , S1 ) and one absorbing state (S0 ).
According to the theory, the transition matrix of a Markov chain witht transient states and r absorbing states can be rewritten as:
whereQt is a t×t matrix that shows the probability of transitioning from some transient state to another transient state, while R is a t×r matrix with the probabilities of transitioning from one of the t transient states to one of the r absorbing states. The identity matrix Ir shows us that when any of the r absorbing state is reached, there is no transition away from that state. The all zeros matrix 0r×t can be interpreted as that there is no transition from any of the r absorbing states to any of the t transient states.
The(i,j) entry of Qt represents probability of transitioning from a state i to a state j in exactly one step. To get the probability for k steps we need the (i,j) entry of Qkt . Summing for all k , we get a matrix that contains in its (i,j) entry the expected number of visits to transient state j after starting from transient state i .
To get the number of steps until being absorbed, just sum the values of each row of(It−Qt)−1 . This can be represented by
where1 is a column vector with all components equal to 1.
Let us apply this to our case:
As stated above, in our case we havet =3 transient states and r =1 absorbing state, therefore:
The matrix with the expected number of visits is
This matrix can be interpreted as follows. Starting from stateS3 and before getting absorbed at S0 we visit, on average, S3 2.5 times, S2 4.5 times, and S1 3 times.
The expected number of steps from stateS3 to state S0 is given by the first component of the following vector:
The second and third components oft are the expected number of steps to S0 if we start from S2 and S1 respectively.
fuente
Letx∗ be the number of expected steps. Let x1 be the number of expected steps from any corner adjacent to the origin of the spider and x0 ditto for the ant.
Thenx∗=1+x1 and x0=1+23x1
We get our answer asx∗=10 .
Edit:
If we draw the cube with coordinates(x,y,z) then 111 is the starting position of the spider and 000 the position of the ant.
The spider can move to either011 , 101 or 110 .
By the symmetry of the cube these must have the same number of expected steps to the ant, denoted byx1 . From x1 , we can either return to the origin (with probability 1/3 ) or (with probability 2/3 ) we can go to one of the points 001 , 100 , 010 depending on which state we are in.
Again, by symmetry, these points will have the same number of expected steps which we callx0 . From these positions we can reach the goal in one step with probability 1/3 or go back to one of the x1 -positions with probability 2/3 . This means that
x0=131+23(1+x1)=1+23x1 .
fuente
One nice abstraction to think of it is this:
Think of the Position of the Ant as(0,0,0) and Spider (1,1,1) , now each move the spider can make will essentially switch exactly one of the three components from 1→0 or 0→1 . So the question becomes:
We see the shortest way is 3 switches. Since it doesn't matter with which bit I start the probability of that happening is
1 * 2/3 * 1/3 = 2/9
. If we make 1 mistake (switch one bit back to 1) we will need 5 steps. And the chances of making a mistake are 7/9 - if we want to make only one mistake, we have to get from there back and do everything right again - so the chance of making exactly 1 mistake resulting in 5 steps is7/9 * 2/9
and the chance of making 2 mistakes aka 7 steps is(7/9)² * 2/9
and so on.So the formula for the expected average number of steps is:
fuente
n
is the current integer in that infinite sum.Just to compliment tiagotvv's answer:
I don't naturally think of these kinds of problems as matrices (even though they are). I have to draw it out, which I've done below. You can see that there are 3 places to move from S, all of which are As. From any A, you can either return to the S, or move to one of two Bs. From any B, you can move to the E, or to one of two As. This all translates to the transition matrix given by tiagotvv, which can also be drawn in graph form.
Because I am terrible at math, I would just try to simulate your problem. You can do this with the markovchain package in R.
tiagotvv's answer can be calcuated in R as:
fuente
Parity considerations give a very clean solution, using surprisingly simple machinery: no Markov chains, no iterated expectations, and only high school level summations. The basic idea is that if the spider has moved an even number of times in thex direction, it has returned to its original x coordinate so can't be at the ant's position. If it has moved an odd number of times in the x direction, then its x coordinate matches the ant's. Only if it has moved an odd number of times in all three directions will it match the x , y and z coordinates of the ant.
Initially the spider has made zero moves in any of the three directions, so the parity for each direction is even. All three parities need to be flipped to reach the ant.
After the spider's first move (let's label that directionx ), exactly one direction has odd parity and the other two (y and z ) are even. To catch the ant, only those two parities need to be reversed. Since that can't be achieved in an odd number of subsequent moves, from now on we consider pairs of moves. There are nine possible combinations for the first paired move:
We need to move in they and z directions to reach the ant after one paired move, and two out of nine combinations will achieve this: (y,z) and (z,y) would ensure all three parities are odd.
The other seven combinations leave one odd and two even parities. The three repeated moves,(x,x) , (y,y) or (z,z) , leave all parities unchanged so we still require one y and one z movement to reach the ant. The other pairs contain two distinct moves, including one in the x direction. This switches the parity of x and one of the other parities (either y or z ) so we are still left with one odd and two even parities. For instance the pair (x,z) leaves us needing one more x and one more y to reach the ant: an equivalent situation (after relabelling of axes) to where we were before. We can then analyse the next paired move in the same way.
In general paired moves start with one odd and two even parities, and will either end with three odd parities (with probability29 ) and the immediate capture of the ant, or with one odd and two even parities (with probability 79 ) which returns us to the same situation.
LetM be the number of paired moves required to reach the ant. Clearly M follows the geometric distribution on the support {1,2,3,…} with probability of success p=29 so has mean E(M)=p−1=92=4.5 . Let N be the total number of moves required, including the initial move and the M subsequent paired moves. Then N=2M+1 so, applying linearity of expectations, E(N)=2E(M)+1=2×4.5+1=10 .
Alternatively you might noteP(M≥m)=(79)m−1 and apply the well-known formula for the mean of a discrete distribution taking only non-negative integer values, E(M)=∑∞m=1P(M≥m) . This gives E(M)=∑∞m=1(79)m−1 which is a geometric series with first term a=1 and common ratio r=79 so has sum a1−r=11−7/9=12/9=92 . We can then take E(N) as before.
Comparison to Markov chain solutions
How might I have spotted this from the Markov chain transition matrix? Using @DLDahly's notation, the states in the transition matrix correspond to my description of the number of the number of directions with odd parity.
The one-step transition matrix is
The first row show us that after one movement, the spider is guaranteed to be in state A (one odd and two even parities). The two-step transition matrix is:
The second row shows us that once the spider has entered state A, in two moves time it has either returned to state A with probability7/9 or has reached state E (all odd parities) and captured the ant, with probabilty 2/9 . So having reached state A, we see from the two-step transition matrix that the number of two-step moves required can be analysed using the geometric distribution as above. This isn't how I found my solution, but it is sometimes worth calculating the first few powers of the transition matrix to see if a useful pattern like this can be exploited. I have occasionally found this to give simpler solutions than having to invert a matrix or perform an eigendecomposition by hand - admittedly something that is only really relevant in an exam or interview situation.
fuente
He escrito un breve programa Java para responder a su pregunta numéricamente. El recorrido de la araña es verdaderamente aleatorio, lo que significa que también puede atravesar en ciclos antes de llegar a la hormiga.
Sin embargo, no definió el término "esquina opuesta", por lo que tengo dos escenarios diferentes. Enfrente como a través del mismo plano o como a través del cubo. En el primer escenario, la ruta más corta es de 2 pasos y 3 pasos en el segundo escenario.
He usado 100 millones de repeticiones y los resultados son los siguientes:
Código fuente:
EDITAR: corrigió un error tipográfico en el script (y también actualizó los resultados)
fuente
{0, 2, 6}
. He vuelto a ejecutar el programa y obtuve el siguiente resultado: 10.00000836 pasos para recorrer desde la esquina # 0 a la esquina # 5 (diagonal del cuerpo del cubo). Esto también es consistente con @Hunaphu.Resolví tu enigma a través de simulaciones de Monte Carlo (n = 104 4 ) y obtenido metroe a n ( s t e p s ) ≈10 .
Aquí está el código R que utilicé:
fuente
R
funciones nativas para acelerar esto en menos de un segundo:n.sim <- 1e6; x <- matrix(runif(n.sim*3), ncol=3); moves <- x >= pmax(x[, 1], x[, 2], x[, 3]); positions <- apply(moves, 2, cumsum) %% 2; types <- rowSums(positions); vertices <- types[types==0 | types==3]; transitions <- cumsum(diff(vertices) != 0); n.sim / transitions[length(transitions)]
Creo que alesc está en el camino correcto cuando menciona "Sin embargo, no definió el término" esquina opuesta "A menos que me falte algo en la pregunta, no hay una respuesta correcta, solo respuestas basadas en suposiciones. El tamaño del cubo no está definido IE 10 pies cúbicos, 1000 pies cúbicos, etc. El tamaño de la hormiga no está definido IE pequeño jardín, carpintero, rojo gigante, etc. El tipo de araña no está definido (para determinar el tamaño del escalón) IE pequeño jardín, tarántula, etc. SI combina todo "no definido "variables. la respuesta podría ser 0 pasos o un número indeterminado / infinito de pasos.
fuente