14
$\begingroup$

fixed in 10.1 (windows)


There's something wrong with how Min and Max are implemented for TimeObject:

times = {TimeObject[List[0, 14, 55.99`]], TimeObject[List[0, 14, 57.8`]], 
   TimeObject[List[0, 14, 59.09`]], TimeObject[List[0, 14, 59.11`]], 
   TimeObject[List[0, 14, 59.12`]], TimeObject[List[0, 14, 59.14`]], 
   TimeObject[List[0, 14, 59.4`]], TimeObject[List[0, 14, 59.44`]], 
   TimeObject[List[0, 14, 59.45`]], TimeObject[List[0, 14, 59.47`]], 
   TimeObject[List[0, 15, 0.39`]], TimeObject[List[0, 15, 3.27`]], 
   TimeObject[List[0, 15, 5.44`]], TimeObject[List[0, 15, 8.45`]], 
   TimeObject[List[0, 15, 9.34`]], TimeObject[List[0, 15, 12.65`]], 
   TimeObject[List[0, 15, 19.96`]], TimeObject[List[0, 15, 20.82`]]};

based on timing:

Table[k -> (Take[times, k] // Min // Timing // First), {k, 15}] 

{1 -> 0.000021, 2 -> 0.000643, 3 -> 0.000955, 4 -> 0.001439, 5 -> 0.002542, 6 -> 0.004146, 7 -> 0.008497, 8 -> 0.019078, 9 -> 0.042076, 10 -> 0.097678, 11 -> 0.227000, 12 -> 0.540869, 13 -> 1.331936, 14 -> 3.248148, 15 -> 8.268877}

Similar numbers for Max. Have not tested other functions. This is on a 3.2Ghz Mac. Can anyone else replicate?

$\endgroup$
2
  • 2
    $\begingroup$ I can confirm the problem in 10.0.2 under Windows. $\endgroup$
    – Mr.Wizard
    Mar 6, 2015 at 23:00
  • 1
    $\begingroup$ Confirmed in MacOS Yosemite, using V10.0.2 $\endgroup$
    – Murta
    Mar 7, 2015 at 10:07

3 Answers 3

3
$\begingroup$

fixed in 10.1

Mathematica graphics


Mathematica graphics

code

times = {TimeObject[List[0, 14, 55.99`]], 
   TimeObject[List[0, 14, 57.8`]], TimeObject[List[0, 14, 59.09`]], 
   TimeObject[List[0, 14, 59.11`]], TimeObject[List[0, 14, 59.12`]], 
   TimeObject[List[0, 14, 59.14`]], TimeObject[List[0, 14, 59.4`]], 
   TimeObject[List[0, 14, 59.44`]], TimeObject[List[0, 14, 59.45`]], 
   TimeObject[List[0, 14, 59.47`]], TimeObject[List[0, 15, 0.39`]], 
   TimeObject[List[0, 15, 3.27`]], TimeObject[List[0, 15, 5.44`]], 
   TimeObject[List[0, 15, 8.45`]], TimeObject[List[0, 15, 9.34`]], 
   TimeObject[List[0, 15, 12.65`]], TimeObject[List[0, 15, 19.96`]],
    TimeObject[List[0, 15, 20.82`]]};
 Table[k -> (Take[times, k] // Min // Timing // First), {k, 15}]
$\endgroup$
11
$\begingroup$

I can confirm the problem in 10.0.2 under Windows. I think it can only be a bug.

One can at least work around the problem in this example using MinimalBy and MaximalBy:

times2 = RandomSample[times];  (* start with a random order *)

MinimalBy[times2, Identity, 1] // Timing
{0., {TimeObject[{0, 14, 55.99}]}}
MaximalBy[times2, Identity, 1] // Timing
{0., {TimeObject[{0, 15, 20.82}]}}
$\endgroup$
10
$\begingroup$

Confirmed in 10.0.2.0 Windows x64.

Min takes exponential time with respect to the number x of TimeObjects to analyze:

Using Fit[timings, {1, x, Exp[x]}, x] on my results here, I get the following equation for the time required:

-0.0644554 + 2.89365*10^-6 E^x + 0.0157914 x

so, finding the minimum of 20 TimeObjects would level in somewhere around 1400 s.

The current situation with Min in graphical form:

Min for 1 to 15 TimeObjects

Please report this bug to Wolfram and in the meantime go with Mr. Wizard's workaround or use a construct like

times[[Ordering[times, 1]]]

which is faster than MinimalBy for larger TimeObject-lists:

tos=RandomSample@NestList[#+QT[RandomReal[30.],"Seconds"]&,TimeObject[],10^4];
First/@{AbsoluteTiming@tos[[Ordering[tos,1]]],AbsoluteTiming@MinimalBy[tos,Identity,1]}
(* {0.001001, 0.016008} *)
$\endgroup$
7
  • $\begingroup$ +1, and I've filed w/ WRI support. Let me ask about the mothod, a polynomial can fit any finite number of points even if exponentially growing. $\endgroup$ Mar 7, 2015 at 23:59
  • $\begingroup$ @alancalvitti: Try it and you will find, that a polynomial tends to oscillate between the measurements. This one is clearly an exponential. $\endgroup$
    – Jinxed
    Mar 8, 2015 at 0:14
  • $\begingroup$ No, for example, take the timing data in my Q and then interpolate using a spline curve - which afaik are all polynomial, including Bezier: Map[Apply[List]] // Interpolation[#, Method -> "Spline"] & // Plot[#[x], {x, 0, 15}] & $\endgroup$ Mar 8, 2015 at 3:24
  • $\begingroup$ @alancalvitti: True, but have a look at the extrapolation behavior: My function extrapolates correctly. Yours doesn't. Try interpolating a shortened list of timings and observe, if the remainer of the list is "hit". It does with Exp[x], it does not with your polynomial. $\endgroup$
    – Jinxed
    Mar 8, 2015 at 9:02
  • $\begingroup$ Right, that's an appropriate test - but note that comparison isn't in your original answer. $\endgroup$ Mar 8, 2015 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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