void SumToOne::DoBuild() { LOG_TRACE(); for (auto& estimate_label : estimate_labels_) { Estimate* estimate = model_->managers().estimate()->GetEstimateByLabel(estimate_label); if (estimate == nullptr) { LOG_ERROR_P(PARAM_ESTIMATE_LABELS) << "Estimate " << estimate_label << " could not be found. Have you defined it?"; return; } else { LOG_FINE() << "transform with objective = " << transform_with_jacobian_ << " estimate transform " << estimate->transform_for_objective() << " together = " << !transform_with_jacobian_ && !estimate->transform_for_objective(); if (!transform_with_jacobian_ && !estimate->transform_for_objective()) { LOG_ERROR_P(PARAM_LABEL) << "You have specified a transformation that does not contribute a jacobian, and the prior parameters do not refer to the transformed estimate, in the @estimate" << estimate_label_ << ". This is not advised, and may cause bias estimation. Please address the user manual if you need help"; } if (estimate->transform_with_jacobian_is_defined()) { if (transform_with_jacobian_ != estimate->transform_with_jacobian()) { LOG_ERROR_P(PARAM_LABEL) << "This parameter is not consistent with the equivalent parameter in the @estimate block " << estimate_label_ << ". please make sure these are both true or both false."; } } estimates_.push_back(estimate); } } // Validate that the parameters sum to one. Double total = 0.0; for (auto& estimate : estimates_) { LOG_FINEST() << "transformation value = " << estimate->value(); total += estimate->value(); } if (total != 1.0) LOG_ERROR_P(PARAM_ESTIMATE_LABELS) << "The estiamtes you supplied to not sum to 1.0, they sum to " << total << ", please check initial values of these parameters"; // Check that the bounds are sensible if (parameters_.Get(PARAM_UPPER_BOUND)->has_been_defined() & parameters_.Get(PARAM_LOWER_BOUND)->has_been_defined()) { for (unsigned i = 0; i < estimates_.size(); ++i) { if (estimates_[i]->lower_bound() < 0.0 || estimates_[i]->lower_bound() > 1.0) LOG_ERROR_P(PARAM_LOWER_BOUND) << "You cannot specify a lower bound less than 0 and greater than 1.0"; if (estimates_[i]->upper_bound() < 0.0 || estimates_[i]->upper_bound() > 1.0) LOG_ERROR_P(PARAM_UPPER_BOUND) << "You cannot specify a upper bound less than 0 and greater than 1.0"; } } LOG_MEDIUM() << "total = " << total; // Turn off the last estimate LOG_FINE() << "Turning off parameter, this won't be estimated, and will be an outcome of other parameters " << estimates_[estimates_.size() - 1]->parameter() << " in the estimation"; estimates_[estimates_.size() - 1]->set_estimated(false); LOG_MEDIUM() << "flagged estimated = " << estimates_[estimates_.size() - 1]->estimated(); }