anujkhare / iregnet

7 stars 12 forks source link

convergence and standardization tests fail #52

Closed tdhock closed 7 years ago

tdhock commented 7 years ago

Hey @anujkhare I have been testing your code on the penalty.learning data set.

Now with standardize=TRUE I do get a reasonable solution beta matrix. On the bright side, it yields lower validation error rates than the previous algorithm I was using (FISTA with squared hinge loss + L1). This is a very encouraging result!

Below: FISTA gets minimal validation error of about 18%.

figure-fista-penalty-learning

Below: iregnet gets minimal valiadtion error of about 14%.

figure-iregnet-penalty-learning

However I noticed that sometimes 1000 iterations are reached, so the error_status is not zero. That is unexpected, right? I added a test to make sure that error_status is 0 for this data set. Do you have any idea why it is taking so many iterations? One way to fix it would be to use different default thresholds. Do you think that is a good idea, or could you suggest another fix?

Also I tried to fit a model by first scaling the data myself, and then using standardize=FALSE. However, when I tried to scale the data by simply subtracting the mean and dividing by the standard deviation (divided by n not n-1), I was not able to get a solution that is consistent with standardize=TRUE. After looking through the C++ source code I found that https://github.com/anujkhare/iregnet/blob/90194b37746e7d0f0ea0e1b472c75f608c812f5e/src/iregnet_fit.cpp#L473 the standardize_x function only divides by the standard deviation (it does not first subtract the mean). If I use the same scaling in my test, I am able to get results that are consistent with standardize=TRUE. I think this is a bug, since usually we should always standardize the data by centering as well as scaling. Do you think this is easily fixable?

anujkhare commented 7 years ago

@tdhock Those results do look good! Thanks for pointing the bugs out. I have fixed the X centering issue in 0551f59a65ad36fc25756e9ac80809b95610831d.

I will check the convergence issue today.

anujkhare commented 7 years ago

The convergence issue might be due to the scale parameter. Fixing the scale leads to quick convergence..

tdhock commented 7 years ago

ok great, that fixes the standardization issue. Thanks! now the plot looks like this

figure-iregnet-penalty-learning

So the max iterations is less frequent, but still happening sometimes. I wonder if we could try (1) more frequent scale updates during the cyclic coordinate descent or (2) another stopping criterion. Or I guess we could just leave it as is, and remove the test for error_status 0. The algorithm is clearly learning, even if it is not "converging."

By the way, I was expecting that fit$lambda would be strictly decreasing, but it increases at first before decreasing (and that is why the geom_path curves on the iregnet plot are not functions). Isn't that a bug too? I added a test for that.

> sprintf("%.4f", fit$lambda)
  [1] "0.1242" "0.1309" "0.1371" "0.1428" "0.1477" "0.1517" "0.1547" "0.1564"
  [9] "0.1568" "0.1559" "0.1535" "0.1499" "0.1450" "0.1390" "0.1321" "0.1249"
 [17] "0.1240" "0.1226" "0.1201" "0.1167" "0.1125" "0.1077" "0.1024" "0.0966"
 [25] "0.0907" "0.0847" "0.0787" "0.0728" "0.0671" "0.0615" "0.0562" "0.0511"
 [33] "0.0462" "0.0415" "0.0372" "0.0331" "0.0294" "0.0259" "0.0228" "0.0200"
 [41] "0.0175" "0.0153" "0.0134" "0.0116" "0.0101" "0.0088" "0.0077" "0.0067"
 [49] "0.0059" "0.0052" "0.0045" "0.0040" "0.0035" "0.0031" "0.0027" "0.0024"
 [57] "0.0021" "0.0019" "0.0017" "0.0015" "0.0013" "0.0012" "0.0011" "0.0010"
 [65] "0.0009" "0.0008" "0.0007" "0.0006" "0.0006" "0.0005" "0.0005" "0.0004"
 [73] "0.0004" "0.0004" "0.0003" "0.0003" "0.0003" "0.0002" "0.0002" "0.0002"
 [81] "0.0002" "0.0002" "0.0002" "0.0001" "0.0001" "0.0001" "0.0001" "0.0001"
 [89] "0.0001" "0.0001" "0.0001" "0.0001" "0.0001" "0.0001" "0.0001" "0.0001"
 [97] "0.0001" "0.0000" "0.0000" "0.0000"
anujkhare commented 7 years ago

The lambda issue was because of a hack I had put in to make the values match those produced by glmnet exactly. I guess that it is not that important, so I removed it.

Edit: The new plot: image

anujkhare commented 7 years ago

Hey @tdhock , by default, an unregularized fit is also calculated. This can be changed using the unreg_sol=F option.

Using this option, and by increasing maxiter=1e6, I got the following plot: image

For some reason, a few of the coefficients grow very large with respect to the others, as seen below: image

image

This probably has something to do with the data. Maybe the updates are too small because the rest of the coefficients are really small, and that leads to maxing out on the iterations.

If we increase maxiter, it does converge ultimately, so we know that it is not oscillating. I am not sure of the peaks though. Thoughts?

tdhock commented 7 years ago

the new plot looks great, thanks Anuj!

about the convergence issue, I added some printf statements to show us which optimization variables were not converged

iter=1000 lambda=68 beta_19 not converged, abs_change=0.000319 > 0.000100=threshold
iter=1000 lambda=68 beta_22 not converged, abs_change=0.000334 > 0.000100=threshold

iter=1000 lambda=69 beta_19 not converged, abs_change=0.000524 > 0.000100=threshold
iter=1000 lambda=69 beta_22 not converged, abs_change=0.000548 > 0.000100=threshold

iter=1000 lambda=70 beta_19 not converged, abs_change=0.000705 > 0.000100=threshold
iter=1000 lambda=70 beta_22 not converged, abs_change=0.000735 > 0.000100=threshold

iter=1000 lambda=85 beta_9 not converged, abs_change=0.000231 > 0.000100=threshold
iter=1000 lambda=85 beta_22 not converged, abs_change=0.000324 > 0.000100=threshold

iter=1000 lambda=86 beta_3 not converged, abs_change=0.000659 > 0.000100=threshold
iter=1000 lambda=86 beta_8 not converged, abs_change=0.000476 > 0.000100=threshold
iter=1000 lambda=86 beta_9 not converged, abs_change=0.000264 > 0.000100=threshold
iter=1000 lambda=86 beta_11 not converged, abs_change=0.000102 > 0.000100=threshold
iter=1000 lambda=86 beta_13 not converged, abs_change=0.000119 > 0.000100=threshold
iter=1000 lambda=86 beta_18 not converged, abs_change=0.000133 > 0.000100=threshold
iter=1000 lambda=86 beta_22 not converged, abs_change=0.000363 > 0.000100=threshold

iter=1000 lambda=87 beta_3 not converged, abs_change=0.000146 > 0.000100=threshold
iter=1000 lambda=87 beta_8 not converged, abs_change=0.000173 > 0.000100=threshold
iter=1000 lambda=87 beta_9 not converged, abs_change=0.000240 > 0.000100=threshold
iter=1000 lambda=87 beta_22 not converged, abs_change=0.000342 > 0.000100=threshold

iter=1000 lambda=88 beta_0 not converged, abs_change=0.000149 > 0.000100=threshold
iter=1000 lambda=88 beta_1 not converged, abs_change=0.000666 > 0.000100=threshold
iter=1000 lambda=88 beta_3 not converged, abs_change=0.000838 > 0.000100=threshold
iter=1000 lambda=88 beta_8 not converged, abs_change=0.000294 > 0.000100=threshold
iter=1000 lambda=88 beta_9 not converged, abs_change=0.000192 > 0.000100=threshold
iter=1000 lambda=88 beta_11 not converged, abs_change=0.000388 > 0.000100=threshold
iter=1000 lambda=88 beta_13 not converged, abs_change=0.000286 > 0.000100=threshold
iter=1000 lambda=88 beta_14 not converged, abs_change=0.000106 > 0.000100=threshold
iter=1000 lambda=88 beta_18 not converged, abs_change=0.000115 > 0.000100=threshold
iter=1000 lambda=88 beta_22 not converged, abs_change=0.000299 > 0.000100=threshold

iter=1000 lambda=89 beta_0 not converged, abs_change=0.000124 > 0.000100=threshold
iter=1000 lambda=89 beta_1 not converged, abs_change=0.001011 > 0.000100=threshold
iter=1000 lambda=89 beta_3 not converged, abs_change=0.001495 > 0.000100=threshold
iter=1000 lambda=89 beta_5 not converged, abs_change=0.000104 > 0.000100=threshold
iter=1000 lambda=89 beta_8 not converged, abs_change=0.000595 > 0.000100=threshold
iter=1000 lambda=89 beta_9 not converged, abs_change=0.000161 > 0.000100=threshold
iter=1000 lambda=89 beta_11 not converged, abs_change=0.000610 > 0.000100=threshold
iter=1000 lambda=89 beta_13 not converged, abs_change=0.000308 > 0.000100=threshold
iter=1000 lambda=89 beta_14 not converged, abs_change=0.000158 > 0.000100=threshold
iter=1000 lambda=89 beta_15 not converged, abs_change=0.000111 > 0.000100=threshold
iter=1000 lambda=89 beta_18 not converged, abs_change=0.000138 > 0.000100=threshold
iter=1000 lambda=89 beta_20 not converged, abs_change=0.000246 > 0.000100=threshold
iter=1000 lambda=89 beta_22 not converged, abs_change=0.000180 > 0.000100=threshold

iter=1000 lambda=90 beta_0 not converged, abs_change=0.000116 > 0.000100=threshold
iter=1000 lambda=90 beta_1 not converged, abs_change=0.000875 > 0.000100=threshold
iter=1000 lambda=90 beta_3 not converged, abs_change=0.001022 > 0.000100=threshold
iter=1000 lambda=90 beta_4 not converged, abs_change=0.000110 > 0.000100=threshold
iter=1000 lambda=90 beta_8 not converged, abs_change=0.000281 > 0.000100=threshold
iter=1000 lambda=90 beta_9 not converged, abs_change=0.000151 > 0.000100=threshold
iter=1000 lambda=90 beta_11 not converged, abs_change=0.000531 > 0.000100=threshold
iter=1000 lambda=90 beta_13 not converged, abs_change=0.000217 > 0.000100=threshold
iter=1000 lambda=90 beta_14 not converged, abs_change=0.000138 > 0.000100=threshold
iter=1000 lambda=90 beta_15 not converged, abs_change=0.000109 > 0.000100=threshold
iter=1000 lambda=90 beta_18 not converged, abs_change=0.000119 > 0.000100=threshold
iter=1000 lambda=90 beta_20 not converged, abs_change=0.000186 > 0.000100=threshold
iter=1000 lambda=90 beta_22 not converged, abs_change=0.000183 > 0.000100=threshold

iter=1000 lambda=91 beta_1 not converged, abs_change=0.000423 > 0.000100=threshold
iter=1000 lambda=91 beta_3 not converged, abs_change=0.000395 > 0.000100=threshold
iter=1000 lambda=91 beta_4 not converged, abs_change=0.000324 > 0.000100=threshold
iter=1000 lambda=91 beta_9 not converged, abs_change=0.000138 > 0.000100=threshold
iter=1000 lambda=91 beta_11 not converged, abs_change=0.000379 > 0.000100=threshold
iter=1000 lambda=91 beta_14 not converged, abs_change=0.000277 > 0.000100=threshold
iter=1000 lambda=91 beta_20 not converged, abs_change=0.000190 > 0.000100=threshold
iter=1000 lambda=91 beta_22 not converged, abs_change=0.000142 > 0.000100=threshold

iter=1000 lambda=92 beta_3 not converged, abs_change=0.000577 > 0.000100=threshold
iter=1000 lambda=92 beta_4 not converged, abs_change=0.000194 > 0.000100=threshold
iter=1000 lambda=92 beta_8 not converged, abs_change=0.000424 > 0.000100=threshold
iter=1000 lambda=92 beta_9 not converged, abs_change=0.000147 > 0.000100=threshold
iter=1000 lambda=92 beta_13 not converged, abs_change=0.000118 > 0.000100=threshold
iter=1000 lambda=92 beta_14 not converged, abs_change=0.000151 > 0.000100=threshold
iter=1000 lambda=92 beta_18 not converged, abs_change=0.000144 > 0.000100=threshold
iter=1000 lambda=92 beta_20 not converged, abs_change=0.000128 > 0.000100=threshold
iter=1000 lambda=92 beta_22 not converged, abs_change=0.000176 > 0.000100=threshold

iter=1000 lambda=93 beta_1 not converged, abs_change=0.000529 > 0.000100=threshold
iter=1000 lambda=93 beta_3 not converged, abs_change=0.000795 > 0.000100=threshold
iter=1000 lambda=93 beta_4 not converged, abs_change=0.000256 > 0.000100=threshold
iter=1000 lambda=93 beta_8 not converged, abs_change=0.000819 > 0.000100=threshold
iter=1000 lambda=93 beta_9 not converged, abs_change=0.000175 > 0.000100=threshold
iter=1000 lambda=93 beta_11 not converged, abs_change=0.000240 > 0.000100=threshold
iter=1000 lambda=93 beta_13 not converged, abs_change=0.000116 > 0.000100=threshold
iter=1000 lambda=93 beta_18 not converged, abs_change=0.000179 > 0.000100=threshold
iter=1000 lambda=93 beta_22 not converged, abs_change=0.000241 > 0.000100=threshold

