//Starting code #include #include #include #include #include #inclu
Posted: Sat May 14, 2022 3:24 pm
//Starting code
#include <iostream>
#include <vector>
#include <fstream>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
using namespace std;
//Loads the Experiment Measurements from a text file into a
vector of doubles
vector<double> load_dataset_into_vector(string filename)
{
vector<double> word_list;
ifstream file_handle(filename.c_str());
if (file_handle.good()) {
string word_string;
while (true) {
file_handle >>
word_string;
word_list.push_back(atof(word_string.c_str()));
if
(file_handle.eof())
break;
}
}
return word_list;
}
double mean(const vector<double> &value_list) {
//TODO This function takes as input a vector of
values, calculate and return the mean of these values
}
double median(vector<double> value_list) {
//TODO This function takes as input a vector of
values and you need to calculate and return the median of these
values
}
//Find and return the Minimum value that was found in a
vector
double minimum(const vector<double> &value_list) {
//TODO Find and return the minimum value that was
found in a vector of values
}
//Find and return the Maximum value that was found in a
vector
double maximum(const vector<double> &value_list) {
//TODO Find and return the maximum value that was
found in a vector of values
}
vector<int> histogram(vector<double>
value_list,double min_bound,double max_bound,int n_buckets) {
//TODO Generate and return the histogram of the
provided values between the min_bound and max_bound
}
double mode(vector<double> value_list,int n_buckets)
{
//TODO Find Minimum and Maximum bound
//TODO Build Histogram
//TODO Find Maximum Peak/Bucket
//TODO Convert max bucket position to the mode value
and return
}
int main() {
double
groundtruth_lightspeed=3.3368744961031980650362805697393e-9,
measurement_distance=7443.73;
//Load Experiment Measurements
vector<double>
value_list=load_dataset_into_vector("dataset.txt");
//TODO Convert speed of light measurements to
meters per second
//TODO Calculate Mean, Median and Mode
//TODO Calculate Estimation Error and Display
Estimation and Error results
return 0;
}
Faster Tran The SDE OT Lien w Simon Newcomb was a famous Canadian-American astronomer, applied mathematician and autodidactic polymath. He made a number of contributions to timekeeping, economics and statistics. In 1882, Simon Newcomb did a number of experiments to estimate the speed of light. It involved a stationary and a rotating mirror that was placed 3721.86 meters apart at sea level. It consisted of passing light from a rapidly rotating source mirror and a fixed distant mirror, and back again. The light would have travelled a total distance of 7443.73 meters. The velocity of the light can then be determined by measuring the total distance travelled, the speed of the rotating mirror and the angular displacement of the final received image at the source. This experiment was repeated 66 times. We will use the different central tendency techniques (Mean, Median and Mode) to combine the different estimates of the speed of light to provide a more accurate single estimate of the speed of light. The different measured times are stored in the dataset.txt" file. An example program is provided with clearly marked instructions of what needs to be completed for each section. DEVELOPMENT TASKS • mean function: This function takes as input a vector of values, calculate and return the mean of these values. • median function: This function takes as input a vector of values and you need to calculate and return the median of these values. Remember that you need to sort the values and do a different calculation if there are an odd or even number of values minimum function: Find and return the minimum value that was found in a vector of values
maximum function: Find and return the maximum value that was found in a vector of values histogram function: o Generate the histogram of the provided values between the min_bound and max_bound. o The number of buckets is specified by the n_buckets input parameter o The bucket position can be calculated using the following formula value - min bound bucket_count - 1) bucket_id = round range 1 mode function: o Calculate and return the mode of the provided input values Let the min_bound be the minimum value of the value_list, and the max_bound be the maximum value of the value_list o Set the number of buckets to 10 o Use the developed functions to write the mode function The mode can be calculated using the following formula: max_index range mode_value = n_bounds - 1 + min_bound Complete main function: Convert the speed of light measurements in meters per second, the measurements currently represent the total time taken for the light to travel 7443.73 meters o Calculate and store the Mean, Median and Mode of the converted speed of light measurements o Using the provided groundtruth_lightspeed, calculate the measurement error and display the different estimates and their estimation errors
EXAMPLE OUTPUT • Example program output: Mean Estinate -3.33518e-009 Error - 1.69654e-012 Median Estinate - 3.335290-609 Error = 1.58426e-012 Mode Estinate = 3.33578e-999 Error = 1.091670-012 Example output of Histogram generated using the converted speed of light measurements: hist101-1 hist[1] hist 121-9 hist 131-3 hist141-9 bist is 1-1 hist 161-2 hist121-29 hist181-36 hist191-7
#include <iostream>
#include <vector>
#include <fstream>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
using namespace std;
//Loads the Experiment Measurements from a text file into a
vector of doubles
vector<double> load_dataset_into_vector(string filename)
{
vector<double> word_list;
ifstream file_handle(filename.c_str());
if (file_handle.good()) {
string word_string;
while (true) {
file_handle >>
word_string;
word_list.push_back(atof(word_string.c_str()));
if
(file_handle.eof())
break;
}
}
return word_list;
}
double mean(const vector<double> &value_list) {
//TODO This function takes as input a vector of
values, calculate and return the mean of these values
}
double median(vector<double> value_list) {
//TODO This function takes as input a vector of
values and you need to calculate and return the median of these
values
}
//Find and return the Minimum value that was found in a
vector
double minimum(const vector<double> &value_list) {
//TODO Find and return the minimum value that was
found in a vector of values
}
//Find and return the Maximum value that was found in a
vector
double maximum(const vector<double> &value_list) {
//TODO Find and return the maximum value that was
found in a vector of values
}
vector<int> histogram(vector<double>
value_list,double min_bound,double max_bound,int n_buckets) {
//TODO Generate and return the histogram of the
provided values between the min_bound and max_bound
}
double mode(vector<double> value_list,int n_buckets)
{
//TODO Find Minimum and Maximum bound
//TODO Build Histogram
//TODO Find Maximum Peak/Bucket
//TODO Convert max bucket position to the mode value
and return
}
int main() {
double
groundtruth_lightspeed=3.3368744961031980650362805697393e-9,
measurement_distance=7443.73;
//Load Experiment Measurements
vector<double>
value_list=load_dataset_into_vector("dataset.txt");
//TODO Convert speed of light measurements to
meters per second
//TODO Calculate Mean, Median and Mode
//TODO Calculate Estimation Error and Display
Estimation and Error results
return 0;
}
Faster Tran The SDE OT Lien w Simon Newcomb was a famous Canadian-American astronomer, applied mathematician and autodidactic polymath. He made a number of contributions to timekeeping, economics and statistics. In 1882, Simon Newcomb did a number of experiments to estimate the speed of light. It involved a stationary and a rotating mirror that was placed 3721.86 meters apart at sea level. It consisted of passing light from a rapidly rotating source mirror and a fixed distant mirror, and back again. The light would have travelled a total distance of 7443.73 meters. The velocity of the light can then be determined by measuring the total distance travelled, the speed of the rotating mirror and the angular displacement of the final received image at the source. This experiment was repeated 66 times. We will use the different central tendency techniques (Mean, Median and Mode) to combine the different estimates of the speed of light to provide a more accurate single estimate of the speed of light. The different measured times are stored in the dataset.txt" file. An example program is provided with clearly marked instructions of what needs to be completed for each section. DEVELOPMENT TASKS • mean function: This function takes as input a vector of values, calculate and return the mean of these values. • median function: This function takes as input a vector of values and you need to calculate and return the median of these values. Remember that you need to sort the values and do a different calculation if there are an odd or even number of values minimum function: Find and return the minimum value that was found in a vector of values
maximum function: Find and return the maximum value that was found in a vector of values histogram function: o Generate the histogram of the provided values between the min_bound and max_bound. o The number of buckets is specified by the n_buckets input parameter o The bucket position can be calculated using the following formula value - min bound bucket_count - 1) bucket_id = round range 1 mode function: o Calculate and return the mode of the provided input values Let the min_bound be the minimum value of the value_list, and the max_bound be the maximum value of the value_list o Set the number of buckets to 10 o Use the developed functions to write the mode function The mode can be calculated using the following formula: max_index range mode_value = n_bounds - 1 + min_bound Complete main function: Convert the speed of light measurements in meters per second, the measurements currently represent the total time taken for the light to travel 7443.73 meters o Calculate and store the Mean, Median and Mode of the converted speed of light measurements o Using the provided groundtruth_lightspeed, calculate the measurement error and display the different estimates and their estimation errors
EXAMPLE OUTPUT • Example program output: Mean Estinate -3.33518e-009 Error - 1.69654e-012 Median Estinate - 3.335290-609 Error = 1.58426e-012 Mode Estinate = 3.33578e-999 Error = 1.091670-012 Example output of Histogram generated using the converted speed of light measurements: hist101-1 hist[1] hist 121-9 hist 131-3 hist141-9 bist is 1-1 hist 161-2 hist121-29 hist181-36 hist191-7