I am trying to make my calculation faster. I was hoping, when I
compiled it, it would work much faster, but in the end its
even slower. I don't know if I am using Compile
correctly. I am open to any suggestion on how to make this computation faster.
I use the data:
DD = RandomReal[{0, 1}, {1000, 3}];
I have written the following function for calculating correlation dimension (D2):
CORRDIM[data_] := (
m =
ParallelTable[{r,
Total[
Table[
Length[Drop[Nearest[Drop[data, i - 1], data[[i]], {All, r}], 1]],
{i, 1, Length[data]}]]}, {r, 0.001, 0.011, 0.001}];
m);
CORRDIM
works pretty fast, but for a large dataset it is still too slow.
CORRDIM[DD]; // AbsoluteTiming
{0.483119, Null}
I was hoping that Compile
could help me speed up this calculation,
especially that the options
CompilationTarget -> "C",
RuntimeAttributes -> {Listable},
Parallelization -> True
would somehow run the code in multiple threads, but the compile version works even slower than the interpreted version.
fcc =
Compile[{{x, _Real, 2}},
Table[
{r,
Total[
Table[
Length[Drop[Nearest[Drop[x, i - 1], x[[i]], {All, r}], 1]],
{i, 1, Length[x]}]]}, {r, 0.001, 0.011, 0.001}],
CompilationTarget -> "C",
RuntimeAttributes -> {Listable},
Parallelization -> True]`
Map[fcc, {DD}]; // AbsoluteTiming
{0.787973, Null}
Is it there any way to make it faster? Am I making some mistakes in the use of Compile
?
Nearest
.) $\endgroup$