iter=1000 lambda=94 beta_1 not converged, abs_change=0.000535 > 0.000100=threshold
iter=1000 lambda=94 beta_3 not converged, abs_change=0.000725 > 0.000100=threshold
iter=1000 lambda=94 beta_4 not converged, abs_change=0.000244 > 0.000100=threshold
iter=1000 lambda=94 beta_8 not converged, abs_change=0.000751 > 0.000100=threshold
iter=1000 lambda=94 beta_9 not converged, abs_change=0.000181 > 0.000100=threshold
iter=1000 lambda=94 beta_11 not converged, abs_change=0.000288 > 0.000100=threshold
iter=1000 lambda=94 beta_13 not converged, abs_change=0.000130 > 0.000100=threshold
iter=1000 lambda=94 beta_18 not converged, abs_change=0.000148 > 0.000100=threshold
iter=1000 lambda=94 beta_22 not converged, abs_change=0.000252 > 0.000100=threshold

iter=1000 lambda=95 beta_1 not converged, abs_change=0.000611 > 0.000100=threshold
iter=1000 lambda=95 beta_3 not converged, abs_change=0.000681 > 0.000100=threshold
iter=1000 lambda=95 beta_4 not converged, abs_change=0.000136 > 0.000100=threshold
iter=1000 lambda=95 beta_8 not converged, abs_change=0.000686 > 0.000100=threshold
iter=1000 lambda=95 beta_9 not converged, abs_change=0.000185 > 0.000100=threshold
iter=1000 lambda=95 beta_11 not converged, abs_change=0.000381 > 0.000100=threshold
iter=1000 lambda=95 beta_13 not converged, abs_change=0.000107 > 0.000100=threshold
iter=1000 lambda=95 beta_18 not converged, abs_change=0.000114 > 0.000100=threshold
iter=1000 lambda=95 beta_22 not converged, abs_change=0.000253 > 0.000100=threshold

iter=1000 lambda=96 beta_1 not converged, abs_change=0.000676 > 0.000100=threshold
iter=1000 lambda=96 beta_3 not converged, abs_change=0.000696 > 0.000100=threshold
iter=1000 lambda=96 beta_4 not converged, abs_change=0.000162 > 0.000100=threshold
iter=1000 lambda=96 beta_8 not converged, abs_change=0.000626 > 0.000100=threshold
iter=1000 lambda=96 beta_9 not converged, abs_change=0.000185 > 0.000100=threshold
iter=1000 lambda=96 beta_11 not converged, abs_change=0.000344 > 0.000100=threshold
iter=1000 lambda=96 beta_13 not converged, abs_change=0.000153 > 0.000100=threshold
iter=1000 lambda=96 beta_18 not converged, abs_change=0.000143 > 0.000100=threshold
iter=1000 lambda=96 beta_22 not converged, abs_change=0.000254 > 0.000100=threshold

iter=1000 lambda=97 beta_0 not converged, abs_change=0.000117 > 0.000100=threshold
iter=1000 lambda=97 beta_1 not converged, abs_change=0.000512 > 0.000100=threshold
iter=1000 lambda=97 beta_3 not converged, abs_change=0.000115 > 0.000100=threshold
iter=1000 lambda=97 beta_4 not converged, abs_change=0.001091 > 0.000100=threshold
iter=1000 lambda=97 beta_5 not converged, abs_change=0.000210 > 0.000100=threshold
iter=1000 lambda=97 beta_8 not converged, abs_change=0.000363 > 0.000100=threshold
iter=1000 lambda=97 beta_9 not converged, abs_change=0.000151 > 0.000100=threshold
iter=1000 lambda=97 beta_10 not converged, abs_change=0.001366 > 0.000100=threshold
iter=1000 lambda=97 beta_11 not converged, abs_change=0.000152 > 0.000100=threshold
iter=1000 lambda=97 beta_14 not converged, abs_change=0.000215 > 0.000100=threshold
iter=1000 lambda=97 beta_15 not converged, abs_change=0.000115 > 0.000100=threshold
iter=1000 lambda=97 beta_20 not converged, abs_change=0.000261 > 0.000100=threshold
iter=1000 lambda=97 beta_22 not converged, abs_change=0.000187 > 0.000100=threshold

