def draw_survival_curves_and_histograms(simOutputs_mono, simOutputs_combo):
    """ draws the survival curves and the histograms of time until HIV deaths
    :param simOutputs_mono: output of a cohort simulated under mono therapy
    :param simOutputs_combo: output of a cohort simulated under combination therapy
    """

    # get survival curves of both treatments
    survival_curves = [
        simOutputs_mono.get_survival_curve(),
        simOutputs_combo.get_survival_curve()
    ]

    # graph survival curve
    PathCls.graph_sample_paths(sample_paths=survival_curves,
                               title='Survival curve',
                               x_label='Simulation time step (year)',
                               y_label='Number of alive patients',
                               legends=['Mono Therapy', 'Combination Therapy'])

    # histograms of survival times
    set_of_survival_times = [
        simOutputs_mono.get_survival_times(),
        simOutputs_combo.get_survival_times()
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_survival_times,
                          title='Histogram of patient survival time',
                          x_label='Survival time (year)',
                          y_label='Counts',
                          bin_width=1,
                          legend=['Mono Therapy', 'Combination Therapy'],
                          transparency=0.6)
def draw_survival_curves_and_histograms(simOutputs_mono, simOutputs_combo):
    """ draws the survival curves and the histograms of time until HIV deaths
    :param simOutputs_mono: output of a cohort simulated under mono therapy
    :param simOutputs_combo: output of a cohort simulated under combination therapy
    """

    # get survival curves of both treatments
    survival_curves = [
        simOutputs_mono.get_survival_curve(),
        simOutputs_combo.get_survival_curve()
    ]

    # graph survival curve
    PathCls.graph_sample_paths(sample_paths=survival_curves,
                               title='Exposure of antibiotics',
                               x_label='Simulation time step (day)',
                               y_label='Number of patients using antibiotics',
                               legends=['Standard treatment', 'PCT-guided'])

    # histograms of survival times
    set_of_survival_times = [
        simOutputs_mono.get_survival_times(),
        simOutputs_combo.get_survival_times()
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_survival_times,
                          title='Histogram of exposure time to antibiotics',
                          x_label='Exposure time to antibiotics (day)',
                          y_label='Counts',
                          bin_width=1,
                          legend=['Standard care', 'PCT-guided'],
                          transparency=0.5)
def draw_survival_curves_and_histograms(simOutputs_standard,
                                        simOutputs_population):
    """ draws the survival curves and the histograms of time until cancer
    :param simOutputs_standard: output of a cohort simulated under standard testing
    :param simOutputs_population: output of a cohort simulated under population testing
    """
    # get survival curves of both treatments
    survival_curves = [
        simOutputs_standard.get_survival_curve(),
        simOutputs_population.get_survival_curve()
    ]

    # graph survival curve
    PathCls.graph_sample_paths(
        sample_paths=survival_curves,
        title='Survival curve',
        x_label='Simulation time step (year)',
        y_label='Number of alive patients',
        legends=['Standard Testing', 'Population Testing'])

    # histograms of survival times
    set_of_survival_times = [
        simOutputs_standard.get_survival_times(),
        simOutputs_population.get_survival_times()
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_survival_times,
                          title='Histogram of patient survival time',
                          x_label='Survival time (year)',
                          y_label='Counts',
                          bin_width=1,
                          legend=['Mono Therapy', 'Combination Therapy'],
                          transparency=0.6)
