DjPractLelo 0.1.9__tar.gz → 0.2.0__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 (38) hide show
  1. djpractlelo-0.2.0/DjPractLelo/resource_loader.py +35 -0
  2. {djpractlelo-0.1.9 → djpractlelo-0.2.0}/DjPractLelo.egg-info/PKG-INFO +1 -1
  3. djpractlelo-0.2.0/DjPractLelo.egg-info/SOURCES.txt +10 -0
  4. {djpractlelo-0.1.9 → djpractlelo-0.2.0}/PKG-INFO +1 -1
  5. {djpractlelo-0.1.9 → djpractlelo-0.2.0}/pyproject.toml +3 -9
  6. {djpractlelo-0.1.9 → djpractlelo-0.2.0}/setup.py +1 -1
  7. djpractlelo-0.1.9/DjPractLelo/resource_loader.py +0 -42
  8. djpractlelo-0.1.9/DjPractLelo/resources/data_science/practical_manual.docx +0 -0
  9. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/10a_simple_genetic algorithm.py +0 -48
  10. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/10b_genetic-algorithm-city.py +0 -33
  11. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/1a_simple_nueral.py +0 -34
  12. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/1b_binary_bipolar.py +0 -25
  13. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/2a_macclouch_AND.py +0 -24
  14. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/2b_macclouch_OR.py +0 -24
  15. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/2c_macclouch_XOR.py +0 -36
  16. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/3a_hebb_rule.py +0 -56
  17. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/3b_delta_rule.py +0 -63
  18. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/4a_back-prop.py +0 -31
  19. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/4b_back-prop-error.py +0 -34
  20. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/6a_kohonen_self.py +0 -38
  21. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/9a_ratios_fuzzy.py +0 -25
  22. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/9b_tipping problem.py +0 -31
  23. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/Delta Rule.py +0 -28
  24. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/adaptive-resonance.py +0 -21
  25. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/hebbs.py +0 -19
  26. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/hopfield.py +0 -25
  27. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/linear-neural-network.py +0 -15
  28. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/linear-seperability.py +0 -16
  29. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/membership-operators.py +0 -22
  30. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/practical_manual.docx +0 -0
  31. djpractlelo-0.1.9/DjPractLelo/resources/soft_computing/radial-basis-function.py +0 -22
  32. djpractlelo-0.1.9/DjPractLelo.egg-info/SOURCES.txt +0 -34
  33. {djpractlelo-0.1.9 → djpractlelo-0.2.0}/DjPractLelo/__init__.py +0 -0
  34. {djpractlelo-0.1.9 → djpractlelo-0.2.0}/DjPractLelo.egg-info/dependency_links.txt +0 -0
  35. {djpractlelo-0.1.9 → djpractlelo-0.2.0}/DjPractLelo.egg-info/top_level.txt +0 -0
  36. {djpractlelo-0.1.9 → djpractlelo-0.2.0}/LICENCE +0 -0
  37. {djpractlelo-0.1.9 → djpractlelo-0.2.0}/README.md +0 -0
  38. {djpractlelo-0.1.9 → djpractlelo-0.2.0}/setup.cfg +0 -0
@@ -0,0 +1,35 @@
1
+ from importlib.resources import files
2
+ from pathlib import Path
3
+
4
+ # Base resources directory
5
+ BASE_RESOURCES = files("DjPractLelo") / "resources"
6
+
7
+
8
+ def get_txt_file(category: str, filename: str) -> Path:
9
+ """
10
+ Get a specific TXT file from a category.
11
+ category: 'data_science' or 'soft_computing'
12
+ filename: must end with .txt
13
+ """
14
+ if not filename.endswith(".txt"):
15
+ raise ValueError("Only .txt files are allowed")
16
+
17
+ return BASE_RESOURCES / category / filename
18
+
19
+
20
+ def list_txt_files(category: str) -> list[Path]:
21
+ """
22
+ List all TXT files in a category.
23
+ """
24
+ directory = BASE_RESOURCES / category
25
+ return [p for p in directory.iterdir() if p.suffix == ".txt"]
26
+
27
+
28
+ def load_txt(filename: str, category: str = "data_science") -> str:
29
+ """
30
+ Read a TXT file and return its content.
31
+ """
32
+ path = get_txt_file(category, filename)
33
+
34
+ with open(path, "r", encoding="utf-8") as f:
35
+ return f.read()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DjPractLelo
3
- Version: 0.1.9
3
+ Version: 0.2.0
4
4
  Summary: My first Python package