iter=1000 lambda=98 beta_3 not converged, abs_change=0.000278 > 0.000100=threshold
iter=1000 lambda=98 beta_4 not converged, abs_change=0.002066 > 0.000100=threshold
iter=1000 lambda=98 beta_5 not converged, abs_change=0.000441 > 0.000100=threshold
iter=1000 lambda=98 beta_8 not converged, abs_change=0.000251 > 0.000100=threshold
iter=1000 lambda=98 beta_10 not converged, abs_change=0.002604 > 0.000100=threshold
iter=1000 lambda=98 beta_12 not converged, abs_change=0.000131 > 0.000100=threshold
iter=1000 lambda=98 beta_13 not converged, abs_change=0.000174 > 0.000100=threshold
iter=1000 lambda=98 beta_14 not converged, abs_change=0.000344 > 0.000100=threshold
iter=1000 lambda=98 beta_15 not converged, abs_change=0.000139 > 0.000100=threshold
iter=1000 lambda=98 beta_20 not converged, abs_change=0.000442 > 0.000100=threshold

iter=1000 lambda=99 beta_0 not converged, abs_change=0.000120 > 0.000100=threshold
iter=1000 lambda=99 beta_1 not converged, abs_change=0.000259 > 0.000100=threshold
iter=1000 lambda=99 beta_3 not converged, abs_change=0.000232 > 0.000100=threshold
iter=1000 lambda=99 beta_4 not converged, abs_change=0.002429 > 0.000100=threshold
iter=1000 lambda=99 beta_5 not converged, abs_change=0.000467 > 0.000100=threshold
iter=1000 lambda=99 beta_8 not converged, abs_change=0.000385 > 0.000100=threshold
iter=1000 lambda=99 beta_10 not converged, abs_change=0.003051 > 0.000100=threshold
iter=1000 lambda=99 beta_13 not converged, abs_change=0.000111 > 0.000100=threshold
iter=1000 lambda=99 beta_14 not converged, abs_change=0.000417 > 0.000100=threshold
iter=1000 lambda=99 beta_15 not converged, abs_change=0.000175 > 0.000100=threshold
iter=1000 lambda=99 beta_20 not converged, abs_change=0.000531 > 0.000100=threshold

iter=1000 lambda=100 beta_0 not converged, abs_change=0.000189 > 0.000100=threshold
iter=1000 lambda=100 beta_1 not converged, abs_change=0.009196 > 0.000100=threshold
iter=1000 lambda=100 beta_2 not converged, abs_change=0.014089 > 0.000100=threshold
iter=1000 lambda=100 beta_3 not converged, abs_change=0.013880 > 0.000100=threshold
iter=1000 lambda=100 beta_4 not converged, abs_change=0.021450 > 0.000100=threshold
iter=1000 lambda=100 beta_5 not converged, abs_change=0.001476 > 0.000100=threshold
iter=1000 lambda=100 beta_6 not converged, abs_change=0.015418 > 0.000100=threshold
iter=1000 lambda=100 beta_7 not converged, abs_change=0.004489 > 0.000100=threshold
iter=1000 lambda=100 beta_8 not converged, abs_change=0.006411 > 0.000100=threshold
iter=1000 lambda=100 beta_9 not converged, abs_change=0.001652 > 0.000100=threshold
iter=1000 lambda=100 beta_10 not converged, abs_change=0.020020 > 0.000100=threshold
iter=1000 lambda=100 beta_11 not converged, abs_change=0.004888 > 0.000100=threshold
iter=1000 lambda=100 beta_12 not converged, abs_change=0.001375 > 0.000100=threshold
iter=1000 lambda=100 beta_13 not converged, abs_change=0.000826 > 0.000100=threshold
iter=1000 lambda=100 beta_14 not converged, abs_change=0.004221 > 0.000100=threshold
iter=1000 lambda=100 beta_15 not converged, abs_change=0.001205 > 0.000100=threshold
iter=1000 lambda=100 beta_16 not converged, abs_change=0.011938 > 0.000100=threshold
iter=1000 lambda=100 beta_17 not converged, abs_change=0.001000 > 0.000100=threshold
iter=1000 lambda=100 beta_18 not converged, abs_change=0.000239 > 0.000100=threshold
iter=1000 lambda=100 beta_19 not converged, abs_change=0.001655 > 0.000100=threshold
iter=1000 lambda=100 beta_20 not converged, abs_change=0.003510 > 0.000100=threshold
iter=1000 lambda=100 beta_21 not converged, abs_change=0.001055 > 0.000100=threshold
iter=1000 lambda=100 beta_22 not converged, abs_change=0.000498 > 0.000100=threshold

Analysis of the output

> Matrix(with(conv.df, table(variable, lambda)))
23 x 19 sparse Matrix of class "dgCMatrix"
   [[ suppressing 19 column names ‘68’, ‘69’, ‘70’ ... ]]

beta_0  . . . . . . 1 1 1 . . . . . . 1 . 1 1
beta_1  . . . . . . 1 1 1 1 . 1 1 1 1 1 . 1 1
beta_10 . . . . . . . . . . . . . . . 1 1 1 1
beta_11 . . . . 1 . 1 1 1 1 . 1 1 1 1 1 . . 1
beta_12 . . . . . . . . . . . . . . . . 1 . 1
beta_13 . . . . 1 . 1 1 1 . 1 1 1 1 1 . 1 1 1
beta_14 . . . . . . 1 1 1 1 1 . . . . 1 1 1 1
beta_15 . . . . . . . 1 1 . . . . . . 1 1 1 1
beta_16 . . . . . . . . . . . . . . . . . . 1
beta_17 . . . . . . . . . . . . . . . . . . 1
beta_18 . . . . 1 . 1 1 1 . 1 1 1 1 1 . . . 1
beta_19 1 1 1 . . . . . . . . . . . . . . . 1
beta_2  . . . . . . . . . . . . . . . . . . 1
beta_20 . . . . . . . 1 1 1 1 . . . . 1 1 1 1
beta_21 . . . . . . . . . . . . . . . . . . 1
beta_22 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 . . 1
beta_3  . . . . 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
beta_4  . . . . . . . . 1 1 1 1 1 1 1 1 1 1 1
beta_5  . . . . . . . 1 . . . . . . . 1 1 1 1
beta_6  . . . . . . . . . . . . . . . . . . 1
beta_7  . . . . . . . . . . . . . . . . . . 1
beta_8  . . . . 1 1 1 1 1 . 1 1 1 1 1 1 1 1 1
beta_9  . . . 1 1 1 1 1 1 1 1 1 1 1 1 1 . . 1

this indicates that it is the beta (not the scale) which are not converging. It is also not always the same beta. this seems reasonable to me.

tdhock commented 7 years ago

thanks for your analysis Anuj.

ultimately I would like to change the stopping criterion to use the sub-differential or duality gap, but for now I would suggest that for the test case we can use unreg_sol=F and increase the number of iterations, like you propose.

tdhock commented 7 years ago

tests are now passing on my computer, but when running example(iregnet) there is now some problem with NAN values. Are you dividing by zero somewhere in the new C++ code?

Running examples in ‘iregnet-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: iregnet
> ### Title: Fit interval censored AFT models with elastic net regularization
> ### Aliases: iregnet
> 
> ### ** Examples
> 
> # y can be a 2 column matrix.
> set.seed(10)
> X <- matrix(rnorm(50), 10, 5)
> y <- matrix(rnorm(20), 10, 2)
> y <- t(apply(y, 1, sort)) # intervals must be non-decreasing
> fit1 <- iregnet(X, y)
> 
> # Surv objects from survival are also supported.
> data("ovarian")
> X <- cbind(ovarian$ecog.ps, ovarian$rx)
> y <- Surv(ovarian$futime, ovarian$fustat)
> fit2 <- iregnet(X, y)
> 
> # Log-Gaussian is same as Gaussian with log-transformed data
> set.seed(10)
> X <- matrix(rnorm(50), 10, 5)
> y <- matrix(abs(rnorm(20)), 10, 2)
> y <- t(apply(y, 1, sort)) # intervals must be non-decreasing
> fit3 <- iregnet(X, log(y), "gaussian")
Error in eval(substitute(expr), envir, enclos) : NANs produced
Calls: iregnet -> fit_cpp -> .Call
anujkhare commented 7 years ago

Okay, that sounds good. I did not change any relevant C++ code. I am checking it right now.

anujkhare commented 7 years ago

In the example for fit3, the randomly generated data is such that the model does not converge, and hence iregnet throws an error. Verified using:

fits <- survreg(Surv(time=log(y)[, 1], time2=log(y)[, 2]) ~ X)
print(fits)

Changed the data to ovarian.

tdhock commented 7 years ago

That sounds great. Let's merge this PR then?