<jupyter_start><jupyter_text>Q1<jupyter_code>def f1(x1, x2, x3):
    return x1 or x2 or not x3
     
def f2(x1, x2, x3):
    return x1 and x2 and not x3

def f3(x1, x2, x3):
    return x1 or (x2 and not x3)
def set_color(bit_value):
    if bit_value == 0:
        return 'r'
    else:
        return 'b'

functions = [f1, f2, f3]
for fun in functions:    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    for i in range(8):
        x1 = (i & 0b001)
        x2 = (i & 0b010) >> 1
        x3 = (i & 0b100) >> 2
        ax.scatter(x3, x2, x1, c=set_color(fun(x3, x2, x1)), marker='o')<jupyter_output><empty_output><jupyter_text>Q2<jupyter_code># (x1 AND x2) OR (NOT x1 AND NOT x2)
def f(x1, x2):
    return int((x1 and x2) or (not x1 and not x2))
inputs = [
  [0, 0],
  [0, 1],
  [1, 0],
  [1, 1]
]

for i in inputs:
    print f(i[0], i[1])
def Threshold(num):    
    if num > 0:
        return 1
    else:        
        return 0<jupyter_output><empty_output><jupyter_text>![](./img/1.jpg)<jupyter_code>z1_bias = -0.5
z1_weight = [-1, 1]

z2_bias = 1.5
z2_weight = [-1, 1]

y_bias = -0.5
y_weight = [1, 1]

for x in inputs:    
    z1 = Threshold(z1_bias + z1_weight[0] * x[0] + z1_weight[1] * x[1])
    z2 = Threshold(z2_bias + z2_weight[0] * x[0] + z2_weight[1] * x[1])
    y = Threshold(y_bias + z1 * y_weight[0] + z2 * y_weight[1])   
    print(y)<jupyter_output>1
1
1
1<jupyter_text>![](./img/2.jpg)<jupyter_code>z1_bias = -1.5
z1_weight = [1, 1]

z2_bias = 0.5
z2_weight = [-1, -1]

y_bias = -1.5
y_weight = [1, 1]

for x in inputs:    
    z1 = Threshold(z1_bias + z1_weight[0] * x[0] + z1_weight[1] * x[1])
    z2 = Threshold(z2_bias + z2_weight[0] * x[0] + z2_weight[1] * x[1])
    y = Threshold(y_bias + z1 * y_weight[0] + z2 * y_weight[1])   
    print(y)<jupyter_output>0
0
0
0<jupyter_text>![](./img/3.jpg)<jupyter_code>z1_bias = -1.5
z1_weight = [1, 1]

z2_bias = 1.5
z2_weight = [-1, -1]

y_bias = -0.5
y_weight = [1, 1]

for x in inputs:    
    z1 = Threshold(z1_bias + z1_weight[0] * x[0] + z1_weight[1] * x[1])
    z2 = Threshold(z2_bias + z2_weight[0] * x[0] + z2_weight[1] * x[1])
    y = Threshold(y_bias + z1 * y_weight[0] + z2 * y_weight[1])   
    print(y)<jupyter_output>1
1
1
1<jupyter_text>![](./img/4.jpg)<jupyter_code>z1_bias = -1.5
z1_weight = [1, 1]

z2_bias = 0.5
z2_weight = [-1, -1]

y_bias = -0.5
y_weight = [1, 1]

for x in inputs:    
    z1 = Threshold(z1_bias + z1_weight[0] * x[0] + z1_weight[1] * x[1])
    z2 = Threshold(z2_bias + z2_weight[0] * x[0] + z2_weight[1] * x[1])
    y = Threshold(y_bias + z1 * y_weight[0] + z2 * y_weight[1])   
    print(y)<jupyter_output>1
0
0
1<jupyter_text>![](./img/5.jpg)<jupyter_code>z1_bias = -1.5
z1_weight = [1, 1]

z2_bias = 1.5
z2_weight = [-1, -1]

y_bias = -1.5
y_weight = [1, 1]

for x in inputs:    
    z1 = Threshold(z1_bias + z1_weight[0] * x[0] + z1_weight[1] * x[1])
    z2 = Threshold(z2_bias + z2_weight[0] * x[0] + z2_weight[1] * x[1])
    y = Threshold(y_bias + z1 * y_weight[0] + z2 * y_weight[1])   
    print(y)<jupyter_output>0
0
0
0
{'fraction_non_alphanumeric': 0.18045112781954886, 'fraction_numerical': 0.09251389342922524, 'mean_word_length': 2.923076923076923, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 29, 'https://': 0, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '621359', 'license': 'Unlicense', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1546, 'n_words': 326, 'path': 'Coursera_Machine_Learning/1_Machine_Learning_Foundations_A_Case_Study_Approach/Week 6 - Deep Learning/Neural_networks.ipynb', 'repo_name': 'dangkhoa1992/Advanced-Machine-Learning-Specialization', 'size': '3059'}