def draw_infection_curves_and_histograms(simOutputs_ANNUAL, simOutputs_SEMI):
    """ draws the infection curves and the histograms of time until HIV deaths
    :param simOutputs_mono: output of a cohort simulated under mono therapy
    :param simOutputs_combo: output of a cohort simulated under combination therapy
    """

    # histograms of infection times
    set_of_infection_times = [
        simOutputs_ANNUAL.get_infection_durations(),
        simOutputs_SEMI.get_infection_durations()
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_infection_times,
                          title='Histogram of Infection Duration',
                          x_label='Infection Duration (Year)',
                          y_label='Counts',
                          bin_width=1,
                          legend=['Annual Treatment', 'Semi-Annual Treatment'],
                          transparency=0.6)

    #get infection curves of both treatments
    infection_curves = [
        simOutputs_ANNUAL.get_infection_curve(),
        simOutputs_SEMI.get_infection_curve()
    ]

    # graph infection curve
    PathCls.graph_sample_paths(sample_paths=infection_curves,
                               title='infection curve',
                               x_label='Simulation time step (year)',
                               y_label='Number of infected patients',
                               legends=['ANNUAL', '6-month'])
def draw_survival_curves_and_histograms(simOutputs_warfarin,
                                        simOutputs_Dabigitran150):
    """ draws the survival curves and the histograms of time until stoke deaths
    :param simOutputs_warfarin: output of a cohort simulated under warfarin therapy
    :param simOutputs_Dabigitran150: output of a cohort simulated under dab150 therapy
    """

    # get survival curves of both treatments
    survival_curves = [
        simOutputs_warfarin.get_survival_curve(),
        simOutputs_Dabigitran150.get_survival_curve()
    ]

    # graph survival curve
    PathCls.graph_sample_paths(sample_paths=survival_curves,
                               title='Survival curve',
                               x_label='Simulation time step (year)',
                               y_label='Number of alive patients',
                               legends=['Warfarin', 'Dabigitran150 Therapy'])

    # histograms of survival times
    set_of_survival_times = [
        simOutputs_warfarin.get_survival_times(),
        simOutputs_Dabigitran150.get_survival_times()
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_survival_times,
                          title='Histogram of patient survival time',
                          x_label='Survival time (year)',
                          y_label='Counts',
                          bin_width=1,
                          legend=['Warfarin Therapy', 'Dabigitran150 Therapy'],
                          transparency=0.6)
Example #6
0
def draw_survival_curves_and_histograms(sim_output_no_drug,
                                        sim_output_with_drug):
    """ draws the survival curves and the histograms of survival time
    :param sim_output_no_drug: output of a cohort simulated when drug is not available
    :param sim_output_with_drug: output of a cohort simulated when drug is available
    """

    # get survival curves of both treatments
    survival_curves = [
        sim_output_no_drug.get_survival_curve(),
        sim_output_with_drug.get_survival_curve()
    ]

    # graph survival curve
    PathCls.graph_sample_paths(sample_paths=survival_curves,
                               title='Survival curve',
                               x_label='Simulation time step',
                               y_label='Number of alive patients',
                               legends=['No Drug', 'With Drug'])

    # histograms of survival times
    set_of_survival_times = [
        sim_output_no_drug.get_survival_times(),
        sim_output_with_drug.get_survival_times()
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_survival_times,
                          title='Histogram of patient survival time',
                          x_label='Survival time',
                          y_label='Counts',
                          bin_width=1,
                          legend=['No Drug', 'With Drug'],
                          transparency=0.6)
Example #7
0
def graph_sample_paths\
                (sample_paths, title, x_label, y_label, output_type=Fig.OutType.SHOW,
                 legends=None, transparency=1, common_color_code=None,
                 if_same_color=False):
    """
    :param sample_paths: a list of sample paths
    :param title: (string) title of the figure
    :param x_label: (string) x-axis label
    :param y_label: (string) y-axis label
    :param output_type: select from OutType.SHOW, OutType.PDF, or OutType.JPG
    :param legends: list of strings for legend
    :param transparency: float (0.0 transparent through 1.0 opaque)
    :param common_color_code: (string) color code if all sample paths should have the same color
        'b'	blue 'g' green 'r' red 'c' cyan 'm' magenta 'y' yellow 'k' black
    :param if_same_color: logical, default False, if set True, paint the sample paths the same color
    """

    if len(sample_paths) == 1:
        raise ValueError('Only one sample path is provided. Use graph_sample_path instead.')

    fig = plt.figure(title)
    plt.title(title)        # title
    plt.xlabel(x_label)     # x-axis label
    plt.ylabel(y_label)     # y-axis label

    # color
    color_marker_text = '-'
    if not (common_color_code is None):
        color_marker_text = common_color_code+color_marker_text

        # x and y values
    if if_same_color:
        for path in sample_paths:
            x_values = path.get_times()
            y_values = path.get_values()
            # plot
            plt.plot(x_values, y_values, common_color_code, alpha=transparency)
    else:
        for path in sample_paths:
            x_values = path.get_times()
            y_values = path.get_values()
            # plot
            plt.plot(x_values, y_values, color_marker_text, alpha=transparency)

    # add legend if provided
    if not (legends is None):
        if common_color_code is None:
            plt.legend(legends)
        else:
            plt.legend([legends])


    # set the minimum of y-axis to zero
    plt.ylim(ymin=0)  # the minimum has to be set after plotting the values

    # output figure
    Fig.output_figure(plt, output_type, title)
Example #8
0
def draw_survival_curves_and_histograms(simOutputs_none, simOutputs_anticoag):
    """ draws the survival curves and the histograms of time until HIV deaths
    :param simOutputs_none: output of a cohort simulated under the natural history of disease
    :param simOutputs_anticoag: output of a cohort simulated under angicoagulation therapy recepit
    """

    # get survival curves of both treatments
    survival_curves = [
        simOutputs_none.get_survival_curve(),
        simOutputs_anticoag.get_survival_curve()
    ]

    # graph survival curve
    PathCls.graph_sample_paths(
        sample_paths=survival_curves,
        title='Survival curve',
        x_label='Simulation time step (year)',
        y_label='Number of alive patients',
        legends=['No Therapy', 'Anticoagulation Therapy'])

    # histograms of survival times
    set_of_survival_times = [
        simOutputs_none.get_survival_times(),
        simOutputs_anticoag.get_survival_times()
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_survival_times,
                          title='Histogram of patient survival time',
                          x_label='Survival time (year)',
                          y_label='Counts',
                          bin_width=1,
                          legend=['No Therapy', 'Anticoagulation Therapy'],
                          transparency=0.6)

    # histograms of the number of strokes
    set_of_stroke_counts = [
        simOutputs_none.get_if_developed_stroke(),
        simOutputs_anticoag.get_if_developed_stroke()
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_stroke_counts,
                          title='Histogram of patient stroke counts',
                          x_label='Number of strokes',
                          y_label='Counts',
                          bin_width=1,
                          legend=['No Therapy', 'Anticoagulation Therapy'],
                          transparency=0.6)
Example #9
0
def draw_stroke_histograms(simOutputs_none, simOutputs_anticoag):
    set_of_strokes = [
        simOutputs_none.get_numbers_of_strokes(),
        simOutputs_anticoag.get_numbers_of_strokes()
    ]

    Figs.graph_histograms(
        data_sets=set_of_strokes,
        title='Histogram of number of strokes',
        x_label='Number of Strokes',
        y_label='Counts',
        bin_width=1,
        legend=['No Therapy', 'Anticoagulation Therapy'],
        transparency=0.6
    )
Example #10
0
def draw_reward_histograms(sim_output_fair_coin, sim_output_unfair_coin):

    set_of_game_rewards = [
        sim_output_fair_coin.get_rewards(),
        sim_output_unfair_coin.get_rewards()
    ]

    Fig.graph_histograms(
        data_sets=set_of_game_rewards,
        title='Histogram of game reward',
        x_label='Game rewards',
        y_label='Counts',
        bin_width=50,
        legend=['Fair Coin', 'Unfair Coin'],
        transparency=0.6
    )
def make_plots(output_fair_coin, output_biased_coin):
    # makes histogram of the game rewards

    # histograms of game rewards
    set_of_game_rewards = [
        output_fair_coin.get_rewards(),
        output_biased_coin.get_rewards()
    ]

    Figs.graph_histograms(data_sets=set_of_game_rewards,
                          title='Histogram of Game Rewards',
                          x_label='Game rewards',
                          y_label='Counts',
                          bin_width=20,
                          legend=['Fair coin', 'Unfair coin'],
                          transparency=0.6)
Example #12
0
def draw_histogram(sim_output_fair, sim_output_unfair):

    # histograms of payouts
    set_of_payouts = [
        sim_output_fair.get_payouts(),
        sim_output_unfair.get_payouts()
    ]

    # graph histograms
    Fig.graph_histograms(data_sets=set_of_payouts,
                         title='Histogram of payouts',
                         x_label='Payouts',
                         y_label='Counts',
                         bin_width=50,
                         legend=['Fair Coin', 'Unfair Coin'],
                         transparency=0.6)
Example #13
0
def draw_histograms(multiGames1, multiGames2):

    # histograms of average rewards
    set_of_rewards = [
        multiGames1.get_all_total_rewards(),
        multiGames2.get_all_total_rewards()
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_rewards,
                          title='Histogram of total rewards (in 10 games)',
                          x_label='Rewards',
                          y_label='Counts',
                          bin_width=15,
                          legend=['50%', '45%'],
                          transparency=0.5,
                          x_range=[-1500, 1000])
def draw_histograms(multi_cohort_fair_coin, multi_cohort_unfair_coin):

    set_of_game_rewards = [
        multi_cohort_fair_coin.get_all_mean_reward(),
        multi_cohort_unfair_coin.get_all_mean_reward()
    ]

    # graph histograms
    Fig.graph_histograms(
        data_sets=set_of_game_rewards,
        title='Histogram of average game reward',
        x_label='Game reward',
        y_label='Counts',
        bin_width=50,
        legend=['Fair Coin', 'Unfair Coin'],
        transparency=0.5,
        #    x_range=[-50, 0]
    )
def make_plots(games_fair_coin, games_biased_coin):

    # histograms of total game rewards
    set_of_game_rewards = [
        games_fair_coin.get_all_total_rewards(),
        games_biased_coin.get_all_total_rewards()
    ]

    # graph histograms
    Figs.graph_histograms(
        data_sets=set_of_game_rewards,
        title="Histogram of the Gambler's Total Rewards from 10 Games",
        x_label='Total Rewards',
        y_label='Count',
        bin_width=40,
        legend=['Fair coin', 'Unfair coin'],
        transparency=0.6,
    )
Example #16
0
def draw_histograms(multi_cohort_fair, multi_cohort_unfair):
    """ draws the histograms of average survival time
    :param multi_cohort_fair: multiple cohorts simulated when using fair coins
    :param multi_cohort_unfair: multiple cohorts simulated when using unfair coins
    """

    # histograms of average survival times
    set_of_game_rewards = [
        multi_cohort_fair.get_all_total_rewards(),
        multi_cohort_unfair.get_all_total_rewards()
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_game_rewards,
                          title='Histogram of average game rewards',
                          x_label='Game rewards',
                          y_label='Counts',
                          legend=['Fair coin', 'Unfair coin'],
                          transparency=0.5,
                          x_range=[0, 20])
def draw_survival_curves_and_histograms(sim_output_fair_coin,
                                        sim_output_unfair_coin):
    """ draws the histograms of game rewards
    :param sim_output_fair_coin: output of a set of games simulated when the coin is fair
    :param sim_output_unfair_coin: output of a set of games simulated when the coin is unfair
    """

    # histograms of game rewards
    set_of_game_rewards = [
        sim_output_fair_coin.get_rewards(),
        sim_output_unfair_coin.get_rewards()
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_game_rewards,
                          title='Histogram of Game Rewards',
                          x_label='Game rewards',
                          y_label='Counts',
                          bin_width=20,
                          legend=['Fair coin', 'Unfair coin'],
                          transparency=0.6)