5
5
  Author: DjPractVala
6
6
  Author-email: DjPractVala <youremail@example.com>
@@ -0,0 +1,10 @@
1
+ LICENCE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ DjPractLelo/__init__.py
6
+ DjPractLelo/resource_loader.py
7
+ DjPractLelo.egg-info/PKG-INFO
8
+ DjPractLelo.egg-info/SOURCES.txt
9
+ DjPractLelo.egg-info/dependency_links.txt
10
+ DjPractLelo.egg-info/top_level.txt
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DjPractLelo
3
- Version: 0.1.9
3
+ Version: 0.2.0
4
4
  Summary: My first Python package
5
5
  Author: DjPractVala
6
6
  Author-email: DjPractVala <youremail@example.com>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "DjPractLelo"
7
- version = "0.1.9"
7
+ version = "0.2.0"
8
8
  description = "My first Python package"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.7"
@@ -25,12 +25,6 @@ where = ["."]
25
25
 
26
26
  [tool.setuptools.package-data]
27
27
  DjPractLelo = [
28
- "resources/**/*.json",
29
- "resources/**/*.csv",
30
- "resources/**/*.docx",
31
- "resources/**/*.R",
32
- "resources/**/*.jpg",
33
- "resources/**/*.mp4",
34
- "resources/**/*.mp3",
35
- "resources/**/*.xml"
28
+ "resources/data_science/*.txt",
29
+ "resources/soft_computing/*.txt"
36
30
  ]
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="DjPractLelo",
5
- version="0.1.9",
5
+ version="0.2.0",
6
6
  author="DjPractVala",
7
7
  description="My demo Python package",
8
8
  packages=find_packages(),
