程式語言

23
程程程程 程程程程

Upload: cheryl

Post on 06-Jan-2016

45 views

Category:

Documents


6 download

DESCRIPTION

程式語言. Subtractive Clustering. Repeat while any point ( x i ) is left to be assigned to a cluster Use Eq. (1) to get the potential of x i Find the point with the highest potential and choose it as the kth cluster center - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 程式語言

程式語言程式語言

Page 2: 程式語言

2

Subtractive ClusteringSubtractive Clustering

Repeat while any point (xi) is left to be

assigned to a cluster

a) Use Eq. (1) to get the potential of xi

b) Find the point with the highest potential and choose

it as the kth cluster center

c) Form the kth cluster by assigning N points closest to

the centroid (Euclidean distance)

d) Remove the chosen N points

n

j jii xxP1

2)exp( (1

)

Page 3: 程式語言

Create Random DataCreate Random Data• $mean_x[1] = 1;

$sdev_x[1] = 0.1;$mean_x[2] = -1;$sdev_x[2] = 0.15;$mean_x[3] = 1;$sdev_x[3] = 0.1;$mean_x[4] = -1;$sdev_x[4] = 0.15;

$mean_y[1] = 1;$sdev_y[1] = 0.1;$mean_y[2] = 1;$sdev_y[2] = 0.15;$mean_y[3] = -1;$sdev_y[3] = 0.1;$mean_y[4] = -1;$sdev_y[4] = 0.15;

Page 4: 程式語言

Create Random DataCreate Random Data• @x=@y=();

open OUTFILE, ">xy.txt" or die "Cannot open gene_list.txt!\n ($!)";

for ($i=1;$i<=4;$i++){ for ($j=1;$j<=80;$j++) { $x_tmp = gaussian_rand() * $sdev_x[$i] + $mean_x[$i]; $y_tmp = gaussian_rand() * $sdev_y[$i] + $mean_y[$i];

printf(OUTFILE "%.2f \t %.2f \n", $x_tmp, $y_tmp); }}

Page 5: 程式語言

Create Random DataCreate Random Data• for ($j=1;$j<=20;$j++)

{ $x_tmp = rand(2); $y_tmp = rand(2);

printf(OUTFILE "%.2f \t %.2f \n", $x_tmp, $y_tmp);}

Page 6: 程式語言

Random Data GraphRandom Data Graph

Page 7: 程式語言

7

Subtractive ClusteringSubtractive Clustering

Repeat while any point (xi) is left to be

assigned to a cluster

a) Use Eq. (1) to get the potential of xi

b) Find the point with the highest potential and choose

it as the kth cluster center

c) Form the kth cluster by assigning N points closest to

the centroid (Euclidean distance)

d) Remove the chosen N points

n

j jii xxP1

2)exp( (1

)

Page 8: 程式語言

CenterCenter• open (FILE1,“xy.txt”) || die “open error!” ; #FILE1¬Oradom date

open FILE2, “>aixes.txt” or die “Cannot open gene_list.txt!\n ($!)”;

@aa = <FILE1>;chomp (@aa);

# 用 @x_one 和 y_one 載 random date 的 x,y

• for ($z=0; $z<=$#aa; $z++){ $bb = $aa[$z]; $bb =~ /(\S+)\s+(\S+)/; @x_one[$z] =$1; @y_one[$z] =$2;}

Page 9: 程式語言

CenterCenter# 計算出每點與各點的 potient, 用 @sum 裝•

while ($n <4){ @sum = 0, $bb = 0 ; for ($i=0; $i<=$#x_one ;$i++) {

for ($j=1; $j<=$#x_one; $j++) { $bb = exp ( -(($x_one[$i]-$x_one[$j])**2 + ($y_one[$i] - $y_one[$j])**2 ));

@sum[$i] += $bb; }

}

Page 10: 程式語言

10

Subtractive ClusteringSubtractive Clustering

Repeat while any point (xi) is left to be

assigned to a cluster

a) Use Eq. (1) to get the potential of xi

b) Find the point with the highest potential and choose

it as the kth cluster center

c) Form the kth cluster by assigning N points closest to

the centroid (Euclidean distance)

d) Remove the chosen N points

n

j jii xxP1

