Record Statistics for Discrete Random Walks
up vote
3
down vote
favorite
I code a random walk of length 100 drawn from a LaplaceDistribution:
Accumulate[RandomVariate[LaplaceDistribution[0, 1], 10000]]
I am having trouble counting the number of record events in a discrete random walk. A record occurs at time t if the value of the random walk at time t is greater than all values of the walk for all times less than t. I want a function that will let count the number of records that occur in a walk of length n.
Thanks.
probability-or-statistics random discrete random-process
New contributor
add a comment |
up vote
3
down vote
favorite
I code a random walk of length 100 drawn from a LaplaceDistribution:
Accumulate[RandomVariate[LaplaceDistribution[0, 1], 10000]]
I am having trouble counting the number of record events in a discrete random walk. A record occurs at time t if the value of the random walk at time t is greater than all values of the walk for all times less than t. I want a function that will let count the number of records that occur in a walk of length n.
Thanks.
probability-or-statistics random discrete random-process
New contributor
1
Why do you first generate 10000 samples and then only keep 100 of them randomly?
– Thies Heidecke
7 hours ago
I've realised it is completely pointless to do that lol.
– Will
7 hours ago
No problem :) Just wanted to clarify if there's some deeper meaning behind it that i missed.
– Thies Heidecke
7 hours ago
Is the mean number of records in such a walk the desired end result? If so, then nBinomial[2 n, n]/2^(2 n - 1)
withn
the step number suffices...
– ciao
5 hours ago
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I code a random walk of length 100 drawn from a LaplaceDistribution:
Accumulate[RandomVariate[LaplaceDistribution[0, 1], 10000]]
I am having trouble counting the number of record events in a discrete random walk. A record occurs at time t if the value of the random walk at time t is greater than all values of the walk for all times less than t. I want a function that will let count the number of records that occur in a walk of length n.
Thanks.
probability-or-statistics random discrete random-process
New contributor
I code a random walk of length 100 drawn from a LaplaceDistribution:
Accumulate[RandomVariate[LaplaceDistribution[0, 1], 10000]]
I am having trouble counting the number of record events in a discrete random walk. A record occurs at time t if the value of the random walk at time t is greater than all values of the walk for all times less than t. I want a function that will let count the number of records that occur in a walk of length n.
Thanks.
probability-or-statistics random discrete random-process
probability-or-statistics random discrete random-process
New contributor
New contributor
edited 5 hours ago
New contributor
asked 7 hours ago
Will
163
163
New contributor
New contributor
1
Why do you first generate 10000 samples and then only keep 100 of them randomly?
– Thies Heidecke
7 hours ago
I've realised it is completely pointless to do that lol.
– Will
7 hours ago
No problem :) Just wanted to clarify if there's some deeper meaning behind it that i missed.
– Thies Heidecke
7 hours ago
Is the mean number of records in such a walk the desired end result? If so, then nBinomial[2 n, n]/2^(2 n - 1)
withn
the step number suffices...
– ciao
5 hours ago
add a comment |
1
Why do you first generate 10000 samples and then only keep 100 of them randomly?
– Thies Heidecke
7 hours ago
I've realised it is completely pointless to do that lol.
– Will
7 hours ago
No problem :) Just wanted to clarify if there's some deeper meaning behind it that i missed.
– Thies Heidecke
7 hours ago
Is the mean number of records in such a walk the desired end result? If so, then nBinomial[2 n, n]/2^(2 n - 1)
withn
the step number suffices...
– ciao
5 hours ago
1
1
Why do you first generate 10000 samples and then only keep 100 of them randomly?
– Thies Heidecke
7 hours ago
Why do you first generate 10000 samples and then only keep 100 of them randomly?
– Thies Heidecke
7 hours ago
I've realised it is completely pointless to do that lol.
– Will
7 hours ago
I've realised it is completely pointless to do that lol.
– Will
7 hours ago
No problem :) Just wanted to clarify if there's some deeper meaning behind it that i missed.
– Thies Heidecke
7 hours ago
No problem :) Just wanted to clarify if there's some deeper meaning behind it that i missed.
– Thies Heidecke
7 hours ago
Is the mean number of records in such a walk the desired end result? If so, then n
Binomial[2 n, n]/2^(2 n - 1)
with n
the step number suffices...– ciao
5 hours ago
Is the mean number of records in such a walk the desired end result? If so, then n
Binomial[2 n, n]/2^(2 n - 1)
with n
the step number suffices...– ciao
5 hours ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
4
down vote
Here's one take:
path = Accumulate[RandomVariate[LaplaceDistribution[0, 1], 1000]];
records = FoldList[Max, path];
ListPlot[{
path,
records
}]
records
has lots of duplicates in it. It's a list where in each position we have the largest value up to that point. If we take the union of the values (or use DeleteDuplicates
), we get the unique largest-so-far values, and if we count those we get the desired answer:
Length@Union[records]
52
Thank you. This is perfect.
– Will
7 hours ago
add a comment |
up vote
3
down vote
Let's generate data from a random walk first
SeedRandom[42]
walkdata = Accumulate[RandomVariate[LaplaceDistribution[0, 1], 100]]
, then one way to get what you want is with a Fold
:
Last@Fold[
Function[{state,newvalue},
With[{currentrecord=state[[1]],recordcounter=state[[2]]},
If[newvalue > currentrecord,
{newvalue,recordcounter+1},
state
]
]
],
{0,0},
walkdata
]
33
During the fold we keep track of the currentrecord
and the number of records (starting with {0,0}
) and update it when we find a higher value, otherwise we keep the old. The endresult is the last record and the number of records we encountered from which we just keep the number of record updates (with Last
).
Comparing it with C.E.s solution this mainly trades some code clarity (if that's most important definitely go with C.E.s version) for some potential speed up by saving the overhead of the Union
function call. If you are dealing with long random walks or doing a lot of them this might become relevant. There is also the additional option to Compile
if you need better performance.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
Here's one take:
path = Accumulate[RandomVariate[LaplaceDistribution[0, 1], 1000]];
records = FoldList[Max, path];
ListPlot[{
path,
records
}]
records
has lots of duplicates in it. It's a list where in each position we have the largest value up to that point. If we take the union of the values (or use DeleteDuplicates
), we get the unique largest-so-far values, and if we count those we get the desired answer:
Length@Union[records]
52
Thank you. This is perfect.
– Will
7 hours ago
add a comment |
up vote
4
down vote
Here's one take:
path = Accumulate[RandomVariate[LaplaceDistribution[0, 1], 1000]];
records = FoldList[Max, path];
ListPlot[{
path,
records
}]
records
has lots of duplicates in it. It's a list where in each position we have the largest value up to that point. If we take the union of the values (or use DeleteDuplicates
), we get the unique largest-so-far values, and if we count those we get the desired answer:
Length@Union[records]
52
Thank you. This is perfect.
– Will
7 hours ago
add a comment |
up vote
4
down vote
up vote
4
down vote
Here's one take:
path = Accumulate[RandomVariate[LaplaceDistribution[0, 1], 1000]];
records = FoldList[Max, path];
ListPlot[{
path,
records
}]
records
has lots of duplicates in it. It's a list where in each position we have the largest value up to that point. If we take the union of the values (or use DeleteDuplicates
), we get the unique largest-so-far values, and if we count those we get the desired answer:
Length@Union[records]
52
Here's one take:
path = Accumulate[RandomVariate[LaplaceDistribution[0, 1], 1000]];
records = FoldList[Max, path];
ListPlot[{
path,
records
}]
records
has lots of duplicates in it. It's a list where in each position we have the largest value up to that point. If we take the union of the values (or use DeleteDuplicates
), we get the unique largest-so-far values, and if we count those we get the desired answer:
Length@Union[records]
52
answered 7 hours ago
C. E.
49.1k395197
49.1k395197
Thank you. This is perfect.
– Will
7 hours ago
add a comment |
Thank you. This is perfect.
– Will
7 hours ago
Thank you. This is perfect.
– Will
7 hours ago
Thank you. This is perfect.
– Will
7 hours ago
add a comment |
up vote
3
down vote
Let's generate data from a random walk first
SeedRandom[42]
walkdata = Accumulate[RandomVariate[LaplaceDistribution[0, 1], 100]]
, then one way to get what you want is with a Fold
:
Last@Fold[
Function[{state,newvalue},
With[{currentrecord=state[[1]],recordcounter=state[[2]]},
If[newvalue > currentrecord,
{newvalue,recordcounter+1},
state
]
]
],
{0,0},
walkdata
]
33
During the fold we keep track of the currentrecord
and the number of records (starting with {0,0}
) and update it when we find a higher value, otherwise we keep the old. The endresult is the last record and the number of records we encountered from which we just keep the number of record updates (with Last
).
Comparing it with C.E.s solution this mainly trades some code clarity (if that's most important definitely go with C.E.s version) for some potential speed up by saving the overhead of the Union
function call. If you are dealing with long random walks or doing a lot of them this might become relevant. There is also the additional option to Compile
if you need better performance.
add a comment |
up vote
3
down vote
Let's generate data from a random walk first
SeedRandom[42]
walkdata = Accumulate[RandomVariate[LaplaceDistribution[0, 1], 100]]
, then one way to get what you want is with a Fold
:
Last@Fold[
Function[{state,newvalue},
With[{currentrecord=state[[1]],recordcounter=state[[2]]},
If[newvalue > currentrecord,
{newvalue,recordcounter+1},
state
]
]
],
{0,0},
walkdata
]
33
During the fold we keep track of the currentrecord
and the number of records (starting with {0,0}
) and update it when we find a higher value, otherwise we keep the old. The endresult is the last record and the number of records we encountered from which we just keep the number of record updates (with Last
).
Comparing it with C.E.s solution this mainly trades some code clarity (if that's most important definitely go with C.E.s version) for some potential speed up by saving the overhead of the Union
function call. If you are dealing with long random walks or doing a lot of them this might become relevant. There is also the additional option to Compile
if you need better performance.
add a comment |
up vote
3
down vote
up vote
3
down vote
Let's generate data from a random walk first
SeedRandom[42]
walkdata = Accumulate[RandomVariate[LaplaceDistribution[0, 1], 100]]
, then one way to get what you want is with a Fold
:
Last@Fold[
Function[{state,newvalue},
With[{currentrecord=state[[1]],recordcounter=state[[2]]},
If[newvalue > currentrecord,
{newvalue,recordcounter+1},
state
]
]
],
{0,0},
walkdata
]
33
During the fold we keep track of the currentrecord
and the number of records (starting with {0,0}
) and update it when we find a higher value, otherwise we keep the old. The endresult is the last record and the number of records we encountered from which we just keep the number of record updates (with Last
).
Comparing it with C.E.s solution this mainly trades some code clarity (if that's most important definitely go with C.E.s version) for some potential speed up by saving the overhead of the Union
function call. If you are dealing with long random walks or doing a lot of them this might become relevant. There is also the additional option to Compile
if you need better performance.
Let's generate data from a random walk first
SeedRandom[42]
walkdata = Accumulate[RandomVariate[LaplaceDistribution[0, 1], 100]]
, then one way to get what you want is with a Fold
:
Last@Fold[
Function[{state,newvalue},
With[{currentrecord=state[[1]],recordcounter=state[[2]]},
If[newvalue > currentrecord,
{newvalue,recordcounter+1},
state
]
]
],
{0,0},
walkdata
]
33
During the fold we keep track of the currentrecord
and the number of records (starting with {0,0}
) and update it when we find a higher value, otherwise we keep the old. The endresult is the last record and the number of records we encountered from which we just keep the number of record updates (with Last
).
Comparing it with C.E.s solution this mainly trades some code clarity (if that's most important definitely go with C.E.s version) for some potential speed up by saving the overhead of the Union
function call. If you are dealing with long random walks or doing a lot of them this might become relevant. There is also the additional option to Compile
if you need better performance.
edited 6 hours ago
answered 7 hours ago
Thies Heidecke
6,7562438
6,7562438
add a comment |
add a comment |
Will is a new contributor. Be nice, and check out our Code of Conduct.
Will is a new contributor. Be nice, and check out our Code of Conduct.
Will is a new contributor. Be nice, and check out our Code of Conduct.
Will is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f187255%2frecord-statistics-for-discrete-random-walks%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Why do you first generate 10000 samples and then only keep 100 of them randomly?
– Thies Heidecke
7 hours ago
I've realised it is completely pointless to do that lol.
– Will
7 hours ago
No problem :) Just wanted to clarify if there's some deeper meaning behind it that i missed.
– Thies Heidecke
7 hours ago
Is the mean number of records in such a walk the desired end result? If so, then n
Binomial[2 n, n]/2^(2 n - 1)
withn
the step number suffices...– ciao
5 hours ago