Thread rekursive Clustering mit der Hilfe Perl-Module 'Text::Bayon' (0 answers)
Opened by kimmy at 2012-03-26 12:02

kimmy
 2012-03-26 12:02
#157038 #157038
User since
2010-09-10
87 Artikel
BenutzerIn
[default_avatar]
Hallo,

ich hätte eine Frage;
ich möchte mit einer wie folgt strukturierte Datei Clustern erstellen.
Code: (dl )
1
2
3
4
5
6
A;B;1
Ab;B;3
A;Ca;2
B;C;1
...
...

Und mein Skript sieht so aus;
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/perl

use strict;
use warnings;
use Text::Bayon;

my $bayon = Text::Bayon->new;

my %distanz;
while(<>){
        chomp;
        my ($bez1, $bez2, $dis) = split /;/;
        $distanz{$bez1}->{$bez2} = $dis;
}
my $hash_ref = \%distanz;
my $output = $bayon->clustering($hash_ref);

my %hash = %$output;
my %extr_dist;
foreach my $key (sort keys %hash){
        my $cl_inhalt = join(', ', @{$hash{$key}});
        my @arr = split(/, /, $cl_inhalt);
        # Extraktion Inputdatei (Distanztabelle) & Erstellung neues Hash
        for(my $i=0;$i<=$#arr;$i++){
                for(my $j=$i+1;$j<=$#arr;$j++){
                        if(defined $distanz{$arr[$i]}->{$arr[$j]}){
                                $extr_dis{$arr[$i]}->{$arr[$j]}=$distanz{$arr[$i]}->{$arr[$j]};
                        }
                        else{
                                $extr_dis{$arr[$i]}->{$arr[$j]}->0;
                        }
                }
        }       
        print "Cluster $key\t($#{$hash{$key}})\t$cl_inhalt\n\n";
}

Aber was ich haben möchte ist, falls die Anzahl von irgendeinem Cluster mehr als 10 ist möchte ich den Clsuter nochmal zerlegn. d.h.
Code (perl): (dl )
1
2
3
4
5
if($#arr>=10){
   my $extr_ref = \%extr_dist;
   my $extr_output = $bayon->clustering($extr_ref);
   ...
   ...

Wie kann ich die Sub-Clustering rekursiv machen?
Und als Ergebnis wie folgt bekommen?
Code (perl): (dl )
1
2
3
4
5
6
print "Cluster $key\t($#{$hash{$key}})\t$cl_inhalt\n";
print "\tCluster $sub_key\t($#{$sub_hash{$sub_key}})\t$sub_cl_inhalt\n";
#fall es gibt
print "\t\tCluster $sub_sub_key\t($#{$sub_sub_hash{$sub_sub_key}})\t$sub_sub_cl_inhalt\n";
...
...

View full thread rekursive Clustering mit der Hilfe Perl-Module 'Text::Bayon'