1

I have made a program that goes like this, the goal is to estimate the remaining time of a function (it is running a bunch of solveChase[] functions with different parameters which can be seen in the best answer of this question):

count=0;
count2=0;
precision=100;

Table[
    {
        Do[{
            Somefunction[var],
            count2++
            },
            {precision}
        ];
        count2=0;
        count++;
    },
    {i,3},
    {i,3}
]

If in another cell I put:

Print[Dynamic@Round[100 (precision count + count2)/(precision max1 max2),.01], "%" ];

(which shows the percentage of all the process, from 0 to 100%)

That value will change, but because of SomeFunction[var] (a NDSolve result which its running time depends on i and j) not in a linear way.

It has different rates of change in some parts, so it has a velocity which is not constant and can be calculated.

This is a example(sorry for bad quality):

example of not linear remaining time on some calculations


My guess is to insert another variable t, which depends on time, and then do something with it, but I don't know how to do it.

Any help will be appreciated.

Arcotick
  • 629
  • 3
  • 13
  • "It has different rates of change in some parts, so it has a velocity which is not constant and can be calculated." : If you are able to calculate the time needed for each calculation the problem is trivial, isn't it? – Dr. belisarius Jan 29 '14 at 12:13
  • 1
    see http://mathematica.stackexchange.com/questions/116/continuous-evaluation-of-complex-calculations and http://mathematica.stackexchange.com/questions/26438/monitoring-the-evaluation-of-ndsolve-time-to-finish-estimation and http://reference.wolfram.com/mathematica/ref/StepMonitor.html – Nasser Jan 29 '14 at 12:14
  • @belisarius Yeah you are right, but I have noticed that the rate of change is diferent, not mathematica, I don't know how to do it, so the problem now is to find the time needed for each calculation. – Arcotick Jan 29 '14 at 12:19
  • 1
    @Arcotick http://meta.mathematica.stackexchange.com/q/5/193 – Dr. belisarius Jan 29 '14 at 13:09

2 Answers2

2
n = 10; {a, b} = {0, 0};
somefun[i_, j_] := (Pause[i/40]; Pause[j/80]; i + j)
estimatedTime[i_, j_] := i/40 + j/80
totalTime = Sum[estimatedTime[i, j], {i, n}, {j, n}];

timeUpToij[h_, k_] := Sum[estimatedTime[i, j], {i, h}, {j, n}] - 
                      Sum[estimatedTime[h, j], {j, k + 1, n}]

Dynamic@ProgressIndicator[timeUpToij[a, b]/totalTime]
Table[({a, b} = {i, j}; somefun[i, j]), {i, n}, {j, n}]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • If I run this code, I get a ProgressIndicator which runs on a "random" way, which is similar to the example. I'm actually trying to calculate the calculating speed at any time t – Arcotick Jan 29 '14 at 13:05
  • @Arcotick You need to fill in estimatedTime[] with YOUR estimated time – Dr. belisarius Jan 29 '14 at 13:07
  • By the way, how did you take a photo of the output cell? – Arcotick Jan 29 '14 at 13:07
  • But what if I don't know the estimated time? it can any number bigger than 0. Do I need to calculate the timing of that function and then multiply it by the steps? – Arcotick Jan 29 '14 at 13:10
  • @Arcotick You can't make a linear progress indicator if you can't estimate the time, sorry – Dr. belisarius Jan 29 '14 at 13:22
1

Unless you know the run-time for each invocation of your function in advance it is not possible to display progress (in terms of time).

You can estimate the time remaining using (1-f)(t-t0)/f where f is the fraction of invocations so far, t is the current time and t0 is the start time.

As a simple example, first set-up an approximate remaining-time estimate display:

Dynamic[(iMax/count - 1) (AbsoluteTime[] - t0)]

Then run the "calculation":

iMax = 100;
count = 0;
t0 = AbsoluteTime[];
Table[count++;Pause[RandomReal[{0.1, 0.3}]];i, {i, iMax}]

Replace Pause[...];i with your calculation.

MikeLimaOscar
  • 3,456
  • 17
  • 29