cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Ressel
Level VI

Long shot: How to use numpy.polyfit to reproduce Vec Quadratic() results?

Apologies for the transgression, which is; ironically; a direct result of my personal progress in JSL.

A very helpful computer scientist in my organization is trying to translate something initially written in JSL to Python. Specifically, the challenge is how to reproduce what the JSL function 'Vec Quadratic()' is doing? See also the attached example table .

Background:

The JSL application to be translated creates formula columns for the confidence and prediction intervals. The formulas are then used to calculate the values of the confidence and prediction intervals for some user specified value of x, aka independent variable.

Questions:

Screenshots for orientation:

  • What we want to achieve in Python (results inside the red frame)
    Ressel_1-1714051995324.png

 

  • How the columns shown above were generated
    Ressel_2-1714052092940.png

     

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ressel
Level VI

Re: Long shot: How to use numpy.polyfit to reproduce Vec Quadratic() results?

Thanks, that's very kind! It is possible we found a solution: https://numpy.org/doc/stable/reference/generated/numpy.cov.html

 

Edit: The title of this posting is misleading. numpy.polyfit is probably no suitable for emulating 'Vec Quadratic()'.

View solution in original post

14 REPLIES 14
txnelson
Super User

Re: Long shot: How to use numpy.polyfit to reproduce Vec Quadratic() results?

Have you ask the Python community about this.  Personally, it seems counter productive to the JMP Community to put effort into assisting in moving someone away from JMP.

Jim
Ressel
Level VI

Re: Long shot: How to use numpy.polyfit to reproduce Vec Quadratic() results?

True on the one hand. On the other hand, though, Python is integrated into JMP18, which suggests there must be people getting to terms with this reality. I was hoping for someone in the community being able to explain, since I consider it infinitely more likely that a JSL user would know the Python equivalent of 'Vec Quadratic()', rather than vice versa. (And what will the Python community tell me when I ask them?)

Re: Long shot: How to use numpy.polyfit to reproduce Vec Quadratic() results?

While the jmp.DataTable object will enable some user's an easier path to export JMP data, the improved Python integration is focused on benefiting the JMP user.  

  • It provides an environment that users new to JMP, but familiar with Python can be productive immediately.
  • The design of the Python integration focuses on improving JMP's capability at being the hub of the workflow. At reducing the need to leave JMP to get the job done. The hope / desire is that the JMP environment becomes more convenient, more enticing, that work will be brought into JMP rather than exported away from JMP.  That JMP / Python integration becomes greater than simply the aggregation of JMP and Python.  For example:
    • File formats not yet supported by JMP can be opened using external Python packages, parquet, hdf5, ...
    • Allow JMP users to utilize desktop GPUs through packages such as pyopencl, and pyCUDA.
    • Additional statistical capabilities such as hierarchical density clustering (HDBSCAN)
    • Additional plotting and graphing capabilities with packages such as matplotlib, plotly, ...
    • Integration with other software systems through the Python interface.  SAS, MatLab, R, ...

The JMP statisticians and testers put a lot of effort into creating code that is reliable, accurate and well tested.  That is the value proposition.  We focus on the statistics so you can focus on your application, rather than having to reinvent the statistical 'wheel'.  

Ressel
Level VI

Re: Long shot: How to use numpy.polyfit to reproduce Vec Quadratic() results?

I don't doubt that JMP statisticians put a lot of effort into creating reliable code. What I doubt is the expectation to keep this forum free from Python related questions.

Craige_Hales
Super User

Re: Long shot: How to use numpy.polyfit to reproduce Vec Quadratic() results?

Maybe the

NormalContour = sqrt(ChiSquare Quantile( 0.95, 2 ));

idea from Ellipse  will point you in the right direction. I do pictures, not statistics, so I might be way off. But to make the ellipse picture I had to answer a similar question.

 

Craige
Ressel
Level VI

Re: Long shot: How to use numpy.polyfit to reproduce Vec Quadratic() results?

Thanks, that's very kind! It is possible we found a solution: https://numpy.org/doc/stable/reference/generated/numpy.cov.html

 

Edit: The title of this posting is misleading. numpy.polyfit is probably no suitable for emulating 'Vec Quadratic()'.

Re: Long shot: How to use numpy.polyfit to reproduce Vec Quadratic() results?

We welcome Python questions in the JMP blogs.  I have been answering a lot of them lately.  Including sample code, and discussions on how best to use Python in JMP to its best advantage.  

 

@txnelson comment on asking the Python community is a valid one, as would asking statistical blogs.  Though instead of asking how to replicate JSL's 'Vec Quadratic()' you phrase it in terms of asking how to graph the results you want, how to do the statistics you want in Python.

 

As for answering this specific ask, I can't help you.  I have no knowledge of how 'Vec Quadratic()' works internally.  But I can tell you what the Scripting Index says.  The scripting index definition of Vec Quadratic( S, X ) states it evaluates as Vec Diag ( X * S * X ).  Vec Diag( X ) description in the Scripting index is Returns the diagonal elements of the square matrix as a vector. Unless I'm missing something that appears to be straightforward matrix math.  

 

As for how do I call 'Vec Quadriatic()' from my Python program running in JMP so I can further process the results... That is the kind of question that would be interesting.  

 

You can use a numpy array for S and X and you can do the Python Get(S), Python Get(X) to get the numpy array values into JSL environment as a JSL Matrix. And you can call jmp.run_jsl( 'Vec Quadratic( S, X)' ).    Then from Python in JMP you can get the column results directly from the data table in Python.  See the Scripting Index on jmp.DataTable and jmp.DataTable.Column objects.

 

Derived from the JSL "Vec Quadratic()' example in the Scripting Index.

import jmp
import numpy as np

s = np.array( [[1,3,5],[3,2,6], [5,6,1] ])
x = np.array( [[1,3,5],[2,4,6] ])
jmp.run_jsl('''
S = Python Get(s);
X = Python Get(x);
show(Vec Quadratic(S, X));
''')

giving results

/*:

//:*/

S = Python Get(s);
X = Python Get(x);
show(Vec Quadratic(S, X));

/*:

Vec Quadratic(S, X) = [292, 528];

 

Ressel
Level VI

Re: Long shot: How to use numpy.polyfit to reproduce Vec Quadratic() results?

@Paul_Nelson, thank you. I already knew what the JSL function 'Vec Quadratic()' did before posting. Apologies for inadequately phrasing my question in this post. Not everyone is this forum is an English native speaker. And just for completeness:

 

Your comment:

Though instead of asking how to replicate JSL's 'Vec Quadratic()'  ...

My original question:

How to use numpy.polyfit to reproduce Vec Quadratic() results?


 Is it the use of "reproduce" that is offensive?

hogi
Level XI

Re: Long shot: How to use numpy.polyfit to reproduce Vec Quadratic() results?

if you ask Copilot:

hogi_0-1714153432076.png