Elizabethxyhu / NeurIPS_Two_Stage_Predict-Optimize

14 stars 2 forks source link

Something wrong in the code of val_loss function for 0-1 knapsack experiments #1

Closed Felix-Feng closed 8 months ago

Felix-Feng commented 8 months ago

Hi Eliza,

I took a close look at your code, and found there maybe something wrong in val_loss function of your 0-1 knapsack experiments.

https://github.com/Elizabethxyhu/NeurIPS_Two_Stage_Predict-Optimize/blob/main/code/0-1%20knapsack/train.py#L194

According to the code, "x" in Gurobi model seems to be equal to the first-stage decision, and "sigma" denotes the difference between the first- and second-stage decision. Then, the resulting objective of second-stage model is different to what you explained in Appendix C.2. Actually, it becomes $f^{\top} x_1^ - \sigma f^{\top} (x_1^ - x)$. Btw, the coefficient purchase_fee is also missed when formulating the compensation fee.

Please feel free to share your feedback. Thanks.

Elizabethxyhu commented 8 months ago

Thank you for posting this issue. After checking the code and appendix, I found that there might be some misunderstanding due to the variable naming of the code. According to the Appendix C.2., the objective function of the second-stage OP is: $\sum (purchasePersent price_i)x_i - \sum (compensationPercent purchasePersent price_i)(x^_{1i}-x_i)$, where $(purchasePersent price_i)$ refers to $f_i$ and $(compensationPercent purchasePersent * price_i)$ refers to $\sigma f_i$ in Equation (23) in Appendix C.2.

For simplicity, we use $\alpha$ to represent the purchase percent, and $\beta$ to represent the compensation percent. Then we have:

Screenshot 2023-12-14 at 5 30 39 PM

In the code, "x" represents the first-stage decision, i.e., Screenshot 2023-12-14 at 5 46 20 PM, and "sigma" represents the difference between the first and second-stage decision, i.e., Screenshot 2023-12-14 at 5 47 04 PM Therefore, the code writes:

Screenshot 2023-12-14 at 5 36 15 PM

In the code, "purchase_fee" refers to $\alpha$, and "compensation_fee" refers to $(1+\beta)*\alpha$

We apologize for the misleading naming of variables in the code. Hope this comment can answer all your questions.

Felix-Feng commented 8 months ago

Thanks for your prompt feedback.

However, I add a breakpoint at: https://github.com/Elizabethxyhu/NeurIPS_Two_Stage_Predict-Optimize/blob/main/code/0-1%20knapsack/train.py#L196 It looks that "compensation_fee" is NOT equal to $(1+\beta) * \alpha$ in the code. In fact, it takes the value of the compensation percent, which is initialized at https://github.com/Elizabethxyhu/NeurIPS_Two_Stage_Predict-Optimize/blob/main/code/0-1%20knapsack/train.py#L27

Please take a check if I miss something. Thanks

Elizabethxyhu commented 8 months ago

I think the reason for this misunderstanding is that the "purchase_fee" and "compensation_fee" are hardcoded. In lines 26 and 27, the code writes "purchase_fee = 0.2, compensation_fee = 0.21" <=> $\alpha = 0.2, (1+\beta)*\alpha = 0.21$ <=> $\alpha = 0.2, \beta = 0.05$ For example, if a friend asks the buyer to buy a product for which the price is 100 dollars. The buyer will get 20 dollars as the profit if the buyer successfully buys the product. If the buyer promises to buy the product but cannot buy it back, the buyer cannot get the profit and will give the friend 1 dollar as compensation.

Felix-Feng commented 8 months ago

Well, it makes sense. Many thanks for your concrete explanation.