Skip to content

Instantly share code, notes, and snippets.

@tyler1zhang
tyler1zhang / sample2_3.py
Created March 11, 2021 08:17
Bayesian Network, partial sample info and graph structure know. Use EM step to update the pred and prob
def e_step(dic):
numerator = dic['pb_pa'] * (1-dic['pc_pb'])
denorminator = numerator + (1 - dic['pb_pa'])*(1-dic['pc_nb'])
dic['pb_panc'] = round(numerator/denorminator,5)
return dic['pb_panc']
def m_step(dic):
dic['pb_pa'] = round((dic['pb_panc'] + 1)/3, 5)
@tyler1zhang
tyler1zhang / sample1.py
Last active March 11, 2021 08:08
Bayesian Network, partial sample info and graph structure know. Use EM step to update the pred and prob
import numpy as np
def find_prob(prob_dic, string):
dic = {'p':'n', 'n':'p'}
neg_str = dic[string[0]] + string[1:]
prob = prob_dic.get(string)
# for key not exist, need to use neg_status prob to calc
@tyler1zhang
tyler1zhang / tree.py
Created August 16, 2020 16:50
Neo's third assignment
# coding=utf-8
class TreeNode:
def __init__(self, name='root', data=None, parent=None, children=None):
self.name = name
self.data = data
if parent:
assert isinstance(parent, TreeNode)
parent.add_child(self)
@tyler1zhang
tyler1zhang / primes.py
Last active August 8, 2020 16:53
Neo's assignment #2
from math import sqrt
from itertools import islice
from datetime import datetime
#%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
#################### iterable classes ####################
# method mentioned in previous class
@tyler1zhang
tyler1zhang / wifi.py
Created July 25, 2020 08:53
wifi_connection
# Hello World program in Python
from math import sqrt
e_num = int(input())
#print(e_num)
engineers = []
for i in range(e_num):
a = input().split(" ")
b = [int(x) for x in a]
@tyler1zhang
tyler1zhang / dialog_system.py
Last active July 23, 2020 09:41
Neo's assignment #1
from time import sleep
from simpleeval import simple_eval
from termcolor import colored
import random
from googletrans import Translator
################# Define a BasicBot with few attributes which could be used for all classes ##################
class BasicBot: