Skip to content

Commit

Permalink
ADD: accessor for estimate class to get hyper prior values and parame…
Browse files Browse the repository at this point in the history
…ters.
Craig44 committed Jul 25, 2022
1 parent 9db0bf1 commit bd136b6
Showing 19 changed files with 151 additions and 33 deletions.
2 changes: 1 addition & 1 deletion BuildSystem/Version.iss
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// WARNING: THIS FILE IS AUTOMATICALLY GENERATED BY doBuild version. DO NOT EDIT THIS FILE
AppVersion='v22.07 (2022-07-20)'
AppVersion='v22.07 (2022-07-22)'
16 changes: 14 additions & 2 deletions CASAL2/source/Estimates/Common/Beta.cpp
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 6/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* $Date: 2008-03-04 16:33:32 +1300 (Tue, 04 Mar 2008) $
*/
@@ -54,6 +54,18 @@ Double Beta::GetScore() {

return score_;
}

/**
* GetPriorValues()
*
* @return vector of mu and sigma
*/
vector<Double> Beta::GetPriorValues() {
vector<Double> result = {mu_, sigma_, a_, b_};
return result;
}
vector<string> Beta::GetPriorLabels() {
vector<string> result = {PARAM_MU, PARAM_SIGMA, PARAM_A, PARAM_B};
return result;
}
} /* namespace estimates */
} /* namespace niwa */
5 changes: 3 additions & 2 deletions CASAL2/source/Estimates/Common/Beta.h
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 6/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* @section DESCRIPTION
*
@@ -34,7 +34,8 @@ class Beta : public niwa::Estimate {
virtual ~Beta() = default;
void DoValidate() override final;
Double GetScore() override final;

vector<Double> GetPriorValues() override final;
vector<string> GetPriorLabels() override final;
private:
// Members
Double mu_ = 0.0;
14 changes: 13 additions & 1 deletion CASAL2/source/Estimates/Common/Lognormal.cpp
Original file line number Diff line number Diff line change
@@ -30,6 +30,18 @@ Double Lognormal::GetScore() {
Double score_ = log(value()) + 0.5 * pow(log(value() / mu_) / sigma_ + sigma_ * 0.5, 2);
return score_;
}

/**
* GetPriorValues()
*
* @return vector of mu and sigma
*/
vector<Double> Lognormal::GetPriorValues() {
vector<Double> result = {mu_, cv_};
return result;
}
vector<string> Lognormal::GetPriorLabels() {
vector<string> result = {PARAM_MU, PARAM_CV};
return result;
}
} /* namespace estimates */
} /* namespace niwa */
6 changes: 4 additions & 2 deletions CASAL2/source/Estimates/Common/Lognormal.h
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 8/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* @section DESCRIPTION
*
@@ -34,7 +34,9 @@ class Lognormal : public niwa::Estimate {
virtual ~Lognormal() = default;
void DoValidate() override final{};
Double GetScore() override final;

vector<Double> GetPriorValues() override final;
vector<string> GetPriorLabels() override final;

private:
Double mu_ = 0;
Double cv_ = 0;
16 changes: 14 additions & 2 deletions CASAL2/source/Estimates/Common/Normal.cpp
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 8/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* $Date: 2008-03-04 16:33:32 +1300 (Tue, 04 Mar 2008) $
*/
@@ -36,6 +36,18 @@ Double Normal::GetScore() {
Double score_ = 0.5 * ((value() - mu_) / (cv_ * mu_)) * ((value() - mu_) / (cv_ * mu_));
return score_;
}

/**
* GetPriorValues()
*
* @return vector of mu and sigma
*/
vector<Double> Normal::GetPriorValues() {
vector<Double> result = {mu_, cv_};
return result;
}
vector<string> Normal::GetPriorLabels() {
vector<string> result = {PARAM_MU, PARAM_CV};
return result;
}
} /* namespace estimates */
} /* namespace niwa */
6 changes: 4 additions & 2 deletions CASAL2/source/Estimates/Common/Normal.h
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 8/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* @section DESCRIPTION
*
@@ -34,7 +34,9 @@ class Normal : public niwa::Estimate {
virtual ~Normal() = default;
void DoValidate() override final{};
Double GetScore() override final;

vector<Double> GetPriorValues() override final;
vector<string> GetPriorLabels() override final;

private:
// Members
Double mu_;
16 changes: 15 additions & 1 deletion CASAL2/source/Estimates/Common/NormalByStdev.cpp
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 8/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* $Date: 2008-03-04 16:33:32 +1300 (Tue, 04 Mar 2008) $
*/
@@ -44,5 +44,19 @@ Double NormalByStdev::GetScore() {
return score_;
}

/**
* GetPriorValues()
*
* @return vector of mu and sigma
*/
vector<Double> NormalByStdev::GetPriorValues() {
vector<Double> result = {mu_, sigma_};
return result;
}
vector<string> NormalByStdev::GetPriorLabels() {
vector<string> result = {PARAM_MU, PARAM_SIGMA};
return result;
}

} /* namespace estimates */
} /* namespace niwa */
6 changes: 4 additions & 2 deletions CASAL2/source/Estimates/Common/NormalByStdev.h
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 8/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* @section DESCRIPTION
*
@@ -34,7 +34,9 @@ class NormalByStdev : public niwa::Estimate {
virtual ~NormalByStdev() = default;
void DoValidate() override final{};
Double GetScore() override final;

vector<Double> GetPriorValues() override final;
vector<string> GetPriorLabels() override final;

private:
// Members
Double mu_;
16 changes: 15 additions & 1 deletion CASAL2/source/Estimates/Common/NormalLog.cpp
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 8/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* $Date: 2008-03-04 16:33:32 +1300 (Tue, 04 Mar 2008) $
*/
@@ -37,5 +37,19 @@ Double NormalLog::GetScore() {
return score_;
}

/**
* GetPriorValues()
*
* @return vector of mu and sigma
*/
vector<Double> NormalLog::GetPriorValues() {
vector<Double> result = {mu_, sigma_};
return result;
}
vector<string> NormalLog::GetPriorLabels() {
vector<string> result = {PARAM_MU, PARAM_SIGMA};
return result;
}

} /* namespace estimates */
} /* namespace niwa */
6 changes: 4 additions & 2 deletions CASAL2/source/Estimates/Common/NormalLog.h
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 8/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* @section DESCRIPTION
*
@@ -34,7 +34,9 @@ class NormalLog : public niwa::Estimate {
virtual ~NormalLog() = default;
void DoValidate() override final{};
Double GetScore() override final;

vector<Double> GetPriorValues() override final;
vector<string> GetPriorLabels() override final;

private:
// Members
Double mu_;
18 changes: 17 additions & 1 deletion CASAL2/source/Estimates/Common/Uniform.cpp
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 8/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* $Date: 2008-03-04 16:33:32 +1300 (Tue, 04 Mar 2008) $
*/
@@ -22,5 +22,21 @@ namespace estimates {
*/
Uniform::Uniform(shared_ptr<Model> model) : Estimate(model) {}


/**
* GetPriorValues()
*
* @return empty vector no prior parameters for this estimate type
*/
vector<Double> Uniform::GetPriorValues() {
vector<Double> result = {0};
return result;
}
vector<string> Uniform::GetPriorLabels() {
vector<string> result = {"none"};
return result;
}


} /* namespace estimates */
} /* namespace niwa */
4 changes: 3 additions & 1 deletion CASAL2/source/Estimates/Common/Uniform.h
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 8/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* @section DESCRIPTION
*
@@ -34,6 +34,8 @@ class Uniform : public niwa::Estimate {
virtual ~Uniform() = default;
void DoValidate() override final{};
Double GetScore() override final { return 0; }
vector<Double> GetPriorValues() override final;
vector<string> GetPriorLabels() override final;
};

} /* namespace estimates */
15 changes: 14 additions & 1 deletion CASAL2/source/Estimates/Common/UniformLog.cpp
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 8/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* $Date: 2008-03-04 16:33:32 +1300 (Tue, 04 Mar 2008) $
*/
@@ -31,6 +31,19 @@ Double UniformLog::GetScore() {
Double score_ = log(value());
return score_;
}
/**
* GetPriorValues()
*
* @return empty vector no prior parameters for this estimate type
*/
vector<Double> UniformLog::GetPriorValues() {
vector<Double> result = {0};
return result;
}
vector<string> UniformLog::GetPriorLabels() {
vector<string> result = {"none"};
return result;
}

} /* namespace estimates */
} /* namespace niwa */
5 changes: 4 additions & 1 deletion CASAL2/source/Estimates/Common/UniformLog.h
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* @date 8/03/2013
* @section LICENSE
*
* Copyright NIWA Science ©2013 - www.niwa.co.nz
* Copyright NIWA Science 2013 - www.niwa.co.nz
*
* @section DESCRIPTION
*
@@ -34,6 +34,9 @@ class UniformLog : public niwa::Estimate {
virtual ~UniformLog() = default;
void DoValidate() override final{};
Double GetScore() override final;
vector<Double> GetPriorValues() override final;
vector<string> GetPriorLabels() override final;

};

} /* namespace estimates */
3 changes: 2 additions & 1 deletion CASAL2/source/Estimates/Estimate.h
Original file line number Diff line number Diff line change
@@ -49,7 +49,8 @@ class Estimate : public niwa::base::Object {
// pure methods
virtual void DoValidate() = 0;
virtual Double GetScore() = 0;

virtual vector<Double> GetPriorValues() = 0;
virtual vector<string> GetPriorLabels() = 0;
// Accessors
void set_target(Double* new_target) { target_ = new_target; };
void set_creator_parameter(const string& parameter) { creator_parameter_ = parameter; }
10 changes: 10 additions & 0 deletions CASAL2/source/Reports/Common/EstimateSummary.cpp
Original file line number Diff line number Diff line change
@@ -51,6 +51,16 @@ void EstimateSummary::DoExecute(shared_ptr<Model> model) {
cache_ << "value: " << AS_DOUBLE(estimate->value()) << REPORT_EOL;
cache_ << "initial_value: " << AS_DOUBLE(estimate->get_initial_value()) << REPORT_EOL;
cache_ << "phase: " << estimate->phase() << REPORT_EOL;
vector<Double> prior_values = estimate->GetPriorValues();
vector<string> prior_labs = estimate->GetPriorLabels();
cache_ << "hyperparameters:";
for(unsigned i = 0; i < prior_labs.size(); ++i)
cache_ << " " << prior_labs[i];
cache_ << REPORT_EOL;
cache_ << "hyperparameter_values:";
for(unsigned i = 0; i < prior_labs.size(); ++i)
cache_ << " " << prior_values[i];
cache_ << REPORT_EOL;
// NOTE: this assumes that the estimated parameters and the covariance matrix are in the same order
if (model->run_mode() == RunMode::kEstimation && minimiser_)
cache_ << "std_dev: " << est_std_dev[est_idx] << REPORT_EOL;
10 changes: 5 additions & 5 deletions CASAL2/source/Version.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// WARNING: THIS FILE IS AUTOMATICALLY GENERATED BY doBuild version. DO NOT EDIT THIS FILE
#ifndef VERSION_H_
#define VERSION_H_
#define VERSION "22.07 (2022-07-20)"
#define VERSION "22.07 (2022-07-22)"
#define VERSION_NUMBER "22.07"
#define SOURCE_CONTROL_REVISION b3e4cd3e7a061926b35266208d918baf8e7dbc9d
#define SOURCE_CONTROL_DATE "2022-07-20"
#define SOURCE_CONTROL_REVISION 9db0bf1e97caaa150d626c4873aa072a341d333e
#define SOURCE_CONTROL_DATE "2022-07-22"
#define SOURCE_CONTROL_YEAR "2022"
#define SOURCE_CONTROL_MONTH "July"
#define SOURCE_CONTROL_TIME "09:09:33"
#define SOURCE_CONTROL_VERSION "2022-07-20 09:09:33 UTC (rev. b3e4cd3e)"
#define SOURCE_CONTROL_TIME "03:20:12"
#define SOURCE_CONTROL_VERSION "2022-07-22 03:20:12 UTC (rev. 9db0bf1e)"
#endif
10 changes: 5 additions & 5 deletions Documentation/UserManual/Version.tex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
% WARNING: THIS FILE IS AUTOMATICALLY GENERATED BY doBuild version. DO NOT EDIT THIS FILE
\newcommand{\Version}{22.07 (2022-07-20)}
\newcommand{\Version}{22.07 (2022-07-22)}
\newcommand{\VersionNumber}{22.07}
\newcommand{\SourceControlRevision}{b3e4cd3e7a061926b35266208d918baf8e7dbc9d}
\newcommand{\SourceControlDateDoc}{2022-07-20}
\newcommand{\SourceControlRevision}{9db0bf1e97caaa150d626c4873aa072a341d333e}
\newcommand{\SourceControlDateDoc}{2022-07-22}
\newcommand{\SourceControlYearDoc}{2022}
\newcommand{\SourceControlMonthDoc}{July}
\newcommand{\SourceControlTimeDoc}{09:09:33}
\newcommand{\SourceControlVersion}{2022-07-20 09:09:33 UTC (rev. b3e4cd3e)}
\newcommand{\SourceControlTimeDoc}{03:20:12}
\newcommand{\SourceControlVersion}{2022-07-22 03:20:12 UTC (rev. 9db0bf1e)}

0 comments on commit bd136b6

Please sign in to comment.