def run(): """ Run Monte Carlo simulations with different numbers of trials to estimate the expectation that you will get 3-of-a-kind when rolling 5 dice. Actual probability of 3-of-a-kind: .1929 """ trial_sizes = [10, 100, 1000, 10000, 100000] estimates = [] for ntrials in trial_sizes: estimates.append((ntrials, monte_carlo(ntrials))) for ntrials, est in estimates: print ntrials, ":", est log_estimates = [(math.log(ntrials, 10), est) for ntrials, est in estimates] simpleplot.plot_bars("3-of-a-Kind", 400, 300, "Log(Trials)", "Expectation", [log_estimates]) # Uncomment to run #run() ##================================================================= ##=================================================================
def main(): # type: () -> None """Open a plot.""" datalist = [(1, 2), (2, 3), (5, 4), (8, 3), (9, 2)] dataset = {1: 3, 2: 4, 5: 5, 8: 4, 9: 3} filename = None if SIMPLEGUICS2PYGAME: from sys import argv # pylint: disable=import-outside-toplevel if len(argv) == 2: filename = argv[1] if filename is None: simpleplot.plot_bars('Test plot_bars', 400, 400, 'x', 'y', (datalist, dataset), ('datalist', 'dataset')) else: simpleplot.plot_bars('Test plot_bars', 400, 400, 'x', 'y', (datalist, dataset), ('datalist', 'dataset'), _filename=filename) if SIMPLEGUICS2PYGAME and (len(argv) != 2): simpleplot._block() # pylint: disable=protected-access
def plot_indeg_distribution(graph_dictionary, ref_str, plot_type): """ Part 1: graphs the log-log plot of the normalized in-degree distribution for the input dictionary called ref_str """ # gets the unnormalized distribution and normalizes it graph_dist = deg_analysis.in_degree_distribution(graph_dictionary) sum_total = 0.0 for key in graph_dist.keys(): sum_total += graph_dist[key] graph_dist_norm = {} for key in graph_dist.keys(): graph_dist_norm[key] = graph_dist[key]/sum_total # creates the log/log data set graph_dist_log = {} for key in graph_dist_norm.keys(): graph_dist_log[math.log(key, 10)] = math.log(graph_dist_norm[key], 10) # graph types if plot_type == "LOGLOG": simpleplot.plot_scatter("LogLog of Normalized In-Degree Distribution for " + ref_str, 800, 600, "Log Degree", "Log Amount", [graph_dist_log]) elif plot_type == "NORMAL": simpleplot.plot_scatter("Normalized In-Degree Distribution for " + ref_str, 800, 600, "Degree", "Amount", [graph_dist_norm]) elif plot_type == "BARS": simpleplot.plot_bars("Bar Plot of Normalized In-Degree Distribution for " + ref_str, 800, 600, "Degree", "Amount", [graph_dist_norm])
def question4(): """ create hypothesis testing distribution """ null_dist = {} if DESKTOP: # load sequences and scoring matrix score_matrix = read_scoring_matrix(PAM50_URL) human_eyeless = read_protein(HUMAN_EYELESS_URL) fruitfly_eyeless = read_protein(FRUITFLY_EYELESS_URL) # generate the null distribution null_dist = generate_null_distribution(human_eyeless, fruitfly_eyeless, score_matrix, 1000) else: # previously calculated using desktop python null_dist = {38: 1, 39: 1, 40: 6, 41: 8, 42: 17, 43: 31, 44: 41, 45: 47, 46: 65, 47: 76, 48: 66, 49: 63, 50: 62, 51: 69, 52: 69, 53: 57, 54: 49, 55: 37, 56: 26, 57: 30, 58: 33, 59: 23, 60: 25, 61: 20, 62: 5, 63: 11, 64: 11, 65: 7, 66: 5, 67: 4, 68: 5, 69: 4, 70: 5, 71: 3, 72: 3, 73: 4, 74: 1, 75: 2, 80: 3, 81: 1, 82: 1, 85: 1, 87: 1, 92: 1} # normalize null_dist for key in null_dist.keys(): null_dist[key] /= float(1000) simpleplot.plot_bars("Normalized Null Distribution of Human and Fruitfly Local Alignment (n=1000 trials)", 800, 600, "Local Alignment Score", "Distribution", [null_dist])
def run(): """ Run Monte Carlo simulations with different numbers of trials to estimate the expectation that you will get 3-of-a-kind when rolling 5 dice. Actual probability of 3-of-a-kind: .1929 """ trial_sizes = [10, 100, 1000, 10000, 100000] estimates = [] for ntrials in trial_sizes: estimates.append((ntrials, monte_carlo(ntrials))) for ntrials, est in estimates: print ntrials, ":", est log_estimates = [(math.log(ntrials, 10), est) for ntrials, est in estimates] simpleplot.plot_bars("3-of-a-Kind", 400, 300, "Log(Trials)", "Expectation", [log_estimates])
def run(): """ Load a graph and play the Kevin Bacon Game. """ graph5000 = movies.load_graph('subgraph5000') if len(graph5000.nodes()) > 0: # You can/should use smaller graphs and other actors while # developing and testing your code. play_kevin_bacon_game(graph5000, 'Kevin Bacon', ['Amy Adams', 'Andrew Garfield', 'Anne Hathaway', 'Barack Obama', \ 'Benedict Cumberbatch', 'Chris Pine', 'Daniel Radcliffe', \ 'Jennifer Aniston', 'Joseph Gordon-Levitt', 'Morgan Freeman', \ 'Sandra Bullock', 'Tina Fey']) # Plot distance histograms for person in ['Kevin Bacon', 'Stephanie Fratus']: hist = distance_histogram(graph5000, person) simpleplot.plot_bars(person, 400, 300, 'Distance', \ 'Frequency', [hist], ["distance frequency"])
import simpleplot dataset1 = {3: 5, 8: 2, 1: 3} dataset2 = [(1, 2), (4, 7), (2, 5), (7, 6)] simpleplot.plot_bars('Sample', 400, 300, 'x', 'y', [dataset1, dataset2], ['dataset1', 'dataset2'])
def plot_hist_data(score_list): """ Shows a plot of the histogram data returned by hist_data(). """ simpleplot.plot_bars("Histogram", 400, 300, "range", "count", [zip([0, 20, 40, 60, 80], hist_data(score_list))])
PYTHON_VERSION = 'Python ' + python_version.split()[0] MATPLOTLIB_VERSION = 'matplotlib ' + matplotlib_version else: PYTHON_VERSION = 'CodeSkulptor' # http://www.codeskulptor.org/ MATPLOTLIB_VERSION = '' datalist = [(1, 2), (2, 3), (5, 4), (8, 3), (9, 2)] dataset = {1: 3, 2: 4, 5: 5, 8: 4, 9: 3} filename = None if SIMPLEGUICS2PYGAME: from sys import argv if len(argv) == 2: filename = argv[1] if filename is None: simpleplot.plot_bars('Test plot_bars', 400, 400, 'x', 'y', (datalist, dataset), ('datalist', 'dataset')) else: simpleplot.plot_bars('Test plot_bars', 400, 400, 'x', 'y', (datalist, dataset), ('datalist', 'dataset'), _filename=filename) if SIMPLEGUICS2PYGAME and (len(argv) != 2): simpleplot._block()
PYTHON_VERSION = 'Python ' + python_version.split()[0] MATPLOTLIB_VERSION = 'matplotlib ' + matplotlib_version else: PYTHON_VERSION = 'CodeSkulptor' # http://www.codeskulptor.org/ MATPLOTLIB_VERSION = '' datalist = [(1, 2), (2, 3), (5, 4), (8, 3), (9, 2)] dataset = {1: 3, 2: 4, 5: 5, 8: 4, 9: 3} filename = None if SIMPLEGUICS2PYGAME: from sys import argv if len(argv) == 2: filename = argv[1] if filename is None: simpleplot.plot_bars('Test', 400, 400, 'x', 'y', (datalist, dataset), ('datalist', 'dataset')) else: simpleplot.plot_bars('Test', 400, 400, 'x', 'y', (datalist, dataset), ('datalist', 'dataset'), _filename=filename) if SIMPLEGUICS2PYGAME and (len(argv) != 2): simpleplot._block()