Maximizing Minimizing Probability
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I have to create an Array A, and for the sake of making things clear, I will create A = [a,b,c,d] with length n, 4 in this case. Then I feed A to the following algorithm;
For i in 1...n: do
generate a random number j
Swap(A[i], A[j])
Now how do I come up with this array, call it A (array contents decided by me), so the probability that the new array generated by this algorithm after giving it A as input, is closest to A. So I have to create an Array, A, feed it to the algorithm and the result should be as close as possible to the original Array, A.
probability
|
show 1 more comment
up vote
-1
down vote
favorite
I have to create an Array A, and for the sake of making things clear, I will create A = [a,b,c,d] with length n, 4 in this case. Then I feed A to the following algorithm;
For i in 1...n: do
generate a random number j
Swap(A[i], A[j])
Now how do I come up with this array, call it A (array contents decided by me), so the probability that the new array generated by this algorithm after giving it A as input, is closest to A. So I have to create an Array, A, feed it to the algorithm and the result should be as close as possible to the original Array, A.
probability
So lost. I don't get this
– Rushabh Mehta
Sep 11 at 2:31
Shouldn't your array be of length $n$? Call the array you are given $A$ and your array $B$. It sounds like you do $n$ times swapping a random element of $A$ with the element that is $B(i)$. In your example, if the starting $A$ is $[a,b,c,d]$ and the first random is $3$ you would swap the third element $c$ with $a$ and get $[c,b,a,d]$. Then if the next random is $2$ you would swap $b$ with $c$ and get $[b,c,a,d]$. OK so far? But then you say we do the loop $4$ times, so what do we swap with for the last two?
– Ross Millikan
Sep 11 at 2:32
Are we allowed to duplicate elements in $B$? If not, $B$ must be a permutation of $A$. I suspect that you can then prove it doesn't matter what the permutation is.
– Ross Millikan
Sep 11 at 2:36
So sorry, not the best at explaining. I edited the Post.
– Carlson Bimbuh
Sep 11 at 2:54
What does "closest to A" mean? How do you determine which of two permutations is closer to the original one?
– saulspatz
Sep 11 at 3:06
|
show 1 more comment
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have to create an Array A, and for the sake of making things clear, I will create A = [a,b,c,d] with length n, 4 in this case. Then I feed A to the following algorithm;
For i in 1...n: do
generate a random number j
Swap(A[i], A[j])
Now how do I come up with this array, call it A (array contents decided by me), so the probability that the new array generated by this algorithm after giving it A as input, is closest to A. So I have to create an Array, A, feed it to the algorithm and the result should be as close as possible to the original Array, A.
probability
I have to create an Array A, and for the sake of making things clear, I will create A = [a,b,c,d] with length n, 4 in this case. Then I feed A to the following algorithm;
For i in 1...n: do
generate a random number j
Swap(A[i], A[j])
Now how do I come up with this array, call it A (array contents decided by me), so the probability that the new array generated by this algorithm after giving it A as input, is closest to A. So I have to create an Array, A, feed it to the algorithm and the result should be as close as possible to the original Array, A.
probability
probability
edited Sep 11 at 2:50
asked Sep 11 at 2:24
Carlson Bimbuh
11
11
So lost. I don't get this
– Rushabh Mehta
Sep 11 at 2:31
Shouldn't your array be of length $n$? Call the array you are given $A$ and your array $B$. It sounds like you do $n$ times swapping a random element of $A$ with the element that is $B(i)$. In your example, if the starting $A$ is $[a,b,c,d]$ and the first random is $3$ you would swap the third element $c$ with $a$ and get $[c,b,a,d]$. Then if the next random is $2$ you would swap $b$ with $c$ and get $[b,c,a,d]$. OK so far? But then you say we do the loop $4$ times, so what do we swap with for the last two?
– Ross Millikan
Sep 11 at 2:32
Are we allowed to duplicate elements in $B$? If not, $B$ must be a permutation of $A$. I suspect that you can then prove it doesn't matter what the permutation is.
– Ross Millikan
Sep 11 at 2:36
So sorry, not the best at explaining. I edited the Post.
– Carlson Bimbuh
Sep 11 at 2:54
What does "closest to A" mean? How do you determine which of two permutations is closer to the original one?
– saulspatz
Sep 11 at 3:06
|
show 1 more comment
So lost. I don't get this
– Rushabh Mehta
Sep 11 at 2:31
Shouldn't your array be of length $n$? Call the array you are given $A$ and your array $B$. It sounds like you do $n$ times swapping a random element of $A$ with the element that is $B(i)$. In your example, if the starting $A$ is $[a,b,c,d]$ and the first random is $3$ you would swap the third element $c$ with $a$ and get $[c,b,a,d]$. Then if the next random is $2$ you would swap $b$ with $c$ and get $[b,c,a,d]$. OK so far? But then you say we do the loop $4$ times, so what do we swap with for the last two?
– Ross Millikan
Sep 11 at 2:32
Are we allowed to duplicate elements in $B$? If not, $B$ must be a permutation of $A$. I suspect that you can then prove it doesn't matter what the permutation is.
– Ross Millikan
Sep 11 at 2:36
So sorry, not the best at explaining. I edited the Post.
– Carlson Bimbuh
Sep 11 at 2:54
What does "closest to A" mean? How do you determine which of two permutations is closer to the original one?
– saulspatz
Sep 11 at 3:06
So lost. I don't get this
– Rushabh Mehta
Sep 11 at 2:31
So lost. I don't get this
– Rushabh Mehta
Sep 11 at 2:31
Shouldn't your array be of length $n$? Call the array you are given $A$ and your array $B$. It sounds like you do $n$ times swapping a random element of $A$ with the element that is $B(i)$. In your example, if the starting $A$ is $[a,b,c,d]$ and the first random is $3$ you would swap the third element $c$ with $a$ and get $[c,b,a,d]$. Then if the next random is $2$ you would swap $b$ with $c$ and get $[b,c,a,d]$. OK so far? But then you say we do the loop $4$ times, so what do we swap with for the last two?
– Ross Millikan
Sep 11 at 2:32
Shouldn't your array be of length $n$? Call the array you are given $A$ and your array $B$. It sounds like you do $n$ times swapping a random element of $A$ with the element that is $B(i)$. In your example, if the starting $A$ is $[a,b,c,d]$ and the first random is $3$ you would swap the third element $c$ with $a$ and get $[c,b,a,d]$. Then if the next random is $2$ you would swap $b$ with $c$ and get $[b,c,a,d]$. OK so far? But then you say we do the loop $4$ times, so what do we swap with for the last two?
– Ross Millikan
Sep 11 at 2:32
Are we allowed to duplicate elements in $B$? If not, $B$ must be a permutation of $A$. I suspect that you can then prove it doesn't matter what the permutation is.
– Ross Millikan
Sep 11 at 2:36
Are we allowed to duplicate elements in $B$? If not, $B$ must be a permutation of $A$. I suspect that you can then prove it doesn't matter what the permutation is.
– Ross Millikan
Sep 11 at 2:36
So sorry, not the best at explaining. I edited the Post.
– Carlson Bimbuh
Sep 11 at 2:54
So sorry, not the best at explaining. I edited the Post.
– Carlson Bimbuh
Sep 11 at 2:54
What does "closest to A" mean? How do you determine which of two permutations is closer to the original one?
– saulspatz
Sep 11 at 3:06
What does "closest to A" mean? How do you determine which of two permutations is closer to the original one?
– saulspatz
Sep 11 at 3:06
|
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
0
down vote
I assume that duplicates are not allowed. That is, the initial arrangement must be a permutation of the number $1,2,3,4.$ According to my calculations, it doesn't matter what the initial arrangement is, as indeed seems true intuitively.
Here's a python script to test this:
from itertools import permutations, product
for p in permutations(range(4)):
a = list(p)
count = 0
for d in product(range(4), repeat=4):
for i in range(4):
a[i], a[d[i]], = a[d[i]], a[i]
if a == list(p): count += 1
print(p, count)
This produces the output
(0, 1, 2, 3) 10
(0, 1, 3, 2) 10
(0, 2, 1, 3) 10
(0, 2, 3, 1) 10
(0, 3, 1, 2) 10
(0, 3, 2, 1) 10
(1, 0, 2, 3) 10
(1, 0, 3, 2) 10
(1, 2, 0, 3) 10
(1, 2, 3, 0) 10
(1, 3, 0, 2) 10
(1, 3, 2, 0) 10
(2, 0, 1, 3) 10
(2, 0, 3, 1) 10
(2, 1, 0, 3) 10
(2, 1, 3, 0) 10
(2, 3, 0, 1) 10
(2, 3, 1, 0) 10
(3, 0, 1, 2) 10
(3, 0, 2, 1) 10
(3, 1, 0, 2) 10
(3, 1, 2, 0) 10
(3, 2, 0, 1) 10
(3, 2, 1, 0) 10
so in all cases the probability is the same: $10over4^4=0.0390625$
I'm sure that it can be proved that this is true for any $n:$ the initial permutation doesn't matter, although the technique escapes me. As a way to discover the proof, I suggest modifying the above script to print out the random numbers (d
in the script) that leave the permutations fixed for two specific permutations, and trying to see how one sequence maps to the other. This will probably give you the pattern you need to prove.
I think your solution is right, just that having to generate the permutations consumes time. But I have fixed that. But I will like to implore your help one more time. What about minimum probability? How will I get a permutation farthest away from the original array?
– Carlson Bimbuh
Sep 12 at 12:55
@CarlsonBimbuh I don't understand what you mean by "farthest away."
– saulspatz
Sep 12 at 13:01
I mean how will I generate a permutation such that, the probability for the algorithm to get it is minimal possible.
– Carlson Bimbuh
Sep 12 at 13:17
add a comment |
up vote
0
down vote
For the new formulation, if all the elements of $A$ are distinct, all that matters is the number of elements in $A$. Shorter is better because there are less permutations to choose from. Before you run your algorithm you can permute the elements into any order you want. Now imagine the permuted one is $[1,2,3,ldots n]$. You have some probability to end with $[1,2,3,ldots n]$. That will be the same for any given length of $A$.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I assume that duplicates are not allowed. That is, the initial arrangement must be a permutation of the number $1,2,3,4.$ According to my calculations, it doesn't matter what the initial arrangement is, as indeed seems true intuitively.
Here's a python script to test this:
from itertools import permutations, product
for p in permutations(range(4)):
a = list(p)
count = 0
for d in product(range(4), repeat=4):
for i in range(4):
a[i], a[d[i]], = a[d[i]], a[i]
if a == list(p): count += 1
print(p, count)
This produces the output
(0, 1, 2, 3) 10
(0, 1, 3, 2) 10
(0, 2, 1, 3) 10
(0, 2, 3, 1) 10
(0, 3, 1, 2) 10
(0, 3, 2, 1) 10
(1, 0, 2, 3) 10
(1, 0, 3, 2) 10
(1, 2, 0, 3) 10
(1, 2, 3, 0) 10
(1, 3, 0, 2) 10
(1, 3, 2, 0) 10
(2, 0, 1, 3) 10
(2, 0, 3, 1) 10
(2, 1, 0, 3) 10
(2, 1, 3, 0) 10
(2, 3, 0, 1) 10
(2, 3, 1, 0) 10
(3, 0, 1, 2) 10
(3, 0, 2, 1) 10
(3, 1, 0, 2) 10
(3, 1, 2, 0) 10
(3, 2, 0, 1) 10
(3, 2, 1, 0) 10
so in all cases the probability is the same: $10over4^4=0.0390625$
I'm sure that it can be proved that this is true for any $n:$ the initial permutation doesn't matter, although the technique escapes me. As a way to discover the proof, I suggest modifying the above script to print out the random numbers (d
in the script) that leave the permutations fixed for two specific permutations, and trying to see how one sequence maps to the other. This will probably give you the pattern you need to prove.
I think your solution is right, just that having to generate the permutations consumes time. But I have fixed that. But I will like to implore your help one more time. What about minimum probability? How will I get a permutation farthest away from the original array?
– Carlson Bimbuh
Sep 12 at 12:55
@CarlsonBimbuh I don't understand what you mean by "farthest away."
– saulspatz
Sep 12 at 13:01
I mean how will I generate a permutation such that, the probability for the algorithm to get it is minimal possible.
– Carlson Bimbuh
Sep 12 at 13:17
add a comment |
up vote
0
down vote
I assume that duplicates are not allowed. That is, the initial arrangement must be a permutation of the number $1,2,3,4.$ According to my calculations, it doesn't matter what the initial arrangement is, as indeed seems true intuitively.
Here's a python script to test this:
from itertools import permutations, product
for p in permutations(range(4)):
a = list(p)
count = 0
for d in product(range(4), repeat=4):
for i in range(4):
a[i], a[d[i]], = a[d[i]], a[i]
if a == list(p): count += 1
print(p, count)
This produces the output
(0, 1, 2, 3) 10
(0, 1, 3, 2) 10
(0, 2, 1, 3) 10
(0, 2, 3, 1) 10
(0, 3, 1, 2) 10
(0, 3, 2, 1) 10
(1, 0, 2, 3) 10
(1, 0, 3, 2) 10
(1, 2, 0, 3) 10
(1, 2, 3, 0) 10
(1, 3, 0, 2) 10
(1, 3, 2, 0) 10
(2, 0, 1, 3) 10
(2, 0, 3, 1) 10
(2, 1, 0, 3) 10
(2, 1, 3, 0) 10
(2, 3, 0, 1) 10
(2, 3, 1, 0) 10
(3, 0, 1, 2) 10
(3, 0, 2, 1) 10
(3, 1, 0, 2) 10
(3, 1, 2, 0) 10
(3, 2, 0, 1) 10
(3, 2, 1, 0) 10
so in all cases the probability is the same: $10over4^4=0.0390625$
I'm sure that it can be proved that this is true for any $n:$ the initial permutation doesn't matter, although the technique escapes me. As a way to discover the proof, I suggest modifying the above script to print out the random numbers (d
in the script) that leave the permutations fixed for two specific permutations, and trying to see how one sequence maps to the other. This will probably give you the pattern you need to prove.
I think your solution is right, just that having to generate the permutations consumes time. But I have fixed that. But I will like to implore your help one more time. What about minimum probability? How will I get a permutation farthest away from the original array?
– Carlson Bimbuh
Sep 12 at 12:55
@CarlsonBimbuh I don't understand what you mean by "farthest away."
– saulspatz
Sep 12 at 13:01
I mean how will I generate a permutation such that, the probability for the algorithm to get it is minimal possible.
– Carlson Bimbuh
Sep 12 at 13:17
add a comment |
up vote
0
down vote
up vote
0
down vote
I assume that duplicates are not allowed. That is, the initial arrangement must be a permutation of the number $1,2,3,4.$ According to my calculations, it doesn't matter what the initial arrangement is, as indeed seems true intuitively.
Here's a python script to test this:
from itertools import permutations, product
for p in permutations(range(4)):
a = list(p)
count = 0
for d in product(range(4), repeat=4):
for i in range(4):
a[i], a[d[i]], = a[d[i]], a[i]
if a == list(p): count += 1
print(p, count)
This produces the output
(0, 1, 2, 3) 10
(0, 1, 3, 2) 10
(0, 2, 1, 3) 10
(0, 2, 3, 1) 10
(0, 3, 1, 2) 10
(0, 3, 2, 1) 10
(1, 0, 2, 3) 10
(1, 0, 3, 2) 10
(1, 2, 0, 3) 10
(1, 2, 3, 0) 10
(1, 3, 0, 2) 10
(1, 3, 2, 0) 10
(2, 0, 1, 3) 10
(2, 0, 3, 1) 10
(2, 1, 0, 3) 10
(2, 1, 3, 0) 10
(2, 3, 0, 1) 10
(2, 3, 1, 0) 10
(3, 0, 1, 2) 10
(3, 0, 2, 1) 10
(3, 1, 0, 2) 10
(3, 1, 2, 0) 10
(3, 2, 0, 1) 10
(3, 2, 1, 0) 10
so in all cases the probability is the same: $10over4^4=0.0390625$
I'm sure that it can be proved that this is true for any $n:$ the initial permutation doesn't matter, although the technique escapes me. As a way to discover the proof, I suggest modifying the above script to print out the random numbers (d
in the script) that leave the permutations fixed for two specific permutations, and trying to see how one sequence maps to the other. This will probably give you the pattern you need to prove.
I assume that duplicates are not allowed. That is, the initial arrangement must be a permutation of the number $1,2,3,4.$ According to my calculations, it doesn't matter what the initial arrangement is, as indeed seems true intuitively.
Here's a python script to test this:
from itertools import permutations, product
for p in permutations(range(4)):
a = list(p)
count = 0
for d in product(range(4), repeat=4):
for i in range(4):
a[i], a[d[i]], = a[d[i]], a[i]
if a == list(p): count += 1
print(p, count)
This produces the output
(0, 1, 2, 3) 10
(0, 1, 3, 2) 10
(0, 2, 1, 3) 10
(0, 2, 3, 1) 10
(0, 3, 1, 2) 10
(0, 3, 2, 1) 10
(1, 0, 2, 3) 10
(1, 0, 3, 2) 10
(1, 2, 0, 3) 10
(1, 2, 3, 0) 10
(1, 3, 0, 2) 10
(1, 3, 2, 0) 10
(2, 0, 1, 3) 10
(2, 0, 3, 1) 10
(2, 1, 0, 3) 10
(2, 1, 3, 0) 10
(2, 3, 0, 1) 10
(2, 3, 1, 0) 10
(3, 0, 1, 2) 10
(3, 0, 2, 1) 10
(3, 1, 0, 2) 10
(3, 1, 2, 0) 10
(3, 2, 0, 1) 10
(3, 2, 1, 0) 10
so in all cases the probability is the same: $10over4^4=0.0390625$
I'm sure that it can be proved that this is true for any $n:$ the initial permutation doesn't matter, although the technique escapes me. As a way to discover the proof, I suggest modifying the above script to print out the random numbers (d
in the script) that leave the permutations fixed for two specific permutations, and trying to see how one sequence maps to the other. This will probably give you the pattern you need to prove.
answered Sep 11 at 14:20
saulspatz
12.7k21327
12.7k21327
I think your solution is right, just that having to generate the permutations consumes time. But I have fixed that. But I will like to implore your help one more time. What about minimum probability? How will I get a permutation farthest away from the original array?
– Carlson Bimbuh
Sep 12 at 12:55
@CarlsonBimbuh I don't understand what you mean by "farthest away."
– saulspatz
Sep 12 at 13:01
I mean how will I generate a permutation such that, the probability for the algorithm to get it is minimal possible.
– Carlson Bimbuh
Sep 12 at 13:17
add a comment |
I think your solution is right, just that having to generate the permutations consumes time. But I have fixed that. But I will like to implore your help one more time. What about minimum probability? How will I get a permutation farthest away from the original array?
– Carlson Bimbuh
Sep 12 at 12:55
@CarlsonBimbuh I don't understand what you mean by "farthest away."
– saulspatz
Sep 12 at 13:01
I mean how will I generate a permutation such that, the probability for the algorithm to get it is minimal possible.
– Carlson Bimbuh
Sep 12 at 13:17
I think your solution is right, just that having to generate the permutations consumes time. But I have fixed that. But I will like to implore your help one more time. What about minimum probability? How will I get a permutation farthest away from the original array?
– Carlson Bimbuh
Sep 12 at 12:55
I think your solution is right, just that having to generate the permutations consumes time. But I have fixed that. But I will like to implore your help one more time. What about minimum probability? How will I get a permutation farthest away from the original array?
– Carlson Bimbuh
Sep 12 at 12:55
@CarlsonBimbuh I don't understand what you mean by "farthest away."
– saulspatz
Sep 12 at 13:01
@CarlsonBimbuh I don't understand what you mean by "farthest away."
– saulspatz
Sep 12 at 13:01
I mean how will I generate a permutation such that, the probability for the algorithm to get it is minimal possible.
– Carlson Bimbuh
Sep 12 at 13:17
I mean how will I generate a permutation such that, the probability for the algorithm to get it is minimal possible.
– Carlson Bimbuh
Sep 12 at 13:17
add a comment |
up vote
0
down vote
For the new formulation, if all the elements of $A$ are distinct, all that matters is the number of elements in $A$. Shorter is better because there are less permutations to choose from. Before you run your algorithm you can permute the elements into any order you want. Now imagine the permuted one is $[1,2,3,ldots n]$. You have some probability to end with $[1,2,3,ldots n]$. That will be the same for any given length of $A$.
add a comment |
up vote
0
down vote
For the new formulation, if all the elements of $A$ are distinct, all that matters is the number of elements in $A$. Shorter is better because there are less permutations to choose from. Before you run your algorithm you can permute the elements into any order you want. Now imagine the permuted one is $[1,2,3,ldots n]$. You have some probability to end with $[1,2,3,ldots n]$. That will be the same for any given length of $A$.
add a comment |
up vote
0
down vote
up vote
0
down vote
For the new formulation, if all the elements of $A$ are distinct, all that matters is the number of elements in $A$. Shorter is better because there are less permutations to choose from. Before you run your algorithm you can permute the elements into any order you want. Now imagine the permuted one is $[1,2,3,ldots n]$. You have some probability to end with $[1,2,3,ldots n]$. That will be the same for any given length of $A$.
For the new formulation, if all the elements of $A$ are distinct, all that matters is the number of elements in $A$. Shorter is better because there are less permutations to choose from. Before you run your algorithm you can permute the elements into any order you want. Now imagine the permuted one is $[1,2,3,ldots n]$. You have some probability to end with $[1,2,3,ldots n]$. That will be the same for any given length of $A$.
answered Sep 11 at 14:33
Ross Millikan
286k23195363
286k23195363
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2912661%2fmaximizing-minimizing-probability%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
So lost. I don't get this
– Rushabh Mehta
Sep 11 at 2:31
Shouldn't your array be of length $n$? Call the array you are given $A$ and your array $B$. It sounds like you do $n$ times swapping a random element of $A$ with the element that is $B(i)$. In your example, if the starting $A$ is $[a,b,c,d]$ and the first random is $3$ you would swap the third element $c$ with $a$ and get $[c,b,a,d]$. Then if the next random is $2$ you would swap $b$ with $c$ and get $[b,c,a,d]$. OK so far? But then you say we do the loop $4$ times, so what do we swap with for the last two?
– Ross Millikan
Sep 11 at 2:32
Are we allowed to duplicate elements in $B$? If not, $B$ must be a permutation of $A$. I suspect that you can then prove it doesn't matter what the permutation is.
– Ross Millikan
Sep 11 at 2:36
So sorry, not the best at explaining. I edited the Post.
– Carlson Bimbuh
Sep 11 at 2:54
What does "closest to A" mean? How do you determine which of two permutations is closer to the original one?
– saulspatz
Sep 11 at 3:06