mmcdara

7891 Reputation

22 Badges

9 years, 61 days

MaplePrimes Activity


These are replies submitted by mmcdara



My strong filling is that when the development team introduced the DeepLearning package in Maple 2020 they followed the law of least effort.
This package is an extremely pale and incomplete version of Keras and I strongly advice you to browse Keras' site to understand how DeepLearning work (or is intended to work).
At least you will find decent help pages.

When I first used this package with Maple 2020 I've been extremely disappointed by its limitations, lack of features, and slowness.
It took me less than a week to return to R  and its keras (not capital K) package.
If you want to play with deep learning forget Maple or wait for a future release.

Of course, this is my personal opinion and other members feel free to disagree with it.

@MaPal93 

The piece of code concerning the Sylvester's criterion is not written in a generic way. Whatever the value of N the two "extreme" minors are cor_Matrix[1, 1] and Determinant(cor_Matrix).

  • N = 2:
    No other minor if required.
  • N > 2
    You have N-2 "intermediate" minors.
    The (principal) minor of order p of a matrix M is the determinant of the submatrix of M obtained by removing the las (N-p) column and rows.
    For instance, in cas N = 3, the minot of order 2 is the determinant of cor_Matrix[1..2, 1..2])
with(LinearAlgebra):
A := Matrix(3, 3, [$1..9]):
Minor(A, 3, 3);
Determinant(A[1..2, 1..2]);
                               -3
                               -3
N := 5:
A := RandomMatrix(N$2, generator=0. .. 1.):
for n from 1 to N do
  printf("Principal Minor of order %d : %1.6f\n", n, Determinant(A[1..n, 1..n]));
end do;
Principal Minor of order 1 : 0.627384
Principal Minor of order 2 : 0.007251
Principal Minor of order 3 : 0.073320
Principal Minor of order 4 : 0.120326
Principal Minor of order 5 : -0.015124

Here is an example of a 5-by-5 random matrix where only one arbitrary element is replaced by x.
A system of 5 inequalities is solved to determine for the ranges of x (if any) for which A is positive-definite.

A := RandomMatrix(N$2, generator=0. .. 1.):
A[3, 2] := x:

Sylvester_eqs := NULL:
for n from 1 to N do
  d := Determinant(A[1..n, 1..n]):
  Sylvester_eqs :=  Sylvester_eqs, d:
  printf("Principal Minor of order %d : %a\n", n, Determinant(A[1..n, 1..n]));
end do:
Principal Minor of order 1 : .915991244131425297
Principal Minor of order 2 : .136420343e-1
Principal Minor of order 3 : .3626471264e-1*x-.1140974042e-1
Principal Minor of order 4 : .4197962538e-2-.4533761488e-2*x
Principal Minor of order 5 : .1468450919-.1473851962*x
solve([Sylvester_eqs] >~ 0)
              {0.3146237648 < x, x < 0.9259336975}


Note that it is extremly complex to build a symmetric positive definite matrix of diension N > 3.
This piece of code assesses the probability that random a "correlation-like matrice" is positive definite :
 

CheckPositivity := proc(N, R) local failures, r, A, i, n: failures := 0: for r from 1 to R do   A := RandomMatrix(N$2, generator=-1. .. 1., shape=symmetric):
  for i from 1 to N do A[i, i] := 1 end do:   for n from 1 to N do      if Determinant(A[1..n, 1..n]) < 0 then
       failures := failures + 1:
       break      end if:   end do; end do: evalf[3](failures/R) end proc: CheckPositivity(2, 1000);
CheckPositivity(3, 1000);
CheckPositivity(4, 1000);
CheckPositivity(5, 1000);
                               0.
                             0.383
                             0.840
                             0.975

 

@Saha 

The error message is however very clear: you want to  plot(v(t), x = .101 .. .109), but v(t) is not a function of x.
Do this to convince you:

# syntax changed because yours is not accepted in Maple 2015
v := unapply( sum(u[r]*t^r, r = 0 .. 2), t):
# this command returns the namas of all indeterminates
indets(v(t), name)
                          {e, t, x, y}

Then v(t) is a function of 4 parameters.
To plot it versus x you must set t, y, and e to numerical values.

BTW: a common newbie mistake is to write e^x instead of exp(x), so if you want to use exp, change all your e^ accordingly.
This will remove e from the indetrterminates.
Compare this

plot(eval(v(1), [y=2]), x=0.101..0.109)
Warning, expecting only range variable x in expression 19/12+17/12*e^(x+2)+7/24*e^(x+2)*ln(e)^2+4/45*(e^(x+2))^2+1/60*(e^(x+2))^2*ln(e)^2+1/80*e^(x+2)*ln(e)^4+1/252*(e^(x+2))^3+1/15*e^(x+2)*(1/6*e^(x+2)*ln(e)^2+1/3*e^(x+2)) to be plotted but found name e

to this

plot(eval(v(1), [y=2, e=exp(1)]), x=0.101..0.109)

which returns a correct plot.

 

restart

with(LinearAlgebra):

F := proc (x) options operator, arrow; x^2 end proc:

u[0] := 1+t*exp(x+y);

1+t*exp(x+y)

 

(1+t*exp(x+y))^2

(1)

for n from 0 while n <= 6 do V[n] := (diff(F(sum(lambda^i*u[i], i = 0 .. n)), [`$`(lambda, n)]))/factorial(n) end do:

lambda := 0;

0

(2)

for i from 0 while i <= n-1 do A[i] := V[i] end do;

(1+t*exp(x+y))^2

 

2*(1+t*exp(x+y))*u[1]

 

u[1]^2+2*(1+t*exp(x+y))*u[2]

 

2*u[1]*u[2]+2*(1+t*exp(x+y))*u[3]

 

u[2]^2+2*u[1]*u[3]+2*(1+t*exp(x+y))*u[4]

 

2*u[2]*u[3]+2*u[1]*u[4]+2*(1+t*exp(x+y))*u[5]

 

u[3]^2+2*u[2]*u[4]+2*u[1]*u[5]+2*(1+t*exp(x+y))*u[6]

(3)

for n from 0 to 1 do u[n+1] := (1/2)*(int(int(diff(add(u[i], i = 0 .. n), x, x)+diff(add(u[n], i = 0 .. n), y, y), t = 0 .. t), t = 0 .. t))+int(int(A[n], t = 0 .. t), t = 0 .. t) end do;

(1/2)*exp(x+y)*t^3+(1/12)*(exp(x+y))^2*t^4+(1/2)*t^2

 

(1/12)*exp(x+y)*t^3+(11/80)*exp(x+y)*t^5+(1/18)*(exp(x+y))^2*t^6+(1/252)*(exp(x+y))^3*t^7+(1/12)*t^4

(4)

v := proc (t) options operator, arrow; sum(u[r]*t^r, r = 0 .. 2) end proc:

# syntax changed becaurse yours is not accepted in Maple 2015
v := unapply( sum(u[r]*t^r, r = 0 .. 2), t):

indets(v(t), name)

{t, x, y}

(5)

plots:-display(
  seq(
    plot(
      eval(v(t), y=2), x=0.101..0.709, legend=typeset('t'=t)
      , color=ColorTools:-Color([rand()/10^12, rand()/10^12, rand()/10^12])
    )
    , t in [seq](0.8..1.2, 0.2)
   )
);

 

plot3d(eval(v(1)), x=0.101..0.709, y=0.101..0.709):

# I suggest you to devine v this way
v := unapply( sum(u[r]*t^r, r = 0 .. 2), [x, y, t]):
plot3d(v(x, y, 1), x=0.101..0.709, y=0.101..0.709)

 

``


 

Download ADM_TRY_mmcdara.mw

@sursumCorda 

A rather close question has been posted several weeks ago.

If I'm not mistaken a few high ranked contributors gave explanations about the reasons solve didn't (seem to) return the good solution

@MaPal93 

My apologies; replace procedure Inv by this one:

Inv := proc(s::Matrix)
  MatrixInverse(s)
end proc:

I also made another mistake in the expression of CondExp(E, X, Y), it should be

mu__X + Sigma__12 . Inv(Sigma__22) . (YY - mu__Y)

3_gaussian_1.mw

@MaPal93 

Point 1: Because the first time I answered one of your question it was about correlating 2 gaussian random variables, than it's now to correlate 3 such rvs and I thought it was better to provide you a more generic way to proceed. 

Point 2: I advice you not to use ad hoc notations gut simpler and more generic ones.
Once you will get the desired result you have all the time ti substitute "standard" notations but you own notations.

Point 3: Just that I didn't check your formulas.

In the attached file you will find an example to code the conditional expectation and variance of a random vector X by a random vector Y (of same lengths).
As the formula will be very lengthy, I wrote themsymbolically (remove the simple quotes to evaluate the conditional statistics):

3_gaussian_1.mw

By the way: I don't understand why you want to use Maple and keep writting incredibly lengthy formulas like your betas and alpha in the LinearProjectionTheorem...mf file ????
If these variables are the result of some computation, just provide the formuas to derive them.
I find this a pure waste of time, not speaking of the risk of typos.

Or maybe did you catch these expressions from another worksheet you don't want us to know about?

@MaPal93 @Carl Love

In these articles the variance is multiplied by a factor in such a way that the two terms have the same dimension.

@Carl Love 

I had not paid attention to this, good point for you!

@sursumCorda 

Thanks.

@norma.muhtar

restart

# First model

model_1 := convert( k__1/(1 + (k__1/80 - 1)*2.73^(r__1*t)), exp)

k__1/(1+((1/80)*k__1-1)*exp(1.004301609*r__1*t))

(1)

# Second model

model_2 := k__2/(1 + (k__2/80 - 1)*exp(-r__2*t));

k__2/(1+((1/80)*k__2-1)*exp(-r__2*t))

(2)

# at the evidence the two models are identical under the transformation

transf := [k__2 = k__1, r__2 = -1.004301609*r__1]

[k__2 = k__1, r__2 = -1.004301609*r__1]

(3)

# proof

is( eval(model_2, transf) = model_1);

true

(4)

# Conclusion:
# if (k_1_opt, r_1_opt) is the best fit vector for model 1,
# then (k_2_opt = k_1_opt, r_2_opt = -1.004301609*r_1_opt) is the best fit vector for model 2.

.

Download fit_1bis_mmcdara.mw

If you really want to do the optimization with this new model (which is useless), you can do this
fit_2_mmcdara.mw

You miss one boundary condition and the 8th BC is trivial (0=0).
 

@lcz 

No need to apologize, no harm done

ShortestPath selects one of shortest paths between two vertices:

You're right, I recognized that I could have been lucky while finding the same paths that you give for your first example (in fact there was no other solution).
But it made me understand that, when at a given step there are two shortest paths of the same length with common edges, the choice of one of them, coupled with the strategy of deleting all the vertices except the departure and arrival ones, can lead to forget paths that the alternative choice would have revealed. 
To try and fix this problem, I thought of deleting only some (how to choose them?) intermediate vertices.
But this appeared relatively complex to code and I postponed this question.

@lcz 

...it's you who failed in using it!

If you read carefully the code I provided, you will see there is the line 

s := ShortestPath(G, 1, 7);

I would have thought that you would have yourself adapted this line to your new example before saying that you had found a counter example.

g:=Graph({{1,2},{1,3},{1,4},{1,5},{2,6},{3,7},{4,8},{5,9},{2,7},{6,10},{7,10},{8,10},{9,10}}):

G := CopyGraph(g):
d := NULL:

while IsConnected(G) do
  s := ShortestPath(G, 1, 10);
  c := s[2..-2]:
       HighlightEdges(G, {seq({s[i], s[i+1]}, i=1..nops(s)-1)}, red);
  d := d, DrawGraph(G, style=planar);
  G := DeleteVertex(G, c);
  print(s);
end do:
d := d, DrawGraph(G):

plots:-display(`<|>`(d))
                         [1, 2, 6, 10]
                         [1, 3, 7, 10]
                         [1, 4, 8, 10]
                         [1, 5, 9, 10]

@lcz  ,  @Carl Love  here is an updated version of my initial worksheet where:

  1. A procedure named DisjointPaths encapsulates my initial the lines of code.
    It takes 3 arguments: a graph, the vertex of departure, the vertex of arrival.
  2. The 3 examples that have been discussed here

DisjointPaths.mw

@acer 

Thank you for your answer.

Here is the result obtained with Maple 2015.2
Maple2015.mw
Thereare no problem ar all

First 51 52 53 54 55 56 57 Last Page 53 of 154