Example #18
0
def graph_sample_path(sample_path, title, x_label, y_label,
                      output_type=Fig.OutType.SHOW, legend=None, color_code=None):
    """
    produces a sample path
    :param sample_path: a sample path
    :param title: (string) title of the figure
    :param x_label: (string) x-axis label
    :param y_label: (string) y-axis label
    :param output_type: select from OutType.SHOW, OutType.PDF, or OutType.JPG
    :param legend: string for the legend
    :param color_code: (string) 'b' blue 'g' green 'r' red 'c' cyan 'm' magenta 'y' yellow 'k' black
    """

    fig = plt.figure(title)
    plt.title(title)        # title
    plt.xlabel(x_label)     # x-axis label
    plt.ylabel(y_label)     # y-axis label

    # x and y values
    x_values = sample_path.get_times()
    y_values = sample_path.get_values()

    # color
    color_marker_text = '-'
    if not (color_code is None):
        color_marker_text = color_code + color_marker_text

    # plot
    plt.plot(x_values, y_values, color_marker_text)

    # add legend if provided
    if not (legend is None):
        plt.legend([legend])
        
    # set the minimum of y-axis to zero
    plt.ylim(ymin=0)  # the minimum has to be set after plotting the values

    # output figure
    Fig.output_figure(plt, output_type, title)
def draw_histograms(multigamesetsfair, multigamesetsunfair):
    """ draws the histograms of average survival time
    :param multi_cohort_no_drug: multiple cohorts simulated when drug is not available
    :param multi_cohort_with_drug: multiple cohorts simulated when drug is available
    """

    # histograms of average survival times
    totalreward = [
        multigamesetsfair.get_all_total_rewards(),
        multigamesetsunfair.get_all_total_rewards()
    ]

    # graph histograms
    Figs.graph_histograms(
        data_sets= totalreward,
        title='Histogram of total reward',
        x_label='Reward',
        y_label='Counts',
        bin_width=50,
        legend=['Fair coin', 'Unfair coin'],
        transparency=0.5,
    )
def draw_reward_histograms(sim_output_fair_coin, sim_output_unfair_coin):
    """ draws the histograms of game rewards
    :param sim_output_fair_coin: output of a cohort simulated game-set with a fair coin
    :param sim_output_unfair_coin: output of a cohort simulated game-set with an unfair coin
    """

    # histograms of game rewards
    set_of_game_rewards = [
        sim_output_fair_coin.get_rewards(),
        sim_output_unfair_coin.get_rewards()
    ]

    # graph histograms
    Figs.graph_histograms(
        data_sets=set_of_game_rewards,
        title='Histogram of game reward',
        x_label='Game rewards',
        y_label='Counts',
        bin_width=50,
        legend=['Fair Coin', 'Unfair Coin'],
        transparency=0.6
    )
Example #21
0
def draw_histograms(multi_games_fair_coin, multi_games_unfair_coin):
    """ draws the histograms of average game rewards
    :param multi_games_fair_coin: multiple sets of games simulated when the coin is fair
    :param multi_games_unfair_coin: multiple sets of games simulated when the coin is unfair
    """

    # histograms of average game rewards
    set_of_game_rewards = [
        multi_games_fair_coin.get_all_total_rewards(),
        multi_games_unfair_coin.get_all_total_rewards()
    ]

    # graph histograms
    Figs.graph_histograms(
        data_sets=set_of_game_rewards,
        title="Histogram of the Gambler's Average Total Game Rewards",
        x_label='Mean Game Rewards',
        y_label='Count',
        bin_width=40,
        legend=['Fair coin', 'Unfair coin'],
        transparency=0.6,
    )
def draw_survival_curves_and_histograms(sim_output_1, sim_output_2):
    """ draws the survival curves and the histograms of survival time
    :param sim_output_no_drug: output of a cohort simulated when drug is not available
    :param sim_output_with_drug: output of a cohort simulated when drug is available
    """

    # histograms of rewards
    set_of_rewards = [
        sim_output_1.get_rewards(),
        sim_output_2.get_rewards()
    ]

    # graph histograms
    Figs.graph_histograms(
        data_sets=set_of_rewards,
        title='Histogram of rewards',
        x_label='Rewards',
        y_label='Counts',
        bin_width=15,
        legend=['50%', '45%'],
        transparency=0.6
    )
    def Simulate(self, number_of_flips, number_of_realizations):
        self.number_of_flips = number_of_flips
        self.number_of_realizations = number_of_realizations

        gamecost = -250 # cost of playing the game
        totalwinnings = 0 # initialize total winnings
        winningslist = [] # empty list to place each game's winnging into and then graph
        losecount = 0 # keep track of any time you lose money

        for j in range(0, self.number_of_realizations):
            fliplist = "" # create an empty string

            for i in range(0, self.number_of_flips): # iterate through 20 flips, treating 1's as heads and 0's as tails
                fliplist = fliplist + str((numpy.random.binomial(1, self.flip_probability))) #per https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.binomial.html, add each flip to fliplist

            winnings = gamecost+(100*(fliplist.count("001"))) # find the number of Tails, Tails, Heads, multiply by fifty, add to cost of game to find winnings
            winningslist.append(winnings) # append winningslist with each games winnings
            if winnings < 0:
                losecount = losecount +1 # if winnings are less than 0, add to losecount
            totalwinnings = totalwinnings + winnings # add all the realizations of winnings together

        averagewinnings = '${:,.2f}'.format((totalwinnings/self.number_of_realizations)) # find the average winnings

        # print("Expected reward: ", averagewinnings) # print the average winnings

        # Problem 1
        FigureSupport.graph_histogram(
            observations=winningslist,
            title='Histogram of Game Winnings (1000 Games)',
            x_label='Game Winnings (Dollars)',
            y_label='Count')


        print("Problem 1: It appears that the minimum award is approximately $ -250 while the maximum award is approximately $ 250")

        # Problem 2
        loseprob = losecount/self.number_of_realizations
        print("Problem 2: Probability of Losing Money: ",loseprob)
def draw_survival_curves_and_histograms(simOutputs_no_therapy, simOutputs_anticoagulation):
    """
    :param simOutputs_no_therapy: no therapy
    :param simOutputs_anticoagulation: anticoagulation
    :return:
    """

    # get survival curves of both treatments
    survival_curves = [
        simOutputs_no_therapy.get_survival_curve(),
        simOutputs_anticoagulation.get_survival_curve()
    ]

    # graph survival curve
    PathCls.graph_sample_paths(
        sample_paths=survival_curves,
        title='Survival curve',
        x_label='Simulation time step (year)',
        y_label='Number of alive patients',
        legends=['No Therapy', 'Anticoagulation Therapy']
    )

    # histograms of survival times
    set_of_survival_times = [
        simOutputs_no_therapy.get_survival_times(),
        simOutputs_anticoagulation.get_survival_times()
    ]

    # graph histograms
    Figs.graph_histograms(
        data_sets=set_of_survival_times,
        title='Histogram of patient survival time',
        x_label='Survival time (year)',
        y_label='Counts',
        bin_width=1,
        legend=['No Therapy', 'Anticoagualtion Therapy'],
        transparency=0.6
    )
Example #25
0
def draw_histograms(multi_cohort_UnfairCoin, multi_cohort_FairCoin):
    """ draws the histograms of average survival time
    :param multi_cohort_no_drug: multiple cohorts simulated when drug is not available
    :param multi_cohort_with_drug: multiple cohorts simulated when drug is available
    """

    # histograms of average survival times
    set_of_survival_times = [
        multi_cohort_UnfairCoin.get_mean_total_reward(),
        multi_cohort_FairCoin.get_mean_total_reward()
    ]

    # graph histograms
    Figs.graph_histograms(
        data_sets=set_of_survival_times,
        title='Histogram of average patient survival time',
        x_label='Survival time',
        y_label='Counts',
        bin_width=1,
        legend=['No Drug', 'With Drug'],
        transparency=0.5,
        x_range=[6, 20]
    )