2)exp( (1

)

Page 11: 程式語言

11

Subtractive ClusteringSubtractive Clustering

Repeat while any point (xi) is left to be

assigned to a cluster

a) Use Eq. (1) to get the potential of xi

b) Find the point with the highest potential and choose

it as the kth cluster center

c) Form the kth cluster by assigning N points closest to

the centroid (Euclidean distance)

d) Remove the chosen N points

n

j jii xxP1

2)exp( (1

)

Page 12: 程式語言

CenterCenter比較各點的 potient, 找出最高值為 cluster center $mix = $sum[0], $num = 0; for($k=1; $k<=$#x_one ; $k++){ if ( $sum[$k] > $mix ) { $mix = $sum[$k]; $num = $k ; }} print $x_one[$num]." , ".$y_one[$num]."\n";

printf(FILE2 "%s : %.2f , %.2f %s \n","cluster center", $x_one[$num], $y_one[$num], $m);

Page 13: 程式語言

• Find cluster center!

Page 14: 程式語言

14

Subtractive ClusteringSubtractive Clustering

Repeat while any point (xi) is left to be

assigned to a cluster

a) Use Eq. (1) to get the potential of xi

b) Find the point with the highest potential and choose

it as the kth cluster center

c) Form the kth cluster by assigning N points closest to

the centroid (Euclidean distance)

d) Remove the chosen N points

n

j jii xxP1

2)exp( (1

)

Page 15: 程式語言

15

Subtractive ClusteringSubtractive Clustering

Repeat while any point (xi) is left to be

assigned to a cluster

a) Use Eq. (1) to get the potential of xi

b) Find the point with the highest potential and choose

it as the kth cluster center

c) Form the kth cluster by assigning N points closest to

the centroid (Euclidean distance)

d) Remove the chosen N points

n

j jii xxP1

2)exp( (1

)

Page 16: 程式語言

CenterCenter• 計算出各點與 center 間的距離 -@dis

@dis =(); for ($c=0; $c<$#x_one;$c++) {

if ($c != $num) { $dis[$c] = ( ($x_one[$num] - $x_one[$c])**2 + ($y_one[$num] - $y_one[$c])**2 )**0.5 ;

}

}

Page 17: 程式語言

centercenter• 比較各點之間的唔離大小 - 找出較小的距

離 -@sort

@sort = (); @sort = sort {$a <=> $b} @dis ;

Page 18: 程式語言

centercenter• 把 cluster center 附近的點

@del = (); for ($d=0; $d<=90;$d++) { for ($c=0; $c<=$#dis;$c++) { if ($sort[$d] == $dis[$c]) { print OUTFILE “$x_one[$c] \t $y_one[$c] \t $m \n”); @del[$d] = $c; } } }

Page 19: 程式語言

19

Subtractive ClusteringSubtractive Clustering

Repeat while any point (xi) is left to be

assigned to a cluster

a) Use Eq. (1) to get the potential of xi

b) Find the point with the highest potential and choose

it as the kth cluster center

c) Form the kth cluster by assigning N points closest to

the centroid (Euclidean distance)

d) Remove the chosen N points

n

j jii xxP1

2)exp( (1

)

Page 20: 程式語言

20

Subtractive ClusteringSubtractive Clustering

Repeat while any point (xi) is left to be

assigned to a cluster

a) Use Eq. (1) to get the potential of xi

b) Find the point with the highest potential and choose

it as the kth cluster center

c) Form the kth cluster by assigning N points closest to

the centroid (Euclidean distance)

d) Remove the chosen N points

n

j jii xxP1

2)exp( (1

)

Page 21: 程式語言

CenterCenter• foreach (@del)

{ $x_one[$_] = shift; $y_one[$_] = shift;

}

for ($f=0, $g=0 ;$f<=$#x_one;$f++){ if ($x_one[$f] != "" and $y_one[$f] != "") { $x_one[$g] = $x_one[$f] ; $y_one[$g] = $y_one[$f] ; $g++;

}}

Page 22: 程式語言

CenterCenter• for($e=0; $e<90; $e++)

{pop @x_one;pop @y_one;

}

$n++; $m++;}

Page 23: 程式語言

Final Subtractive Clustering Final Subtractive Clustering Graph Graph