Untitled

Run Settings
LanguagePython
Language Version
Run Command
#!/usr/bin/env python3 from random import random def check_cond_prob(side, seq): total = 0 # total num of cases where this side exists and we can condition by it conditioned = 0 # got same side after just seeing it last_letter = seq[0] for letter in seq[1:]: if last_letter == side: total += 1 if last_letter == side and letter == side: conditioned += 1 last_letter = letter print('saw AND got: ' + str(conditioned), 'total: ' + str(total)) return conditioned/total def generate_ran_seq(): seq = '' for _ in range(300): if random() <= 0.5: seq += 'H' else: seq += 'T' return seq def main(): # read in sequences from files into strings seq1 = ''.join([letter for letter in open('ditherSequence1.txt')]) seq2 = ''.join([letter for letter in open('ditherSequence2.txt')]) print('sequence 1') print(seq1) print('P(got heads | saw heads): ' + str(check_cond_prob('H', seq1))) print('P(got tails | saw tails): ' + str(check_cond_prob('T', seq1))) print() print('sequence 2') print(seq2) print('P(got heads | saw heads): ' + str(check_cond_prob('H', seq2))) print('P(got tails | saw tails): ' + str(check_cond_prob('T', seq2))) print() print('Truly random sequence') r = generate_ran_seq() print(r) print('P(got heads | saw heads): ' + str(check_cond_prob('H', r))) print('P(got heads | saw heads): ' + str(check_cond_prob('T', r))) if __name__ == "__main__": main()
Editor Settings
Theme
Key bindings
Full width
Lines