6351 Reputation

17 Badges

7 years, 358 days

MaplePrimes Activity

These are questions asked by mmcdara

(While using Maple 2015 this question concerns any other Maple versions)

I hesitated on the title to write and my first idea was to write "How to modify a built-in functions without making a mess?".
I finally changed my mind in order not to orient the answers in a wrong way.

So this question is about the construction of multi-variate distributions and concerns only the Statistics package.
Here are some of the attributes of a univariate random variable that Maple recognizes, and it is quite normal to expect that the construction of a multi-variate random variable (MVRV for short) distribution should get, at least, some of them.

X := RandomVariable(Normal(a, b)):
map(a -> printf("%a\n", a), [exports(attributes(X)[3])]):

If the distribution is continuous the PDF is fundamental in the sense it enables constructs all the other statistics (=attributes) of a MVRV.
But it is nice to use integrated functions, such as Mean, Support, PDF, and so on, to get the expressions or values of these statistics instead of computing them from this PDF.
Let's that I prefer doing this

MyNormal := proc(m, v)
  description "Reparameterized Normal randomvariable, m=mean, v=variance":
    PDF = (t -> exp(-1/2*(x-m)^2/v)/sqrt(2*Pi*v))
    , Conditions = [Sigma > 0]
    , Mean =m
end proc:

X := RandomVariable(MyNormal(mu, Sigma)):

than doing this

MyNormal := proc(m, v)
  description "Reparameterized Normal randomvariable, m=mean, v=variance":
    PDF = (t -> exp(-1/2*(x-m)^2/v)/sqrt(2*Pi*v))
    , Conditions = [Sigma > 0]
end proc:

X := RandomVariable(MyNormal(mu, Sigma)):
Mean(X);  # of course undefined
mean := int(PDF(X, x), x=-infinity..+infinity) assuming Sigma > 0
                           mean := 1

So, while all the statistics can be recover from the CDF (provided it exists), it's nicer to define these statistics within the Distribution structure (as in the first construction above).

Now some problems appear when you want to construct the Distribution structure for a MVRV.
The attached file contains the construction of MVRV whose ecah components are mutually independent (to keep the things simple) and both have a Unifom distribution.

Here are some observations:

  • Defining a multi-variate PDF goes without problems.
  • Defining the Mean (or many other algebraic or numeric statistics) presents a difficulty related to the type of the arguments the build-in function Mean is aimed to recieve.
    But a workaround, not very elegant, can be found.
  • The case of the Support seems unsolvable: I wasn't able to find any workaround to define the support of a MVRV.
  • I did not consider the Conditions attribute, but I'm not sure that, in the case of, let's say, a bi-gaussian random variable I would be capable to set that the variance is a symmetric positive-definite matrix?

I feel like the main restriction to define such MVRV distributions is the types used in the buid-in functions used in the Distribution structure.

Does anyone have an idea to tackle this problem?

  • Are we doomed to use workarounds like the one I used for defining the MVRV mean?
  • Can we modify the calling sequence of some build-in functions without making a mess and keep them working on build-in distributions?
  • Must we overload the construction of these build-in functions?
    Doing for instance:
    local Mean:
    Mean := proc(...) ... end proc

Thanks in advance for any suggestion and help.

In a recent answer I posted, I had a relation of the form

I*Int(f(x), x) = something - 2*I*Int(f(x), x)

and I wanted to isolate the term Int(f(x), x).
The function isolate failed to do it and I was forced to use some workaround to do the "isolation".

Trying to understand what happened here, it seems that isolate fails when the term to isolate is multiplied by the imaginary unit
Here are a few examples

expr := I*(Int(x^2*ln(-x+sqrt(x^2-1)), x)) = g(x) -(2*I)*(Int(x^2*ln(-x+sqrt(x^2-1)), x))

I*(Int(x^2*ln(-x+(x^2-1)^(1/2)), x)) = g(x)-(2*I)*(Int(x^2*ln(-x+(x^2-1)^(1/2)), x))


# no isolation

isolate(expr, lhs(expr))

I*(Int(x^2*ln(-x+(x^2-1)^(1/2)), x)) = g(x)-(2*I)*(Int(x^2*ln(-x+(x^2-1)^(1/2)), x))


# isolation

expr_1 := expand(expr / I)
isolate(expr_1, lhs(expr_1))

Int(x^2*ln(-x+(x^2-1)^(1/2)), x) = -((1/3)*I)*g(x)


# no isolation neither, so the problem is not related to "Int"

expr := I*diff(h(x), x) = g(x) -2*I*diff(h(x), x):
isolate(expr, lhs(expr))

I*(diff(h(x), x)) = g(x)-(2*I)*(diff(h(x), x))


# no isolation neither, so the problem comes from "I"

expr := I*A = g(x) -2*I*A:
isolate(expr, lhs(expr))

I*A = g(x)-(2*I)*A


# isolation (of course)

expr := c*A = g(x) -2*c*A:
isolate(expr, lhs(expr))

c*A = (1/3)*g(x)




I guess this is a known behavior, but why it is so?
Is there a way to force the "isolation" without using a trick like in result (3)

Thanks in advance

Let P(x) a polynomial with a single indeterminate.
In Maple 2015 (please, do not consider this question if Maple >=2021 doesn't present this problemcoeffs returns the coefficients P(x) in a different in some circumstances:

m := [$1..3]:

add(m[k]*(R)^(k-1), k=1..3):
c:= coeffs(%, R, 't'): [c], [t];

                              [ 2      ]
                   [3, 2, 1], [R , R, 1]
add(m[k]*(R)^(k-1), k=1..2):
c:= coeffs(%, R, 't'): [c], [t];
                        [1, 2], [1, R]

The order in the first case is R^2, R^1, R^0 while it is R^1, R^0 in the second one.

It's quite easy to check if P(x) is of the form a+b*R and to reverse the output of coeffs. But does it exist an option of coeffs which monitors the output order.


Is there a simpler and more elegant way to get the last result in this code snippet?

                          f(a) + f(b)
# simpler and more elegant
map(f, a+b);
                          f(a) + f(b)
# now I want to obtain this result
add(f~([op(a+b)], t)[]);
                       f(a, t) + f(b, t) 


I met a an unexpected behaviour of a procedure when the parameter sequence contains the type ':-RandomVariable':  

f1 := proc(A::':-RandomVariable')
end proc:

Z := RandomVariable(Normal(mu, sigma)):
hastype(Z, ':-RandomVariable');
Error, invalid input: f1 expects its 1st argument, A, to be of type 'RandomVariable', but received _R
# Another attempt
f2 := proc(A)
  if hastype(A, ':-RandomVariable') then Mean(A) end if;
end proc:


Why does f1 generate this error?

5 6 7 8 9 10 11 Last Page 7 of 43