tinycodinglm / reason /reason-0060.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame Contribute Delete
1.84 kB
opencode trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

Explain probabilistic reasoning with concrete examples and common pitfalls. Include a runnable code example with its expected output.

Assistant

Bayesian Updating: P(H|D) = P(D|H) · P(H) / P(D)

Steps:

  1. Start with prior P(H) — belief before evidence
  2. Calculate likelihood P(D|H) — how likely is evidence given hypothesis
  3. Update to posterior P(H|D) — belief after evidence
python
def bayesian_update(prior, likelihood, evidence):
    posterior = likelihood * prior / evidence
    return posterior

# Spam filter example
def spam_filter(email_words, spam_freq, ham_freq, spam_prior=0.3):
    p_spam = spam_prior
    p_ham = 1 - spam_prior

    for word in email_words:
        p_spam *= spam_freq.get(word, 1e-6)
        p_ham *= ham_freq.get(word, 1e-6)

    total = p_spam + p_ham
    return p_spam / total if total > 0 else 0.5

spam_freq = {'free': 0.8, 'winner': 0.7, 'buy': 0.6}
ham_freq = {'free': 0.1, 'meeting': 0.5, 'report': 0.6}
email = ['free', 'winner']
print(f'Spam probability: {spam_filter(email, spam_freq, ham_freq):.1%}')
# Spam probability: 96.5%

Convergence: With enough evidence, prior choice matters less.