Fast way of computing covariance matrix of nonstationary kernel in PythonIdentity covariance matrix,...

Why has the mole been redefined for 2019?

Can I write a book of my D&D game?

If I delete my router's history can my ISP still provide it to my parents?

What is the purpose of easy combat scenarios that don't need resource expenditure?

It took me a lot of time to make this, pls like. (YouTube Comments #1)

How to deal with an incendiary email that was recalled

Explain the objections to these measures against human trafficking

Why did the villain in the first Men in Black movie care about Earth's Cockroaches?

Finding a mistake using Mayer-Vietoris

How long is the D&D Starter Set campaign?

What is the wife of a henpecked husband called?

Incorporating research and background: How much is too much?

What is the lore based reason that the Spectator has the Create Food and Water trait, instead of simply not requiring food and water?

Can I string the D&D Starter Set campaign into another module, keeping the same characters?

Can a hotel cancel a confirmed reservation?

Why isn't there a non-conducting core wire for high-frequency coil applications

How can I deliver in-universe written lore to players without it being dry exposition?

Blindfold battle as a gladiatorial spectacle - what are the tactics and communication methods?

Traveling through the asteriod belt?

Why is mind meld hard for T'pol in Star Trek: Enterprise?

Why do no American passenger airlines still operate dedicated cargo flights?

Why is working on the same position for more than 15 years not a red flag?

Can an insurance company drop you after receiving a bill and refusing to pay?

Can a person refuse a presidential pardon?



Fast way of computing covariance matrix of nonstationary kernel in Python


Identity covariance matrix, decorrelated data?Is GridSearchCV computing SVC with rbf kernel and different degrees?Fast, efficient way to zoom/pan scatterplot with mouseover dataKeras - Computing cosine similarity matrix of two 3D tensorsIntuition for prediction based on SVM trained with Gaussian kernelCan't understand this simple matrix multiplication in pythonPython XGBoost killing kernelNormalize matrix in Python numpyHow to create a complex Gaussian random noise with a specific covariance matrixFaster 3D Matrix Operation - Python













1












$begingroup$


Suppose I have symmetric positive definite covariance function $k:mathbb{R}timesmathbb{R}rightarrow mathbb{R}$ that is non-stationary (i.e. $k(x,y) neq g(|x-y|)$ for any function $g$). Is there a fast way in Python given data $X = (x_1,ldots,x_n$) to calculate its covariance matrix $(k(x_i,x_j))_{i,j}$?



If the covariance function is stationary then we can compute the whole matrix at once using numpy's matrix operations and avoid slow Python loops - e.g. in this.



Currently my implementation is:

dim = len(X)
kern_mat = np.zeros((dim,dim))
for i in range(dim):
for j in range(i+1):
kern_mat[i,j] = kern(X[i],X[j])
kern_mat[j,i] = kern_mat[i,j]

Any help with speedups or otherwise is appreciated!










share|improve this question









New contributor




Timothy Hedgeworth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$

















    1












    $begingroup$


    Suppose I have symmetric positive definite covariance function $k:mathbb{R}timesmathbb{R}rightarrow mathbb{R}$ that is non-stationary (i.e. $k(x,y) neq g(|x-y|)$ for any function $g$). Is there a fast way in Python given data $X = (x_1,ldots,x_n$) to calculate its covariance matrix $(k(x_i,x_j))_{i,j}$?



    If the covariance function is stationary then we can compute the whole matrix at once using numpy's matrix operations and avoid slow Python loops - e.g. in this.



    Currently my implementation is:

    dim = len(X)
    kern_mat = np.zeros((dim,dim))
    for i in range(dim):
    for j in range(i+1):
    kern_mat[i,j] = kern(X[i],X[j])
    kern_mat[j,i] = kern_mat[i,j]

    Any help with speedups or otherwise is appreciated!










    share|improve this question









    New contributor




    Timothy Hedgeworth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      1












      1








      1





      $begingroup$


      Suppose I have symmetric positive definite covariance function $k:mathbb{R}timesmathbb{R}rightarrow mathbb{R}$ that is non-stationary (i.e. $k(x,y) neq g(|x-y|)$ for any function $g$). Is there a fast way in Python given data $X = (x_1,ldots,x_n$) to calculate its covariance matrix $(k(x_i,x_j))_{i,j}$?



      If the covariance function is stationary then we can compute the whole matrix at once using numpy's matrix operations and avoid slow Python loops - e.g. in this.



      Currently my implementation is:

      dim = len(X)
      kern_mat = np.zeros((dim,dim))
      for i in range(dim):
      for j in range(i+1):
      kern_mat[i,j] = kern(X[i],X[j])
      kern_mat[j,i] = kern_mat[i,j]

      Any help with speedups or otherwise is appreciated!










      share|improve this question









      New contributor




      Timothy Hedgeworth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      Suppose I have symmetric positive definite covariance function $k:mathbb{R}timesmathbb{R}rightarrow mathbb{R}$ that is non-stationary (i.e. $k(x,y) neq g(|x-y|)$ for any function $g$). Is there a fast way in Python given data $X = (x_1,ldots,x_n$) to calculate its covariance matrix $(k(x_i,x_j))_{i,j}$?



      If the covariance function is stationary then we can compute the whole matrix at once using numpy's matrix operations and avoid slow Python loops - e.g. in this.



      Currently my implementation is:

      dim = len(X)
      kern_mat = np.zeros((dim,dim))
      for i in range(dim):
      for j in range(i+1):
      kern_mat[i,j] = kern(X[i],X[j])
      kern_mat[j,i] = kern_mat[i,j]

      Any help with speedups or otherwise is appreciated!







      machine-learning python statistics numpy gaussian






      share|improve this question









      New contributor




      Timothy Hedgeworth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Timothy Hedgeworth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 9 hours ago









      ebrahimi

      73321021




      73321021






      New contributor




      Timothy Hedgeworth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 14 hours ago









      Timothy HedgeworthTimothy Hedgeworth

      1062




      1062




      New contributor




      Timothy Hedgeworth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Timothy Hedgeworth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Timothy Hedgeworth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          2












          $begingroup$

          I still would apply numpy's covaranice function using numpy.apply_along_axis



          import numpy as np

          x = np.array([[0, 2], [1, 1], [2, 0]]).T
          np.apply_along_axis(func1d=np.cov, arr=x, axis=0)





          share|improve this answer









          $endgroup$













            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "557"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            Timothy Hedgeworth is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f46404%2ffast-way-of-computing-covariance-matrix-of-nonstationary-kernel-in-python%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2












            $begingroup$

            I still would apply numpy's covaranice function using numpy.apply_along_axis



            import numpy as np

            x = np.array([[0, 2], [1, 1], [2, 0]]).T
            np.apply_along_axis(func1d=np.cov, arr=x, axis=0)





            share|improve this answer









            $endgroup$


















              2












              $begingroup$

              I still would apply numpy's covaranice function using numpy.apply_along_axis



              import numpy as np

              x = np.array([[0, 2], [1, 1], [2, 0]]).T
              np.apply_along_axis(func1d=np.cov, arr=x, axis=0)





              share|improve this answer









              $endgroup$
















                2












                2








                2





                $begingroup$

                I still would apply numpy's covaranice function using numpy.apply_along_axis



                import numpy as np

                x = np.array([[0, 2], [1, 1], [2, 0]]).T
                np.apply_along_axis(func1d=np.cov, arr=x, axis=0)





                share|improve this answer









                $endgroup$



                I still would apply numpy's covaranice function using numpy.apply_along_axis



                import numpy as np

                x = np.array([[0, 2], [1, 1], [2, 0]]).T
                np.apply_along_axis(func1d=np.cov, arr=x, axis=0)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 13 hours ago









                Brian SpieringBrian Spiering

                3,7881028




                3,7881028






















                    Timothy Hedgeworth is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    Timothy Hedgeworth is a new contributor. Be nice, and check out our Code of Conduct.













                    Timothy Hedgeworth is a new contributor. Be nice, and check out our Code of Conduct.












                    Timothy Hedgeworth is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Data Science Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f46404%2ffast-way-of-computing-covariance-matrix-of-nonstationary-kernel-in-python%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown