mmcdara

7891 Reputation

22 Badges

9 years, 63 days

MaplePrimes Activity


These are replies submitted by mmcdara

@vs140580 

If your model is Y=a0+a1*x1+a2*x2+....... +a9*x9
then you have the solution in my last reply (example_2.mw and example_3.mw).
Have your read it?
PS : No need here to use PolynomialFit ;  LinearFit does the job, all the more that (cf help page) "The PolynomialFit command fits a univariate polynomial"


If your model is polynomial with terms such as x1^2 (why do you present a model of order 4? is it what you want)
or has interaction effects such as x1*x2
then you had the solution in my first answer (still with LinearFit).
But, given you have just 26 observations you won't be able to fit a model with more than 26 terms.
Which means you can fit a quadratic model without interactions (19 terms) but nothing more.
Even in this case your model will be overfitted by ordinary standards


If you do not understant how to "mix" my to answers
then look at this example
example_4.mw
If it doesn't suit you I can't do anything more for you.


By the way: a model like Y=a0+a1*x1+a2*x2+....... +a9*x9 is a usually termed "linear model".
The expression "polynomial model" is generally restricted to more complex models like
Y=sum( a[k]*f[k], k=1..K) where each f[k] is a polynomial of indeterminates  x1, ...xP where at least one of them has a total degree strictly greater than 1.
But of course your model is also polynomial with f[k] := (x1, ...xP) -> x[k]

You write "The output is from maple": what version do you use?
what is the meaning of your original question if the answer is in the Maple's help pages?

@vs140580 

Could you clearly say:

  • what are the independent variables (the nine X's ?)
  • what is the polynomial model you want to fit?

Several points : 

  • The ouput you present is the one of R ; for as far as I know there is no such default display in Maple.
    Of course you can write a (small) chunk of Maple code (example below) in order that it returns a very close display to the one R produces, but I do not understand the need to do this. If you prefer R just use R.
     
  • I use Maple 2015 when I'm at home and unfortunately  tvalue and tstatistic (the name Maple refers to R's  P(>|t|) ) are not avaliable.
    Is you use a more recent version of Maple you have just to read carefully the LinearFit help page to understand how to complete the output=[parametervector, standarderrors] in my code in order to obtain the informations you want.

Here is an example of what you can do

@vv 

Sorry, I'm ashamed, I'd better clean my spectacles

@acer 

But it's not necessary at the top level.
Yeah, I realized this as our exchange developped.
(I implicitely knew this without having really realized it ; for instance

a:=1: b:=2;
f:=proc()
a+b:
end proc:
f()

means both a and b are global.
When I used global at the top level I had this erroneous idea thata variable declared global at some level could be global only for lower levels, not for upper ones.
This is why initializing G:=[ ] at the top level while declaring G global only within procedure f intuitively seemed an error to me ... (of course I've just checked it works perfectly!!!)

More of this the presence of a warning in the example below always disturbs me: as X is explicitely declared global in the parent procedure f why does Maple return this warning? Couldn't it undersand that the X within proc g must really be considered global and that the absence of any explicit declaration of X is not an omission?

restart:
f := proc()
  global X:
  g := proc() X:=X+1 end proc;
  X:=1:
  return g()
end proc:

Warning, `g` is implicitly declared local to procedure `f`
f()

 

@acer 

Here is an oversimplified excerpt of the code I develop in MAPLE 2015

restart:
with(Maplets):
with(Maplets[Elements]):
with(Statistics):
f := proc()
  global G:
  local g, maplet:
 
  g := proc(p)
    local d:
    d:=diff(args[1], args[2]):
    Maplets:-Tools:-Set('TF1'('value')=d):
    G := [[args[1], d], G[]]:
  end proc:
 
  maplet := Maplet([
   ["Enter an expression", TextField['TF1']('width' = 30)],
   [
      "Differentiate w.r.t. x:",
      Button("Do It",
         Evaluate('function'=g, Argument('TF1'), Argument('value'=x) )
      ),
      Button("OK", Shutdown(['TF1']))
   ]
  ]):
  Maplets[Display](maplet);
  return
end proc:


global G:
G :=  []:
f():
G;
                    [[sin(x), cos(x)], [x, 1]]

This one is likely not to work in Maple 2020.
I understand that the declaration global G is unnecessary because "all names are global unless otherwise specified" (Maple V language reference manual p 114) and is a mistake.
A mistake but not a coding error for it didn't generate any in Maple 2015 (but one in Maple 2020).

The previous code should be modified this way to run in Maple 2020 and Maple 2015

restart:
with(Maplets):
with(Maplets[Elements]):
with(Statistics):
f := proc()
  global G:
  local g, maplet:
  G:=[ ]:
 
  g := proc(p)
    local d:
    d:=diff(args[1], args[2]):
    Maplets:-Tools:-Set('TF1'('value')=d):
    G := [[args[1], d], G[]]:
  end proc:
 
  maplet := Maplet([
   ["Enter an expression", TextField['TF1']('width' = 30)],
   [
      "Differentiate w.r.t. x:",
      Button("Do It",
         Evaluate('function'=g, Argument('TF1'), Argument('value'=x) )
      ),
      Button("OK", Shutdown(['TF1']))
   ]
  ]):
  Maplets[Display](maplet);
  return
end proc:


f():
G;


What is the reason that you did the global declaration explicitly in Maple 2015? I'll repeat my very first query: What effect do you think it had?
How do you do to transmit the content of G without explicitely using the global declaration?

@acer 

I believe I am not explaining myself clearly.
This worksheet

restart:
# reading of some data files
:
:
# reshaping of the data
:
:
:

Main := proc()  # how I badly wrote this line was confusing in my previous reply
global G:
:
M := Maplet(......)
:
:
Display(M)
end proc:

global G:=[ ]:
Main():

works correctly in Maple 2015 but not in Maple 2020 where I get an error message saying that (from memoryp "global can be used outside a procedure".
But this one

restart:
# reading of some data files
:
:
# reshaping of the data
:
:
:

Main := proc()  # how I badly wrote this line was confusing in my previous reply
global G:=[ ];
:
M := Maplet(......)
:
:
Display(M)
end proc:


Main():

works perfectly in Maple 2015 and Maple 2020.
Next monday I will return to my office where I can use Maple 2020.
I will write a little piece of code to clarify all of this and I will send you it.
But I'm pretty sure that this simple one doesn't work in Maple 2020:

restart
global x:=0:

f := proc() 
  global x: 
  x:=x+1: 
end proc:

f()
                               1

 

@acer 

I guess this is a more correct description of my current worksheet (still under development)

restart:
# reading of some data files
:
:
# reshaping of the data
:
:
:

Main := proc()  # how I badly wrote this line was confusing in my previous reply
global G:
:
M := Maplet(......)
:
:
Display(M)
end proc:

global G:=[ ]:
Main():

As soon as the  application will be operational :

  • I will copy/paste the procedure Main in a separate worksheet, "encapsulate" it in a module..end module structure with  option package,
  • I will save it in an archive named SA.mla located in directory MyDir
  • And use it in a worksheet this way
    restart:
    libname:=libname ".", libname, MyDir:
    with(SA):
    
    # reading of some data files
    :
    :
    # reshaping of the data
    :
    :
    :
    
    # Statistical analysis itself
    global G:=[ ]:
    Main():
    

 

I do not think that attaching a 300 Ko file could be of any help.

All the more so since my initial question was quite simple: "Why does the use of  global  at the top level of a worksheet is no longer accepted in the most recent versions of Maple (it still was in Maple 2015), but only within procedures?"
If the development team allowed wrting something like

# top of the worksheet
restart:
global G:
:
:
:

I think this is because that did mean something.
So why this is no longer allowed today?

@acer 

This concerns the maplets-based application dedicated to statistical analysis I already told you about

This application (for the moment) resumes to a single procedure Main()  which contains:

  • several procedures p1, ..., pn
  • and a single maplet M

In M several buttons are used  to run some of the procedures amid p1, ..., pn in order executes specific Satistical Analysis (SA). Such a SA always generates plots (a single one or a lot of plots).
For instance p1 will generate graphs g1, ..., gm .
Only g1 is displayed in the  Plotter element M contains; buttons are used to display the previous plot or the next one (by rotating the "local" list g1, ..., gm).

As a SA procedure is called through a 'onclick'=Evaluate('function'=pi) strategy, it's not possible (or I didn't find out how) to return the "local" list g1, ..., gm as one usually do.
The way I do this is to define a global variable G  of type list, initially set to [ ], ant to write in any SA procedure
G := [g1, ..., gm, G[ ] ].

It is important to conserve  G  even when the user closes the maplets M and thus terminates Main().


The first think I've done with  Maple 2015 is this

Main()
global G:
:
M := Maplet(......)
:
:
Display(M)
end proc:

global G:=[ ]:
Main():

But this doesn't work in Maplet 2020 which forbids using global outside of a procedure.
Thus my code now looks like this.

Main()
global G:= [ ]:
:
M := Maplet(......)
:
:
Display(M)
end proc:

Main():

 

@Carl Love  @acer

Sorry to send you so late a reply.

I think that both of you made me discover a lot of interesting things through this question and the previous one about Sunflowers, in particular the use of evalindets and subsindets.
I was aware of the existence of these procedures, but their help pages always seemed a bit abstract to me and I never really understood their real purpose.

To @Carl Love 
It's probably a matter of turn of mind but I have a better understanding of the mechanism behind c-> (c, _rest)  than those of  1@@0.
Thanks for your ls comment.

To @acer
I've just seen you modified one of your previous reply, thank you for that.

@acer 

Thanks for this lengthy and interesting reply.

A few specific info you gave:

  • In particular please not that in Maple 2017.2 (and 2020.1, etc) the Histogram command accepts and makes use of the legend option.
    I'm currently teleworking, probably as some other people here, and I have to juggle with two rather different versions of Maple, spending a non negligeable time to insure that what is done with Maple2015 still works with 2020.
    So hearing you saying that legend are habdled with the most recent Maple versions is a very good news.
     
  • I don't know how terse/flexible/powerful you need this code to be, as I don't know all the scenarios in which you might use it. I'm sure you realize that there are many degrees and ways to make it more or less flexible or general or easy to re-use.
    It's not a multi-purpose application but a field-oriented application (even though the structure of the data is usually the one met in a lot of computational codes when used to do uncertainty propagation ; if you're not familiar with this topic, here is (IMO) a short and clear presentation of it document.
    So I want my application flexible and powerful, easy to use, but I do not want it to be a nth product of this type (I think there are enough: List_of_uncertainty_propagation_software). 
     
  • You might find mildly interesting an older Post I made which uses a similar technique, for adding legends for 2D contours...
    I won't be "mildly interested" in this: I assume you're referring to some posts you wrote about a year ago?
    They were extremely interesting, I uploaded the mw files but I haven't used them so far.
    I will take a closer look at them as soon as possible.

There are a few questions about the Adomian method here.
For instance Adomian Decomposition
On the right top of this windox just type <Adomian>   in the Search feld and click on the Search button.
Maybe this will give you some starting point.

@Carl Love 

Ok, 
and you need to use 1@@0 here because you want to add legends to a list of "PLOT structure" in a single shot.
I sometimes use @@n but I had never payed attention to the  fact that n is an integer, nor just a positive integer.
Thank you for this precision

@acer 

Than you acer.
I agree with your opinion in your second phrase, it seems more logical to add associate the legend to the POLYGONS themselves.

Concerning overrideoption you're right, I had made a confusion between replacing and adding.

If it's not too demanding I have a last question to you and @Carl Love
I'm currently developping a Maplet-based application to help people in analyzing statistical data (roughly a number table < X | Y > of "inputs" X and "outputs" Y.
In my first attempt to add legends to histograms I used the name COLOUR : this worked perfectly when I tested outside the main procedure of my Maplet-based application, but not within it.
I discovered that I needed to replace COLOUR by COLOR.
Could you explain me why?

@Carl Love 

Thank you for this comment and for your improved code.
It's going to take me some effort to understand it properly, this in particular:

 1@@0, #multi-argument identity function

 

@acer @Carl Love

A remark.

From plots:-display help page:
"However, options such as color or linestyle that apply to individual elements like curves or polygons do not affect previously set colors or linestyles. You must set overrideoption to true, to have a new option of this type override an existing one."

It seems that

plots:-display(a,color=red,overrideoption);

is a short for

plots:-display(a,color=red,overrideoption=true);

 

First 89 90 91 92 93 94 95 Last Page 91 of 154