Note that there are some explanatory texts on larger screens.

plurals
  1. POVectorized computation of 3-point correlation functions in Matlab?
    primarykey
    data
    text
    <p>I would like to compute the 2- and 3-point correlation functions R2, R3 of samples of a vector by appropriate histogramming of the elements of a vector (num_samples samples of length system_size), and the corresponding cluster functions T2, T3. For simplicity I am considering histogramming across uniform bins.</p> <p>What is a good way to vectorize and/or speed up the following code?</p> <pre><code>n = length(mesh); R2 = zeros(n, n); R3 = zeros(n, n, n); for sample_id=1:num_samples s = samples(:, sample_id); d = mesh(2) - mesh(1); % Which bin does the ith sample s belong to? bins = ceil((s - mesh(1))/d); % Compute two-point correlation function for i = 1:system_size for j = 1:system_size if i ~= j R2(bins(i), bins(j))=R2(bins(i), bins(j))+1; end end end % Compute three-point correlation function for i = 1:system_size for j = 1:system_size if i ~= j for k = 1:system_size if k ~= j &amp;&amp; k ~= i R3(bins(i), bins(j), bins(k))=R3(bins(i), bins(j), bins(k))+1; T3(x1, x2, x3) = R3(x1,x2,x3)-R1(x1)*R2(x2,x3)-R1(x2)*R2(x1,x3)... -R1(x3)*R2(x1,x2)+2*R1(x1)*R1(x2)*R1(x3); end end end end end end R2 = R2/sum(R2(:)); R3 = R3/sum(R3(:)); T3 = zeros(n, n, n); % Compute three-point cluster function for i = 1:n for j = 1:n if i ~= j for k = 1:n if k ~= j &amp;&amp; k ~= i T3(x1, x2, x3) = R3(x1,x2,x3)-R1(x1)*R2(x2,x3)-R1(x2)*R2(x1,x3)... -R1(x3)*R2(x1,x2)+2*R1(x1)*R1(x2)*R1(x3); end end end end end </code></pre> <p>Naively I thought hist3(bins, bins...) or crosstab(bins, bins) would almost do what I want, which is to look for correlated occurrences of elements of the vector, but it doesn't.</p> <hr> <p>Example:</p> <p>If my inputs within the outermost loop are </p> <pre><code>s = [1.2 3.1 4.6 4.7 5.1] mesh = 0:0.5:6 </code></pre> <p>then the quantized data should be</p> <pre><code>bins = [3 7 10 10 11] </code></pre> <p>and R2 should be</p> <pre><code>&gt;&gt; R2 R2 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 2 0 0 2 2 0 0 0 1 0 0 0 1 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </code></pre>
    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.
    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