davidhallac/TICC

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

Closed this issue · 6 comments

I was following the readme.md and when I was executing this
(cluster_assignment, cluster_MRFs) = TICC_solver.solve(window_size = 10,number_of_clusters = 5, lambda_parameter = 11e-2, beta = 400, maxIters = 70, threshold = 2e-5, write_out_file = True, input_file = "data.csv", prefix_string = "output_folder/")
it throws me error:
IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

I am using anaconda python 2.7 with cvxpy and snap just installed today.

Hmmm, can you copy-paste the full error trace so I can try to see where it occurred? Thanks!

Hi David,

So what I did is:
$python ./paper\ code/generate_synthetic_data.py
$cp ./paper\ code/Synthetic\ Data\ Matrix\ rand_seed\ =[0,1]\ generated2.csv ../data.csv
$python test.py

where test.py is just two lines:
mport TICC_solver as TICC
(cluster_assignment, cluster_MRFs) = TICC.solve(window_size = 10,number_of_clusters = 5, lambda_parameter = 11e-2, beta = 400, maxIters = 100, threshold = 2e-5, write_out_file = False, input_file = "data.csv", prefix_string = "output_folder/")

Then this is the stdout:

ITERATION ### 0
completed INITIALIZATION
OPTIMIZATION for Cluster # 0 DONE!!!
OPTIMIZATION for Cluster # 1 DONE!!!
OPTIMIZATION for Cluster # 2 DONE!!!
OPTIMIZATION for Cluster # 3 DONE!!!
OPTIMIZATION for Cluster # 4 DONE!!!
length of the cluster 0 ------> 2
length of the cluster 1 ------> 145
length of the cluster 2 ------> 186
length of the cluster 3 ------> 119
length of the cluster 4 ------> 139
UPDATED THE OLD COVARIANCE
beginning with the smoothening ALGORITHM
length of cluster # 0 --------> 0
length of cluster # 1 --------> 0
length of cluster # 2 --------> 591
length of cluster # 3 --------> 0
length of cluster # 4 --------> 0
Done writing the figure
Traceback (most recent call last):
File "test_TICC.py", line 2, in
(cluster_assignment, cluster_MRFs) = TICC.solve(window_size = 10,number_of_clusters = 5, lambda_parameter = 11e-2, beta = 400, maxIters = 100, threshold = 2e-5, write_out_file = False, input_file = "data.csv", prefix_string = "output_folder/")
File "/home/local/ASUAD/rguo12/Downloads/TICC-master/TICC_solver.py", line 1626, in solve
true_confusion_matrix = compute_confusion_matrix(num_clusters,clustered_points,sorted_training_idx)
File "/home/local/ASUAD/rguo12/Downloads/TICC-master/TICC_solver.py", line 1335, in compute_confusion_matrix
true_confusion_matrix[num,cluster] += 1
IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

Thanks,

Thanks for your reply.
I just used your code and the same error it throws.

In [1]: import TICC_solver as TICC

In [2]: (cluster_assignment, cluster_MRFs) = TICC.solve(window_size =
...: 10,number_of_clusters = 5, lambda_parameter = 11e-2, beta = 5, maxIters
...: =
...: 100, threshold = 2e-5, write_out_file = False, input_file = "data.csv",
...: prefix_string = "output_folder/")
lam_sparse 0.11
switch_penalty 5
num_cluster 5
num stacked 10
completed getting the data

ITERATION ### 0
completed INITIALIZATION
OPTIMIZATION for Cluster # 0 DONE!!!
OPTIMIZATION for Cluster # 1 DONE!!!
OPTIMIZATION for Cluster # 2 DONE!!!
OPTIMIZATION for Cluster # 3 DONE!!!
OPTIMIZATION for Cluster # 4 DONE!!!
length of the cluster 0 ------> 2
length of the cluster 1 ------> 145
length of the cluster 2 ------> 186
length of the cluster 3 ------> 119
length of the cluster 4 ------> 139
UPDATED THE OLD COVARIANCE
beginning with the smoothening ALGORITHM
length of cluster # 0 --------> 2
length of cluster # 1 --------> 78
length of cluster # 2 --------> 234
length of cluster # 3 --------> 146
length of cluster # 4 --------> 131
Done writing the figure

IndexError Traceback (most recent call last)
in ()
2 10,number_of_clusters = 5, lambda_parameter = 11e-2, beta = 5, maxIters =
3 100, threshold = 2e-5, write_out_file = False, input_file = "data.csv",
----> 4 prefix_string = "output_folder/")

/home/local/ASUAD/rguo12/Downloads/TICC-master/TICC_solver.pyc in solve(window_size, number_of_clusters, lambda_parameter, beta, maxIters, threshold, write_out_file, input_file, prefix_string)
1624 print "Done writing the figure"
1625
-> 1626 true_confusion_matrix = compute_confusion_matrix(num_clusters,clustered_points,sorted_training_idx)
1627
1628 ####TEST SETS STUFF

/home/local/ASUAD/rguo12/Downloads/TICC-master/TICC_solver.pyc in compute_confusion_matrix(num_clusters, clustered_points_algo, sorted_indices_algo)
1333 #CASE E : ABCABC
1334 num = (int(sorted_indices_algo[point]/seg_len) %num_clusters)
-> 1335 true_confusion_matrix[num,cluster] += 1
1336
1337 ##CASE D : ABABABAB

IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

I'm running the exact code that you are, and it's working on my machine (Anaconda Python 2.7).

That bug refers to an array index being a non-integer. Can you replace line 1335 with: "true_confusion_matrix[int(num),int(cluster)] += 1" and let us know if that works?

It works! Thank you for the help!