@@ -1,42 +0,0 @@
1
- from importlib.resources import files
2
- from pathlib import Path
3
- import json
4
-
5
- # Base resources directory
6
- BASE_RESOURCES = files("DjPractLelo") / "resources"
7
-
8
-
9
- def get_resource(category: str, filename: str) -> Path:
10
- """
11
- Get any resource file from a category.
12
- category: 'data_science' or 'soft_computing'
13
- filename: exact filename
14
- """
15
- return BASE_RESOURCES / category / filename
16
-
17
-
18
- def list_files(category: str, extension: str | None = None) -> list[Path]:
19
- """
20
- List files in a category.
21
- extension: '.csv', '.json', '.py', '.R', '.mp3', '.mp4', '.xml' etc. (None = all files)
22
- """
23
- directory = BASE_RESOURCES / category
24
- if extension:
25
- return [p for p in directory.iterdir() if p.suffix == extension]
26
- return [p for p in directory.iterdir() if p.is_file()]
27
-
28
-
29
- def load_json(filename: str, category: str = "data_science") -> dict:
30
- """
31
- Load any JSON file from resources.
32
- """
33
- path = get_resource(category, filename)
34
- with open(path, "r", encoding="utf-8") as f:
35
- return json.load(f)
36
-
37
-
38
- def get_manual(category: str) -> Path:
39
- """
40
- Get manual.docx from any category.
41
- """
42
- return get_resource(category, "manual.docx")
@@ -1,48 +0,0 @@
1
- import numpy as np
2
- import random
3
-
4
- def activate_function(x):
5
- return 1 / (1 + np.exp(-x))
6
-
7
-
8
- n = int(input("Enter Number of inputs you want:"))
9
-
10
- # Initial weights (only once)
11
- weights = np.random.randn(n)
12
-
13
- bias = np.random.uniform(0.1, 0.9)
14
-
15
- # User inputs
16
- inputs = []
17
- for i in range(n):
18
- inputs.append(float(input("Enter your input: ")))
19
-
20
- inputs = np.array(inputs)
21
-
22
- print("\nInitial Weights (First Generation):")
23
- print(weights)
24
-
25
- # Crossover (self crossover using split)
26
- crossover_point = random.randint(1, n-1)
27
- child_weights = np.concatenate((weights[:crossover_point], weights[crossover_point:]))
28
-
29
- print("\nAfter Crossover:")
30
- print(child_weights)
31
-
32
- # Mutation (change one weight)
33
- mutation_index = random.randint(0, n-1)
34
- old_weight = child_weights[mutation_index]
35
- child_weights[mutation_index] += np.random.randn()
36
-
37
- print("\nAfter Mutation:")
38
- print(f"Weight {mutation_index} changed from {old_weight} to {child_weights[mutation_index]}")
39
-
40
- # Neuron output using evolved weights
41
- z = 0
42
- for i in range(n):
43
- z += inputs[i] * child_weights[i]
44
-
45
- z += bias
46
-
47
- print("\nFinal Output:")
48
- print(activate_function(z))
@@ -1,33 +0,0 @@
1
- import random, math
2
-
3
- class City:
4
- def __init__(self, x, y):
5
- self.x, self.y = x, y
6
- def distance(self, city):
7
- return math.sqrt((self.x - city.x)**2 + (self.y - city.y)**2)
8
- def __repr__(self):
9
- return f"({self.x},{self.y})"
10
-
11
- class Fitness:
12
- def __init__(self, route):
13
- self.route = route
14
- def distance(self):
15
- total = 0
16
- for i in range(len(self.route)):
17
- total += self.route[i].distance(self.route[(i+1)%len(self.route)])
18
- return total
19
- def fitness(self):
20
- return 1 / self.distance()
21
-
22
- cities = [City(random.randint(0,50), random.randint(0,50)) for _ in range(5)]
23
-
24
- population = [random.sample(cities, len(cities)) for _ in range(4)]
25
-
26
- for _ in range(5):
27
- population.sort(key=lambda r: Fitness(r).fitness(), reverse=True)
28
- parent1, parent2 = population[0], population[1]
29
- child = parent1[:2] + [c for c in parent2 if c not in parent1[:2]]
30
-
31
- best = population[0]
32
- print("Best Route:", best)
33
- print("Distance:", Fitness(best).distance())
@@ -1,34 +0,0 @@
1
- import numpy as np
2
- import random
3
-
4
- def activate_function(x):
5
- return 1 / (1 + np.exp(-x))
6
-
7
-
8
- n=int(input("Enter Number of inputs you want:"))
9
-
10
- weights = np.random.randn(n)
11
-
12
- bias = np.random.uniform(low=0.1, high=0.9)
13
-
14
- #User input
15
- inputs = []
16
- for i in range(number):
17
- val = float(input(f"Enter your input: "))
18
- inputs.append(val)
19
-
20
- z=0
21
- for i in range(n):
22
- z += (inputs[i] * weights[i])
23
-
24
- z = z + bias
25
-
26
- # Apply activation function
27
- print(activate_function(z))
28
-
29
-
30
-
31
-
32
-
33
-
34
-
@@ -1,25 +0,0 @@
1
- import math
2
- import numpy as np
3
-
4
- n=int(input("Enter Number of inputs you want:"))
5
-
6
- weights = np.random.randn(n)
7
-
8
- bias = np.random.uniform(low=0.1, high=0.9)
9
-
10
- inputs = []
11
- for i in range(n):
12
- val = float(input(f"Enter your input: "))
13
- inputs.append(val)
14
-
15
- z=0
16
- for i in range(n):
17
- z += (inputs[i] * weights[i])
18
-
19
- z = z + bias
20
-
21
- binary_sigmoidal = 1 / (1 + np.exp(-z))
22
- bipolar_sigmoidal = 2 / (1 + np.exp(-z)) - 1
23
-
24
- print("Binary Sigmoidal = ", round(binary_sigmoidal, 3))
25
- print("Bipolar Sigmoidal = ", round(bipolar_sigmoidal, 3))
@@ -1,24 +0,0 @@
1
- #Mcclouch AND
2
-
3
- x1inputs = [0, 0, 1, 1]
4
- x2inputs = [0, 1, 0, 1]
5
-
6
- # Weights (excitatory)
7
- w1 = 1
8
- w2 = 1
9
-
10
- # Threshold(must be sum of weights to fire only when both inputs are 1)
11
- threshold = w1+w2
12
-
13
- print("x1 x2 sum Y")
14
- for x1, x2 in zip(x1inputs, x2inputs):
15
-
16
- addittion = x1 * w1 + x2 * w2
17
-
18
- # Apply threshold
19
- if addittion >= threshold:
20
- Y = 1
21
- else:
22
- Y = 0
23
-
24
- print(f"{x1} {x2} {addittion} {Y}")
@@ -1,24 +0,0 @@
1
- # McCulloch-Pitts OR
2
-
3
- x1inputs = [0, 0, 1, 1]
4
- x2inputs = [0, 1, 0, 1]
5
-
6
- # Weights (excitatory)
7
- w1 = 1
8
- w2 = 1
9
-
10
- # Threshold (must be 1 to fire when at least one input is 1)
11
- threshold = 1 # minimum excitatory input to fire
12
-
13
- print("x1 x2 sum Y")
14
- for x1, x2 in zip(x1inputs, x2inputs):
15
-
16
- addition = x1 * w1 + x2 * w2
17
-
18
- # Apply threshold
19
- if addition >= threshold:
20
- Y = 1
21
- else:
22
- Y = 0
23
-
24
- print(f"{x1} {x2} {addition} {Y}")
@@ -1,36 +0,0 @@
1
- '''XOR= '''
2
- ''' 0 if inputs are same,else 1'''
3
-
4
- x1inputs = [0, 0, 1, 1]
5
- x2inputs = [0, 1, 0, 1]
6
-
7
- print("x1 x2 Y")
8
-
9
- for x1, x2 in zip(x1inputs, x2inputs):
10
-
11
- # First layer neurons
12
- # Neuron1 = x1 AND NOT x2
13
- neuron1_sum = x1 * 1 + x2 * -1
14
- neuron1_threshold = 1
15
- if neuron1_sum >= neuron1_threshold:
16
- neuron1 = 1
17
- else:
18
- neuron1 = 0
19
-
20
- # Neuron2 = NOT x1 AND x2
21
- neuron2_sum = x1 * -1 + x2 * 1
22
- neuron2_threshold = 1
23
- if neuron2_sum >= neuron2_threshold:
24
- neuron2 = 1
25
- else:
26
- neuron2 = 0
27
-
28
- # Output neuron = Neuron1 OR Neuron2
29
- output_sum = neuron1 * 1 + neuron2 * 1
30
- output_threshold = 1
31
- if output_sum >= output_threshold:
32
- Y = 1
33
- else:
34
- Y = 0
35
-
36
- print(f"{x1} {x2} {Y}")
@@ -1,56 +0,0 @@
1
- import numpy as np
2
-
3
- # Sigmoid activation function
4
- def activate_function(x):
5
- return 1 / (1 + np.exp(-x))
6
-
7
- # Learning rate for Hebbian learning
8
- learning_rate = 0.1
9
-
10
- n = int(input("Enter number of inputs you want: "))
11
-
12
- weights = np.random.randn(n)
13
- bias = np.random.randn()
14
-
15
- print("\nInitial weights:", weights)
16
- print("Bias:", bias, "\n")
17
-
18
- inputs = []
19
- for i in range(n):
20
- val = float(input(f"Enter input {i+1}: "))
21
- inputs.append(val)
22
-
23
- inputs = np.array(inputs)
24
-
25
- y=0
26
- for i in range(n):
27
- y += (inputs[i] * weights[i])
28
-
29
- y = y + bias
30
- print("\nWeighted sum (z) before Hebbian update:", y)
31
-
32
- output = activate_function(y)
33
- print("Output before Hebbian update:", round(output, 3))
34
-
35
-
36
-
37
-
38
- #Hebbian Learning Rule
39
- target = round(output)
40
-
41
- # Update weights according to Hebb's rule
42
- weights += learning_rate * inputs
43
- bias += learning_rate
44
-
45
- print("\nWeights after Hebbian learning:", weights)
46
- print("Bias after Hebbian learning:", bias)
47
-
48
- #Compute new sum and output after learning
49
- for i in range(n):
50
- y += (inputs[i] * weights[i])
51
-
52
- y= y + bias
53
- output_new = activate_function(y)
54
-
55
- print("\nSum after Hebbian update:",y)
56
- print("Output after Hebbian update:",output)
@@ -1,63 +0,0 @@
1
- import numpy as np
2
-
3
- # Sigmoid activation function
4
- def activate_function(x):
5
- return 1 / (1 + np.exp(-x))
6
-
7
- # Learning rate
8
- learning_rate = 0.1
9
-
10
- n = int(input("Enter number of inputs you want: "))
11
-
12
- weights = np.random.randn(n)
13
- bias = np.random.randn()
14
-
15
- print("\nInitial weights:", weights)
16
- print("Bias:", bias, "\n")
17
-
18
- inputs = []
19
- for i in range(n):
20
- val = float(input(f"Enter input {i+1}: "))
21
- inputs.append(val)
22
-
23
- inputs = np.array(inputs)
24
-
25
- y = 0
26
- for i in range(n):
27
- y += (inputs[i] * weights[i])
28
-
29
- y = y + bias
30
- print("\nWeighted sum (z) before learning:", y)
31
-
32
- output = activate_function(y)
33
- print("Output before learning:",output)
34
-
35
-
36
-
37
-
38
-
39
-
40
- # -------- Delta Rule --------
41
- target = float(input("Enter target output (0 or 1): "))
42
-
43
- error = target - output
44
- print(error)
45
-
46
-
47
- # Update weights and bias using Delta rule
48
- weights += learning_rate * inputs*error
49
- bias += learning_rate
50
-
51
- print("\nWeights after Delta learning:", weights)
52
- print("Bias after Delta learning:", bias)
53
-
54
- #New sum and output after learning
55
- y = 0
56
- for i in range(n):
57
- y += (inputs[i] * weights[i])
58
-
59
- y = y + bias
60
- output = activate_function(y)
61
-
62
- print("\nSum after Delta update:", y)
63
- print("Output after Delta update:", output)
@@ -1,31 +0,0 @@
1
- import numpy as np
2
-
3
- # Activation function and derivative
4
- sig = lambda x: 1/(1+np.exp(-x))
5
- dsig = lambda x: x*(1-x)
6
-
7
- # Number of inputs
8
- n = int(input("Enter number of inputs: "))
9
-
10
- # Initialize weights and bias
11
- weights = np.random.randn(n)
12
- bias = np.random.rand()
13
-
14
- # User input
15
- inputs = np.array([float(input(f"Enter input {i+1}: ")) for i in range(n)])
16
- target = float(input("Enter target output: "))
17
-
18
- # Training
19
- lr = 0.1
20
- for _ in range(1000):
21
- out = sig(np.dot(inputs, weights) + bias)
22
- error = target - out
23
- delta = error * dsig(out)
24
- weights += lr * delta * inputs
25
- bias += lr * delta
26
-
27
- # Output
28
- out = sig(np.dot(inputs, weights) + bias)
29
- print("Trained output:", out)
30
- print("Trained weights:", weights)
31
- print("Trained bias:", bias)
@@ -1,34 +0,0 @@
1
- import numpy as np
2
-
3
- # Sigmoid and derivative
4
- sig = lambda x: 1/(1+np.exp(-x))
5
- dsig = lambda x: x*(1-x)
6
-
7
- # Number of inputs
8
- n = int(input("Enter number of inputs: "))
9
-
10
- # User inputs
11
- inputs = np.array([float(input(f"Enter input {i+1}: ")) for i in range(n)])
12
- target = float(input("Enter target output: "))
13
-
14
- # Initialize weights and bias
15
- weights = np.random.randn(n)
16
- bias = np.random.rand()
17
-
18
- # Learning rate and epochs
19
- lr = 0.1
20
- epochs = 1000
21
-
22
- # Training loop (backpropagation)
23
- for _ in range(epochs):
24
- out = sig(np.dot(inputs, weights) + bias) # Forward pass
25
- error = target - out
26
- delta = error * dsig(out)
27
- weights += lr * delta * inputs # Update weights
28
- bias += lr * delta # Update bias
29
-
30
- # Final output
31
- out = sig(np.dot(inputs, weights) + bias)
32
- print("Trained output:", out)
33
- print("Trained weights:", weights)
34
- print("Trained bias:", bias)
@@ -1,38 +0,0 @@
1
- import random
2
- cities = [
3
- [0, 0], # Kudal
4
- [-25, 0], # Malvan
5
- [0, -18], # Sawantwadi
6
- [0, 35], # Kanakavali
7
- [0, 65], # Vaibhavwadi
8
- [-35, 65], # Devgad
9
- [-20, -18] # Vengurle
10
- ]
11
-
12
- city_names = ["Kudal", "Malvan", "Sawantwadi", "Kanakavali", "Vaibhavwadi", "Devgad", "Vengurle"]
13
-
14
- neurons = 3 # number of clusters.
15
- learning_rate = 0.3
16
- epochs = 50
17
-
18
- # Initialize neuron positions randomly
19
- weights = [[random.uniform(-50, 70), random.uniform(-20, 70)] for _ in range(neurons)]
20
-
21
- #Training
22
- for _ in range(epochs):
23
- for city in cities:
24
- winner = min(range(neurons), key=lambda i: (city[0]-weights[i][0])**2 + (city[1]-weights[i][1])**2)
25
- for j in range(2):
26
- weights[winner][j] += learning_rate * (city[j] - weights[winner][j])
27
-
28
- # Print cluster centers
29
- print("Neuron positions (cluster centers):")
30
- for i, w in enumerate(weights):
31
- print(f"Neuron {i}: {w}")
32
-
33
- # Assign each city to its nearest neuron
34
- print("\nCity assignments:")
35
- for idx, city in enumerate(cities):
36
- nearest = min(range(neurons), key=lambda i: (city[0]-weights[i][0])**2 + (city[1]-weights[i][1])**2)
37
- print(f"{city_names[idx]} -> Cluster {nearest}")
38
-
@@ -1,25 +0,0 @@
1
- #membership function
2
- def fuzzy(x, a=4, b=7, c=10):
3
- if x <= a or x >= c:
4
- return 0
5
- elif x <= b:
6
- return (x - a) / (b - a)
7
- else:
8
- return (c - x) / (c - b)
9
-
10
- n = int(input("Enter number of shops: "))
11
- ratings = []
12
-
13
- # User input
14
- for i in range(n):
15
- ratings.append(float(input(f"Enter rating for Shop {i+1}: ")))
16
-
17
- # Fuzzification
18
- memberships = [fuzzy(r) for r in ratings]
19
- total = sum(memberships)
20
-
21
- # Fuzzy ratios
22
- print("\nShop Membership Fuzzy Ratio")
23
- for i in range(n):
24
- ratio = memberships[i] / total if total != 0 else 0
25
- print(f"{i+1:>3} {memberships[i]:.2f} {ratio:.2f}")
@@ -1,31 +0,0 @@
1
- def fuzzy(x, a, b, c):
2
- if x <= a or x >= c:
3
- return 0
4
- elif x <= b:
5
- return (x - a) / (b - a)
6
- else:
7
- return (c - x) / (c - b)
8
-
9
- # ---- User Input ----
10
- service = float(input("Enter service quality (0-10): "))
11
- food = float(input("Enter food quality (0-10): "))
12
-
13
- # ---- Fuzzification ----
14
- service_poor = fuzzy(service, 0, 0, 5)
15
- service_avg = fuzzy(service, 3, 5, 7)
16
- service_good = fuzzy(service, 5, 10, 10)
17
-
18
- food_bad = fuzzy(food, 0, 0, 5)
19
- food_avg = fuzzy(food, 3, 5, 7)
20
- food_good = fuzzy(food, 5, 10, 10)
21
-
22
- # ---- Rule Evaluation ----
23
- low_tip = max(service_poor, food_bad)
24
- medium_tip = service_avg
25
- high_tip = min(service_good, food_good)
26
-
27
- # ---- Defuzzification (Weighted Average) ----
28
- tip = (low_tip*5 + medium_tip*15 + high_tip*25) / \
29
- (low_tip + medium_tip + high_tip)
30
-
31
- print(f"\nRecommended Tip: {tip:.2f}%")
@@ -1,28 +0,0 @@
1
- # Initial values
2
- w1 = 0.5 # old weight
3
- w2 = -0.3 # old weight
4
- b = 0.2 # old bias
5
-
6
- # Inputs
7
- x1 = 1
8
- x2 = 0
9
-
10
- # Target and output
11
- t = 1 # target output
12
- y = 0 # actual output (predicted by neuron)
13
-
14
- # Learning rate
15
- eta = 0.1
16
-
17
- # Error
18
- error = t - y
19
-
20
- # Delta rule update
21
- w1_new = w1 + eta * error * x1
22
- w2_new = w2 + eta * error * x2
23
- b_new = b + eta * error
24
-
25
- # Print results
26
- print("Old w1:", w1, "-> New w1:", w1_new)
27
- print("Old w2:", w2, "-> New w2:", w2_new)
28
- print("Old b :", b, "-> New b :", b_new)
@@ -1,21 +0,0 @@
1
- import numpy as np
2
-
3
- X = np.array([[1,1,0,0],
4
- [1,0,0,0],
5
- [0,0,1,1],
6
- [0,0,1,0]])
7
-
8
- rho = 0.6
9
- clusters = []
10
-
11
- for x in X:
12
- for i, w in enumerate(clusters):
13
- if np.sum(x & w) / np.sum(x) >= rho:
14
- clusters[i] = x & w
15
- break
16
- else:
17
- clusters.append(x.copy())
18
-
19
- print("Clusters formed:", len(clusters))
20
- for i, c in enumerate(clusters):
21
- print("Cluster", i+1, ":", c)
@@ -1,19 +0,0 @@
1
- # Initial values
2
- w1 = 0.5 # old weight
3
- w2 = -0.3 # old weight
4
- b = 0.2 # old bias
5
-
6
- # Inputs
7
- x1 = 1
8
- x2 = 0
9
- y = 1 # target/output
10
-
11
- # Update rule
12
- w1_new = w1 + x1 * y
13
- w2_new = w2 + x2 * y
14
- b_new = b + y
15
-
16
- # Print results
17
- print("Old w1:", w1, "-> New w1:", w1_new)
18
- print("Old w2:", w2, "-> New w2:", w2_new)
19
- print("Old b :", b, "-> New b :", b_new)
@@ -1,25 +0,0 @@
1
- import numpy as np
2
-
3
- # 1. Store patterns (-1 and 1 only)
4
- p1 = np.array([1, -1, 1, -1])
5
- p2 = np.array([-1, 1, -1, 1])
6
- patterns = [p1, p2]
7
-
8
- # 2. Create weight matrix
9
- W = np.zeros((4, 4))
10
- for p in patterns:
11
- W += np.outer(p, p)
12
- np.fill_diagonal(W, 0)
13
-
14
- # 3. Recall function
15
- def recall(x):
16
- for _ in range(5): # update few times
17
- x = np.sign(W @ x)
18
- return x
19
-
20
- # 4. Noisy input
21
- test = np.array([1, -1, -1, -1])
22
-
23
- # 5. Output
24
- print("Noisy Input :", test)
25
- print("Recalled :", recall(test))
@@ -1,15 +0,0 @@
1
- # Take inputs from user
2
- x1 = float(input("Enter first input (x1): "))
3
- x2 = float(input("Enter second input (x2): "))
4
- b= float(input("Enter bias value : "))
5
-
6
-
7
- # Weights (fixed)
8
- w1 = 0.5
9
- w2 = 1.0
10
-
11
- # Linear Neural Network formula
12
- y = w1*x1 + w2*x2 + b
13
- print("The weights and biase are ",w1,w2,b)
14
-
15
- print("Output:", y)
@@ -1,16 +0,0 @@
1
- import numpy as np
2
- import matplotlib.pyplot as plt
3
-
4
- height = np.linspace(140, 190, 100)
5
- weight = 0.5 * height - 30
6
-
7
- plt.plot(height, weight)
8
- plt.title("Linear Separability: Boys vs Girls")
9
- plt.xlabel("Height (cm)")
10
- plt.ylabel("Weight (kg)")
11
-
12
- plt.text(150, 70, "Boys Region")
13
- plt.text(150, 30, "Girls Region")
14
-
15
- plt.grid(True)
16
- plt.show()
@@ -1,22 +0,0 @@
1
- print("---- Membership Operators ----")
2
-
3
- nums = [10, 20, 30]
4
- text = "Python"
5
- data = {"name": "Sam", "age": 22}
6
-
7
- print(nums,"\n",text,"\n",data)
8
-
9
- print("20 is present in 'nums' array :",20 in nums)
10
- print("40 is not present in 'nums' array :",40 not in nums)
11
-
12
- print("\n---- Identity Operators ----")
13
-
14
- a = [1, 2, 3]
15
- b = a
16
- c = [1, 2, 3]
17
-
18
- print(a is b)
19
- print(a is not b)
20
-
21
- print(a is c)
22
- print("Array 'a' has same elements like 'c' ",a == c)
@@ -1,22 +0,0 @@
1
- import math
2
-
3
- # Radial Basis Function (Gaussian)
4
- def rbf(x, c, sigma):
5
- return math.exp(-((x - c)**2) / (2 * sigma**2))
6
-
7
- # Hidden neurons centers
8
- centers = [1, 2, 3] # positions of RBF neurons
9
- sigma = 1.0 # width of Gaussian
10
-
11
- # Output weights
12
- weights = [0.5, -1.0, 0.8]
13
-
14
- # User input
15
- x = float(input("Enter input value: "))
16
-
17
- # Compute output
18
- y = 0
19
- for i in range(len(centers)):
20
- y += weights[i] * rbf(x, centers[i], sigma)
21
-
22
- print("RBF Network Output:", y)
@@ -1,34 +0,0 @@
1
- LICENCE
2
- README.md
3
- pyproject.toml
4
- setup.py
5
- DjPractLelo/__init__.py
6
- DjPractLelo/resource_loader.py
7
- DjPractLelo.egg-info/PKG-INFO
8
- DjPractLelo.egg-info/SOURCES.txt
9
- DjPractLelo.egg-info/dependency_links.txt
10
- DjPractLelo.egg-info/top_level.txt
11
- DjPractLelo/resources/data_science/practical_manual.docx
12
- DjPractLelo/resources/soft_computing/10a_simple_genetic algorithm.py
13
- DjPractLelo/resources/soft_computing/10b_genetic-algorithm-city.py
14
- DjPractLelo/resources/soft_computing/1a_simple_nueral.py
15
- DjPractLelo/resources/soft_computing/1b_binary_bipolar.py
16
- DjPractLelo/resources/soft_computing/2a_macclouch_AND.py
17
- DjPractLelo/resources/soft_computing/2b_macclouch_OR.py
18
- DjPractLelo/resources/soft_computing/2c_macclouch_XOR.py
19
- DjPractLelo/resources/soft_computing/3a_hebb_rule.py
20
- DjPractLelo/resources/soft_computing/3b_delta_rule.py
21
- DjPractLelo/resources/soft_computing/4a_back-prop.py
22
- DjPractLelo/resources/soft_computing/4b_back-prop-error.py
23
- DjPractLelo/resources/soft_computing/6a_kohonen_self.py
24
- DjPractLelo/resources/soft_computing/9a_ratios_fuzzy.py
25
- DjPractLelo/resources/soft_computing/9b_tipping problem.py
26
- DjPractLelo/resources/soft_computing/Delta Rule.py
27
- DjPractLelo/resources/soft_computing/adaptive-resonance.py
28
- DjPractLelo/resources/soft_computing/hebbs.py
29
- DjPractLelo/resources/soft_computing/hopfield.py
30
- DjPractLelo/resources/soft_computing/linear-neural-network.py
31
- DjPractLelo/resources/soft_computing/linear-seperability.py
32
- DjPractLelo/resources/soft_computing/membership-operators.py
33
- DjPractLelo/resources/soft_computing/practical_manual.docx
34
- DjPractLelo/resources/soft_computing/radial-basis-function.py
File without changes
File without changes
File without changes