empca icon indicating copy to clipboard operation
empca copied to clipboard

RunTimeWarning: line 129

Open petitvic opened this issue 11 years ago • 6 comments

Hi,

I just started using empca and it works great. However in a few instances, I have the following Warning which seems to make the PCA stop: empca.py:129: RuntimeWarning: invalid value encountered in double_scalars self.eigvec[k, j] = x.dot(cw) / c.dot(cw)

Any advice on how to get rid of this message?

Thanks in advance.

petitvic avatar Feb 19 '14 13:02 petitvic

Hi.

At first I thought this would be due to NaN or Inf values in one of the vectors (x, cw, or c), but I haven't been able to reproduce that in separate tests. Can you check if the vectors have any funny values? e.g.

if N.any(x != x): print "x has NaN values"

Alternately, is it possible that some of your variables have weight=0 for every observation?

Stephen

On Feb 19, 2014, at 5:43 AM, petitvic [email protected] wrote:

Hi,

I just started using empca and it works great. However in a few instances, I have the following Warning which seems to make the PCA stop: empca.py:129: RuntimeWarning: invalid value encountered in double_scalars self.eigvec[k, j] = x.dot(cw) / c.dot(cw)

Any advice on how to get rid of this message?

Thanks in advance.

— Reply to this email directly or view it on GitHub.

sbailey avatar Feb 20 '14 05:02 sbailey

Hi Stephen,

thanks for your quick answer and the pb was indeed that some of my observations had all weights set to 0. It works like a charm now!

Victor

On Thu, Feb 20, 2014 at 6:06 AM, sbailey [email protected] wrote:

Hi.

At first I thought this would be due to NaN or Inf values in one of the vectors (x, cw, or c), but I haven't been able to reproduce that in separate tests. Can you check if the vectors have any funny values? e.g.

if N.any(x != x): print "x has NaN values"

Alternately, is it possible that some of your variables have weight=0 for every observation?

Stephen

On Feb 19, 2014, at 5:43 AM, petitvic [email protected] wrote:

Hi,

I just started using empca and it works great. However in a few instances, I have the following Warning which seems to make the PCA stop: empca.py:129: RuntimeWarning: invalid value encountered in double_scalars self.eigvec[k, j] = x.dot(cw) / c.dot(cw)

Any advice on how to get rid of this message?

Thanks in advance.

Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHubhttps://github.com/sbailey/empca/issues/1#issuecomment-35589696 .

petitvic avatar Feb 20 '14 10:02 petitvic

Glad it worked out. You are the second user who has been confused by the cryptic effect of inputs with all weights=0. I should probably add a check at the beginning for that case and refuse to start the fitting until the input is cleaned up.

Curiosity: what are you using empca for?

Stephen

On Feb 20, 2014, at 2:16, petitvic [email protected] wrote:

Hi Stephen,

thanks for your quick answer and the pb was indeed that some of my observations had all weights set to 0. It works like a charm now!

Victor

On Thu, Feb 20, 2014 at 6:06 AM, sbailey [email protected] wrote:

Hi.

At first I thought this would be due to NaN or Inf values in one of the vectors (x, cw, or c), but I haven't been able to reproduce that in separate tests. Can you check if the vectors have any funny values? e.g.

if N.any(x != x): print "x has NaN values"

Alternately, is it possible that some of your variables have weight=0 for every observation?

Stephen

On Feb 19, 2014, at 5:43 AM, petitvic [email protected] wrote:

Hi,

I just started using empca and it works great. However in a few instances, I have the following Warning which seems to make the PCA stop: empca.py:129: RuntimeWarning: invalid value encountered in double_scalars self.eigvec[k, j] = x.dot(cw) / c.dot(cw)

Any advice on how to get rid of this message?

Thanks in advance.

Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHubhttps://github.com/sbailey/empca/issues/1#issuecomment-35589696 .

— Reply to this email directly or view it on GitHub.

sbailey avatar Feb 20 '14 15:02 sbailey

The check would be good for new users I guess. Regarding my use of empca, we have some NGS Cancer data with several normal and tumoral samples for each patient. I am visualizing these data per patient to see whether there is any mix-ups between the normal and tumoral samples.

