cran2367 / sgt

Sequence Graph Transform
105 stars 21 forks source link

Issue in python package - different sequences returned same results #1

Closed Cyeee closed 4 years ago

Cyeee commented 4 years ago

Hi Chitta Ranjan, Thanks so much for developing this method/package. It is super helpful to me and is driving real business impact on my work. One issue I noticed is that in the python package, it gave same results for sequence ['a','b'] and ['e','f']. I assume the results should be different? Many thanks again for developing this! Yi

Screen Shot 2019-12-01 at 8 35 29 PM
Cyeee commented 4 years ago

I modified the code a bit and it seems this will work.

` alphabets_in_sequence = np.unique(sequence)

    for i, u in enumerate(alphabets_in_sequence):
        index = [p[0] for p in positions].index(u)

        U = np.array(positions[index][1]).ravel()

        for j, v in enumerate(alphabets_in_sequence):
            index = [p[0] for p in positions].index(v)

            V2 = np.array(positions[index][1]).ravel()

            C = [(i,j) for i in U for j in V2 if j > i]

            ## yi added
            pos_i = alphabets_list.index(u)
            pos_j = alphabets_list.index(v)

            W0[pos_i,pos_j] = len(C)
            ## yi added end

            cu = np.array([i[0] for i in C]) 
            cv = np.array([i[1] for i in C]) 

            ## yi added
            Wk[pos_i,pos_j] = np.sum(np.exp(-kappa * np.abs(cu - cv)))
            ## yi added end`
Cyeee commented 4 years ago

alphabets_list = list(alphabets)

gabrielelanaro commented 4 years ago

I agree this seems to be incorrect. Basically the indexes of W0 and Wk can change if the alphabet is not entirely in the sequence.

alphabets_in_sequence = np.unique(sequence)
for i, u in enumerate(alphabets_in_sequence):
cran2367 commented 4 years ago

@Cyeee @gabrielelanaro I am reviewing this. You can expect a resolution in a week. In the meantime, there is an R package on my github repo that you can use.

cran2367 commented 4 years ago

@Cyeee @gabrielelanaro The issue is resolved. Please

Cyeee commented 4 years ago

Thanks for fixing this!

Cyeee commented 4 years ago

Thanks for fixing it! Yi

Sent from my iPhone

On Dec 17, 2019, at 4:34 PM, cran2367 notifications@github.com wrote:

 @Cyeee @gabrielelanaro The issue is resolved. Please

uninstall your current sgt using pip uninstall sgt. Reinstall with pip install sgt==1.0.0. Run the notebook here: https://github.com/cran2367/sgt/blob/master/python/sgt.ipynb If any problem is still there please comment. If the problem is resolved, please close the issue. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.