Skip to content

Commit

Permalink
Merge pull request #1272 from veg/develop
Browse files Browse the repository at this point in the history
2.5.26rc
  • Loading branch information
spond authored Jan 14, 2021
2 parents 4781997 + baac141 commit 927e226
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
47 changes: 43 additions & 4 deletions res/TemplateBatchFiles/SelectionAnalyses/RELAX.bf
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,20 @@ if (relax.model_set == "All") { // run all the models
relax.weight_multipliers = parameters.helper.stick_breaking (utility.SwapKeysAndValues(utility.MatrixToDict(relax.distribution["weights"])),None);
relax.constrain_parameters = parameters.ConstrainMeanOfSet(relax.distribution["rates"],relax.weight_multipliers,1,"relax");


relax.i = 0;
for (key, value; in; relax.constrain_parameters[terms.global]){
model.generic.AddGlobal (relax.ge.bsrel_model, value, key);
parameters.SetRange (value, terms.range_almost_01);
relax.i += 1;
if (relax.i < relax.rate_classes) {
parameters.SetRange (value, terms.range_almost_01);
} else {
parameters.SetRange (value, terms.range_gte1);
}

}


relax.distribution["rates"] = Transpose (utility.Values (relax.constrain_parameters[terms.global]));

for (relax.i = 1; relax.i < relax.rate_classes; relax.i += 1) {
Expand All @@ -397,7 +406,8 @@ if (relax.model_set == "All") { // run all the models
math.Mean (
utility.Map (selection.io.extract_global_MLE_re (relax.final_partitioned_mg_results, "^" + terms.parameters.omega_ratio + ".+"), "_v_", "_v_[terms.fit.MLE]"));

relax.init_grid_setup (relax.distribution);

relax.init_grid_setup (relax.distribution);
relax.initial_grid = estimators.LHC (relax.initial_ranges,relax.initial_grid.N);
relax.initial_grid = utility.Map (relax.initial_grid, "_v_",
'relax._renormalize (_v_, "relax.distribution", relax.initial.test_mean)'
Expand All @@ -406,8 +416,11 @@ if (relax.model_set == "All") { // run all the models


parameters.DeclareGlobalWithRanges ("relax.bl.scaler", 1, 0, 1000);
for (i, v; in; relax.initial_grid) {
v["relax.bl.scaler"] = {terms.id : "relax.bl.scaler", terms.fit.MLE : Random (2,4)};
}


relax.grid_search.results = estimators.FitLF (relax.filter_names, relax.trees,{ "0" : {"DEFAULT" : "relax.ge"}},
relax.final_partitioned_mg_results,
relax.model_object_map,
Expand All @@ -429,7 +442,8 @@ if (relax.model_set == "All") { // run all the models
}
);




relax.general_descriptive.fit = estimators.FitLF (relax.filter_names,
relax.trees,
{ "0" : {"DEFAULT" : "relax.ge"}},
Expand Down Expand Up @@ -1462,6 +1476,31 @@ function relax.init_grid_setup (omega_distro) {

//------------------------------------------------------------------------------

function relax.init_grid_setup_scaled (omega_distro) {
utility.ForEachPair (omega_distro[terms.parameters.rates], "_index_", "_name_",
'
relax.initial_ranges [_name_] = {
terms.lower_bound : 0,
terms.upper_bound : 1
};

'
);


utility.ForEachPair (omega_distro[terms.parameters.weights], "_index_", "_name_",
'
relax.initial_ranges [_name_] = {
terms.lower_bound : 0,
terms.upper_bound : 1
};
'
);

}

//------------------------------------------------------------------------------

lfunction relax._renormalize (v, distro, mean) {

parameters.SetValues (v);
Expand Down
2 changes: 1 addition & 1 deletion res/TemplateBatchFiles/libv3/tasks/estimators.bf
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function estimators.SetGlobals2(key2, value) {
if (Type(__init_value) != "AssociativeList") {
__init_value = (initial_values[terms.global])[key2];
}


if (Type(__init_value) == "AssociativeList") {
if (__init_value[terms.fix]) {
Expand Down
14 changes: 7 additions & 7 deletions src/core/likefunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2675,7 +2675,7 @@ void _LikelihoodFunction::CheckDependentBounds (void) {
lowerBounds.theData[index] = cornholio->GetLowerBound();
upperBounds.theData[index] = cornholio->GetUpperBound();

//fprintf (stderr, "_LikelihoodFunction::CheckDependentBounds variable %s (%d), current value %g, range %g to %g\n", cornholio->theName->sData, index, currentValues.theData[index], lowerBounds.theData[index], upperBounds.theData[index]);
//fprintf (stderr, "_LikelihoodFunction::CheckDependentBounds variable %s (%d), current value %g, range %g to %g\n", cornholio->theName->get_str(), index, currentValues.theData[index], lowerBounds.theData[index], upperBounds.theData[index]);

bool badApple = currentValues.theData[index]<lowerBounds.theData[index] || currentValues.theData[index]>upperBounds.theData[index];
if (badApple) {
Expand Down Expand Up @@ -2734,7 +2734,7 @@ void _LikelihoodFunction::CheckDependentBounds (void) {
SetIthIndependent (index,temp);
}

//fprintf (stderr, "\n%s\n", _String((_String*)dependancies.toStr()).sData);
//fprintf (stderr, "\n%s\n", _String((_String*)dependancies.toStr()).get_str());

// now we can go through the dependant variables which are out of bounds one at a time
// and attempt to move them back in.
Expand Down Expand Up @@ -2863,31 +2863,31 @@ void _LikelihoodFunction::CheckDependentBounds (void) {

tagged.ReorderList();

// fprintf (stderr, "Tagged the following variables %s\n", _String((_String*)_aux.toStr()).sData);
//fprintf (stderr, "Tagged the following variables %s\n", _String((_String*)_aux.toStr()).get_str());


for (index = 0; index<indexInd.lLength; index++) {
dependancies.Store (0,index,GetIthIndependentBound (index,true));
dependancies.Store (1,index,(GetIthIndependentBound (index,false)>10?10:GetIthIndependentBound (index,true))-dependancies(0,index));
dependancies.Store (1,index,(GetIthIndependentBound (index,false)>10?10:GetIthIndependentBound (index,false))-dependancies(0,index));
dependancies.Store (2,index,GetIthIndependent (index));
}

// fprintf (stderr, "\n%s\n", _String((_String*)dependancies.toStr()).sData);
//fprintf (stderr, "\n%s\n", _String((_String*)dependancies.toStr()).get_str());


for (i = 0L; i < 10000L; i++) {
// choose random values for the variables that are involved with bad constraints
for (long v = 0L; v < _aux.lLength; v++) {
index = _aux.get(v);
SetIthIndependent (index,dependancies(0,index)+genrand_real2()*dependancies(1,index));
//fprintf (stderr, "[%d] %s => %g\n", index, GetIthIndependentName(index)->sData, GetIthIndependent(index));
//fprintf (stderr, "[%d] %s => %g (%g - %g)\n", index, GetIthIndependentName(index)->get_str(), GetIthIndependent(index), dependancies(0,index), dependancies(1,index));
}
for (j = 0; j < nonConstantDep->lLength; j++) {
// check whether any of the dependent variables are out of bounds
long j_corrected = nonConstantIndices.get(j);
currentValues.theData[j_corrected] = LocateVar(nonConstantDep->list_data[j])->Compute()->Value();
//fprintf (stderr, "[%d] %g (%g, %g)\n", j, j_corrected, currentValues.theData[j_corrected], lowerBounds.theData[j_corrected], upperBounds[j_corrected]);
if (currentValues.theData[j_corrected]<lowerBounds.theData[j_corrected] || currentValues.theData[j_corrected]>upperBounds.theData[j_corrected]) {
//fprintf (stderr, "[%d] %s => %g (%g, %g)\n", j, LocateVar(nonConstantDep->list_data[j])->GetName()->get_str(), j_corrected, currentValues.theData[j_corrected], lowerBounds.theData[j_corrected], upperBounds[j_corrected]);
//fprintf (stderr, "===| CHECK FAILED\n");
badConstraint = nonConstantDep->list_data[j];
break;
Expand Down

0 comments on commit 927e226

Please sign in to comment.