<jupyter_start><jupyter_text>Install neccessary dependencies Source code small_probs: https://github.com/wlad111/small_probs pymc3_ext: https://github.com/wlad111/pymc3---<jupyter_code>pip install --upgrade git+https://github.com/wlad111/pymc3.git
pip install --upgrade git+https://github.com/wlad111/small_probs.git
pip install nose
pip install arviz
from small_probs.probability import ProbabilityEstimator
from scipy.spatial.distance import hamming
import numpy as np
from scipy.stats import norm

import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Users code with proposal, score, initial value<jupyter_code>class string2:


    def __init__(self, length):
        self.n_letters = length
        self.state_fixed = np.array(["A"] * self.n_letters)
        alphabet = frozenset("ATGC")
        self.letters_list = list(alphabet)
        self.proposed = 0
        self.propose_letters = np.random.choice(a=self.letters_list, size=100000)
        self.propose_positions = np.random.choice(a=self.n_letters, size=100000)

    def score(self, state):
        return self.n_letters - np.sum(state != self.state_fixed)

    def proposal(self, state):
        if (self.proposed == 100000):
            self.propose_letters = np.random.choice(a=self.letters_list, size=100000)
            self.propose_positions = np.random.choice(a=self.n_letters, size=100000)
            self.proposed = 0
        state[self.propose_positions[self.proposed]] = self.propose_letters[self.proposed]
        self.proposed += 1
        return state<jupyter_output><empty_output><jupyter_text>Simulating markov chain<jupyter_code>s2 = string2(10)
    
ps = ProbabilityEstimator(p=None, scorefun=s2.score, proposal=s2.proposal, default_val=s2.state_fixed, save_trace=True)
ps.estimate_between(10, 11)

gamma = 0.95<jupyter_output><empty_output><jupyter_text>Confidence interal and variance estimae<jupyter_code>print("True value: ", 1/4**10)
print("Probability estimation: ", ps.prob)
print("OBM variance estimation: ", ps.var)
print(gamma, " confidence interval for true probability ", ps.confint(0.95))

trace = ps.score_trace<jupyter_output><empty_output><jupyter_text>Plot trace<jupyter_code>plt.figure(figsize=(35,10))
plt.plot(trace[-15000:])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11676909569798069, 'fraction_numerical': 0.03467954345917471, 'mean_word_length': 4.769620253164557, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '132160', 'license': 'Apache-2.0', 'n_tokens_mistral': 856, 'n_tokens_neox': 771, 'n_words': 133, 'path': 'notebooks/example_strings.ipynb', 'repo_name': 'wlad111/small_probs', 'size': '2278'}