<jupyter_start><jupyter_text>**Nombre: <NAME>****Carné: 21001127****Statical Learning II****Sección U****Ejercicio: XOR con composición y perceptrones**<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Perceptrón NOT<jupyter_code>def not_function(X):
  parameters = [-1,1]
  X = np.append(X, np.ones((X.shape[0], 1)), axis = -1)
  result = np.matmul(X,parameters)  
  return result.reshape(len(result), 1)
X = np.array([[1], [0], [1]])
not_function(X)<jupyter_output><empty_output><jupyter_text>Perceptrón OR<jupyter_code>def or_function(X1, X2=[]):
  parameters = [1, 1, 0]
  if len(X2):
    X = np.append(X1, X2, axis = -1)
    X = np.append(X, np.ones((X.shape[0], 1)), axis = -1)
  else:
    X = np.append(X1, np.ones((X1.shape[0], 1)), axis = -1)
  result = np.matmul(X,parameters) > 0
  return result.reshape(len(result), 1).astype(int)
X1 = np.array([[1], [1], [0]])
X2 = np.array([[1], [0], [0]])
or_function(X1, X2)
X = np.array([[1,1], [0,1], [0,0]])
or_function(X)<jupyter_output><empty_output><jupyter_text>Perceptrón AND<jupyter_code>def and_function(X1, X2=[]):
  parameters = [1, 1, -1]
  if len(X2):
    X = np.append(X1, X2, axis = -1)
    X = np.append(X, np.ones((X.shape[0], 1)), axis = -1)
  else:
    X = np.append(X1, np.ones((X1.shape[0], 1)), axis = -1)
  result = np.matmul(X,parameters) > 0
  return result.reshape(len(result), 1).astype(int)
X1 = np.array([[1], [1], [0]])
X2 = np.array([[1], [0], [0]])
and_function(X1, X2)
X = np.array([[1,1], [0,1], [0,0]])
and_function(X)<jupyter_output><empty_output><jupyter_text>Perceptrón XOR<jupyter_code>def xor_function(X):  
  X1_temp = not_function(and_function(X))
  X2_temp = or_function(X)
  result = and_function(X1_temp, X2_temp)
  return result.reshape(len(result), 1)
X = np.array([[1,1], [0,1], [0,0], [1,0]])
xor_function(X)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21995708154506438, 'fraction_numerical': 0.0536480686695279, 'mean_word_length': 5.475694444444445, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 24, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '66762', 'license': 'MIT', 'n_tokens_mistral': 870, 'n_tokens_neox': 851, 'n_words': 148, 'path': 'Ejercicio_XOR_Composicion_Perceptrones.ipynb', 'repo_name': 'alejandrolq/StaticalLearningII-Practicas', 'size': '1883'}