davidhallac/TICC

Some of the value in "optRes" will be nan.

Closed this issue · 4 comments

Hi,
Could you please help me with this.

I have a problem running your code on my dataset.
When I'm in Iteration 0 and calling the function "train_clusters", the return value "optRes" seems to contain some nan.
So when the function "optimize_clusters" got the value "optRes" from the function "train_clusters", it raised the error.

I did print out the value of "val" every time. Here is the output and the error information:
##################################################
ITERATION ### 0
/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py:497: RuntimeWarning: Degrees of freedom <= 0 for slice
/usr/local/lib/python3.5/dist-packages/numpy/lib/function_base.py:3093: RuntimeWarning: divide by zero encountered in double_scalars
c *= 1. / np.float64(fact)
/usr/local/lib/python3.5/dist-packages/numpy/lib/function_base.py:3093: RuntimeWarning: invalid value encountered in multiply
c *= 1. / np.float64(fact)
val: [0.2301 0.1450 -0.0000 ..., 0.9513 -0.0000 0.3904]
OPTIMIZATION for Cluster # 0 DONE!!!
val: [0.7449 0.0000 -0.0000 ..., 1.0000 -0.0000 0.5509]
OPTIMIZATION for Cluster # 1 DONE!!!
val: [0.9931 0.0000 0.0000 ..., 0.7676 -0.0000 0.5487]
OPTIMIZATION for Cluster # 2 DONE!!!
val: [0.4735 0.0000 0.0000 ..., 0.7480 0.0000 0.3804]
OPTIMIZATION for Cluster # 3 DONE!!!
val: [0.1999 0.1088 0.0000 ..., 0.8651 0.0000 0.5592]
OPTIMIZATION for Cluster # 4 DONE!!!
val: [0.0202 0.0314 0.0143 ..., 0.7245 0.0000 0.1511]
OPTIMIZATION for Cluster # 5 DONE!!!
val: [nan nan nan ..., nan nan nan]
OPTIMIZATION for Cluster # 6 DONE!!!
/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py:567: RuntimeWarning: invalid value encountered in less
/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py:567: RuntimeWarning: invalid value encountered in greater

LinAlgErrorTraceback (most recent call last)
in fit(self, input_file)
274 #print("opt_res: " + str(opt_res))
275 self.optimize_clusters(computed_covariance, len_train_clusters, log_det_values, opt_res,
--> 276 train_cluster_inverse)
277
278 # update old computed covariance

in optimize_clusters(self, computed_covariance, len_train_clusters, log_det_values, optRes, train_cluster_inverse)
467 X2 = S_est
468 #print(S_est)
--> 469 u, _ = np.linalg.eig(S_est)
470 cov_out = np.linalg.inv(X2)
471

/usr/local/lib/python3.5/dist-packages/numpy/linalg/linalg.py in eig(a)
1126 _assertRankAtLeast2(a)
1127 _assertNdSquareness(a)
-> 1128 _assertFinite(a)
1129 t, result_t = _commonType(a)
1130

/usr/local/lib/python3.5/dist-packages/numpy/linalg/linalg.py in _assertFinite(*arrays)
215 for a in arrays:
216 if not (isfinite(a).all()):
--> 217 raise LinAlgError("Array must not contain infs or NaNs")
218
219 def _isEmpty2d(arr):

LinAlgError: Array must not contain infs or NaNs
##################################################

I assume that there are some problems when the program calculate (use) the ADMM_solver.
Do you know what's wrong with this?
Thank you for your time.

Btw, I did normalize my dataset and set lambda to 0.1, 1, ...

I'm sorry.
Apparently I'm using the old version of TICC.
I'll try the latest one.
Thank you for your time.

Hi,
I tried the latest version of TICC.
It seems that it depend on the length of the dataset.
If length is not long enough (around 1000), it will occur the error (error message: "numpy.linalg.linalg.LinAlgError: Array must not contain infs or NaNs").
Is it possible that I can input the small dataset without occurring the error?
Thank you for your time.

Hi! Typically this error occurs when one of the clusters is "empty", meaning the parameters in the problem were poorly tuned. This occasionally occurs because TICC is a non-convex problem, so there is no way to guarantee that you reach the globally optimal solution, and occasionally it gets stuck in a local minimum that it can't get out of. Can you play around with the problem parameters (beta, number of clusters, etc.) and see if that fixes it? In general, fewer clusters and a smaller beta will decrease the probability of that occurring. Thanks!

Hi,
You are right.
When I adjust the value of #clusters to lower, the error won't happen again!
Thank you very much for your help.