I was looking at the Mathematica code given at http://community.wolfram.com/groups/-/m/t/326240
where example code is given to simulate the spreading of a supposed Ebola outbreak in Nigeria:
CountryData["Nigeria", "Population"]
Graphics[CountryData["Nigeria", "Polygon"]]
names = CityData[{All, "Nigeria"}];
citypop =
Table[CityData[names[[i]], "Population"], {i, 1, Length[names]}];
citycoords =
Table[CityData[names[[i]], "Coordinates"], {i, 1, Length[names]}];
Needs["ComputationalGeometry`"]
dtri = DelaunayTriangulation[citycoords]; list = {}; Table[
Do[AppendTo[list, {i, dtri[[All, 2]][[i, j]]}], {j, 1,
Length[dtri[[All, 2]][[i, All]]]}], {i, 1, Length[dtri]}];
coupling = Table[0, {i, 1, Length[names]}, {j, 1, Length[names]}];
For[i = 1, i < Length[list] + 1, i++,
coupling[[list[[i]][[1]], list[[i]][[2]]]] = 1;]
coulinginterm = coupling;
coupling = SparseArray[coulinginterm];
Graphics[Join[
Table[Circle[citycoords[[i]], 0.02], {i, 1, Length[names]}],
DeleteCases[
Flatten[Table[
If[coupling[[i, j]] == 1,
Line[{citycoords[[i]], citycoords[[j]]}]], {i, 1,
Length[names]}, {j, 1, i}], 1], Null]]]
\[Rho] = 0.2; \[Lambda] = 0.1; Mcities = Length[names]; \[Mu] = 0.05;
For[i = 1, i <= Mcities, i++, sus[1, i] = 1.; inf[1, i] = 0.0;
rec[1, i] = 0.;]
sus[1, 1] = 0.95; inf[1, 1] = 0.05;
rec[1, 1] = 0.0;
meanNN = coupling.citypop;
sumind = Table[
Take[Flatten[ArrayRules[coupling[[k, All]]][[All, 1]]],
Length[ArrayRules[coupling[[k, All]]]] - 1], {k, 1, Mcities}];
sus[i_, j_] :=
sus[i, j] = (1 - \[Mu]) (sus[i - 1,
j] - \[Rho] sus[i - 1, j] inf[i - 1, j]) + \[Mu] Total[
Table[sus[i - 1, sumind[[j, u]]]*citypop[[sumind[[j, u]]]], {u,
1, Length[sumind[[j]]]}]]/meanNN[[j]];
inf[i_, j_] :=
inf[i, j] = (1 - \[Mu]) (inf[i - 1,
j] + \[Rho] sus[i - 1, j] inf[i - 1, j] - \[Lambda] inf[i - 1,
j]) + \[Mu] Total[
Table[inf[i - 1, sumind[[j, u]]]*citypop[[sumind[[j, u]]]], {u,
1, Length[sumind[[j]]]}]]/meanNN[[j]];
rec[i_, j_] :=
rec[i, j] = (1 - \[Mu]) (rec[i - 1,
j] + \[Lambda] inf[i - 1, j]) + \[Mu] Total[
Table[rec[i - 1, sumind[[j, u]]]*citypop[[sumind[[j, u]]]], {u,
1, Length[sumind[[j]]]}]]/meanNN[[j]];
LaunchKernels[];
tcourse =
ParallelTable[{sus[i, j], inf[i, j], rec[i, j]}, {i, 1, 500}, {j,
1, Mcities}]; // AbsoluteTiming
poly = Graphics[
Polygon[Flatten[CountryData["Nigeria", "Coordinates"], 1]],
ImagePadding -> None];
Animate[ImageSubtract[
Graphics[ListDensityPlot[
Join[{{4, 3.25, 0}, {4, 14, 0}, {14, 3.25, 0}, {14, 14, 0}},
Table[{citycoords[[k]][[1]], citycoords[[k]][[2]],
1. - tcourse[[t, k, 1]]}, {k, 1, Mcities}]],
InterpolationOrder -> 3, ColorFunction -> "Rainbow",
PlotRange -> All, Frame -> False, PlotRangePadding -> None]],
poly], {t, 1, 500, 1}, DefaultDuration -> 20.]

In Mathematica 9 this runs just fine, and the line
tcourse =
ParallelTable[{sus[i, j], inf[i, j], rec[i, j]}, {i, 1, 500}, {j,
1, Mcities}]; // AbsoluteTiming
just takes 29 seconds to complete the calculation of the system of recurrence equations.
If I try the same in Mathematica 10 it takes ages to complete though - in fact I didn't have the patience to wait for it to complete... Does anyone know what could be wrong in Mathematica 10, or what needs changing to make it run at the same speed as in Mathematica 9?
EntityandQuantityobjects since version 10. While it is possible to use these in many calculations they of course are slowing down things remarkably. So I would suggest to get rid of those usingEntityValueandQuantityValue. I think there is also a global option to change the behavior of the data functions to what it was in version 9, to be found on this site... – Albert Retey Dec 09 '14 at 11:19SetSystemOptions["DataOptions" -> "ReturnQuantities" -> False]indeed seems to solve the issue using a global option. How would I have to useEntityValueto getnames = CityData[{All, country}]; citypop = Table[CityData[names[[i]], "Population"], {i, 1, Length[names]}]; citycoords = Table[CityData[names[[i]], "Coordinates"], {i, 1, Length[names]}];working though without setting global options? – Tom Wenseleers Dec 09 '14 at 11:43QuantityandEntityin your data without changing global options... – Albert Retey Dec 09 '14 at 12:11