Solving Probability Project: Acceptable Error Rate?

Click For Summary

Discussion Overview

The discussion revolves around a programming project related to probability and error rates in a voting scenario. Participants are trying to understand how to incorporate an error rate into their simulations and whether the given data about the number of votes for A and B is relevant to the problem at hand.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant seeks clarification on the project specifications, particularly regarding the implications of a 15% error rate on the validity of the results.
  • Another participant suggests a method to introduce the error rate into the code, explaining how to implement the error conditionally based on a random number generator.
  • There is a question about the use of the expression (rand()%100) + 1, with an explanation provided about its purpose in generating a number between 1 and 100.
  • Participants discuss whether the specific numbers of votes for A and B (520000 and 480000) are necessary for the simulation or if they are extraneous information.
  • It is noted that the code can accommodate any realizable percent error, but there is uncertainty about how it behaves with errors beyond 100% or negative values.

Areas of Agreement / Disagreement

Participants exhibit some agreement on the implementation of the error rate in the code, but there is no consensus on the relevance of the specific vote counts or the necessity of the provided data. The discussion remains unresolved regarding the importance of the initial vote counts in the context of the project.

Contextual Notes

Participants express uncertainty about how to determine an acceptable error rate and whether the provided vote counts influence the simulation's outcomes. There are also unresolved questions about the behavior of the code under extreme error conditions.

Who May Find This Useful

Individuals interested in programming simulations involving probability, error analysis, or those working on similar projects related to statistical modeling may find this discussion beneficial.

magnifik
Messages
350
Reaction score
0
can anyone help me understand the following project specs? it is supposed to be relatively simply to code, but i can't even figure out what exactly I'm supposed to do.

there are 1000000 people choosing A or B. the process repeats 1000 times. 520000 chose A while 480000 chose B. but there was a 15% error in which B was mistaken for A or A was mistaken for B. is the 15% rate enough to make the results invalid? find the acceptable error rate.

this is what i have so far. I'm not sure how to take into account the error or number of people who actually choose A or B.
Code:
int main(){
	int A = 0;
	int B = 0;
	int aWins = 0;

	srand(time(0));
	for (int j = 0; j < 1000; j++){
	for (int i = 0; i < 1000000; i++){
		if ((rand()%2) == 0)
			B++;
		else
			A++;
	}
	if (A > B)
		aWins++;
	}
	cout << aWins << endl;
	cout << (double)(aWins*100)/1000<< endl;
}
 
Physics news on Phys.org
You can introduce the swapping error into your code like so:

Code:
int main(){
	int A = 0;
	int B = 0;
	int aWins = 0;
        [B]int errorPercent = 15; // errorPercent% of the time, the comparison will be incorrect
[/B]
	srand(time(0));
	for (int j = 0; j < 1000; j++){
	for (int i = 0; i < 1000000; i++){
		if ((rand()%2) == 0)
                        [B]if( (rand()%100) + 1 > errorPercent )
			      B++;
                         else
                               A++;[/B]
		else
                        [B]if( (rand()%100) + 1 > errorPercent )
			      A++;
                         else
                              B++;[/B]
	}
	if (A > B)
		aWins++;
	}
	cout << aWins << endl;
	cout << (double)(aWins*100)/1000<< endl;
}

Though, I'm not sure how you could find what is being asked... seems kind of silly. Maybe you just compare different levels of swapping error until you see a large difference between no swapping error and that level of swapping error?
 
just wondering.. why do you use (rand()%100) + 1?
 
Last edited:
magnifik said:
just wondering.. why do you use (rand()%100) + 1?

rand()%100 + 1 returns a number from 1 to 100.
rand()%100 alone returns a number from 0 to 99.

We can examine a smaller example so we can work through the logic step by step:
rand()%3
A random integer has three possibilities: it is evenly divided by 3 (remainder 0), it has a remainder of 1 after division by 3, or it has a remainder of 2 after division by 3. Therefore, we see that rand()%n returns a number from 0 to n-1. Adding 1 brings this to a more "regular" range of 1 to n.

Then, in my code, I say that if a random number from 1 to 100 is greater than the error percent (15 in this case), then there is no swap. 16-100 are greater than that (which is exactly 85 numbers). 1 to 15 are below or equal to it (15 numbers). So we can see that the comparison yields true 85% of the time and false 15% of the time.
 
so regardless of the percent error, you would still use rand()%100 + 1?
 
magnifik said:
so regardless of the percent error, you would still use rand()%100 + 1?

Yes. The program will work for any realizable percent error (0-100). I haven't thought about how it behaves past 100% error or for negative percents, because that has no practical use here.
 
is it unnecessary information to have the 520000 people who voted for A and the 480000 people who voted for B?
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K