Note that there are some explanatory texts on larger screens.

plurals
  1. POPython - Difficulty Calculating Partition Function using Large NumPy arrays
    primarykey
    data
    text
    <p>I had a pretty compact way of computing the partition function of an Ising-like model using itertools, lambda functions, and large NumPy arrays. Given a network consisting of <code>N</code> nodes and <code>Q</code> "states"/node, I have two arrays, <code>h</code>-fields and <code>J</code>-couplings, of sizes <code>(N,Q)</code> and <code>(N,N,Q,Q)</code> respectively. J is upper-triangular, however. Using these arrays, I have been computing the partition function <code>Z</code> using the following method:</p> <pre><code># Set up lambda functions and iteration tuples of the form (A_1, A_2, ..., A_n) iters = itertools.product(range(Q),repeat=N) hf = lambda s: h[range(N),s] jf = lambda s: np.array([J[fi,fj,s[fi],s[fj]] \ for fi,fj in itertools.combinations(range(N),2)]).flatten() # Initialize and populate partition function array pf = np.zeros(tuple([Q for i in range(N)])) for it in iters: hterms = np.exp(hf(it)).prod() jterms = np.exp(-jf(it)).prod() pf[it] = jterms * hterms # Calculates partition function Z = pf.sum() </code></pre> <p>This method works quickly for small <code>N</code> and <code>Q</code>, say <code>(N,Q) = (5,2)</code>. However, for larger systems <code>(N,Q) = (18,3)</code>, this method cannot even create the <code>pf</code> array due to memory issues because it has <code>Q^N</code> nontrivial elements. Any ideas on how to either overcome this memory issue or how to alter the code to work on subarrays?</p> <p>Edit: Made a small mistake in the definition of <code>jf</code>. It has been corrected.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload