Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5421 > unrolled thread
| Started by | michael partensky <partensky@gmail.com> |
|---|---|
| First post | 2011-10-06 08:19 +0000 |
| Last post | 2011-10-08 18:49 +0000 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
average of the consecutive coin tosses michael partensky <partensky@gmail.com> - 2011-10-06 08:19 +0000
Re: average of the consecutive coin tosses Jonas <coroa@online.de> - 2011-10-07 09:01 +0000
Re: average of the consecutive coin tosses Peter Pein <petsie@dordos.net> - 2011-10-07 09:10 +0000
Re: average of the consecutive coin tosses Peter Pein <petsie@dordos.net> - 2011-10-07 09:11 +0000
Re: average of the consecutive coin tosses "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-10-08 18:49 +0000
| From | michael partensky <partensky@gmail.com> |
|---|---|
| Date | 2011-10-06 08:19 +0000 |
| Subject | average of the consecutive coin tosses |
| Message-ID | <j6jobf$lv7$1@smc.vnet.net> |
Hi.
What are the better ways of doing what this guy does very inefficiently for
the average of the consecutive coin tosses:
tr = (flips = 1; (#/flips++) & /@ Accumulate[Table[toss, {1000}]]) // N);
where
toss= RandomInteger[];
Thanks
Michael
[toc] | [next] | [standalone]
| From | Jonas <coroa@online.de> |
|---|---|
| Date | 2011-10-07 09:01 +0000 |
| Message-ID | <j6mf5v$7i9$1@smc.vnet.net> |
| In reply to | #5421 |
On Thu, Oct 06 2011, michael partensky wrote:
> tr = (flips = 1; (#/flips++) & /@ Accumulate[Table[toss, {1000}]]) // N);
>
Accumulate[RandomInteger[{0,1}, 1000]]/Range[1000] // N
should do the trick.
[toc] | [prev] | [next] | [standalone]
| From | Peter Pein <petsie@dordos.net> |
|---|---|
| Date | 2011-10-07 09:10 +0000 |
| Message-ID | <j6mfmn$7nd$1@smc.vnet.net> |
| In reply to | #5421 |
Am 06.10.2011 10:19, schrieb michael partensky:
> Hi.
>
> What are the better ways of doing what this guy does very inefficiently for
> the average of the consecutive coin tosses:
>
> tr = (flips = 1; (#/flips++) & /@ Accumulate[Table[toss, {1000}]]) // N);
>
> where
>
> toss= RandomInteger[];
>
> Thanks
> Michael
Hi Michael,
1.) generate the table with RandomInteger[]
2.) make use of the attribute Listable.
Divide the Table by the Range of integers:
tr = Accumulate[RandomInteger[1, 1000]]Range[1000]^(-1);
This is approximately 3.5 as fast as your approach.
Peter
[toc] | [prev] | [next] | [standalone]
| From | Peter Pein <petsie@dordos.net> |
|---|---|
| Date | 2011-10-07 09:11 +0000 |
| Message-ID | <j6mfnm$7nr$1@smc.vnet.net> |
| In reply to | #5421 |
Am 06.10.2011 10:19, schrieb michael partensky:
> Hi.
>
> What are the better ways of doing what this guy does very inefficiently for
> the average of the consecutive coin tosses:
>
> tr = (flips = 1; (#/flips++) & /@ Accumulate[Table[toss, {1000}]]) // N);
>
> where
>
> toss= RandomInteger[];
>
> Thanks
> Michael
sorry, I forgot to mention that using machine-precision floats is a lot
faster:
Accumulate[RandomInteger[1, 1000]//N]N[Range[1000]]^-1
is ~65 times faster than the element-wise code
[toc] | [prev] | [next] | [standalone]
| From | "Dr. Wolfgang Hintze" <weh@snafu.de> |
|---|---|
| Date | 2011-10-08 18:49 +0000 |
| Message-ID | <j6q5ve$p11$1@smc.vnet.net> |
| In reply to | #5421 |
Hi,
a = Table[2*Random[Integer, {0, 1}] - 1, {10^3}];
b = FoldList[Plus, a[[1]], Drop[a, 1]];
N[Mean[b]]
... and say hello to "this guy" ;-)
Wolfgang
"michael partensky" <partensky@gmail.com> schrieb im Newsbeitrag
news:j6jobf$lv7$1@smc.vnet.net...
> Hi.
>
> What are the better ways of doing what this guy does very
> inefficiently for
> the average of the consecutive coin tosses:
>
> tr = (flips = 1; (#/flips++) & /@ Accumulate[Table[toss, {1000}]]) //
> N);
>
> where
>
> toss= RandomInteger[];
>
> Thanks
> Michael
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web