xuyiqing / tjbal

Trajectory Balancing
MIT License
11 stars 10 forks source link

Issue during optimization when output reads "Trying XX dims of K; distance at NaN" #3

Closed lmgibson closed 5 years ago

lmgibson commented 5 years ago

The error is read as:

Error in if (dist.now < mindistsofar) { : missing value where TRUE/FALSE needed

I've attached code and an example dataset. The error goes away if I change sigma to another value. tjbal_error.zip

xuyiqing commented 5 years ago

Thank you. I'm busy during the next 10 days. But I'll address it asap.

On Sun, Nov 11, 2018 at 3:32 PM Landon Gibson notifications@github.com wrote:

The error is read as:

Error in if (dist.now < mindistsofar) { : missing value where TRUE/FALSE needed

I've attached code and an example dataset. The error goes away if I change sigma to another value. tjbal_error.zip https://github.com/xuyiqing/tjbal/files/2570049/tjbal_error.zip

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/xuyiqing/tjbal/issues/3, or mute the thread https://github.com/notifications/unsubscribe-auth/AHT1GA6zVgR3hggbNusn7bq3Dn6D-GuHks5uuLOKgaJpZM4YYwGT .

-- Yiqing Xu

Assistant Professor Department of Political Science University of California, San Diego http://yiqingxu.org/

lmgibson commented 5 years ago

Just bumping this. It seems to be an error that instead of outputting 999 it outputs NaN.

xuyiqing commented 5 years ago

Thanks, Landon. I'll get to it as soon as I can. Teaching two courses this quarter...

On Wed, Feb 20, 2019 at 5:21 PM Landon Gibson notifications@github.com wrote:

Just bumping this. It seems to be an error that instead of outputting 999 it outputs NaN.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/xuyiqing/tjbal/issues/3#issuecomment-465822818, or mute the thread https://github.com/notifications/unsubscribe-auth/AHT1GN2LLyGfP8OnjCGUMRmeAI8zgks1ks5vPfSQgaJpZM4YYwGT .

-- Yiqing Xu

Assistant Professor Department of Political Science University of California, San Diego http://yiqingxu.org/

lmgibson commented 5 years ago

No worries, I have a rough workaround for the time being. Thank you.

lmgibson commented 5 years ago

Hi Yiqing. I took a look at this and I'm pretty sure I found the root error. I'm not certain how to fix the root error but I was able to propose a fix to the KBAL code that bandaids the issue.

The root error comes from line 282 in KBAL/R/kbal.R (from Chad's repository) in the get.dist function where _ebalancecustom is used on the SVD of the kernel matrix to find weights for a given number of dimensions of the middle matrix. Something is happening to the _ebalancecustom function call to another function, eb, such that it reports a weights vector containing one element equal to NA, another element equal to 1, and all remaining elements equal to 0. Unfortunately, I'm not familiar enough with the operationalization of ebalance to know what a weight value of NA would be caused by.

Here's some background on how I found this error if the context is needed. I figured the error had to be coming from KBAL since I couldn't find the code of interest in the tjbal package. Once in the KBAL code, I found the line that was causing issues "if (dist.now < mindistsofar)" and from there was able to identify the get.dist.out function as the source. Once there it was a matter of identifying which pieces in defining the L1 were NA, which lead me to pX_D0w. I was then able to modify the code to report "w" and found the vector I noted above.

xuyiqing commented 5 years ago

Thanks for letting me know, Landon. I'll try to fix some bugs in May.

On Sat, Apr 20, 2019 at 9:34 AM Landon Gibson notifications@github.com wrote:

Hi Yiqing. I took a look at this and I'm pretty sure the root of the error comes from line 282 in KBAL/R/kbal.R (from Chad's repository) in the get.dist function where ebalance_custom is used on the SVD of the kernel matrix to find weights for a given number of dimensions of the middle matrix. Something is happening to the ebalance_custom function call to another function, eb, such that it reports a weights vector containing one element equal to NA, another element equal to 1, and all remaining elements equal to 0. I think it has to do with the X input into ebalance_custom (K2) but I'm not sure why.

Here's some background on how I found this error if the context is needed. I figured the error had to be coming from KBAL since I couldn't find the code of interest in the tjbal package. Once in the KBAL code, I found the line that was causing issues "if (dist.now < mindistsofar)" and from there was able to identify the get.dist.out function as the source. Once there it was a matter of identifying which pieces in defining the L1 were NA, which lead me to pX_D0w. I was then able to modify the code to report "w" and found the vector I noted above.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/xuyiqing/tjbal/issues/3#issuecomment-485141201, or mute the thread https://github.com/notifications/unsubscribe-auth/AB2PKGFE65IDAT3UZ7NWNWLPRNAZ3ANCNFSM4GDDAGJQ .

-- Yiqing Xu

Assistant Professor Department of Political Science University of California, San Diego http://yiqingxu.org/