From d26b5e844ac807790850bd33802d0731fdde8478 Mon Sep 17 00:00:00 2001 From: Van Dung Nguyen <vdg.nguyen@gmail.com> Date: Mon, 2 Nov 2020 23:59:00 +0100 Subject: [PATCH] correct option for initialize weights --- NonLinearSolver/modelReduction/Tree.cpp | 21 +++++++++++++-------- NonLinearSolver/modelReduction/Tree.h | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/NonLinearSolver/modelReduction/Tree.cpp b/NonLinearSolver/modelReduction/Tree.cpp index 1c7cf9c7a..e00abd926 100644 --- a/NonLinearSolver/modelReduction/Tree.cpp +++ b/NonLinearSolver/modelReduction/Tree.cpp @@ -2130,7 +2130,7 @@ void Tree::clear() _root = NULL; }; -void Tree::initialize(bool rand) +void Tree::initialize(bool rand, bool normalizedWeight) { // random weight for leaves unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); @@ -2155,23 +2155,28 @@ void Tree::initialize(bool rand) for (int i=0; i< allLeaves.size(); 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); } + for (int i=0; i< allLeaves.size(); i++) { TreeNode* n = allLeaves[i]; - double vv = (n->af->getVal(n->weight))/toltalWeightLeaves; - n->weight *= n->af->getReciprocalVal(vv); + if (normalizedWeight) + { + double vv = (n->af->getVal(n->weight))/toltalWeightLeaves; + n->weight = n->af->getReciprocalVal(vv); + } // propagate data double w = n->weight; - while (n->parent != NULL) + TreeNode* parent = n->parent; + while (parent != NULL) { - n->parent->weight += n->af->getVal(w); - n = n->parent; + parent->weight += n->af->getVal(w); + parent = parent->parent; }; }; - //printf("pi = %e\n",pi); double minAlpha = 0.; double maxAlpha = 1; diff --git a/NonLinearSolver/modelReduction/Tree.h b/NonLinearSolver/modelReduction/Tree.h index 20610abe2..add67981d 100644 --- a/NonLinearSolver/modelReduction/Tree.h +++ b/NonLinearSolver/modelReduction/Tree.h @@ -59,7 +59,7 @@ class Tree void printTree() const; void printTreeInteraction(const std::string fname="treeInteraction.txt", bool colorMat = true, int dir=1) const; void clear(); - void initialize(bool rand=true); + void initialize(bool rand=true, bool normalizedWeight=false); const TreeNode* getRootNode() const {return _root;}; void assignMaterialLaws(int numPhases); -- GitLab