epostma

1494 Reputation

19 Badges

17 years, 58 days
Maplesoft

Social Networks and Content at Maplesoft.com

I am the manager of the Mathematical Software Group, working mostly on the Maple library. I have been working at Maplesoft since 2007, mostly on the Statistics and Units packages and on contract work with industry users. My background is in abstract algebra, in which I completed a PhD at Eindhoven University of Technology. During my studies I was always searching for interesting questions at the crossroads of math and computer science. When I came to Canada in 2007, I had nothing but a work permit, some contacts at Maplesoft (whom I had met at a computer algebra conference a year earlier), and a plan to travel around beautiful Canada for a few months. Since Maplesoft is a company that solves more interesting math and computer science related questions than just about anywhere else, I was quite eager to join them, and after about three months, I could start.

MaplePrimes Activity


These are replies submitted by epostma

Note that both ?copy and ?LinearAlgebra:-Copy will work. They do almost exactly the same thing if their argument is a Matrix or Vector.

Erik Postma
Maplesoft.

Hi herclau,

If you call ?randomize with a fixed argument, you always set the random generator to the same state, so you will always get the same matrices. That's its purpose.

If you want to get different results, it's probably best to just not restart in between subsequent runs. Alternatively, you can omit the argument in the call to randomize(); that will set the random seed to something based on the current internal clock time of your computer (though I believe it only uses a granularity of seconds, so don't do it in, say, a loop - in which case you're doing something wrong anyway, because for obvious reasons you can't restart from within a loop.)

HTH,

Erik Postma
Maplesoft.

Hi herclau,

If you call ?randomize with a fixed argument, you always set the random generator to the same state, so you will always get the same matrices. That's its purpose.

If you want to get different results, it's probably best to just not restart in between subsequent runs. Alternatively, you can omit the argument in the call to randomize(); that will set the random seed to something based on the current internal clock time of your computer (though I believe it only uses a granularity of seconds, so don't do it in, say, a loop - in which case you're doing something wrong anyway, because for obvious reasons you can't restart from within a loop.)

HTH,

Erik Postma
Maplesoft.

Hi Daniel / SamuelTuvare,

Could you show us the details of what you have done so far?

Erik Postma
Maplesoft.

Taking the time interval between t=0 and t=0 and dividing it into 100 time steps, you get steps of length 0. The system is not set up for this. Similarly, you also can't ask for the value at negative times.

Hope this helps,

Erik Postma
Maplesoft.

Taking the time interval between t=0 and t=0 and dividing it into 100 time steps, you get steps of length 0. The system is not set up for this. Similarly, you also can't ask for the value at negative times.

Hope this helps,

Erik Postma
Maplesoft.

@Markiyan Hirnyk : Another option that is equally fast (measured to within measurement accuracy on an i7 running linux-64) is:

nops(select(`<`, thelist, 0));

The big advantage of this over the version with c -> c < 0 is that it only uses a kernel-internal procedure in the inner loop. 

Met vriendelijke groet,

Erik Postma
Maplesoft. 

@Markiyan Hirnyk : Another option that is equally fast (measured to within measurement accuracy on an i7 running linux-64) is:

nops(select(`<`, thelist, 0));

The big advantage of this over the version with c -> c < 0 is that it only uses a kernel-internal procedure in the inner loop. 

Met vriendelijke groet,

Erik Postma
Maplesoft. 

 It uses default values of 10^2 (equally long) time steps and 10^4 iterations.

This is determined by the procedures Finance:-ExpectedValue:-ProcessParameters and Finance:-ExpectedValue:-ProcessCommonOptions. You can look at the source code for these guys by doing:

kernelopts(opaquemodules=false):
showstat(Finance:-ExpectedValue:-ProcessParameters);
showstat(Finance:-ExpectedValue:-ProcessCommonOptions);

and if you showstat(Finance:-ExpectedValue) you can see how these two are called.

Hope this helps,

Erik Postma
Maplesoft.

 It uses default values of 10^2 (equally long) time steps and 10^4 iterations.

This is determined by the procedures Finance:-ExpectedValue:-ProcessParameters and Finance:-ExpectedValue:-ProcessCommonOptions. You can look at the source code for these guys by doing:

kernelopts(opaquemodules=false):
showstat(Finance:-ExpectedValue:-ProcessParameters);
showstat(Finance:-ExpectedValue:-ProcessCommonOptions);

and if you showstat(Finance:-ExpectedValue) you can see how these two are called.

Hope this helps,

Erik Postma
Maplesoft.

Hi mah00,

Here's a few hints to help you get started.

Statistics' ExpectedValue command doesn't know how to deal with Finance's processes - just with Statistics' RandomVariables. (For Statistics, the BrownianMotion process you define looks like a simple non-stochastic variable (you could say, a parameter), and the expected value of a parameter is that parameter itself. (_X is the name Finance gives to the process). You'll need to use Finance's ExpectedValue command, which estimates the expected value from a number of realizations (sample paths).

Also, you'll need to specify a scalar involving the time values at which you want to know the expected value. For example:

ExpectedValue(abs(xi1(1)[1] - xi1(1)[2]), timesteps=100, replications=10^4);

to get the average absolute difference between the first and second of the four components of xi1 at t=1.

Whether you want a Brownian motion or a Wiener process is up to you - you'll need to decide which of those two fits your needs.

Erik Postma
Maplesoft.

Hi mah00,

Here's a few hints to help you get started.

Statistics' ExpectedValue command doesn't know how to deal with Finance's processes - just with Statistics' RandomVariables. (For Statistics, the BrownianMotion process you define looks like a simple non-stochastic variable (you could say, a parameter), and the expected value of a parameter is that parameter itself. (_X is the name Finance gives to the process). You'll need to use Finance's ExpectedValue command, which estimates the expected value from a number of realizations (sample paths).

Also, you'll need to specify a scalar involving the time values at which you want to know the expected value. For example:

ExpectedValue(abs(xi1(1)[1] - xi1(1)[2]), timesteps=100, replications=10^4);

to get the average absolute difference between the first and second of the four components of xi1 at t=1.

Whether you want a Brownian motion or a Wiener process is up to you - you'll need to decide which of those two fits your needs.

Erik Postma
Maplesoft.

Let me try to help you with a general remark, because I'm not sure what you are trying to do exactly. If you want to find some statistical property (such as the expected value, or the covariance) of a random variable, or a group of random variables, you'll need to choose between two options.

The first option is to do everything symbolically. You could characterize this approach by the fact that you never take a sample, using Statistics:-Sample or Finance:-SamplePath, or use data from the outside - it's just the use of the abstract distribution. You can for example ask for the ExpectedValue of the square of the normal distribution with parameters mu and sigma. This is almost exclusively the domain of the Statistics package - the Finance package typically requires the use of the second approach.

The second option is to use data. You can generate SamplePaths or Samples and then measure the properties of these realizations of the random variables. In this case, you'll need to make sure that for every call to a statistical property you want to compute, you have a sample of data for that call. In particular, if you want to find the covariance between, say, a property of a process at t=1 and a property of the process at t=2, then you'll need a sufficient number of replications of the sample path as a whole and pass the values at t=1 and t=2 of all sample paths to the proper function call. You can't compute the covariance by calling ExpectedValue on every data point individually.

Let us know if this helps, and if it doesn't then tell us exactly what you are trying to compute.

Hope this helps,

Erik Postma
Maplesoft.

Let me try to help you with a general remark, because I'm not sure what you are trying to do exactly. If you want to find some statistical property (such as the expected value, or the covariance) of a random variable, or a group of random variables, you'll need to choose between two options.

The first option is to do everything symbolically. You could characterize this approach by the fact that you never take a sample, using Statistics:-Sample or Finance:-SamplePath, or use data from the outside - it's just the use of the abstract distribution. You can for example ask for the ExpectedValue of the square of the normal distribution with parameters mu and sigma. This is almost exclusively the domain of the Statistics package - the Finance package typically requires the use of the second approach.

The second option is to use data. You can generate SamplePaths or Samples and then measure the properties of these realizations of the random variables. In this case, you'll need to make sure that for every call to a statistical property you want to compute, you have a sample of data for that call. In particular, if you want to find the covariance between, say, a property of a process at t=1 and a property of the process at t=2, then you'll need a sufficient number of replications of the sample path as a whole and pass the values at t=1 and t=2 of all sample paths to the proper function call. You can't compute the covariance by calling ExpectedValue on every data point individually.

Let us know if this helps, and if it doesn't then tell us exactly what you are trying to compute.

Hope this helps,

Erik Postma
Maplesoft.

It turns out that the issue is mathematically much simpler - it is simply use of the ExpectedValue command in a way that it's not meant to be used. For every call to ExpectedValue that you make, the argument is just a constant floating point number. The expected value of a floating point number is always that same floating point number - it's constant! Similarly, the covariance between two constants is always zero - neither of them will ever change.

What you meant to do is take the covariance of the random variables that generated those floating point numbers. I'm looking into how your computation works and will get back to you in a few minutes. (I started writing my previous answer just before you posted yours, and sadly we don't get notified of newer answers or comments when writing answers. But it is still useful information for the case that you described in your initial question, so I'll let the answer stand.)

Erik Postma
Maplesoft.

2 3 4 5 6 7 8 Last Page 4 of 21