Skip to content

Debugging

Toby Dylan Hocking edited this page Apr 21, 2017 · 4 revisions

The code includes the following which should help with debugging.

run-time optimality checks via check_min_of

The code uses check_min_of to make sure that set_to_min_less_of, set_to_min_more_of, and set_to_min_env_of return optimal solutions. If there is some problem (one of the inputs that is less than the output, which should be the min) then check_min_of throws an exception and prints a message about the functions that caused the error. At the bottom of the message are the actual coefficients and intervals stored, so you can copy that text and paste them into a plotting program to see if there are any problems which are visually obvious (there usually are). For example, here is a message I got recently:

=min more(prev up cost)
    Linear        Log        Constant    min_log_mean    max_log_mean   prev_log_mean data_i
0.00000000000000000000e+00 0.00000000000000000000e+00 -1.50579293620309506707e+00            -inf        1.098612        1.098612 13374
1.47372169993798088653e-04 -4.42116509981394238855e-04 -1.50574933808218780484e+00        1.098612        4.127134             inf 13374
=prev down cost
    Linear        Log        Constant    min_log_mean    max_log_mean   prev_log_mean data_i
1.47372169993798088653e-04 -4.42116509981394238855e-04 -1.50582645029657946623e+00            -inf        0.000000        0.000000 13373
2.94744339987596177307e-04 -5.89488679975192354614e-04 -1.50597382246657351956e+00        0.000000        4.127134             inf 13373
=new down cost model
    Linear        Log        Constant    min_log_mean    max_log_mean   prev_log_mean data_i
0.00000000000000000000e+00 0.00000000000000000000e+00 -1.50579293620309506707e+00            -inf        0.000000        1.098612 13374
2.94744339987596177307e-04 -5.89488679975192354614e-04 -1.50597382246657351956e+00        0.000000        1.098612             inf 13373
1.47372169993798088653e-04 -4.42116509981394238855e-04 -1.50574933808218780484e+00        1.098612        4.127134             inf 13374

There are three blocks which start with an equals sign. Each block represents one of the functions involved in the operation which caused the error. For example here we are trying to compute the down cost and we have

  • min more(prev up cost) which is the min more operator of the cost of being up/peak at the previous data point.
  • prev down cost which is the cost of being down at the previous data point.
  • new down cost model which is the result of the using set_to_min_env_of on the previous two functions.

Each of those blocks is a table with one row for each function piece (interval) and the following columns:

  • Linear, Log, Constant: coefficients of the Poisson loss.
  • min_log_mean, max_log_mean: left and right limit of the interval in the log(mean) space.
  • prev_log_mean: mean of previous segment, computed by a previous min-less/more operation.
  • data_i: end of previous segment.

After copying this code to https://github.com/tdhock/coseg/blob/master/tests/testthat/plot.R, the resulting plot (after zooming in) is as below, It is clear from inspection of this plot that there was some problem with the min_env computation – you can see the discontinuity in the green curve which starts near log(mean)=0.

To see more details about what led to this problem, when the error is detected, the set_to_min_env_of method is re-run with verbose=1, meaning that details are printed during each step of the min_env computation. These details usually help determine the cause of the problem. If necessary, you can add more statements like if(verbose)printf("something") in the code for the min less/more/env operations.

Show details of computations (verbose=1)

In PeakSegPDPALog you can edit the #define IFPRINT statement at the top in order to specify a data point and model size for which the details of all min less/more/env computations will be printed.

Clone this wiki locally