mmcdara

7891 Reputation

22 Badges

9 years, 63 days

MaplePrimes Activity


These are replies submitted by mmcdara

@tomleslie 

I think you have missed something:
u is not equal to 

u:= convert(f, string);

but defined by

u  := sprintf("%Zm", f);

and I can't change the way u is constructed.


Where does this sprintf("%Zm", f) come from?
Here is an example

C1 := Cell( Textfield(style=TwoDimOutput,Equation(sqrt(x))) ):
T := Table(Column(), widthmode=percentage, width=10, alignment=center,
           Row( C1)):
InsertContent(Worksheet(Group(Input( T )))):  # Maple 2015

Looking to T, we see that the region corresponding to sqrt(x) corresponds to the code

`_XML_Text-field`("alignment" = "centred", "style" = "2D Output", "layout" = "Normal", _XML_Equation("executable" = "false", "style" = "2D Output", "KiQlInhHIyIiIiIiIw=="))

where 

 "KiQlInhHIyIiIiIiIw=="

is the "code" for sqrt(x).
I was able to find ( showstat(DocumentTools:-Layout:-Equation) ) that this code was obtained this way

u  := sprintf("%Zm", sqrt(x));    

     u := "*$%"xG#"""""#"
               
s  := StringTools:-Encode(u,':-base64');

    s := "KiQlInhHIyIiIiIiIw=="

"Inverting" the last coding to retrieve u is obvious

v := StringTools:-Decode( s, 'encoding' = ':-base64' );

    v := "*$%"xG#"""""#"

Now I wonder if it is possible to "invert" the first coding to retrieve the expression sqrt(x).

Why do I want to do this:

  • Suppose someone has constructed the table T and has given you T itself and NOT the code he used to build T.
    in the example above the only thing you know is this
    _XML_Table("interior" = "all", "showinput" = "true", "alignment" = "center", "exterior" = "all", "width" = "10%", "showlabel" = "false", "captionalignment" = "0", "title" = "", "drawtitle" = "false", "order" = "row", "drawcaption" = "false", "randomized" = "false", "captionposition" = "1", "showgroup" = "false", "plotalignlists" = "", "pagebreak" = "none", "postexecute" = "advance", `_XML_Table-Column`("separator" = "true", "weight" = "100"), `_XML_Table-Row`("align" = "top", "separator" = "true", `_XML_Table-Cell`("columnspan" = "1", "backgroundstyle" = "0", "rowspan" = "1", "fillcolor" = "[255,255,255]", `_XML_Text-field`("alignment" = "centred", "style" = "2D Output", "layout" = "Normal", _XML_Equation("executable" = "false", "style" = "2D Output", "KiQlInhHIyIiIiIiIw==")))))

 

  • You can visualise this table and see that the cell contains sqrt(x), but how can you obtain this expression by decoding the las operatot of the field _XML_Equation
     
  • In this simple cas you could tell me "just write sqrt(x)", but it's not a safe solution for _XML_Equation may contain a more complex expression and the table may contain several _XML_Equation fields.


 

 

@ogunmiloro 

Here are a few linear fits of these new data.

The problem is interesting for it enables introducing a basic trick in statistical regression: the scaling of the data.
The worksheet must be read step by step:

  1. In a first attempt I try to fit (Statistics:-LinearFit) a high degree (14) polynomial without any precaution.
    The result is obviously non acceptable (you can reduce the value of P [degree of the polynomial] to see when the "problem" begins to occur).
     
  2. The reason comes from the huge values the leading monomial being xP takes when X is close to 300. 
    This is a classical issue which can be (generally) fixed by centering and scaling the data.
    Once done Statistics:-LinearFit returns an acceptable model.
     
  3. The exact reason of the problem is detailed in step 3: the condition numbers of the "Fisher matrix" are computed for the RAW data (about 1070) and SCALED data (about 1011).
    The algebra used in Statistics:-LinearFit is very simple and I wrote the relations that give the values of the regression parameters (vector beta).
    Note I still operate with SCALED data.
     
  4. I show now how to transform the model obtained on SCALED data into a model on RAW data.
    From the plots we can make a few observations:
    1. the model presents some oscillations near X=0 and is not as flat as Y is,
    2. the model decreases near X=300 (this comes from the last value of Y which "attracts" the model (this is something thar cn be investigated with Statistics:-LinearFit [on SCALED data] by studying the leverages abd the Cook's distance [ output=[leverages, CookDstatistic] ]
       
  5. In this final step I show how to constraint the model in order it be flatter near X=0 and increasing for the higher values of X.
    The solution relies upon  Optimization:-Minimize where an objective function J (residual sum of squares) is minimized under constraints
    1. the first 5 derivatives of the model are null at XC[1] (which corresponds to X=0)
    2. the value of the model at XC[1] = YC[1]
    3. the first and second derivatives of the model are non negative on the las 10 points


Fit_of_your_NEW_data.mw



 

 

@ogunmiloro 

On point (2) the answer is "technically yes" but, as Carl noted it seems less "natural"... unless you have evidence to say that the expectation of the model is indeed a "double sigmoid"  and the data equal this trend plus an additive "noise" (which is the framework of statistical regression).
 

@Carl Love @ogunmiloro

Thanks Carl  for your comments
 

"Show the extrapolation of the sum-of-sigmoids fit out to its upper horizontal asymptote. I think x=500 is a good stopping point."
That is a good idea, so I have completed my previous reply accordingly.

One of my prefered type of model is named  Kriging.
It is implemented in Maple since, I believe, Maple 2019 to answer problems related to spatial statistics (aka geostatistics).
Thet are very versatile models, even extremely parcimonous (fhey may give astonishingly good models [if you use them carefully] even if they depend only on a small handull of parameters).

There are different forms of Kriging (ordinary, simple, universal, ...).
All of them are of the form a Trend plus a Gaussian Process
In the Universal Kriging (UK) the trend is generally a function that already captures long sacle behaviours, leaving it to the gaussian process component to capture small scales.
(In simple Kriging the trend is a constant and, in some sense, the gaussian process does almost all the job).

The idea is to use the 6 parameters (positive) model and to complete, or correct) it by a gaussian process
The final model is

  • positive for all x
  • monotonically increasing for almost all x
    (oscillations at earlier values of x comes from the fact that Y has  identival values repeated several times)
  • equal to 1 for X=1
  • bounded for extrapolation for x >> max(X)=298

The computation of the error of prediction is not given (the procedure KG is not a full implementation of a Kriging emulator).

On the left most figure zoom in the region defined by the rectangle to see what happens when extrapolation begins;
The Kriging model abruptly connects to the trend over a x-range which is of the order of the correlation length (chosen to 2.5).
 





Kriging_of_your_data.mw

@ogunmiloro 

I think that you would have said clearly what you wanted in your initial question.

What do you want:

  • statistical estimation of parameters of an a priori model
    • your a priori model A*exp(r*x) 
    • a polynomial model (tomleslie) which won't respect positivity constraints (that you seem to say now they are important!!!)
  • smoothing
    • spline interpolation model (Kitonum) (whose residual sum of squares is obviously 0)

Why do you want to obtain such a "fit"

  • to predict the future ("what Y can I expect for X > 298?"
    in this case spline interpolation or polynomial fitting is useless
  • to interpolate in the range X=0..298
    then use spline interpolatoin


Please look to my last reply.


 

@tomleslie 

This is not an answer to the question!

@Carl Love 

Thanks, excellent!

@Carl Love 

Nice way.
I vote up even if this doesn't work in Maple 2015 :-)
(Fr is correct)



It is a shame that DrawGraph transforms rationals into strings whereas TEXT can display rationals  (I followed the track with the library assistant without finding exactly where it's done).

More of this I discovered that only rational or float weights are enabled by Graph (weights like Pi, sqrt(2), ... generate an error).

@Carl Love 

There's a silver lining to everything: writing snippets of code (I do not remember there did exist a few years ago) probably leads to smaller contributions (some take almost a whole mapleprimes' page), attaching an image can be more explicit and appealing than putting it in the middle of a long worksheet ... 
Personally I think it's not that stupid to favour code snippets instead of  "file contents", but if it is a policy I feel it must be stated clearly.

Wait and see

@dnaviaux 

No problem

Hi, 
Could you detail what you mean by "table":

  • is it a "table" in the Maple's sense
  • or the type of "table" one get using DocumentTools:-Layout for instance

Is this question related to this thread What might be the best way to convey calculated re... ?

 

@dnaviaux 

By the way, I didn(t pay a careful attention to all the contributions about the "presentation" of the results.
Maybe this alternative to your procedure rprintf might interest you

SEA_SI_3.mw

@dnaviaux 

Thnak you,
I will look at it with interest, ... after Christmas Eve.

Happy Christmas

 

@dnaviaux 

To be a little bit more exhaustive, here is a new worksheet which

  1. contains the previous one 
  2. gives an answer to calculate a kind of worst case (extremal values)
    1. first by using the Tolerances package... but as you already observed yourself it fails when the expressions are too complicated
    2. secondly by Monte-Carlo simulation

The coding I use for Monte-Carlo simulation could be enhanced when the quantity of interest is not a function of an independant variable (t in my toy example)  but, as it seems to be your case, the solution of an algebraic system.

SEA_SI_2.mw

@Carl Love 

You were right, the good term to use was "parameter", "factor" or even "contributing factor" to be more precise, but not "contributor" whose, as you said, "usually refers to a person who contributes".

Here again there is a subtle difference between correcting and editing.
As you can see here "to correct" has few translations in French.
https://www.linguee.fr/francais-anglais/search?source=auto&query=to+correct
but one of them ("corriger") has many more in English (including "to correct").
https://www.linguee.fr/francais-anglais/search?source=auto&query=corriger
In French, "correct" (= "to correct") doesn't make as many different meanings as in English, and "to correct" can be either nice or rough depending on the words you use with it.

 

 

 

First 92 93 94 95 96 97 98 Last Page 94 of 154