daphne-eu / daphne

DAPHNE: An Open and Extensible System Infrastructure for Integrated Data Analysis Pipelines
Apache License 2.0
65 stars 58 forks source link

Multinomial Logistic Regression throws execution error. #553

Open aristotelis96 opened 1 year ago

aristotelis96 commented 1 year ago

According to readme file (scripts/algorithms/README.md), multiLogReg.daph should work, however daphne returns the following error message:

$ bin/daphne scripts/algorithms/multiLogReg.daph XY=\"data/wine.csv\"

-- Initially:  Objective = 4898.000000,  Gradient Norm = 329546.501426,  Trust Delta = 0.002849
-- Outer Iteration 1: Had 1 CG iterations, trust bound REACHED
   -- Obj.Reduction:  Actual = 114.631208,  Predicted = 894.703251  (A/P: 0.128100),  Trust Delta = 0.001425
   -- New Objective = 4783.368792,  Beta Change Norm = 0.002849,  Gradient Norm = 295509.204778
Execution error: EwBinaryMat(Dense) - lhs and rhs must either have the same dimensions, or one of them must be a row/column vector with the width/height of the other

Lines 154-156 seem to affect P matrix during the second iteration, causing issues when assigning P_1K.

Added print to lines 157 and 293 to help demonstrate the error:

// line 151
while ( converge != 1 ) #TODO !converge
{
    print("iteration starts...");
    # SOLVE TRUST REGION SUB-PROBLEM
    S = fill(0.0, D, K);
    R = Grad * -1.0; #TODO -Grad / 0-Grad support
    print(nrow(P) + " " + ncol(P));
    V = R;
    delta2 = delta ^ 2.0
    // ...
    // rest of the code...
    // ...
    print(nrow(P) + " " + ncol(P)); // line 273
    print("iteration ends...");
}

Output:

-- Initially:  Objective = 4898.000000,  Gradient Norm = 329546.501426,  Trust Delta = 0.002849
iteration starts...
4898 10
-- Outer Iteration 1: Had 1 CG iterations, trust bound REACHED
   -- Obj.Reduction:  Actual = 114.631208,  Predicted = 894.703251  (A/P: 0.128100),  Trust Delta = 0.001425
   -- New Objective = 4783.368792,  Beta Change Norm = 0.002849,  Gradient Norm = 295509.204778
4898 10
iteration ends...
iteration starts...
9 9
Execution error: EwBinaryMat(Dense) - lhs and rhs must either have the same dimensions, or one of them must be a row/column vector with the width/height of the other
corepointer commented 1 year ago

I tracked it down to missing reference management on slice operations (which is what the right indexing of P_1K = P[0:N1, 0:K]; is doing).

pdamme commented 1 year ago

Thanks for reporting this bug, @aristotelis96. I can also reproduce it. Unfortunately, I wasn't able to quickly find the cause, but following up on @corepointer's comment, I can confirm that the script works when calling daphne with --no-obj-ref-mgnt. Please shout out if this issue is blocking you.

In fact, this script used to work properly. We need to add test cases that check if the examples work at some point (see #559) to avoid breaking the examples again in the future...