Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °
| |
|
|
You are not logged in. #1 2012-07-26 23:46:47
An expectation problem:A list of 1000 zeroes is created called M. A random number is picked from 1 to 1000. Each time one of these is picked, the zero in the list ( at that index ) is changed to a 1. For instance if the random number is 276 then M[276]=1. What is the average number of random numbers that must be picked to have 200 ones in the list? In mathematics, you don't understand things. You just get used to them. Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means. 90% of mathematicians do not understand 90% of currently published mathematics. #2 2012-07-27 00:02:52
Re: An expectation problem:To check our analytic solution, we may try a simulation: Code:from random import randint
zeroes = [0]*1000
tries = 10000
hit = 0
for i in range(tries):
while sum(zeroes) < 200:
zeroes[randint(0, 999)] = 1
hit += 1
zeroes = [0]*1000
print hit / float(tries)"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense" - Buddha? "Data! Data! Data!" he cried impatiently. "I can't make bricks without clay." #3 2012-07-27 06:28:21
Re: An expectation problem:This idea uses a different approach. Instead of finding the number of picks it uses the analytical answer and then uses a simulation to test if it is correct. Code:fubar[l_]:=Module[{h1,g1},
g1=l;
h1=RandomInteger[{1,Length[l]}];
g1[[h1]]=1;
g1]Now run this: Code:Table[s=Table[0,{1000}];Count[Table[s=fubar[s],{223}]//Last,1],{100}]//Mean//NThe output is 200.03. In mathematics, you don't understand things. You just get used to them. Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means. 90% of mathematicians do not understand 90% of currently published mathematics. #4 2012-07-28 03:40:29
Re: An expectation problem:In R, we may speed up the simulation using the sample function: Code:sa <- c(1:1000)*0
trials <- 10000
hit <- 0
for (i in 1:trials)
{
sa[sample(1:1000, 200, replace = TRUE)] <- 1
hit <- hit + 200
while (sum(sa) < 200)
{
sa[sample(1:1000,1)] <- 1
hit <- hit + 1
}
sa <- c(1:1000)*0
}
print (hit / trials)"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense" - Buddha? "Data! Data! Data!" he cried impatiently. "I can't make bricks without clay." #5 2012-07-30 00:08:39
Re: An expectation problem:Hi Bobby, Code: FOR cycles = 1 TO 10000
M$ = ""
FOR zeroes = 1 TO 1000
M$ = M$ + "0"
NEXT zeroes
'initial 199 picks
FOR picks = 1 TO 199
random = INT(RND(1) * 1000) + 1
M$ = LEFT$(M$,random - 1) + "1" + RIGHT$(M$,1000 - random)
NEXT picks
picks = picks - 1
[morepicks]
FOR count = 1 TO 1000
sum = sum + VAL(MID$(M$,count,1))
NEXT count
IF sum = 200 THEN GOTO [nextcycle]
random = INT(RND(1) * 1000) + 1
M$ = LEFT$(M$,random - 1) + "1" + RIGHT$(M$,1000 - random)
sum = 0
picks = picks + 1
GOTO [morepicks]
[nextcycle]
totalpicks = totalpicks + picks
NEXT cycles
cycles = cycles - 1
'results
PRINT "Cycles: ";cycles
PRINT "Total picks: ";totalpicks
PRINT "Average picks per cycle: ";totalpicks / cycles
END"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson #6 2012-07-30 00:15:50
Re: An expectation problem:Hi phrontister; In mathematics, you don't understand things. You just get used to them. Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means. 90% of mathematicians do not understand 90% of currently published mathematics. #7 2012-07-30 00:39:15
Re: An expectation problem:Hi Code:program Expectation;
type
arr=array[1..1000] of boolean;
function count(a:arr):integer;
var
i,cnt:integer;
begin
cnt:=0;
for i:=1 to 1000 do
cnt:=cnt+ord(a[i]);
count:=cnt;
end;
var
a:arr;
i,j,number:integer;
expect:real;
begin
randomize;
expect:=0;
for i:=1 to 10000 do
begin
for j:=1 to 1000 do
a[j]:=false;
number:=0;
while count(a)<200 do
begin
a[random(1000)+1]:=true;
number:=number+1;
end;
expect:=expect+number;
end;
writeln(expect/10000);
end.Last edited by anonimnystefy (2012-07-30 01:30:03) The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #8 2012-07-30 00:42:15
Re: An expectation problem:Hi; In mathematics, you don't understand things. You just get used to them. Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means. 90% of mathematicians do not understand 90% of currently published mathematics. #9 2012-07-30 00:45:34
Re: An expectation problem:What is the actual number, again? The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #10 2012-07-30 00:53:41
Re: An expectation problem:In mathematics, you don't understand things. You just get used to them. Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means. 90% of mathematicians do not understand 90% of currently published mathematics. #11 2012-07-30 00:57:37
Re: An expectation problem:And in the decimal form? The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #12 2012-07-30 00:58:47
Re: An expectation problem:Hi; In mathematics, you don't understand things. You just get used to them. Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means. 90% of mathematicians do not understand 90% of currently published mathematics. #13 2012-07-30 01:02:29
Re: An expectation problem:I ran the simulation once again and got the same number as before. The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #14 2012-07-30 01:05:27
Re: An expectation problem:The exact same number? Then you have a bug in the code. In mathematics, you don't understand things. You just get used to them. Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means. 90% of mathematicians do not understand 90% of currently published mathematics. #15 2012-07-30 01:31:49
Re: An expectation problem:Changed my code a little, but now it always gives output less then, but close to the actual answer. Haven't gotten a number over 223 with the new code. The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #16 2012-07-30 04:27:19
Re: An expectation problem:What is the output of a couple of runs? In mathematics, you don't understand things. You just get used to them. Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means. 90% of mathematicians do not understand 90% of currently published mathematics. #17 2012-07-30 05:25:46
Re: An expectation problem:One was something aroung 222.8 and another one was around 222.9. Let me get the actual figures. The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #18 2012-07-30 05:52:39
Re: An expectation problem:That seems reasonable. Over many runs you will average out to around 223. In mathematics, you don't understand things. You just get used to them. Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means. 90% of mathematicians do not understand 90% of currently published mathematics. #19 2012-07-30 05:59:06
Re: An expectation problem:Here is what I got now: Code:2.23019100000000E+002 2.23065900000000E+002 2.23091500000000E+002 2.23027800000000E+002 2.23021100000000E+002 2.22971200000000E+002 2.23048500000000E+002 2.23036800000000E+002 2.22945700000000E+002 2.23067400000000E+002 2.23025500000000E+002 2.23024000000000E+002 Last edited by anonimnystefy (2012-07-30 06:04:28) The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #20 2012-07-30 06:02:29
Re: An expectation problem:That is about right. In mathematics, you don't understand things. You just get used to them. Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means. 90% of mathematicians do not understand 90% of currently published mathematics. #21 2012-07-30 06:03:19
Re: An expectation problem:I will add a few more values in a minute. The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #22 2012-07-30 06:08:11
Re: An expectation problem:The answer is a little more than 223, I think. In mathematics, you don't understand things. You just get used to them. Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means. 90% of mathematicians do not understand 90% of currently published mathematics. #23 2012-07-30 06:11:00
Re: An expectation problem:Did you see the edited post 19? The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #24 2012-07-30 06:13:17
Re: An expectation problem:Yes, it looks fine to me. The sd is very small on this problem. In mathematics, you don't understand things. You just get used to them. Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means. 90% of mathematicians do not understand 90% of currently published mathematics. #25 2012-07-30 06:14:45
Re: An expectation problem:Standard deviation? The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón |