1
$\begingroup$

I am trying to parallelize the computation of the CDF of a random variable (more precisely, a doubly noncentral $F$ variable) for a matrix of values.

This is a MWE:

rows = {3, 4, 5};
columns = {0.1, 0.2, 0.3};
ones = Table[{1}, 3];
RO = ones.{rows};(* 3x3 matrix with all ROWS equal to `rows` *) 
CO = Transpose[
  ones.{columns}];(* 3x3 matrix with all COLUMNS equal to `columns` *)
Q1 = RO + CO; (* Matrix of input values *)
Q2 = Parallelize[CDF[NoncentralFRatioDistribution[10, 2, 5, 1], Q1]]

The result is

Parallelize::nopar1: CDF[NoncentralFRatioDistribution[10,2,5,1],Q1] cannot be parallelized; proceeding with sequential evaluation.

[...]

My real problem does not deal with $3 \times 3$ but $400 \times 400$ matrices, and the time consumed is excessive without parallelization. Can this be done in a different way, taking profit of parallelization?


UPDATE

I am not very familiar with parallelizing operations. I would usually do this with two nested for loops. But, as fas as I know, many languages allow for parallelization, which is, operating on a vector or a matrix as if it was a number (roughly speaking), and it seems to be faster than nested loops.

So... That is how I finally arrived to the impasse I have just reported. I do not know how to continue or solve this.

$\endgroup$
1
$\begingroup$

You may use ParallelMap. First note that CDF[dist] should return a Pure Function of the CDF but in some cases, like the 4-parameter version of NoncentralFRatioDistribution, it does not. Therefore, a pure function of the CDF is created and mapped in parallel over the items in Q1.

ParallelMap[CDF[NoncentralFRatioDistribution[10, 2, 5, 1], #] &, Q1, {-1}]
{{0.745711,0.800896,0.836492},
 {0.752554,0.805134,0.839367},
 {0.759042,0.809196,0.842143}}

A read of the Method option of Parallelize would help you as ParallelMap uses this option as described there.

Hope this helps.

$\endgroup$
  • $\begingroup$ Thank you. How would this be done with a function that needs two inputs?? I am trying to do it, without success for now. $\endgroup$ – Vicent Nov 29 '17 at 16:25
  • $\begingroup$ I think it can be done with MapThread. Is it a good solution? $\endgroup$ – Vicent Nov 29 '17 at 16:33
  • $\begingroup$ @Vicent Try something along the lines of ParallelMap[f[#[[1]], 1, #[[2]]] &, Partition[Range[12], 2]]. You should have a look at the Functional Programming guide and the tutorials found there. $\endgroup$ – Edmund Nov 29 '17 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.