예제 #1
0
import Parameters as P
import HW6 as Cls
import SupportTransientState as Support

# create multiple cohorts for when the coin is head
multiCohort1 = Cls.MultipleGameSets(
    ids=range(1000),  # [0, 1, 2 ..., NUM_SIM_COHORTS-1]
    n_games_in_a_set=[P.REAL_POP_SIZE] *
    P.NUM_SIM_COHORTS,  # [REAL_POP_SIZE, REAL_POP_SIZE, ..., REAL_POP_SIZE]
    prob_head=[P.HEAD_PROB] * P.NUM_SIM_COHORTS  # [p, p, ...]
)
# simulate all cohorts
multiCohort1.simulation()

# create multiple cohorts for when the coin is tail
multiCohort2 = Cls.MultipleGameSets(
    ids=range(
        1000,
        2000),  # [NUM_SIM_COHORTS, NUM_SIM_COHORTS+1, NUM_SIM_COHORTS+2, ...]
    n_games_in_a_set=[P.REAL_POP_SIZE] *
    P.NUM_SIM_COHORTS,  # [REAL_POP_SIZE, REAL_POP_SIZE, ..., REAL_POP_SIZE]
    prob_head=[P.HEAD_PROBTWO] * P.NUM_SIM_COHORTS)
# simulate all cohorts
multiCohort2.simulation()

# print outcomes of each cohort
Support.print_outcomes(multiCohort1, 'Fair coin:')
Support.print_outcomes(
    multiCohort2, 'Unfair coin for which the probability of head is 45%:')

# print comparative outcomes
예제 #2
0
 def test_123(self):
     self.assertEqual(HW6.solve([1, 2, 3]), 3)
예제 #3
0
import HW6 as lol

#Q1
headProb = 0.5
timeSteps = 20
realizationNumber = 1000
ALPHA = 0.05

print(
    'The probability of getting a head is 0.5, and 20 flips/experiment, and 1000 experiments.'
)

myCohort = lol.Realization(id=2,
                           game_times=realizationNumber,
                           head_prob=headProb)
realizationOutcomes = myCohort.simulate(timeSteps)

#estimate the prob of losing money in this game
probLoss = myCohort.get_loss_num()
print('Problem 1')
print('Average expected reward (dollors):', myCohort.get_ave_exp_value())
print('The 95% t-based CI for the expected reward (dollars) is',
      realizationOutcomes.get_CI_exp_value(ALPHA))
print('The probability of losing money in this game is:',
      realizationOutcomes.get_mean_loss_result())
#print ('The maximum reward is:', max(myCohort._expValue), "dollars, and the minimum reward is:", min(myCohort._expValue), 'dollars.')
print('The 95% t-based CI for the probability of loss is',
      realizationOutcomes.get_CI_loss_result(ALPHA))

print('Problem 2')
print(
예제 #4
0
 def test_3(self):
     self.assertEqual(HW6.solve([1, 4, 3, 9, 1, 2, 4, 10]), 10)
예제 #5
0
 def test_111(self):
     self.assertEqual(HW6.solve([1, 1, 1, 1, 1, 1]), 1)
예제 #6
0
 def test_2(self):
     self.assertEqual(HW6.solve([3, 4, 5, 6]), 6)
예제 #7
0
 def test_123(self):
     self.assertEqual(HW6.solve([1,2,3]), 3)
예제 #8
0
 def test_111(self):
     self.assertEqual(HW6.solve([1,1,1,1,1,1]), 1)
예제 #9
0
 def test_3(self):
     self.assertEqual(HW6.solve([1,4,3,9,1,2,4,10]), 10)
예제 #10
0
 def test_2(self):
     self.assertEqual(HW6.solve([3,4,5,6]), 6)