Question
A Monte Carlo Simulation. Implement the process of converting historical data into the probability of occurrence of the various outcomes, extracting probability distributions, assigning random
A Monte Carlo Simulation. Implement the process of converting historical data into the probability of occurrence of the various outcomes, extracting probability distributions, assigning random number intervals, and running a simulation. Assume we are dealing with bacteria counts in Escambia bay. Our data might be like the following for 100 days of observation:
The goal will be to read the data, compute the probability distribution, carry out a simulation, and predict the expected bacterial reading. Data will be in a file entitled readings.txt. The file readings.txt will first have an integer indicating how many days of data are included (100 in the above example) followed by the number of categories of data (7 in the above example). This second integer will be followed by the textual description of the range of values, a colon (:), and then the number of days on which that observation occurred. This part of the program should read these values, simulate a user-specified number of days (see below), and compute and display the expected value from the analytical model.
100 7 0-2000/ml: 15 2000-4000/ml: 25 4000-8000/ml: 20 8000-12000/ml: 15 12000-18000/ml: 10 18000-24000/ml: 10 24000-28000/ml: 5
Output from this data might look like this:
Analytical model: 8500.0. Expected value is in the 8000-12000/ml range. Simulation: 7800.5. Expected value is in the 4000-8000ml range.
Note: Since the categories have values that are on a range, we will need to use category mean values for the analytical model and simulation. Here is a small program that will tokenize the strings holding the categories and turn the values into integers:
/*****************************************************
Program: MonteTokenizer.c
Programmer: John Coffey
Purpose: Demonstrate tokenizing the ranges out of
text data for project 4.
*****************************************************/
#include
#include
#define LEN 100
char* getMeasure(char * line, int which)
{
char *token;
char *search = "-:";
token = strtok(line, search);
if (which==1)
return token;
else
{
token = strtok(NULL, search);
return token;
}
}
int main()
{
char measure[LEN] = "4000-8000:";
char temp[LEN];
strcpy(temp, measure);
char* val = getMeasure(temp,1);
printf("after call 1 val = %d ",atoi(val));
strcpy(temp, measure);
val = getMeasure(temp,2);
printf("after call 2 val = %d ",atoi(val));
return 0;
}
Inputs and Outputs When your program runs, It will prompt the user for the number of days to simulate and then perform the simulation. It will also calculate and report the expected value of the analytical model. ALL results will go to the console. Note that different data (categories and percents) in readings.txt should work properly. program must be in C.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started