More documentation.
This commit is contained in:
+43
-9
@@ -1,4 +1,7 @@
|
||||
/** @file mean_variance_pair.h
|
||||
*
|
||||
* The class implementation that represents a running sample mean and
|
||||
* variance pair.
|
||||
*
|
||||
* @author Dongryeol Lee (dongryel@cc.gatech.edu)
|
||||
*/
|
||||
@@ -8,47 +11,79 @@
|
||||
|
||||
namespace core {
|
||||
namespace monte_carlo {
|
||||
|
||||
/** @brief The mean variance pair class.
|
||||
*/
|
||||
class MeanVariancePair {
|
||||
|
||||
private:
|
||||
|
||||
/** @brief The number of samples gathered.
|
||||
*/
|
||||
int num_samples_;
|
||||
|
||||
/** @brief The sample mean.
|
||||
*/
|
||||
double sample_mean_;
|
||||
|
||||
/** @brief The sample variance.
|
||||
*/
|
||||
double sample_variance_;
|
||||
|
||||
public:
|
||||
|
||||
/** @brief The default constructor that sets everything to zero.
|
||||
*/
|
||||
MeanVariancePair() {
|
||||
SetZero();
|
||||
}
|
||||
|
||||
/** @brief The copy constructor.
|
||||
*/
|
||||
MeanVariancePair(const MeanVariancePair &pair_in) {
|
||||
CopyValues(pair_in);
|
||||
}
|
||||
|
||||
/** @brief Copies another MeanVariancePair object.
|
||||
*/
|
||||
void CopyValues(const MeanVariancePair &pair_in) {
|
||||
num_samples_ = pair_in.num_samples();
|
||||
sample_mean_ = pair_in.sample_mean();
|
||||
sample_variance_ = pair_in.sample_variance();
|
||||
}
|
||||
|
||||
/** @brief The number of samples gathered is returned.
|
||||
*/
|
||||
int num_samples() const {
|
||||
return num_samples_;
|
||||
}
|
||||
|
||||
/** @brief Returns the sample mean.
|
||||
*/
|
||||
double sample_mean() const {
|
||||
return sample_mean_;
|
||||
}
|
||||
|
||||
/** @brief Returns the variance of the sample mean.
|
||||
*/
|
||||
double sample_mean_variance() const {
|
||||
return sample_variance_ / ((double) num_samples_);
|
||||
return sample_variance_ / static_cast<double>(num_samples_);
|
||||
}
|
||||
|
||||
/** @brief Returns the sample variance.
|
||||
*/
|
||||
double sample_variance() const {
|
||||
return sample_variance_;
|
||||
|
||||
// Note that this function scales this way to return the proper
|
||||
// variance.
|
||||
return sample_variance_ * (
|
||||
static_cast<double>(num_samples_) /
|
||||
static_cast<double>(num_samples_ - 1));
|
||||
}
|
||||
|
||||
/** @brief Returns a scaled interval centered around the current
|
||||
* sample mean with the given standard deviation factor.
|
||||
*/
|
||||
void scaled_interval(
|
||||
double scale_in, double standard_deviation_factor,
|
||||
core::math::Range *interval_out) const {
|
||||
@@ -68,17 +103,16 @@ class MeanVariancePair {
|
||||
interval_out->hi = scale_in * (sample_mean_ + error);
|
||||
}
|
||||
|
||||
/** @brief Sets everything to zero.
|
||||
*/
|
||||
void SetZero() {
|
||||
num_samples_ = 0;
|
||||
sample_mean_ = 0;
|
||||
sample_variance_ = 0;
|
||||
}
|
||||
|
||||
void Add(const MeanVariancePair &mv_pair_in) {
|
||||
sample_mean_ += mv_pair_in.sample_mean();
|
||||
sample_variance_ += mv_pair_in.sample_variance();
|
||||
}
|
||||
|
||||
/** @brief Pushes a sample in.
|
||||
*/
|
||||
void push_back(double sample) {
|
||||
|
||||
// Update the number of samples.
|
||||
@@ -94,7 +128,7 @@ class MeanVariancePair {
|
||||
((double) num_samples_);
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+21
@@ -247,6 +247,27 @@ double MixedLogitDCM<TableType>::IntegrationSampleError_(
|
||||
// Assumption: num_active_people in both samples are equal.
|
||||
double simulation_error = 0;
|
||||
|
||||
// Loop over each active people.
|
||||
for(int i = 0; i < first_sample.num_active_people(); i++) {
|
||||
|
||||
// Get the active person index.
|
||||
int person_index = table_.shuffled_indices_for_person(i);
|
||||
|
||||
// Get the integration samples for both samples.
|
||||
const std::vector< arma::vec > &first_integration_samples =
|
||||
first_sample.integration_samples();
|
||||
const std::vector< arma::vec > &second_integration_samples =
|
||||
second_sample.integration_samples();
|
||||
|
||||
// First compute the average difference.
|
||||
core::monte_carlo::MeanVariancePair difference;
|
||||
for(unsigned j = 0; j < first_integration_samples.size(); j++) {
|
||||
double difference = ;
|
||||
average_difference += ;
|
||||
}
|
||||
simulation_error += ;
|
||||
}
|
||||
|
||||
// Lastly divide by squared of the number of active people.
|
||||
simulation_error /=
|
||||
core::math::Sqr(static_cast<double>(first_sample.num_active_people()));
|
||||
|
||||
Reference in New Issue
Block a user