FL33TW00D / rustDTW

Python extension backed by a multi-threaded Rust implementation of Dynamic Time Warping (DTW).
MIT License
23 stars 2 forks source link

Undefined variable in the ABIDE Notebook #9

Open wizofe opened 2 years ago

wizofe commented 2 years ago

In the ABIDE classification example the variable i_lower is undefined, returning the error message

NameError: name 'i_lower' is not defined

Not sure if the code was executed or the variable name is different but I can't grasp where it's coming from. Any insight? Thanks!

FL33TW00D commented 2 years ago

Hi @wizofe, Apologies for this, seems the notebook is incomplete.

I no longer have this setup on my machine, but can give some quick guidance to unblock you. If you're using it for a project I'll find some time to release a new version to clean some things up.

The code you're referring to:

    #Post processing them as per paper recommendations
    for vec in dtw_output:
        sym = np.zeros((n_regions, n_regions))
        sym[i_lower] = vec
        sym += sym.T
        sym *= -1
        StandardScaler().fit_transform(sym)
        connectomes.append(sym_matrix_to_vec(sym))

This is transforming the 1D output vectors from rust-dtw into a normalized 2D matrix, as per the original source code here: https://github.com/MRegina/DTW_for_fMRI/blob/master/Source.cpp#L89 . Therefore, i_lower should be the indices of the lower triangular matrix, which you could generate like so:

i_lower = np.tril_indices(n_regions)

This should work, let me know if you have trouble.

wizofe commented 2 years ago

Thank you @FL33TW00D for your quick reply. I am indeed trying to use this for my research. I would need to dive deeper into the code (maybe re-implement it), although it seems there's no big reason as your Rust DTW package does a great job calculating the 1D output vectors using DTW.

I am interested myself in the ABIDE dataset and I was expecting I could use DTW to compare against Pearson's correlation coefficient calculations. If I use i_lower like this in the loop I am not getting a symmetric connectivity matrix as a result as I would expect (nregions x nregions). Does i_lower need to be part of a for loop iteration? Not sure I get the 1D->2D conversion here.

Considering this, it would be amazing if you could re-release a version of this notebook.

FL33TW00D commented 2 years ago

Thank you @FL33TW00D for your quick reply. I am indeed trying to use this for my research. I would need to dive deeper into the code (maybe re-implement it), although it seems there's no big reason as your Rust DTW package does a great job calculating the 1D output vectors using DTW.

I am interested myself in the ABIDE dataset and I was expecting I could use DTW to compare against Pearson's correlation coefficient calculations. If I use i_lower like this in the loop I am not getting a symmetric connectivity matrix as a result as I would expect (nregions x nregions). Does i_lower need to be part of a for loop iteration? Not sure I get the 1D->2D conversion here.

Considering this, it would be amazing if you could re-release a version of this notebook.

I will release a new version of the library and the notebook this weekend 👍🏻

wizofe commented 2 years ago

@FL33TW00D that would be amazing. Let me know when you do so! Thank you!