dijkstra algoritması python

Dijkstra algoritması, Veri Madenciliğinde (Optimizasyonda) kullanılan Dna’ların benzemezliklerine (benzerliklerine) göre kümeleme algoritmasının Python kodu. (Dijkstra’s Algorithm, Data Mining, Optimization, Clustering Dissimilarity Matrix Calculation)

Ödev Soru 2: (pdf)

A group of plant biologists has identified 12 new species in a restricted geographical area. Based on a DNA sequence study, they have calculated a dissimilarity index (out of 100) for each pair. The resulting dissimilarity matrix is given below. They would like to understand how these species are related with each other. Are they all closely related to each other? Or, are they related to each other in group(s)? In order to answer these questions, they aim to cluster/organize them in groups for which
* dissimilarity within the group is minimal, and
* dissimilarity between the groups is maximal.
To achieve this goal, they use the following procedure:
Step 1. Given a threshold value (D) for dissimilarity index, construct a dissimilarity network where there is an arc between any two species with a dissimilarity index less than or equal to D. Identify each connected component and declare them as groups.
Step 2. Within each group construct a minimum spanning tree of dissimilarity so that the group’s similarity score can be calculated as the ratio of number of species in the group to the total dissimilarity index of the corresponding spanning tree.
As a result of this study, they will also identify a viable threshold value D.
Implement the above classification algorithm using a generic programming language (such as Python) for different values of D, identify each class and calculate the group similarity index for at least three different threshold values where the elements of the clusters and/or clusters’ similarity scores change.



# similarity cluster

import sets

dissimilarity_cluster = [

t = 15 # threshold

items = sets.Set() # 1..12

for i in range(1,len(dissimilarity_cluster)+1):

tree_list_set = [] # result list of cluster sets
tls = 0

comps = sets.Set() # compare set

new_added_flag = 1

while (len(items)>0):
  # print items
  # print comps
  # print tls
  if (new_added_flag==0):
    tree_list_set.append( comps.copy() )
    new_added_flag = 1
    tls += 1
    new_added_flag = 0
  items_tmp = items.copy()
  comps_tmp = comps.copy()
  for i in comps_tmp:
    items_tmp = items.copy()
    comps_tmp = comps.copy()
    for j in items_tmp:
      if dissimilarity_cluster[i-1][j-1]<=t:
        # print "i: "+str(i)+"   j: "+str(j)
        new_added_flag = 1

if len(comps)>0:
  tree_list_set.append( comps.copy() )
  tls += 1

print tree_list_set

Bir cevap yazın