Example #26
0
def histograms(sim_output_fair_coin, sim_output_unfair_coin):
    """ draws the histograms of rewards
        :param sim_output_fair_coin: output of a set of games simulated with a fair coin
        :param sim_output_unfair_coin: output of a set of games simulated with an unfair coin
    """

    # histograms of survival times
    set_of_rewards = [
        sim_output_fair_coin.get_rewards(),
        sim_output_unfair_coin.get_rewards()
    ]


    # graph histograms
    Figs.graph_histograms(
        data_sets=set_of_rewards,
        title="Histogram of Rewards from 1000 Games obtained from the steady-state simulation model",
        x_label="Game Rewards",
        y_label="Frequency",
        bin_width=25,
        legend=['Fair Coin', 'Unfair Coin'],
        transparency=0.5
    )
def draw_histograms(multi_cohort_fair_coin, multi_cohort_unfair_coin):
    """ draws the histograms of average survival time
    :param multi_cohort_fair_coin: multiple gamesets simulated when the coin is fair
    :param multi_cohort_unfair_coin: multiple gamesets simulated when the coin is unfair
    """

    # histograms of game rewards
    set_of_game_rewards = [
        multi_cohort_fair_coin.get_all_mean_reward(),
        multi_cohort_unfair_coin.get_all_mean_reward()
    ]

    # graph histograms
    Figs.graph_histograms(
        data_sets=set_of_game_rewards,
        title='Histogram of average game reward',
        x_label='Game reward',
        y_label='Counts',
        bin_width=50,
        legend=['Fair Coin', 'Unfair Coin'],
        transparency=0.5,
        #    x_range=[-50, 0]
    )
Example #28
0
def draw_survival_curves_and_histograms(simOutputs_anti, simOutputs_none):
    """ draws the survival curves and the histograms of time until STROKE deaths
    :param simOutputs_anti: output of a cohort simulated under ANTI therapy
    :param simOutputs_none: output of a cohort simulated under NONE therapy
    """

    # get survival curves of both treatments
    survival_curves = [
        simOutputs_anti.get_survival_curve(),
        simOutputs_none.get_survival_curve()
    ]

    # graph survival curve
    PathCls.graph_sample_paths(
        sample_paths=survival_curves,
        title='Survival curve',
        x_label='Simulation time step (year)',
        y_label='Number of alive patients',
        legends=['Anticoagulant Therapy', 'None Therapy']
    )

    # histograms of survival times
    set_of_survival_times = [
        simOutputs_anti.get_survival_times(),
        simOutputs_none.get_survival_times()
    ]

    # graph histograms
    Figs.graph_histograms(
        data_sets=set_of_survival_times,
        title='Histogram of patient survival time',
        x_label='Survival time (year)',
        y_label='Counts',
        bin_width=1,
        legend=['Anticoagulant Therapy', 'None Therapy'],
        transparency=0.6
    )
def draw_survival_curves_and_histograms(simOutputs_warfarin,
                                        simOutputs_dabigatran_110,
                                        simOutputs_dabigatran_150):
    # draws the survival curves and the histograms of time until death

    # get survival curves of all treatments
    survival_curves = [
        simOutputs_warfarin.get_survival_curve(),
        simOutputs_dabigatran_110.get_survival_curve(),
        simOutputs_dabigatran_150.get_survival_curve()
    ]

    # graph survival curve
    PathCls.graph_sample_paths(
        sample_paths=survival_curves,
        title='Survival curve',
        x_label='Simulation time step (year)',
        y_label='Number of alive patients',
        legends=['Warfarin', 'Dabigatran 110', 'Dabigatran 150'])

    # histograms of survival times
    set_of_survival_times = [
        simOutputs_warfarin.get_survival_times(),
        simOutputs_dabigatran_110.get_survival_times(),
        simOutputs_dabigatran_150.get_survival_times()
    ]

    # graph histograms
    Figs.graph_histograms(
        data_sets=set_of_survival_times,
        title='Histogram of patient survival time',
        x_label='Survival time (year)',
        y_label='Counts',
        bin_width=0.5,
        legend=['Warfarin', 'Dabigatran 110', 'Dabigatran 150'],
        transparency=0.6)
    def get_ave_reward(self):
            """ returns the average reward from all games"""
            return sum(self._gameRewards) / len(self._gameRewards)


    def get_game_times(self):
        return self._gametimes

    def get_game_rewards(self):
        return self._gameRewards



