Add functions for building Q matrix and generating K transpose and V
Browse filesThis commit introduces new functions to facilitate the construction of a matrix Q and the generation of K transpose and V matrices. The function construir_matriz_Q(palabra) takes a word as input and constructs a matrix Q using NumPy arrays. This matrix represents the presence of each letter in the given word based on a pre-defined dictionary diccionario. The function simple_hash(palabra) computes a simple hash value for the given word.
Additionally, the commit includes the function generar_k_transpuesta_y_v(Q, palabra) which utilizes the Q matrix constructed earlier along with the simple hash value to generate K transpose and V matrices. K transpose is obtained by adding the hash value to the transpose of Q, while V is obtained by adding the hash value to Q itself.
These functions lay the groundwork for further development in the context of text processing and hashing algorithms. They are essential components for tasks such as text encoding, feature extraction, and data preprocessing in machine learning and natural language processing applications.
- matrices.py +20 -0
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from diccionario import diccionario
|
3 |
+
|
4 |
+
def construir_matriz_Q(palabra):
|
5 |
+
num_letras = len(palabra)
|
6 |
+
num_caracteristicas = len(diccionario[0])
|
7 |
+
Q = np.zeros((num_letras, num_caracteristicas))
|
8 |
+
for i, char in enumerate(palabra):
|
9 |
+
index = ord(char) - 65 if char.isupper() else ord(char) - 71
|
10 |
+
Q[i] = diccionario[index]
|
11 |
+
return Q
|
12 |
+
|
13 |
+
def simple_hash(palabra):
|
14 |
+
return sum([ord(char) for char in palabra])
|
15 |
+
|
16 |
+
def generar_k_transpuesta_y_v(Q, palabra):
|
17 |
+
hashed_value = simple_hash(palabra)
|
18 |
+
K_transpose = Q.T + hashed_value
|
19 |
+
V = Q + hashed_value
|
20 |
+
return K_transpose, V
|