Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:09:44+00:00 2026-06-18T12:09:44+00:00

I’m trying to do the following, and repeat until convergence: where each X i

  • 0

I’m trying to do the following, and repeat until convergence:

where each Xi is n x p, and there are r of them in an r x n x p array called samples. U is n x n, V is p x p. (I’m getting the MLE of a matrix normal distribution.)
The sizes are all potentially large-ish; I’m expecting things at least on the order of r = 200, n = 1000, p = 1000.

My current code does

V = np.einsum('aji,jk,akl->il', samples, np.linalg.inv(U) / (r*n), samples)
U = np.einsum('aij,jk,alk->il', samples, np.linalg.inv(V) / (r*p), samples)

This works okay, but of course you’re never supposed to actually find the inverse and multiply stuff by it. It’d also be good if I could somehow exploit the fact that U and V are symmetric and positive-definite.
I’d love to be able to just calculate the Cholesky factor of U and V in the iteration, but I don’t know how to do that because of the sum.

I could avoid the inverse by doing something like

V = sum(np.dot(x.T, scipy.linalg.solve(A, x)) for x in samples)

(or something similar that exploited the psd-ness), but then there’s a Python loop, and that makes the numpy fairies cry.

I could also imagine reshaping samples in such a way that I could get an array of A^-1 x using solve for every x without having to do a Python loop, but that makes a big auxiliary array that’s a waste of memory.

Is there some linear algebra or numpy trick I can do to get the best of all three: no explicit inverses, no Python looping, and no big aux arrays? Or is my best bet implementing the one with a Python loop in a faster language and calling out to it? (Just porting it directly to Cython might help, but would still involve a lot of Python method calls; but maybe it wouldn’t be too much trouble to make the relevant blas/lapack routines directly without too much trouble.)

(As it turns out, I don’t actually need the matrices U and V in the end – just their determinants, or actually just the determinant of their Kronecker product. So if anyone has a clever idea for how to do less work and still get the determinants out, that would be much appreciated.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:09:45+00:00Added an answer on June 18, 2026 at 12:09 pm

    Until someone comes up with a more inspired answer, if I were you, I’d let the fairies cry…

    r, n, p = 200, 400, 400
    
    X = np.random.rand(r, n, p)
    U = np.random.rand(n, n)
    
    In [2]: %timeit np.sum(np.dot(x.T, np.linalg.solve(U, x)) for x in X)
    1 loops, best of 3: 9.43 s per loop
    
    In [3]: %timeit np.dot(X[0].T, np.linalg.solve(U, X[0]))
    10 loops, best of 3: 45.2 ms per loop
    

    So having a python loop, and having to sum all the results together, is taking 390 ms more than 200 times what it takes to solve each of the 200 systems that have to be solved. You’d get less than a 5% improvement if the looping and the summing were free. There may be some calling a python function overhead also, but it’s probably still going to be negligible against the actual time solving the equations, no matter what language you code it in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am confused How to use looping for Json response Array in another Array.
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.