lbehnke / hierarchical-clustering-java

Implementation of an agglomerative hierarchical clustering algorithm in Java. Different linkage approaches are supported.
141 stars 79 forks source link

Hi , How can i specify a cutoff for the algorithm , #21

Open ghost opened 8 years ago

ghost commented 8 years ago

I have test the algorithm on my dataset , the distance height is between 0,1. for example it assign 0, 0, 0 , 0 then the rest are 1.

the distance is a matrix from euclidean distance method .

then if would like cut the tree when distances = 0.5 ?? how can i do that , distances is [][] symatrics matrix.

lbehnke commented 8 years ago

Look into HierarchyBuilder.agglomerate(), line 92. When the linkage strategy instance returns the distance, you could hook-in a filter.

ghost commented 8 years ago

Dear Lars,

Thank you very much for your reply :

The code bellow is line 92 of HierarchyBuilder.agglomerate():

Distance newDistance = linkageStrategy.calculateDistance(distanceValues);

            newLinkage.setLinkageDistance(newDistance.getDistance());

            distances.add(newLinkage);

        }
        clusters.add(newCluster);

}

iam sorry iam confused , how can i specify the cutoff ,

the code above is : producing a linkage proximity matrix, i change the code to :

Distance newDistance = linkageStrategy.calculateDistance(distanceValues);

newLinkage.setLinkageDistance(newDistance.setDistance(0.5));

it does not work , the error is :

Void not allowed

Please need your guidance.

Best

On Mon, Sep 12, 2016 at 10:58 AM, Lars Behnke notifications@github.com wrote:

Look into HierarchyBuilder.agglomerate(), line 92. When the linkage strategy instance returns the distance, you could hook-in a filter.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lbehnke/hierarchical-clustering-java/issues/21#issuecomment-246302344, or mute the thread https://github.com/notifications/unsubscribe-auth/AM7ezULDSWxtAMV7v_yPkBZZUWSm0syJks5qpSJggaJpZM4J4_Cm .

varungadre09 commented 4 years ago

Pls give a reply Ibehnke

emanlee commented 4 years ago

Here is a figure on this home page: https://github.com/lbehnke/hierarchical-clustering-java. From this dendrogram, how can we get clusters or groups. For example, if we want get two clusters, it should be [o6] [o1 o2 o3 o4 o5]; If we want get three clusters, it should be [06] [03 05] [01 02 04 ]. How to use codes to get such clusters and output them to console or files? Thanks!

emanlee commented 4 years ago

In my case, I have more than 800 samples/genes. After clustering, the dendrogram is very big and complex, therfore, we need to divide/cut/sect the dendrogram into clusters and save them to files (each file contains the gene names and represents a cluster/group).