Victor

On Thu, Feb 20, 2014 at 4:07 PM, sbailey [email protected] wrote:

Glad it worked out. You are the second user who has been confused by the cryptic effect of inputs with all weights=0. I should probably add a check at the beginning for that case and refuse to start the fitting until the input is cleaned up.

Curiosity: what are you using empca for?

Stephen

On Feb 20, 2014, at 2:16, petitvic [email protected] wrote:

Hi Stephen,

thanks for your quick answer and the pb was indeed that some of my observations had all weights set to 0. It works like a charm now!

Victor

On Thu, Feb 20, 2014 at 6:06 AM, sbailey [email protected] wrote:

Hi.

At first I thought this would be due to NaN or Inf values in one of the vectors (x, cw, or c), but I haven't been able to reproduce that in separate tests. Can you check if the vectors have any funny values? e.g.

if N.any(x != x): print "x has NaN values"

Alternately, is it possible that some of your variables have weight=0 for every observation?

Stephen

On Feb 19, 2014, at 5:43 AM, petitvic [email protected] wrote:

Hi,

I just started using empca and it works great. However in a few instances, I have the following Warning which seems to make the PCA stop: empca.py:129: RuntimeWarning: invalid value encountered in double_scalars self.eigvec[k, j] = x.dot(cw) / c.dot(cw)

Any advice on how to get rid of this message?

Thanks in advance.

Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHub< https://github.com/sbailey/empca/issues/1#issuecomment-35589696> .

Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHubhttps://github.com/sbailey/empca/issues/1#issuecomment-35630247 .

petitvic avatar Feb 20 '14 15:02 petitvic

Great. Glad to hear that it is getting use beyond astrophysics.

Stephen

On Feb 20, 2014, at 7:17, petitvic [email protected] wrote:

The check would be good for new users I guess. Regarding my use of empca, we have some NGS Cancer data with several normal and tumoral samples for each patient. I am visualizing these data per patient to see whether there is any mix-ups between the normal and tumoral samples.

Victor

On Thu, Feb 20, 2014 at 4:07 PM, sbailey [email protected] wrote:

Glad it worked out. You are the second user who has been confused by the cryptic effect of inputs with all weights=0. I should probably add a check at the beginning for that case and refuse to start the fitting until the input is cleaned up.

Curiosity: what are you using empca for?

Stephen

On Feb 20, 2014, at 2:16, petitvic [email protected] wrote:

Hi Stephen,

thanks for your quick answer and the pb was indeed that some of my observations had all weights set to 0. It works like a charm now!

Victor

On Thu, Feb 20, 2014 at 6:06 AM, sbailey [email protected] wrote:

Hi.

At first I thought this would be due to NaN or Inf values in one of the vectors (x, cw, or c), but I haven't been able to reproduce that in separate tests. Can you check if the vectors have any funny values? e.g.

if N.any(x != x): print "x has NaN values"

Alternately, is it possible that some of your variables have weight=0 for every observation?

Stephen

On Feb 19, 2014, at 5:43 AM, petitvic [email protected] wrote:

Hi,

I just started using empca and it works great. However in a few instances, I have the following Warning which seems to make the PCA stop: empca.py:129: RuntimeWarning: invalid value encountered in double_scalars self.eigvec[k, j] = x.dot(cw) / c.dot(cw)

Any advice on how to get rid of this message?

Thanks in advance.

Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHub< https://github.com/sbailey/empca/issues/1#issuecomment-35589696> .

Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHubhttps://github.com/sbailey/empca/issues/1#issuecomment-35630247 .

— Reply to this email directly or view it on GitHub.

sbailey avatar Feb 20 '14 15:02 sbailey

The solution is something like this:

mask_empty = sp.sum(ivar,axis=0)>0.
init_size = mask_empty.size
flux = flux[:,mask_empty]
ivar = ivar[:,mask_empty]

run empca, then return:

new_eighenvalue = sp.zeros((nbCoeff,init_size) )
for i in range(nbCoeff):
    new_eighenvalue[i,sp.logical_not(mask_empty)] = eighenvalue[i]

londumas avatar Mar 20 '18 20:03 londumas