Skip to content
Snippets Groups Projects
Commit d26b5e84 authored by Van Dung NGUYEN's avatar Van Dung NGUYEN
Browse files

correct option for initialize weights

parent 34a9d9de
No related branches found
No related tags found
1 merge request!309Master
...@@ -2130,7 +2130,7 @@ void Tree::clear() ...@@ -2130,7 +2130,7 @@ void Tree::clear()
_root = NULL; _root = NULL;
}; };
void Tree::initialize(bool rand) void Tree::initialize(bool rand, bool normalizedWeight)
{ {
// random weight for leaves // random weight for leaves
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
...@@ -2155,23 +2155,28 @@ void Tree::initialize(bool rand) ...@@ -2155,23 +2155,28 @@ void Tree::initialize(bool rand)
for (int i=0; i< allLeaves.size(); i++) for (int i=0; i< allLeaves.size(); i++)
{ {
TreeNode* n = allLeaves[i]; TreeNode* n = allLeaves[i];
n->weight = getVal(minWeight,maxWeight); double randVal = getVal(minWeight,maxWeight);
n->weight = n->af->getReciprocalVal(randVal);
toltalWeightLeaves += n->af->getVal(n->weight); toltalWeightLeaves += n->af->getVal(n->weight);
} }
for (int i=0; i< allLeaves.size(); i++) for (int i=0; i< allLeaves.size(); i++)
{ {
TreeNode* n = allLeaves[i]; TreeNode* n = allLeaves[i];
if (normalizedWeight)
{
double vv = (n->af->getVal(n->weight))/toltalWeightLeaves; double vv = (n->af->getVal(n->weight))/toltalWeightLeaves;
n->weight *= n->af->getReciprocalVal(vv); n->weight = n->af->getReciprocalVal(vv);
}
// propagate data // propagate data
double w = n->weight; double w = n->weight;
while (n->parent != NULL) TreeNode* parent = n->parent;
while (parent != NULL)
{ {
n->parent->weight += n->af->getVal(w); parent->weight += n->af->getVal(w);
n = n->parent; parent = parent->parent;
}; };
}; };
//printf("pi = %e\n",pi); //printf("pi = %e\n",pi);
double minAlpha = 0.; double minAlpha = 0.;
double maxAlpha = 1; double maxAlpha = 1;
......
...@@ -59,7 +59,7 @@ class Tree ...@@ -59,7 +59,7 @@ class Tree
void printTree() const; void printTree() const;
void printTreeInteraction(const std::string fname="treeInteraction.txt", bool colorMat = true, int dir=1) const; void printTreeInteraction(const std::string fname="treeInteraction.txt", bool colorMat = true, int dir=1) const;
void clear(); void clear();
void initialize(bool rand=true); void initialize(bool rand=true, bool normalizedWeight=false);
const TreeNode* getRootNode() const {return _root;}; const TreeNode* getRootNode() const {return _root;};
void assignMaterialLaws(int numPhases); void assignMaterialLaws(int numPhases);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment