Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 53276ce1 authored by Vincent Danjean's avatar Vincent Danjean
Browse files

Compute tree representation for efficient stat computation

git-svn-id: svn+ssh://imag/users/huron/danjean/svnroot/claire/altree/trunk@450 cf695345-040a-0410-a956-b889e835fe2e
parent 7bf4e9d6
No related branches found
No related tags found
No related merge requests found
......@@ -606,7 +606,96 @@ sub Association
FillCaseControl($racine,$new_correspondance);
parcours_nosplit_chi2split($racine->{"children"}, $prolonge,
SplitMode::NOSPLIT, $racine, $sign_util);
}
}
sub computeTreeStructure($) {
my $racine=shift;
my $nextIndex=shift;
my (@leaf_refs, @leaf_depth, @leaf_parent, @nleaf_parent);
my $nleaf2id={}; # Hash $node -> [index, $node->Father()]
my $computeNLeaf;
$computeNLeaf = sub {
my $nodeList=shift;
my $max_depth=0;
my $nextIndex=0;
my @childNodeList=();
my $parent;
foreach my $node (@{$nodeList}) {
push @childNodeList, $node->GetChildrenList();
}
if (scalar(@childNodeList) > 0) {
($max_depth,$nextIndex)=$computeNLeaf->(\@childNodeList, $nextIndex);
}
foreach my $node (@{$nodeList}) {
# Si on est un noeud interne sans id, on dfinit un index
if (NbFils($node) != 0 && !exists($nleaf2id->{$node})) {
$nleaf2id->{$node}=[$nextIndex++, $node->Father()];
}
}
if (scalar(@childNodeList) == 1) {
# Dans le cas o on a juste une seule branche, on "fusionne"
# avec le noeud pre (on lui assigne ce dernier le mme index
# que nous)
my $parent=$childNodeList[0]->Father();
if (defined($parent)) {
$nleaf2id->{$parent}=[$nleaf2id->{$childNodeList[0]}->[0], $parent->Father()] ;
}
}
if (scalar(@childNodeList) > 0) {
$max_depth++;
}
return ($max_depth, $nextIndex);
};
my ($max_depth,$nbIntNodes)=$computeNLeaf->([$racine], 0);
foreach my $node (keys(%{$nleaf2id})) {
my ($id_my, $parent)=@{$nleaf2id->{$node}};
if (!defined($parent) || !exists($nleaf2id->{$parent})) {
$nleaf_parent[$id_my]=-1;
} else {
my $id_parent=$nleaf2id->{$parent}->[0];
if ($id_parent != $id_my) {
$nleaf_parent[$id_my]=$id_parent;
}
}
}
my $computeLeaf;
$computeLeaf = sub {
my $nodeList=shift;
my $depth=shift;
my @childNodeList=();
my @leafList=();
foreach my $node (@{$nodeList}) {
if (NbFils($node) != 0) {
push @childNodeList, $node->GetChildrenList();
} else {
push @leafList, $node;
}
}
if (scalar(@childNodeList) > 1) {
$depth++;
}
if (scalar(@childNodeList) > 0) {
$computeLeaf->(\@childNodeList, $depth);
}
foreach my $node (@leafList) {
push @leaf_refs, $node;
push @leaf_depth, $depth;
push @leaf_parent, $nleaf2id->{$node->Father()}->[0];
}
return;
};
$computeLeaf->([$racine], 0);
return (\@leaf_refs, \@leaf_depth, \@leaf_parent, \@nleaf_parent, $max_depth);
}
sub RepeatAssociation
{
my($tree)=shift;
......@@ -618,6 +707,8 @@ sub RepeatAssociation
my($racine)=$tree->GetRoot();
my($leaf_refs,$leaf_depth,$leaf_parent,$nleaf_parent, $max_depth)=computeTreeStructure($racine);
my($ligne_stats)=[];
print "\n Number of permutation: $nb_permutation\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment