Skip to content

Commit

Permalink
valgrind possible fix #25078
Browse files Browse the repository at this point in the history
  • Loading branch information
somu15 committed Aug 2, 2023
1 parent 4219f80 commit d4cb597
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 2,734 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,13 @@ class TestLikelihood : public GeneralReporter, public LikelihoodInterface

/// model prediction values
const std::vector<Real> & _model_pred;

/// Transfer the right outputs to the file
std::vector<Real> & _model_pred_required;

/// The MCMC sampler
Sampler & _sampler;

/// Communicator that was split based on samples that have rows
libMesh::Parallel::Communicator & _local_comm;
};
15 changes: 13 additions & 2 deletions modules/stochastic_tools/test/src/reporters/TestLikelihood.C
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "TestLikelihood.h"
#include "Sampler.h"

registerMooseObject("StochasticToolsTestApp", TestLikelihood);

Expand All @@ -21,14 +22,22 @@ TestLikelihood::validParams()
"function", "function", "Value of the density or mass function.");
params.addRequiredParam<std::vector<UserObjectName>>("likelihoods", "Names of likelihoods.");
params.addRequiredParam<ReporterName>("model_pred", "Reporter with the model predictions.");
params.addParam<ReporterValueName>(
"model_pred_required",
"model_pred_required",
"Modified value of the model output from this reporter class.");
params.addRequiredParam<SamplerName>("sampler", "The sampler object.");
return params;
}

TestLikelihood::TestLikelihood(const InputParameters & parameters)
: GeneralReporter(parameters),
LikelihoodInterface(parameters),
_function(declareValue<std::vector<Real>>("function")),
_model_pred(getReporterValue<std::vector<Real>>("model_pred"))
_model_pred(getReporterValue<std::vector<Real>>("model_pred", REPORTER_MODE_DISTRIBUTED)),
_model_pred_required(declareValue<std::vector<Real>>("model_pred_required")),
_sampler(getSampler("sampler")),
_local_comm(_sampler.getLocalComm())
{
for (const UserObjectName & name : getParam<std::vector<UserObjectName>>("likelihoods"))
_likelihoods.push_back(getLikelihoodFunctionByName(name));
Expand All @@ -39,6 +48,8 @@ TestLikelihood::TestLikelihood(const InputParameters & parameters)
void
TestLikelihood::execute()
{
_model_pred_required = _model_pred;
_local_comm.allgather(_model_pred_required);
for (unsigned i = 0; i < _function.size(); ++i)
_function[i] = _likelihoods[i]->function(_model_pred);
_function[i] = _likelihoods[i]->function(_model_pred_required);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"values": {
"function": {
"type": "std::vector<double>"
},
"model_pred_required": {
"type": "std::vector<double>"
}
}
},
Expand Down Expand Up @@ -49,7 +52,8 @@
"likelihoodtest": {
"function": [
0.0
]
],
"model_pred_required": []
},
"noise_specified": {
"noise_specified": 0.2
Expand All @@ -70,7 +74,12 @@
},
"likelihoodtest": {
"function": [
-13.226275095227445
1.6266368748117197
],
"model_pred_required": [
-0.5769720319127907,
0.4873549495108542,
-0.6411786542848692
]
},
"noise_specified": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"values": {
"function": {
"type": "std::vector<double>"
},
"model_pred_required": {
"type": "std::vector<double>"
}
}
},
Expand Down Expand Up @@ -49,7 +52,8 @@
"likelihoodtest": {
"function": [
0.0
]
],
"model_pred_required": []
},
"noise_specified": {
"noise_specified": 0.2
Expand All @@ -70,7 +74,12 @@
},
"likelihoodtest": {
"function": [
0.09019318612685807
6.453480006168816
],
"model_pred_required": [
-0.5769720319127907,
0.4873549495108542,
-0.6411786542848692
]
},
"noise_specified": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"values": {
"function": {
"type": "std::vector<double>"
},
"model_pred_required": {
"type": "std::vector<double>"
}
}
},
Expand Down Expand Up @@ -49,7 +52,8 @@
"likelihoodtest": {
"function": [
0.0
]
],
"model_pred_required": []
},
"noise_specified": {
"noise_specified": 0.2
Expand All @@ -70,7 +74,12 @@
},
"likelihoodtest": {
"function": [
-2.4058013965978287
1.8646195211506778
],
"model_pred_required": [
-0.5769720319127907,
0.4873549495108542,
-0.6411786542848692
]
},
"noise_specified": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"values": {
"function": {
"type": "std::vector<double>"
},
"model_pred_required": {
"type": "std::vector<double>"
}
}
},
Expand Down Expand Up @@ -49,7 +52,8 @@
"likelihoodtest": {
"function": [
0.0
]
],
"model_pred_required": []
},
"noise_specified": {
"noise_specified": 0.2
Expand All @@ -70,7 +74,12 @@
},
"likelihoodtest": {
"function": [
-2.3832432847464218
1.9242540625981073
],
"model_pred_required": [
-0.5769720319127907,
0.4873549495108542,
-0.6411786542848692
]
},
"noise_specified": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
type = TestLikelihood
likelihoods = 'gaussian'
model_pred = constant/reporter_transfer:average:value
sampler = sample
[]
[]

Expand Down
8 changes: 1 addition & 7 deletions modules/stochastic_tools/test/tests/samplers/mcmc/confg.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
2.0
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
-0.6906555,
-0.48597421,
-0.3830987,
-0.35797811,
-0.1734234,
-0.14960162,
-0.07303159,
-0.15606178
-0.48597421,
Loading

0 comments on commit d4cb597

Please sign in to comment.