games = SetOfGames(prob_head=0.5, n_games=1000)

# print the average reward
print('Expected reward when the probability of head is 0.5:', games.get_ave_reward())
print min(games.get_game_rewards()), max(games.get_game_rewards())

# create a histogram of patient survival time
FigSupport.graph_histogram(
    observations= games.get_game_rewards(),
    title="Histogram of Rewards Distribution",
    x_label="The amount of money we win(dollar)",
    y_label="Count",
    x_range=[min(games.get_game_rewards()),max(games.get_game_rewards())])

# In 20 times filp, we would expect the maximum money we won achieved at 6 time all win "TTH":
# So the maximum reward should be 6*100-250=350
# and the mininum reward shoule be 6*0-250 = -250
Example #31
0
#get mean number of strokes without the drug
cohort = MarkovCls.Cohort(id=0, therapy=P.Therapies.withoutdrug)
simOutput = cohort.simulate()
strokecount_mean_CI_text = F.format_estimate_interval(
    estimate=simOutput.get_sumState_timeToSTROKE().get_mean(),
    interval=simOutput.get_sumState_timeToSTROKE().get_t_CI(alpha=Data.ALPHA),
    deci=2)
print(
    "  Estimate of mean times of stroke and {:.{prec}%} confidence interval without drug is... :"
    .format(1 - Data.ALPHA, prec=0), strokecount_mean_CI_text)

# graph histogram for this non-drug group
Figs.graph_histogram(
    data=simOutput.get_these_stroke_times(),
    title=
    'Stroke Count if the Patient Does Not Receive the Heart-Drug Intervention',
    x_label='Survival time (years)',
    y_label='Stroke Counts (#)',
    bin_width=1)

####NOW for the ppl with the drug ######

#get mean number of strokes with the drug
Adjusted_Cohort = MarkovCls.Cohort(id=0, therapy=P.Therapies.newdrug)
new_simOutputs = Adjusted_Cohort.simulate()
new_strokecount_mean_CI_text = F.format_estimate_interval(
    estimate=new_simOutputs.get_sumState_timeToSTROKE().get_mean(),
    interval=new_simOutputs.get_sumState_timeToSTROKE().get_t_CI(
        alpha=Data.ALPHA),
    deci=2)
print(
Example #32
0
        return sum(self._CountTotalLoss)/sum(self._CountTotalWin)




class SetOfGamesOutcomes:
    def __init__(self, simulated_set_outcomes):
        # extracts outcomes of the simulated set of games
        self._simulated_set_outcomes = simulated_set_outcomes
#not sure if I should move forward with this piece

# run trail of 1000 games to calculate expected reward
games = SetOfGames(prob_head=0.5, n_games=1000)
# print the average reward
print('Expected reward when the probability of head is 0.5:', games.get_ave_reward())
# print the prob of loss
print ('Probability of losing money', games.get_prob_loss())
# Histogram of rewards for 1000 games
FigSupport.graph_histogram(
    observations= SetOfGames.get_reward(games),
    title='Histogram of Rewards',
    x_label='Reward',
    y_label='Count')

# Answer 1: min is -150, max is 250

# Answer 2: Prob of losing money is 100%