libz 0.7__tar.gz → 0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. {libz-0.7 → libz-0.8}/PKG-INFO +1 -1
  2. libz-0.8/libz/DL/__init__.py +15 -0
  3. libz-0.8/libz/DL/prac8.py +73 -0
  4. {libz-0.7 → libz-0.8}/libz/DL/prac9.py +73 -73
  5. libz-0.8/libz/DLG/__init__.py +16 -0
  6. {libz-0.7 → libz-0.8}/libz/__init__.py +1 -1
  7. {libz-0.7 → libz-0.8}/libz.egg-info/PKG-INFO +1 -1
  8. {libz-0.7 → libz-0.8}/pyproject.toml +1 -1
  9. libz-0.7/libz/DL/__init__.py +0 -15
  10. libz-0.7/libz/DL/prac8.py +0 -73
  11. libz-0.7/libz/DLG/__init__.py +0 -16
  12. {libz-0.7 → libz-0.8}/README.md +0 -0
  13. {libz-0.7 → libz-0.8}/libz/AWT/__init__.py +0 -0
  14. {libz-0.7 → libz-0.8}/libz/AWT/prac1.py +0 -0
  15. {libz-0.7 → libz-0.8}/libz/AWT/prac10.py +0 -0
  16. {libz-0.7 → libz-0.8}/libz/AWT/prac2.py +0 -0
  17. {libz-0.7 → libz-0.8}/libz/AWT/prac3.py +0 -0
  18. {libz-0.7 → libz-0.8}/libz/AWT/prac4.py +0 -0
  19. {libz-0.7 → libz-0.8}/libz/AWT/prac5.py +0 -0
  20. {libz-0.7 → libz-0.8}/libz/AWT/prac6.py +0 -0
  21. {libz-0.7 → libz-0.8}/libz/AWT/prac7.py +0 -0
  22. {libz-0.7 → libz-0.8}/libz/AWT/prac8.py +0 -0
  23. {libz-0.7 → libz-0.8}/libz/AWT/prac9.py +0 -0
  24. {libz-0.7 → libz-0.8}/libz/BDA/__init__.py +0 -0
  25. {libz-0.7 → libz-0.8}/libz/BDA/prac1.py +0 -0
  26. {libz-0.7 → libz-0.8}/libz/BDA/prac10.py +0 -0
  27. {libz-0.7 → libz-0.8}/libz/BDA/prac2.py +0 -0
  28. {libz-0.7 → libz-0.8}/libz/BDA/prac3.py +0 -0
  29. {libz-0.7 → libz-0.8}/libz/BDA/prac4.py +0 -0
  30. {libz-0.7 → libz-0.8}/libz/BDA/prac5.py +0 -0
  31. {libz-0.7 → libz-0.8}/libz/BDA/prac6.py +0 -0
  32. {libz-0.7 → libz-0.8}/libz/BDA/prac7.py +0 -0
  33. {libz-0.7 → libz-0.8}/libz/BDA/prac8.py +0 -0
  34. {libz-0.7 → libz-0.8}/libz/BDA/prac9.py +0 -0
  35. {libz-0.7 → libz-0.8}/libz/BIO/__init__.py +0 -0
  36. {libz-0.7 → libz-0.8}/libz/BIO/prac1.py +0 -0
  37. {libz-0.7 → libz-0.8}/libz/BIO/prac10.py +0 -0
  38. {libz-0.7 → libz-0.8}/libz/BIO/prac2.py +0 -0
  39. {libz-0.7 → libz-0.8}/libz/BIO/prac3.py +0 -0
  40. {libz-0.7 → libz-0.8}/libz/BIO/prac4.py +0 -0
  41. {libz-0.7 → libz-0.8}/libz/BIO/prac5.py +0 -0
  42. {libz-0.7 → libz-0.8}/libz/BIO/prac6.py +0 -0
  43. {libz-0.7 → libz-0.8}/libz/BIO/prac7.py +0 -0
  44. {libz-0.7 → libz-0.8}/libz/BIO/prac8.py +0 -0
  45. {libz-0.7 → libz-0.8}/libz/BIO/prac9.py +0 -0
  46. {libz-0.7 → libz-0.8}/libz/DL/prac1.py +0 -0
  47. {libz-0.7 → libz-0.8}/libz/DL/prac2.py +0 -0
  48. {libz-0.7 → libz-0.8}/libz/DL/prac3.py +0 -0
  49. {libz-0.7 → libz-0.8}/libz/DL/prac4.py +0 -0
  50. {libz-0.7 → libz-0.8}/libz/DL/prac5.py +0 -0
  51. {libz-0.7 → libz-0.8}/libz/DL/prac6.py +0 -0
  52. {libz-0.7 → libz-0.8}/libz/DL/prac7.py +0 -0
  53. {libz-0.7 → libz-0.8}/libz/DLG/prac1.py +0 -0
  54. {libz-0.7 → libz-0.8}/libz/DLG/prac2.py +0 -0
  55. {libz-0.7 → libz-0.8}/libz/DLG/prac3.py +0 -0
  56. {libz-0.7 → libz-0.8}/libz/DLG/prac4.py +0 -0
  57. {libz-0.7 → libz-0.8}/libz/DLG/prac5.py +0 -0
  58. {libz-0.7 → libz-0.8}/libz/DLG/prac6.py +0 -0
  59. {libz-0.7 → libz-0.8}/libz/DLG/prac7.py +0 -0
  60. {libz-0.7 → libz-0.8}/libz/_core.py +0 -0
  61. {libz-0.7 → libz-0.8}/libz/_update.py +0 -0
  62. {libz-0.7 → libz-0.8}/libz.egg-info/SOURCES.txt +0 -0
  63. {libz-0.7 → libz-0.8}/libz.egg-info/dependency_links.txt +0 -0
  64. {libz-0.7 → libz-0.8}/libz.egg-info/top_level.txt +0 -0
  65. {libz-0.7 → libz-0.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libz
3
- Version: 0.7
3
+ Version: 0.8
4
4
  Summary: A lightweight Python utility toolkit.
5
5
  Requires-Python: >=3.7
6
6
  Description-Content-Type: text/markdown
@@ -0,0 +1,15 @@
1
+ from libz._core import register
2
+
3
+ TITLES = {
4
+ 1: "pr1-Deep feed forward",
5
+ 2: "pr2-REGULARIZATION AND OPTIMIZATION",
6
+ 3: "pr3-SEMI-SUPERVISED LEARNING",
7
+ 4: "pr4- Multitasking",
8
+ 5: "pr5-CNN-BASED HANDWRITING RECOGNITION",
9
+ 6: "pr6-CNN - UNSUPERVISED FEATURE LEARNING",
10
+ 7: "pr7-RECURRENT NEURAL NETWORK",
11
+ 8: "pr8-RECURSIVE NEURAL NETWORK(tree)",
12
+ 9: "pr9-PCA VS LINEAR AUTOENCODER",
13
+ }
14
+
15
+ register(__name__, globals(), TITLES)
@@ -0,0 +1,73 @@
1
+ # Recursive Neural Networks
2
+
3
+ import torch
4
+ import torch.nn as nn
5
+ import torch.nn.functional as F
6
+
7
+
8
+ class RecursiveNN(nn.Module):
9
+
10
+ def __init__(self, vocab_size, embed_dim, hidden_dim, num_classes):
11
+ super().__init__()
12
+
13
+ self.embedding = nn.Embedding(vocab_size, embed_dim)
14
+ self.combine = nn.Linear(embed_dim * 2, hidden_dim)
15
+ self.classifier = nn.Linear(hidden_dim, num_classes)
16
+
17
+ def forward(self, tree):
18
+
19
+ # Leaf node
20
+ if isinstance(tree, int):
21
+ return self.embedding(torch.tensor(tree))
22
+
23
+ # Recursive case
24
+ left, right = tree
25
+
26
+ left_vec = self.forward(left)
27
+ right_vec = self.forward(right)
28
+
29
+ combined = torch.cat([left_vec, right_vec])
30
+
31
+ return torch.tanh(self.combine(combined))
32
+
33
+
34
+ # Parameters
35
+ VOCAB_SIZE = 100
36
+ EMBED_DIM = 16
37
+ HIDDEN_DIM = 16
38
+ NUM_CLASSES = 2
39
+
40
+ # Create model
41
+ model = RecursiveNN(
42
+ VOCAB_SIZE,
43
+ EMBED_DIM,
44
+ HIDDEN_DIM,
45
+ NUM_CLASSES
46
+ )
47
+
48
+ # Word IDs
49
+ vocab = {
50
+ "the": 10,
51
+ "movie": 25,
52
+ "was": 4,
53
+ "great": 82
54
+ }
55
+
56
+ # Tree: ((the, movie), (was, great))
57
+ tree = (
58
+ (vocab["the"], vocab["movie"]),
59
+ (vocab["was"], vocab["great"])
60
+ )
61
+
62
+ # Get root vector
63
+ root = model(tree)
64
+
65
+ # Classify root
66
+ logits = model.classifier(root)
67
+
68
+ # Convert scores to probabilities
69
+ probabilities = F.softmax(logits, dim=0)
70
+
71
+ print("Root:", root)
72
+ print("Logits:", logits)
73
+ print("Probabilities:", probabilities)
@@ -1,73 +1,73 @@
1
- # Linear Factor Models
2
-
3
- import torch
4
- import torch.nn as nn
5
- import torch.optim as optim
6
- from sklearn.datasets import make_blobs
7
- from sklearn.decomposition import PCA
8
-
9
-
10
- # 1. Create data
11
- X, _ = make_blobs(
12
- n_samples=1000,
13
- n_features=10,
14
- centers=3,
15
- random_state=42
16
- )
17
-
18
- X = torch.tensor(X, dtype=torch.float32)
19
-
20
-
21
- # 2. Linear Factor Model using PCA
22
- pca = PCA(n_components=3)
23
- factors = pca.fit_transform(X.numpy())
24
-
25
- print("PCA Variance:", pca.explained_variance_ratio_)
26
-
27
-
28
- # 3. Linear Autoencoder
29
- class LinearAutoencoder(nn.Module):
30
-
31
- def __init__(self, input_dim, factor_dim):
32
- super().__init__()
33
-
34
- self.encoder = nn.Linear(input_dim, factor_dim)
35
- self.decoder = nn.Linear(factor_dim, input_dim)
36
-
37
- def forward(self, x):
38
- factors = self.encoder(x)
39
- output = self.decoder(factors)
40
-
41
- return output, factors
42
-
43
-
44
- # 4. Create model
45
- model = LinearAutoencoder(10, 3)
46
-
47
- loss_fn = nn.MSELoss()
48
- optimizer = optim.Adam(model.parameters(), lr=0.01)
49
-
50
-
51
- # 5. Train model
52
- for epoch in range(200):
53
-
54
- optimizer.zero_grad()
55
-
56
- output, factors = model(X)
57
-
58
- loss = loss_fn(output, X)
59
-
60
- loss.backward()
61
- optimizer.step()
62
-
63
- if (epoch + 1) % 50 == 0:
64
- print(
65
- "Epoch:", epoch + 1,
66
- "Loss:", loss.item()
67
- )
68
-
69
-
70
- # 6. Get factor loading matrix
71
- W = model.decoder.weight.detach()
72
-
73
- print("Factor Loading Matrix Shape:", W.shape)
1
+ # Linear Factor Models
2
+
3
+ import torch
4
+ import torch.nn as nn
5
+ import torch.optim as optim
6
+ from sklearn.datasets import make_blobs
7
+ from sklearn.decomposition import PCA
8
+
9
+
10
+ # 1. Create data
11
+ X, _ = make_blobs(
12
+ n_samples=1000,
13
+ n_features=10,
14
+ centers=3,
15
+ random_state=42
16
+ )
17
+
18
+ X = torch.tensor(X, dtype=torch.float32)
19
+
20
+
21
+ # 2. Linear Factor Model using PCA
22
+ pca = PCA(n_components=3)
23
+ factors = pca.fit_transform(X.numpy())
24
+
25
+ print("PCA Variance:", pca.explained_variance_ratio_)
26
+
27
+
28
+ # 3. Linear Autoencoder
29
+ class LinearAutoencoder(nn.Module):
30
+
31
+ def __init__(self, input_dim, factor_dim):
32
+ super().__init__()
33
+
34
+ self.encoder = nn.Linear(input_dim, factor_dim)
35
+ self.decoder = nn.Linear(factor_dim, input_dim)
36
+
37
+ def forward(self, x):
38
+ factors = self.encoder(x)
39
+ output = self.decoder(factors)
40
+
41
+ return output, factors
42
+
43
+
44
+ # 4. Create model
45
+ model = LinearAutoencoder(10, 3)
46
+
47
+ loss_fn = nn.MSELoss()
48
+ optimizer = optim.Adam(model.parameters(), lr=0.01)
49
+
50
+
51
+ # 5. Train model
52
+ for epoch in range(200):
53
+
54
+ optimizer.zero_grad()
55
+
56
+ output, factors = model(X)
57
+
58
+ loss = loss_fn(output, X)
59
+
60
+ loss.backward()
61
+ optimizer.step()
62
+
63
+ if (epoch + 1) % 50 == 0:
64
+ print(
65
+ "Epoch:", epoch + 1,
66
+ "Loss:", loss.item()
67
+ )
68
+
69
+
70
+ # 6. Get factor loading matrix
71
+ W = model.decoder.weight.detach()
72
+
73
+ print("Factor Loading Matrix Shape:", W.shape)
@@ -0,0 +1,16 @@
1
+ from libz._core import register
2
+
3
+ TITLES = {
4
+ 1: "pr1-Deep feed forward",
5
+ 2: "pr2-REGULARIZATION AND OPTIMIZATION",
6
+ 3: "pr3-SEMI-SUPERVISED LEARNING",
7
+ 4: "pr4- Multitasking",
8
+ 5: "pr5-CNN-BASED HANDWRITING RECOGNITION",
9
+ 6: "pr6-CNN - UNSUPERVISED FEATURE LEARNING",
10
+ 7: "pr7-RECURRENT NEURAL NETWORK",
11
+ 8: "pr8-RECURSIVE NEURAL NETWORK(tree)",
12
+ 9: "pr9-PCA VS LINEAR AUTOENCODER",
13
+ }
14
+
15
+ # prac8 and prac9 show the DL code (no dynamic version needed)
16
+ register(__name__, globals(), TITLES, links={8: "DL", 9: "DL"})
@@ -2,7 +2,7 @@
2
2
  from libz import AWT, DL, DLG, BIO, BDA
3
3
  from libz._update import check_for_update
4
4
 
5
- __version__ = "0.7"
5
+ __version__ = "0.8"
6
6
  __all__ = ["AWT", "DL", "DLG", "BIO", "BDA"]
7
7
 
8
8
  check_for_update(__version__)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libz
3
- Version: 0.7
3
+ Version: 0.8
4
4
  Summary: A lightweight Python utility toolkit.
5
5
  Requires-Python: >=3.7
6
6
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "libz"
7
- version = "0.7"
7
+ version = "0.8"
8
8
  description = "A lightweight Python utility toolkit."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.7"
@@ -1,15 +0,0 @@
1
- from libz._core import register
2
-
3
- TITLES = {
4
- 1: "Deep feed forward",
5
- 2: "Regularization and optimization",
6
- 3: "Semi-supervised learning",
7
- 4: "Multitasking",
8
- 5: "CNN-based handwriting recognition",
9
- 6: "CNN - unsupervised feature learning",
10
- 7: "Recurrent neural network",
11
- 8: "Recursive neural network (tree)",
12
- 9: "PCA vs linear autoencoder",
13
- }
14
-
15
- register(__name__, globals(), TITLES)
libz-0.7/libz/DL/prac8.py DELETED
@@ -1,73 +0,0 @@
1
- # Recursive Neural Networks
2
-
3
- import torch
4
- import torch.nn as nn
5
- import torch.nn.functional as F
6
-
7
-
8
- class RecursiveNN(nn.Module):
9
-
10
- def __init__(self, vocab_size, embed_dim, hidden_dim, num_classes):
11
- super().__init__()
12
-
13
- self.embedding = nn.Embedding(vocab_size, embed_dim)
14
- self.combine = nn.Linear(embed_dim * 2, hidden_dim)
15
- self.classifier = nn.Linear(hidden_dim, num_classes)
16
-
17
- def forward(self, tree):
18
-
19
- # Leaf node
20
- if isinstance(tree, int):
21
- return self.embedding(torch.tensor(tree))
22
-
23
- # Recursive case
24
- left, right = tree
25
-
26
- left_vec = self.forward(left)
27
- right_vec = self.forward(right)
28
-
29
- combined = torch.cat([left_vec, right_vec])
30
-
31
- return torch.tanh(self.combine(combined))
32
-
33
-
34
- # Parameters
35
- VOCAB_SIZE = 100
36
- EMBED_DIM = 16
37
- HIDDEN_DIM = 16
38
- NUM_CLASSES = 2
39
-
40
- # Create model
41
- model = RecursiveNN(
42
- VOCAB_SIZE,
43
- EMBED_DIM,
44
- HIDDEN_DIM,
45
- NUM_CLASSES
46
- )
47
-
48
- # Word IDs
49
- vocab = {
50
- "the": 10,
51
- "movie": 25,
52
- "was": 4,
53
- "great": 82
54
- }
55
-
56
- # Tree: ((the, movie), (was, great))
57
- tree = (
58
- (vocab["the"], vocab["movie"]),
59
- (vocab["was"], vocab["great"])
60
- )
61
-
62
- # Get root vector
63
- root = model(tree)
64
-
65
- # Classify root
66
- logits = model.classifier(root)
67
-
68
- # Convert scores to probabilities
69
- probabilities = F.softmax(logits, dim=0)
70
-
71
- print("Root:", root)
72
- print("Logits:", logits)
73
- print("Probabilities:", probabilities)
@@ -1,16 +0,0 @@
1
- from libz._core import register
2
-
3
- TITLES = {
4
- 1: "Deep feed forward (any CSV)",
5
- 2: "Regularization and optimization (any CSV)",
6
- 3: "Semi-supervised learning (any text CSV)",
7
- 4: "Multitasking (any CSV)",
8
- 5: "CNN-based handwriting recognition (any image folder / CSV / MNIST)",
9
- 6: "CNN - unsupervised feature learning (any image folder / CSV / digits)",
10
- 7: "Recurrent neural network (any text CSV / IMDB)",
11
- 8: "Recursive neural network (tree)",
12
- 9: "PCA vs linear autoencoder",
13
- }
14
-
15
- # prac8 and prac9 show the DL code (no dynamic version needed)
16
- register(__name__, globals(), TITLES, links={8: "DL", 9: "DL"})
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes