Skip to main content
edited tags
Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k
added 6 characters in body
Source Link
RunnyKine
  • 33.3k
  • 3
  • 110
  • 176

Hello i have been spending time to convert my R tools into Mathematica Packages mainly because i like the functional programming style in Mathematica. In doing so it seems that i run into one conundrum. On one had functional programming suggests to avoid intermediate variables on the other side, a simple example like below clearly shows the potentially significant performance difference when avoiding intermediate (pre-calculated) steps.

do i miss any better solution, or is this really a case where functional style, just looses out ?

  • dfmdfm is simply a List of Lists with some syntactic sugar
  • dfm["SER"]dfm["SER"] is a vector of 25k real numbers
  • dfm["serial"]dfm["serial"] is a vector of 25k string factors

(* check out the add variation as function of model *)
uSerial  = DeleteDuplicates[dfm["serial"]];
tt       = Transpose@{dfm["SER"], dfm["serial"]};
foo[z_] := Select[tt, (Last[#] == z) &][[All, 1]];
serMhdd = Mean /@ Map[foo[#] &, dfm["serial"]] // N; // AbsoluteTiming

uSerial = DeleteDuplicates[dfm["serial"]];
foo[z_] := Select[Transpose@{dfm["detSER"], 
                dfm["serial"]}, (Last[#] == z) &][[All, 1]];
serMhdd = Mean /@ Map[foo[#] &, dfm["serial"]] // N; // AbsoluteTiming

happy holidays, Bernd

Hello i have been spending time to convert my R tools into Mathematica Packages mainly because i like the functional programming style in Mathematica. In doing so it seems that i run into one conundrum. On one had functional programming suggests to avoid intermediate variables on the other side, a simple example like below clearly shows the potentially significant performance difference when avoiding intermediate (pre-calculated) steps.

do i miss any better solution, or is this really a case where functional style, just looses out ?

  • dfm is simply a List of Lists with some syntactic sugar
  • dfm["SER"] is a vector of 25k real numbers
  • dfm["serial"] is a vector of 25k string factors

(* check out the add variation as function of model *)
uSerial  = DeleteDuplicates[dfm["serial"]];
tt       = Transpose@{dfm["SER"], dfm["serial"]};
foo[z_] := Select[tt, (Last[#] == z) &][[All, 1]];
serMhdd = Mean /@ Map[foo[#] &, dfm["serial"]] // N; // AbsoluteTiming

uSerial = DeleteDuplicates[dfm["serial"]];
foo[z_] := Select[Transpose@{dfm["detSER"], 
                dfm["serial"]}, (Last[#] == z) &][[All, 1]];
serMhdd = Mean /@ Map[foo[#] &, dfm["serial"]] // N; // AbsoluteTiming

happy holidays, Bernd

Hello i have been spending time to convert my R tools into Mathematica Packages mainly because i like the functional programming style in Mathematica. In doing so it seems that i run into one conundrum. On one had functional programming suggests to avoid intermediate variables on the other side, a simple example like below clearly shows the potentially significant performance difference when avoiding intermediate (pre-calculated) steps.

do i miss any better solution, or is this really a case where functional style, just looses out ?

  • dfm is simply a List of Lists with some syntactic sugar
  • dfm["SER"] is a vector of 25k real numbers
  • dfm["serial"] is a vector of 25k string factors

(* check out the add variation as function of model *)
uSerial  = DeleteDuplicates[dfm["serial"]];
tt       = Transpose@{dfm["SER"], dfm["serial"]};
foo[z_] := Select[tt, (Last[#] == z) &][[All, 1]];
serMhdd = Mean /@ Map[foo[#] &, dfm["serial"]] // N; // AbsoluteTiming

uSerial = DeleteDuplicates[dfm["serial"]];
foo[z_] := Select[Transpose@{dfm["detSER"], 
                dfm["serial"]}, (Last[#] == z) &][[All, 1]];
serMhdd = Mean /@ Map[foo[#] &, dfm["serial"]] // N; // AbsoluteTiming

happy holidays, Bernd

edited tags
Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Tweeted twitter.com/#!/StackMma/status/415161217679101952
added 19 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
Loading
fix code
Source Link
Nasser
  • 150.6k
  • 12
  • 162
  • 376
Loading
Source Link
bernddude
  • 161
  • 1
  • 4
Loading