21 Data(
long dimension = 0) : dimension(dimension) {
25 Data(
const std::vector<std::shared_ptr<MarkovChain>>& m_markovChains,
long dimension = 0) : dimension(dimension) {
30 this->dimension = dimension;
33 void linkWithChains(
const std::vector<std::shared_ptr<MarkovChain>>& m_markovChains) {
34 chains.resize(m_markovChains.size());
35 for (
size_t i = 0; i < m_markovChains.size(); ++i) {
36 m_markovChains[i]->installDataObject(chains[i]);
42 std::vector<const std::vector<double>*> acceptanceRates(chains.size());
43 for (
size_t i = 0; i < acceptanceRates.size(); ++i) {
44 acceptanceRates[i] = chains[i].acceptanceRates.get();
46 return acceptanceRates;
50 std::vector<const std::vector<double>*> negativeLogLikelihood(chains.size());
51 for (
size_t i = 0; i < negativeLogLikelihood.size(); ++i) {
52 negativeLogLikelihood[i] = chains[i].negativeLogLikelihood.get();
54 return negativeLogLikelihood;
57 std::vector<const std::vector<Eigen::VectorXd>*>
getStates() {
58 std::vector<const std::vector<Eigen::VectorXd>*> states(chains.size());
59 for (
size_t i = 0; i < states.size(); ++i) {
60 states[i] = chains[i].states.get();
66 std::vector<const std::vector<long>*> timestamps(chains.size());
67 for (
size_t i = 0; i < timestamps.size(); ++i) {
68 timestamps[i] = chains[i].timestamps.get();
75 totalNumberOfSamples = 0;
76 for (
size_t i = 0; i < chains.size(); ++i) {
77 totalNumberOfSamples += chains[i].getStates().size();
82 acceptanceRate = Eigen::VectorXd(chains.size());
83 for (
size_t i = 0; i < chains.size(); ++i) {
84 acceptanceRate(i) = chains[i].getAcceptanceRates().back();
89 std::vector<const std::vector<Eigen::VectorXd>*> states(chains.size());
94 for (
size_t i = 0; i < states.size(); ++i) {
95 states[i] = chains[i].states.get();
101 this->effectiveSampleSize = Eigen::Map<Eigen::VectorXd>(effectiveSampleSize.data(), dimension);
105 std::vector<const std::vector<Eigen::VectorXd>*> states(chains.size());
106 if (!chains.size()) {
110 for (
size_t i = 0; i < states.size(); ++i) {
111 states[i] = chains[i].states.get();
116 std::vector<double> expectedSquaredJumpDistance = ::hops::computeExpectedSquaredJumpDistance<Eigen::VectorXd, Eigen::MatrixXd>(states);
117 this->expectedSquaredJumpDistance = Eigen::Map<Eigen::VectorXd>(expectedSquaredJumpDistance.data(), chains.size());
121 std::vector<const std::vector<Eigen::VectorXd>*> states(chains.size());
122 if (!chains.size()) {
126 for (
size_t i = 0; i < states.size(); ++i) {
127 states[i] = chains[i].states.get();
133 this->potentialScaleReductionFactor = Eigen::Map<Eigen::VectorXd>(potentialScaleReductionFactor.data(), dimension);
137 totalTimeTaken = Eigen::VectorXd(chains.size());
138 for (
size_t i = 0; i < chains.size(); ++i) {
139 totalTimeTaken(i) = chains[i].getTimestamps().back() - chains[i].getTimestamps().front();
144 for (
size_t i = 0; i < chains.size(); ++i) {
150 if (!discardRawData) {
151 for (
size_t i = 0; i < chains.size(); ++i) {
153 chains[i].write(fileWriter.get());
159 if (acceptanceRate.size() > 0) {
160 statisticsWriter->write(
"acceptanceRate", Eigen::MatrixXd(acceptanceRate.transpose()));
163 if (expectedSquaredJumpDistance.size() > 0) {
164 statisticsWriter->write(
"expectedSquaredJumpDistance", Eigen::MatrixXd(expectedSquaredJumpDistance.transpose()));
167 if (effectiveSampleSize.size() > 0) {
168 statisticsWriter->write(
"effectiveSampleSize", Eigen::MatrixXd(effectiveSampleSize.transpose()));
171 if (potentialScaleReductionFactor.size() > 0) {
172 statisticsWriter->write(
"potentialScaleReductionFactor", Eigen::MatrixXd(potentialScaleReductionFactor.transpose()));
175 if (totalNumberOfSamples > 0) {
176 statisticsWriter->write(
"totalNumberOfSamples", Eigen::MatrixXd(totalNumberOfSamples * Eigen::MatrixXd::Identity(1,1)));
179 if (totalTimeTaken.size() > 0) {
180 statisticsWriter->write(
"totalTimeTaken", Eigen::MatrixXd(totalTimeTaken.transpose()));
183 if (totalNumberOfTuningSamples > 0) {
185 tuningWriter->write(
"totalNumberOfTuningSamples", std::vector<long>{
static_cast<long>(totalNumberOfTuningSamples)});
186 tuningWriter->write(
"stepSize", std::vector<double>{tunedStepSize});
187 tuningWriter->write(
"objectiveValue", std::vector<double>{tunedObjectiveValue});
188 tuningWriter->write(
"totalTimeTaken", std::vector<double>{totalTuningTimeTaken});
190 if (tuningData.size() > 0) {
191 tuningWriter->write(
"data", tuningData);
194 if (tuningPosterior.size() > 0) {
195 tuningWriter->write(
"posterior", tuningPosterior);
201 this->tuningMethod = tuningMethod;
205 this->totalNumberOfTuningSamples = totalNumberOfTuningSamples;
209 this->tunedStepSize = tunedStepSize;
213 this->tunedObjectiveValue = tunedObjectiveValue;
217 this->totalTuningTimeTaken = totalTuningTimeTaken;
221 this->tuningData = tuningData;
225 this->tuningPosterior = tuningPosterior;
229 std::vector<ChainData> chains;
231 double totalNumberOfSamples;
232 Eigen::VectorXd acceptanceRate;
233 Eigen::VectorXd expectedSquaredJumpDistance;
234 Eigen::VectorXd effectiveSampleSize;
235 Eigen::VectorXd potentialScaleReductionFactor;
236 Eigen::VectorXd totalTimeTaken;
240 unsigned long totalNumberOfTuningSamples = 0;
241 double tunedStepSize;
242 double tunedObjectiveValue;
243 double totalTuningTimeTaken;
245 Eigen::MatrixXd tuningData;
246 Eigen::MatrixXd tuningPosterior;
248 std::vector<std::vector<double>> sampleVariances;
249 std::vector<std::vector<double>> intraChainExpectations;
250 std::vector<double> interChainExpectation;
251 unsigned long numSeen = 0;
264 return data.acceptanceRate;
269 return data.expectedSquaredJumpDistance;
274 return data.effectiveSampleSize;
279 return data.potentialScaleReductionFactor;
284 return data.totalNumberOfSamples;
289 return data.totalTimeTaken;
293 #endif // HOPS_DATA_HPP