Timeline for Evaluate joint probability density function of a Markov random field
Current License: CC BY-SA 4.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 26, 2019 at 17:46 | comment | added | AlexV | @papabiceps: Maybe you should write up a self answer to show your final code. | |
Jul 26, 2019 at 9:47 | comment | added | papabiceps |
try this np.einsum('ij,jk,ik->i',states, J, states) . It is giving me more speedup as the value of n is increases. Ref: stackoverflow.com/questions/57216521/…
|
|
Jul 25, 2019 at 20:44 | comment | added | papabiceps | Thanks for the recommendation, I'll look into them. Is there any way to prevent wasteful calculations done in the full matrix method ? Because we just only need the diagonal of the resulting matrix. | |
Jul 25, 2019 at 20:38 | vote | accept | papabiceps | ||
Jul 25, 2019 at 20:33 | comment | added | AlexV | Regarding your other question: Python Data Science Handbook by Jake VanderPlas as well as his PyCon talks (2017, 2018) are a good start to get going with optimization potential. | |
Jul 25, 2019 at 17:33 | comment | added | AlexV | I have also come up with the solution you posted on pastebin, but hit the same out of memory error. | |
Jul 25, 2019 at 14:28 | comment | added | papabiceps |
Basically I do the operations as shown in the original equation in the question and do trace(result) to get the PDF. Maybe if I use np.einsum it would be faster because I'm doing a lot of wasteful calculations.
|
|
Jul 25, 2019 at 14:25 | comment | added | papabiceps |
I just found out another way to do this with no for loop and all matrices which is in total 6x faster than my first attempt but I could only verify this for n = 10, anything more than that I'm running out of memory and for some n its slower than your method. This is the code to my method pastebin.com/2D64jQQr
|
|
Jul 25, 2019 at 9:13 | comment | added | papabiceps |
I have run your code and timed both of the ways using timeit . I'm also seeing a ~3x speedup. For n = 21, my code clocked 6.21s per loop and your code clocked 2.49s with numba.jit it clocked 0.548s per loop. That's a great a speedup. I'm eagerly for your further analysis. How do I train myself to write optimized code like this, any suggestions ? Thank you for the help :)
|
|
Jul 23, 2019 at 22:26 | history | edited | AlexV | CC BY-SA 4.0 |
added 285 characters in body
|
Jul 23, 2019 at 22:05 | history | answered | AlexV | CC BY-SA 4.0 |