numpysc-lib 1.1.1__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Chirag Vishwakarma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,126 @@
1
+ Metadata-Version: 2.4
2
+ Name: numpysc-lib
3
+ Version: 1.1.1
4
+ Summary: Soft Computing Library
5
+ Home-page:
6
+ Author: andhrew
7
+ Author-email: xyz@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: author
15
+ Dynamic: author-email
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: license
20
+ Dynamic: license-file
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ # Soft Computing Library (`numpysc-lib`)
25
+
26
+ A Python package that stores practical programs for **Soft Computing & Neural Networks** (Simple Neural Networks, Sigmoidal Functions, McCulloch-Pitts, Hebb Rule, Backpropagation, Fuzzy Sets, Perceptron) and prints their source code on demand, from Python or the terminal.
27
+
28
+ Install it once with `pip`, then view any practical code on any machine without copying files around.
29
+
30
+ ---
31
+
32
+ ## Practicals Included
33
+
34
+ | Practical | Topic / Description |
35
+ |---|---|
36
+ | `1A-Simple-Neural-Network` | Design a Simple Neural Network (SNN) with Ramp activation |
37
+ | `1B-Sigmoidal-Functions` | Binary and Bipolar Sigmoidal Activation Functions |
38
+ | `2A-McCulloch-Pitts Neural Network` | ANDNOT function using McCulloch-Pitts Neuron |
39
+ | `2B-XOR function using McCulloch-Pitts Neural Network` | XOR function using McCulloch-Pitts Network |
40
+ | `3-AND Hebb Rule Network` | AND function with Hebbian learning rule (bipolar inputs) |
41
+ | `4-Back Propagation Problem` | Single-step forward & backward error propagation |
42
+ | `5-Error Back Propagation` | Multi-epoch Error Backpropagation Training |
43
+ | `6-Identity Operators` | Identity and Membership Operators in Python |
44
+ | `7-Fuzzy` | Fuzzy Set Operations (Union, Intersection, Complement, Algebraic/Bounded Sum & Diff) |
45
+ | `8-Perceptron` | Perceptron Learning Algorithm for Linear Classification |
46
+
47
+ ---
48
+
49
+ ## Step 1: Install
50
+
51
+ ```bash
52
+ pip install numpysc-lib
53
+ ```
54
+
55
+ To update to the latest version:
56
+
57
+ ```bash
58
+ pip install --upgrade numpysc-lib
59
+ ```
60
+
61
+ Requires Python 3.6 or newer.
62
+
63
+ ---
64
+
65
+ ## Step 2: View the programs
66
+
67
+ ### Option A: From the terminal
68
+
69
+ Show all practicals:
70
+
71
+ ```bash
72
+ numpysc
73
+ # or
74
+ numpysc-lib
75
+ ```
76
+
77
+ Show a single practical (type the name or partial name):
78
+
79
+ ```bash
80
+ numpysc "1A-Simple-Neural-Network"
81
+ numpysc "7-Fuzzy"
82
+ numpysc "8-Perceptron"
83
+ ```
84
+
85
+ ### Option B: From Python
86
+
87
+ ```python
88
+ import numpysc_lib
89
+
90
+ numpysc_lib.show_codes() # Show all practicals
91
+ numpysc_lib.show_codes("7-Fuzzy") # Show specific practical
92
+ numpysc_lib.show_codes("1A-Simple-Neural-Network") # Show specific practical
93
+ ```
94
+
95
+ ### Option C: In Google Colab or Jupyter
96
+
97
+ ```python
98
+ !pip install numpysc-lib
99
+ import numpysc_lib
100
+ numpysc_lib.show_codes("8-Perceptron")
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Publishing a new version (for maintainers)
106
+
107
+ 1. Make any additions or updates in the `numpysc_lib/` folder.
108
+ 2. Increment `version` in `setup.py` (e.g. `1.1.2`).
109
+ 3. Clean old builds:
110
+ ```bash
111
+ rm -rf dist build *.egg-info
112
+ ```
113
+ 4. Build:
114
+ ```bash
115
+ python3 -m build
116
+ ```
117
+ 5. Check and Upload to PyPI:
118
+ ```bash
119
+ python3 -m twine upload dist/*
120
+ ```
121
+
122
+ ---
123
+
124
+ ## License
125
+
126
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,103 @@
1
+ # Soft Computing Library (`numpysc-lib`)
2
+
3
+ A Python package that stores practical programs for **Soft Computing & Neural Networks** (Simple Neural Networks, Sigmoidal Functions, McCulloch-Pitts, Hebb Rule, Backpropagation, Fuzzy Sets, Perceptron) and prints their source code on demand, from Python or the terminal.
4
+
5
+ Install it once with `pip`, then view any practical code on any machine without copying files around.
6
+
7
+ ---
8
+
9
+ ## Practicals Included
10
+
11
+ | Practical | Topic / Description |
12
+ |---|---|
13
+ | `1A-Simple-Neural-Network` | Design a Simple Neural Network (SNN) with Ramp activation |
14
+ | `1B-Sigmoidal-Functions` | Binary and Bipolar Sigmoidal Activation Functions |
15
+ | `2A-McCulloch-Pitts Neural Network` | ANDNOT function using McCulloch-Pitts Neuron |
16
+ | `2B-XOR function using McCulloch-Pitts Neural Network` | XOR function using McCulloch-Pitts Network |
17
+ | `3-AND Hebb Rule Network` | AND function with Hebbian learning rule (bipolar inputs) |
18
+ | `4-Back Propagation Problem` | Single-step forward & backward error propagation |
19
+ | `5-Error Back Propagation` | Multi-epoch Error Backpropagation Training |
20
+ | `6-Identity Operators` | Identity and Membership Operators in Python |
21
+ | `7-Fuzzy` | Fuzzy Set Operations (Union, Intersection, Complement, Algebraic/Bounded Sum & Diff) |
22
+ | `8-Perceptron` | Perceptron Learning Algorithm for Linear Classification |
23
+
24
+ ---
25
+
26
+ ## Step 1: Install
27
+
28
+ ```bash
29
+ pip install numpysc-lib
30
+ ```
31
+
32
+ To update to the latest version:
33
+
34
+ ```bash
35
+ pip install --upgrade numpysc-lib
36
+ ```
37
+
38
+ Requires Python 3.6 or newer.
39
+
40
+ ---
41
+
42
+ ## Step 2: View the programs
43
+
44
+ ### Option A: From the terminal
45
+
46
+ Show all practicals:
47
+
48
+ ```bash
49
+ numpysc
50
+ # or
51
+ numpysc-lib
52
+ ```
53
+
54
+ Show a single practical (type the name or partial name):
55
+
56
+ ```bash
57
+ numpysc "1A-Simple-Neural-Network"
58
+ numpysc "7-Fuzzy"
59
+ numpysc "8-Perceptron"
60
+ ```
61
+
62
+ ### Option B: From Python
63
+
64
+ ```python
65
+ import numpysc_lib
66
+
67
+ numpysc_lib.show_codes() # Show all practicals
68
+ numpysc_lib.show_codes("7-Fuzzy") # Show specific practical
69
+ numpysc_lib.show_codes("1A-Simple-Neural-Network") # Show specific practical
70
+ ```
71
+
72
+ ### Option C: In Google Colab or Jupyter
73
+
74
+ ```python
75
+ !pip install numpysc-lib
76
+ import numpysc_lib
77
+ numpysc_lib.show_codes("8-Perceptron")
78
+ ```
79
+
80
+ ---
81
+
82
+ ## Publishing a new version (for maintainers)
83
+
84
+ 1. Make any additions or updates in the `numpysc_lib/` folder.
85
+ 2. Increment `version` in `setup.py` (e.g. `1.1.2`).
86
+ 3. Clean old builds:
87
+ ```bash
88
+ rm -rf dist build *.egg-info
89
+ ```
90
+ 4. Build:
91
+ ```bash
92
+ python3 -m build
93
+ ```
94
+ 5. Check and Upload to PyPI:
95
+ ```bash
96
+ python3 -m twine upload dist/*
97
+ ```
98
+
99
+ ---
100
+
101
+ ## License
102
+
103
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,18 @@
1
+ # Practical 1A: Design a Simple Neural Network (SNN)
2
+ x = float(input("Enter the input x = "))
3
+ b = float(input("Enter the bias b = "))
4
+ w = float(input("Enter the weight w = "))
5
+
6
+ # Calculating net input value
7
+ net = (x * w) + b
8
+ print("Net =", net)
9
+
10
+ # Activation function (ramp)
11
+ if net < 0:
12
+ out = 0
13
+ elif 0 <= net <= 1:
14
+ out = net
15
+ else:
16
+ out = 1
17
+
18
+ print("Output =", out)
@@ -0,0 +1,19 @@
1
+ # Practical 1B: Binary and Bipolar Sigmoidal Functions
2
+ import math
3
+
4
+ x = float(input("Enter the input x = "))
5
+ b = float(input("Enter the bias b = "))
6
+ w = float(input("Enter the weight w = "))
7
+
8
+ # Net input value
9
+ net = (x * w) + b
10
+ print("Net =", net)
11
+
12
+ # Binary sigmoidal function
13
+ binary_sigmoidal = 1 / (1 + math.exp(-net))
14
+
15
+ # Bipolar sigmoidal function
16
+ bipolar_sigmoidal = (1 - math.exp(-net)) / (1 + math.exp(-net))
17
+
18
+ print("Binary Sigmoidal =", round(binary_sigmoidal, 2))
19
+ print("Bipolar Sigmoidal =", round(bipolar_sigmoidal, 4))
@@ -0,0 +1,27 @@
1
+ # Practical 2A: ANDNOT function using McCulloch-Pitts Neural Network
2
+ import numpy as np
3
+
4
+ class McCullochPittsNeuron:
5
+ def __init__(self, weights, threshold):
6
+ self.weights = np.array(weights)
7
+ self.threshold = threshold
8
+
9
+ def activate(self, inputs):
10
+ weighted_sum = np.dot(inputs, self.weights)
11
+ return 1 if weighted_sum >= self.threshold else 0
12
+
13
+ and_not = McCullochPittsNeuron(weights=[1, -1], threshold=1)
14
+
15
+ print("A B | A AND NOT B")
16
+ print("------------------")
17
+
18
+ inputs = [
19
+ [0, 0],
20
+ [0, 1],
21
+ [1, 0],
22
+ [1, 1]
23
+ ]
24
+
25
+ for x in inputs:
26
+ output = and_not.activate(x)
27
+ print(f"{x[0]} {x[1]} | {output}")
@@ -0,0 +1,32 @@
1
+ # Practical 2B: XOR function using McCulloch-Pitts Neural Network
2
+ # XOR = (A OR B) AND (A NAND B)
3
+ import numpy as np
4
+
5
+ class McCullochPittsNeuron:
6
+ def __init__(self, weights, threshold):
7
+ self.weights = np.array(weights)
8
+ self.threshold = threshold
9
+
10
+ def activate(self, inputs):
11
+ weighted_sum = np.dot(inputs, self.weights)
12
+ return 1 if weighted_sum >= self.threshold else 0
13
+
14
+ or_neuron = McCullochPittsNeuron(weights=[1, 1], threshold=1)
15
+ nand_neuron = McCullochPittsNeuron(weights=[-2, -2], threshold=-3)
16
+ and_neuron = McCullochPittsNeuron(weights=[1, 1], threshold=2)
17
+
18
+ print("A B | XOR")
19
+ print("------------")
20
+
21
+ inputs = [
22
+ [0, 0],
23
+ [0, 1],
24
+ [1, 0],
25
+ [1, 1]
26
+ ]
27
+
28
+ for x in inputs:
29
+ or_output = or_neuron.activate(x)
30
+ nand_output = nand_neuron.activate(x)
31
+ xor_output = and_neuron.activate([or_output, nand_output])
32
+ print(f"{x[0]} {x[1]} | {xor_output}")
@@ -0,0 +1,36 @@
1
+ # Practical 3: AND Hebb Rule Network (bipolar inputs and targets)
2
+ import numpy as np
3
+
4
+ # Input data
5
+ X = np.array([
6
+ [-1, -1],
7
+ [-1, 1],
8
+ [ 1, -1],
9
+ [ 1, 1]
10
+ ])
11
+
12
+ # Target output for AND
13
+ Y = np.array([-1, -1, -1, 1])
14
+
15
+ # Initialize weights and bias
16
+ w = np.zeros(2)
17
+ b = 0
18
+
19
+ print("Initial Weights:", w)
20
+ print("Initial Bias:", b)
21
+
22
+ # Hebbian learning: w_new = w_old + x*y , b_new = b_old + y
23
+ for i in range(len(X)):
24
+ w = w + X[i] * Y[i]
25
+ b = b + Y[i]
26
+
27
+ print("\nFinal Weights:", w)
28
+ print("Final Bias:", b)
29
+
30
+ # Testing AND function
31
+ print("\nTesting AND Function")
32
+ print("Input\t\tTarget\tOutput")
33
+ for i in range(len(X)):
34
+ net = np.dot(X[i], w) + b
35
+ output = 1 if net >= 0 else -1
36
+ print(f"{X[i]}\t{Y[i]}\t{output}")
@@ -0,0 +1,46 @@
1
+ # Practical 4: Back Propagation Problem
2
+ # Network: 1 input -> 1 hidden neuron (tanh) -> 1 output neuron (tanh)
3
+ # Performs ONE forward pass and ONE backward pass (single weight update).
4
+ import math
5
+
6
+ weight_input_hidden = float(input("Enter weight from input to hidden neuron: "))
7
+ bias_hidden = float(input("Enter bias of hidden neuron: "))
8
+ weight_hidden_output = float(input("Enter weight from hidden to output neuron: "))
9
+ bias_output = float(input("Enter bias of output neuron: "))
10
+ learning_rate = float(input("Enter learning rate: "))
11
+ input_value = float(input("Enter input value: "))
12
+ target_output = float(input("Enter target output: "))
13
+
14
+ # ---- Forward propagation ----
15
+ net_hidden = weight_input_hidden * input_value + bias_hidden
16
+ hidden_output = math.tanh(net_hidden)
17
+ net_output = weight_hidden_output * hidden_output + bias_output
18
+ predicted_output = math.tanh(net_output)
19
+
20
+ # ---- Error ----
21
+ error = target_output - predicted_output
22
+ print("\nPredicted output =", predicted_output)
23
+ print("Error (before update) =", error)
24
+
25
+ # ---- Backpropagation (sensitivities = dE/dnet, E = (target - output)^2) ----
26
+ output_sensitivity = -2 * (1 - predicted_output ** 2) * error
27
+ hidden_sensitivity = (1 - hidden_output ** 2) * weight_hidden_output * output_sensitivity
28
+
29
+ # ---- Update (gradient descent: new = old - learning_rate * gradient) ----
30
+ updated_weight_hidden_output = weight_hidden_output - learning_rate * output_sensitivity * hidden_output
31
+ updated_weight_input_hidden = weight_input_hidden - learning_rate * hidden_sensitivity * input_value
32
+ updated_bias_output = bias_output - learning_rate * output_sensitivity
33
+ updated_bias_hidden = bias_hidden - learning_rate * hidden_sensitivity
34
+
35
+ # ---- Display results ----
36
+ print("\n----- Updated Parameters -----")
37
+ print("Updated Input -> Hidden Weight :", updated_weight_input_hidden)
38
+ print("Updated Hidden -> Output Weight:", updated_weight_hidden_output)
39
+ print("Updated Hidden Bias :", updated_bias_hidden)
40
+ print("Updated Output Bias :", updated_bias_output)
41
+
42
+ # ---- Check: error after the update should be smaller ----
43
+ new_hidden = math.tanh(updated_weight_input_hidden * input_value + updated_bias_hidden)
44
+ new_output = math.tanh(updated_weight_hidden_output * new_hidden + updated_bias_output)
45
+ print("\nOutput after update =", new_output)
46
+ print("Error (after update) =", target_output - new_output)
@@ -0,0 +1,42 @@
1
+ # Practical 5: Error Back Propagation Algorithm
2
+ # Same network as Practical 4 (1 input -> 1 hidden tanh -> 1 output tanh),
3
+ # but the forward/backward steps are REPEATED for many epochs until the error is small.
4
+ import math
5
+
6
+ weight_input_hidden = float(input("Enter weight from input to hidden neuron: "))
7
+ bias_hidden = float(input("Enter bias of hidden neuron: "))
8
+ weight_hidden_output = float(input("Enter weight from hidden to output neuron: "))
9
+ bias_output = float(input("Enter bias of output neuron: "))
10
+ learning_rate = float(input("Enter learning rate: "))
11
+ input_value = float(input("Enter input value: "))
12
+ target_output = float(input("Enter target output (between -1 and 1): "))
13
+ epochs = int(input("Enter number of epochs: "))
14
+
15
+ for epoch in range(1, epochs + 1):
16
+ # Forward propagation
17
+ net_hidden = weight_input_hidden * input_value + bias_hidden
18
+ hidden_output = math.tanh(net_hidden)
19
+ net_output = weight_hidden_output * hidden_output + bias_output
20
+ predicted_output = math.tanh(net_output)
21
+
22
+ # Error
23
+ error = target_output - predicted_output
24
+
25
+ # Backward propagation of error
26
+ output_sensitivity = -2 * (1 - predicted_output ** 2) * error
27
+ hidden_sensitivity = (1 - hidden_output ** 2) * weight_hidden_output * output_sensitivity
28
+
29
+ # Update weights and biases (gradient descent)
30
+ weight_hidden_output -= learning_rate * output_sensitivity * hidden_output
31
+ weight_input_hidden -= learning_rate * hidden_sensitivity * input_value
32
+ bias_output -= learning_rate * output_sensitivity
33
+ bias_hidden -= learning_rate * hidden_sensitivity
34
+
35
+ if epoch == 1 or epoch % max(1, epochs // 10) == 0 or epoch == epochs:
36
+ print(f"Epoch {epoch:5d} | Output = {predicted_output:.6f} | Error = {error:.6f}")
37
+
38
+ print("\n----- Final Parameters -----")
39
+ print("Input -> Hidden Weight :", weight_input_hidden)
40
+ print("Hidden -> Output Weight:", weight_hidden_output)
41
+ print("Hidden Bias :", bias_hidden)
42
+ print("Output Bias :", bias_output)
@@ -0,0 +1,20 @@
1
+ # Practical 6: Membership Operators and Identity Operators
2
+
3
+ # ---------- A. Identity Operators (is, is not) ----------
4
+ list1 = [1, 2, 3]
5
+ list2 = [1, 2, 3]
6
+ list3 = list1
7
+
8
+ print("list1 is list3:", list1 is list3)
9
+ print("list1 is list2:", list1 is list2)
10
+ print("list1 is not list2:", list1 is not list2)
11
+ print("list1 is not list3:", list1 is not list3)
12
+
13
+ # ---------- B. Membership Operators (in, not in) ----------
14
+ numbers = [10, 20, 30, 40, 50]
15
+ text = "Python programming"
16
+
17
+ print("\n30 in numbers:", 30 in numbers)
18
+ print("'Python' in text:", "Python" in text)
19
+ print("60 not in numbers:", 60 not in numbers)
20
+ print("'Java' not in text:", "Java" not in text)
@@ -0,0 +1,35 @@
1
+ # Practical 7: Fuzzy Set Operations
2
+ A = {"x1": 0.2, "x2": 0.5, "x3": 0.8, "x4": 1.0}
3
+ B = {"x1": 0.6, "x2": 0.4, "x3": 0.7, "x4": 0.3}
4
+
5
+ def fuzzy_union(A, B):
6
+ return {x: max(A[x], B[x]) for x in A}
7
+
8
+ def fuzzy_intersection(A, B):
9
+ return {x: min(A[x], B[x]) for x in A}
10
+
11
+ def fuzzy_complement(A):
12
+ return {x: round(1 - A[x], 2) for x in A}
13
+
14
+ def algebraic_sum(A, B):
15
+ return {x: round(A[x] + B[x] - A[x] * B[x], 2) for x in A}
16
+
17
+ def algebraic_product(A, B):
18
+ return {x: round(A[x] * B[x], 2) for x in A}
19
+
20
+ def bounded_sum(A, B):
21
+ return {x: round(min(1, A[x] + B[x]), 2) for x in A}
22
+
23
+ def bounded_difference(A, B):
24
+ return {x: round(max(0, A[x] - B[x]), 2) for x in A}
25
+
26
+ print("A =", A)
27
+ print("B =", B)
28
+ print("\n1. Union (A OR B):", fuzzy_union(A, B))
29
+ print("2. Intersection (A AND B):", fuzzy_intersection(A, B))
30
+ print("3. Complement (NOT A):", fuzzy_complement(A))
31
+ print("4. Complement (NOT B):", fuzzy_complement(B))
32
+ print("5. Algebraic Sum:", algebraic_sum(A, B))
33
+ print("6. Algebraic Product:", algebraic_product(A, B))
34
+ print("7. Bounded Sum:", bounded_sum(A, B))
35
+ print("8. Bounded Difference (A - B):", bounded_difference(A, B))
@@ -0,0 +1,51 @@
1
+ # Practical 8: Perceptron Learning Algorithm
2
+ import numpy as np
3
+
4
+ # Input data
5
+ X = np.array([
6
+ [2, 3],
7
+ [3, 4],
8
+ [4, 5],
9
+ [1, 1],
10
+ [2, 1],
11
+ [1, 2]
12
+ ])
13
+
14
+ # Target outputs
15
+ y = np.array([1, 1, 1, 0, 0, 0])
16
+
17
+ # Initialize weights and bias
18
+ weights = np.zeros(2)
19
+ bias = 0
20
+ learning_rate = 0.1
21
+
22
+ # Perceptron learning (stops early once an epoch has no errors)
23
+ for epoch in range(1, 101):
24
+ total_errors = 0
25
+ for i in range(len(X)):
26
+ z = np.dot(X[i], weights) + bias
27
+ prediction = 1 if z >= 0 else 0
28
+ error = y[i] - prediction
29
+ if error != 0:
30
+ weights = weights + learning_rate * error * X[i]
31
+ bias = bias + learning_rate * error
32
+ total_errors += 1
33
+ print(f"Epoch {epoch}: errors = {total_errors}")
34
+ if total_errors == 0:
35
+ break
36
+
37
+ # Display trained parameters
38
+ print("\nWeights:", weights)
39
+ print("Bias:", bias)
40
+
41
+ # Test the network
42
+ test_data = np.array([
43
+ [5, 6],
44
+ [1, 1]
45
+ ])
46
+
47
+ print("\nTesting")
48
+ for point in test_data:
49
+ z = np.dot(point, weights) + bias
50
+ prediction = 1 if z >= 0 else 0
51
+ print(point, "=> Class", prediction)
@@ -0,0 +1,35 @@
1
+ import os
2
+ import sys
3
+
4
+ def show_codes(filename: str = None):
5
+ """
6
+ Displays code included in this package.
7
+ - If filename is given (without .py), shows that file's code.
8
+ - If no filename is given, shows all .py files.
9
+ """
10
+ base_path = os.path.dirname(__file__)
11
+ files = [f for f in os.listdir(base_path) if f.endswith(".py") and f != "__init__.py"]
12
+
13
+ if filename:
14
+ file_path = os.path.join(base_path, f"{filename}.py")
15
+ if os.path.exists(file_path):
16
+ print(f"\n=== Showing {filename}.py ===\n")
17
+ with open(file_path, "r", encoding="utf-8") as f:
18
+ print(f.read())
19
+ else:
20
+ print(f"\n❌ File '{filename}.py' not found in this package.\n")
21
+ print("Available files:")
22
+ for f in files:
23
+ print("•", f.replace(".py", ""))
24
+ else:
25
+ print("\nAll practical codes:\n")
26
+ for f in files:
27
+ print(f"\n=== {f} ===\n")
28
+ with open(os.path.join(base_path, f), "r", encoding="utf-8") as file:
29
+ print(file.read())
30
+
31
+
32
+ def main():
33
+ """Command-line entry point: soft-computing [filename]"""
34
+ filename = " ".join(sys.argv[1:]) or None
35
+ show_codes(filename)
@@ -0,0 +1,126 @@
1
+ Metadata-Version: 2.4
2
+ Name: numpysc-lib
3
+ Version: 1.1.1
4
+ Summary: Soft Computing Library
5
+ Home-page:
6
+ Author: andhrew
7
+ Author-email: xyz@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: author
15
+ Dynamic: author-email
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: license
20
+ Dynamic: license-file
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ # Soft Computing Library (`numpysc-lib`)
25
+
26
+ A Python package that stores practical programs for **Soft Computing & Neural Networks** (Simple Neural Networks, Sigmoidal Functions, McCulloch-Pitts, Hebb Rule, Backpropagation, Fuzzy Sets, Perceptron) and prints their source code on demand, from Python or the terminal.
27
+
28
+ Install it once with `pip`, then view any practical code on any machine without copying files around.
29
+
30
+ ---
31
+
32
+ ## Practicals Included
33
+
34
+ | Practical | Topic / Description |
35
+ |---|---|
36
+ | `1A-Simple-Neural-Network` | Design a Simple Neural Network (SNN) with Ramp activation |
37
+ | `1B-Sigmoidal-Functions` | Binary and Bipolar Sigmoidal Activation Functions |
38
+ | `2A-McCulloch-Pitts Neural Network` | ANDNOT function using McCulloch-Pitts Neuron |
39
+ | `2B-XOR function using McCulloch-Pitts Neural Network` | XOR function using McCulloch-Pitts Network |
40
+ | `3-AND Hebb Rule Network` | AND function with Hebbian learning rule (bipolar inputs) |
41
+ | `4-Back Propagation Problem` | Single-step forward & backward error propagation |
42
+ | `5-Error Back Propagation` | Multi-epoch Error Backpropagation Training |
43
+ | `6-Identity Operators` | Identity and Membership Operators in Python |
44
+ | `7-Fuzzy` | Fuzzy Set Operations (Union, Intersection, Complement, Algebraic/Bounded Sum & Diff) |
45
+ | `8-Perceptron` | Perceptron Learning Algorithm for Linear Classification |
46
+
47
+ ---
48
+
49
+ ## Step 1: Install
50
+
51
+ ```bash
52
+ pip install numpysc-lib
53
+ ```
54
+
55
+ To update to the latest version:
56
+
57
+ ```bash
58
+ pip install --upgrade numpysc-lib
59
+ ```
60
+
61
+ Requires Python 3.6 or newer.
62
+
63
+ ---
64
+
65
+ ## Step 2: View the programs
66
+
67
+ ### Option A: From the terminal
68
+
69
+ Show all practicals:
70
+
71
+ ```bash
72
+ numpysc
73
+ # or
74
+ numpysc-lib
75
+ ```
76
+
77
+ Show a single practical (type the name or partial name):
78
+
79
+ ```bash
80
+ numpysc "1A-Simple-Neural-Network"
81
+ numpysc "7-Fuzzy"
82
+ numpysc "8-Perceptron"
83
+ ```
84
+
85
+ ### Option B: From Python
86
+
87
+ ```python
88
+ import numpysc_lib
89
+
90
+ numpysc_lib.show_codes() # Show all practicals
91
+ numpysc_lib.show_codes("7-Fuzzy") # Show specific practical
92
+ numpysc_lib.show_codes("1A-Simple-Neural-Network") # Show specific practical
93
+ ```
94
+
95
+ ### Option C: In Google Colab or Jupyter
96
+
97
+ ```python
98
+ !pip install numpysc-lib
99
+ import numpysc_lib
100
+ numpysc_lib.show_codes("8-Perceptron")
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Publishing a new version (for maintainers)
106
+
107
+ 1. Make any additions or updates in the `numpysc_lib/` folder.
108
+ 2. Increment `version` in `setup.py` (e.g. `1.1.2`).
109
+ 3. Clean old builds:
110
+ ```bash
111
+ rm -rf dist build *.egg-info
112
+ ```
113
+ 4. Build:
114
+ ```bash
115
+ python3 -m build
116
+ ```
117
+ 5. Check and Upload to PyPI:
118
+ ```bash
119
+ python3 -m twine upload dist/*
120
+ ```
121
+
122
+ ---
123
+
124
+ ## License
125
+
126
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,19 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ numpysc_lib/1A-Simple-Neural-Network.py
5
+ numpysc_lib/1B-Sigmoidal-Functions.py
6
+ numpysc_lib/2A-McCulloch-Pitts Neural Network.py
7
+ numpysc_lib/2B-XOR function using McCulloch-Pitts Neural Network.py
8
+ numpysc_lib/3-AND Hebb Rule Network.py
9
+ numpysc_lib/4-Back Propagation Problem.py
10
+ numpysc_lib/5-Error Back Propagation.py
11
+ numpysc_lib/6-Identity Operators.py
12
+ numpysc_lib/7-Fuzzy.py
13
+ numpysc_lib/8-Perceptron.py
14
+ numpysc_lib/__init__.py
15
+ numpysc_lib.egg-info/PKG-INFO
16
+ numpysc_lib.egg-info/SOURCES.txt
17
+ numpysc_lib.egg-info/dependency_links.txt
18
+ numpysc_lib.egg-info/entry_points.txt
19
+ numpysc_lib.egg-info/top_level.txt
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ numpysc = numpysc_lib:main
3
+ numpysc-lib = numpysc_lib:main
@@ -0,0 +1 @@
1
+ numpysc_lib
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,32 @@
1
+ from setuptools import setup, find_packages
2
+ import io
3
+ import os
4
+
5
+ def read(fname):
6
+ return io.open(os.path.join(os.path.dirname(__file__), fname), encoding="utf-8").read()
7
+
8
+ setup(
9
+ name="numpysc-lib", # must be unique on PyPI
10
+ version="1.1.1",
11
+ author="andhrew",
12
+ author_email="xyz@gmail.com",
13
+ description="Soft Computing Library",
14
+ long_description=read("README.md"),
15
+ long_description_content_type="text/markdown",
16
+ url="", # optional
17
+ packages=find_packages(),
18
+ include_package_data=True,
19
+ install_requires=[],
20
+ entry_points={
21
+ "console_scripts": [
22
+ "numpysc=numpysc_lib:main",
23
+ "numpysc-lib=numpysc_lib:main",
24
+ ],
25
+ },
26
+ license="MIT", # ✅ SPDX-compliant license declaration
27
+ classifiers=[
28
+ "Programming Language :: Python :: 3",
29
+ "Operating System :: OS Independent",
30
+ ],
31
+ python_requires=">=3.6",
32
+ )