randomcode 0.1.0__py3-none-any.whl

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 (59) hide show
  1. randomcode/__init__.py +0 -0
  2. randomcode/anthropic.py +30 -0
  3. randomcode/anyscale.py +23 -0
  4. randomcode/azure_openai.py +23 -0
  5. randomcode/azureml_endpoint.py +30 -0
  6. randomcode/baichuan.py +23 -0
  7. randomcode/baidu_qianfan_endpoint.py +27 -0
  8. randomcode/base_language.py +7 -0
  9. randomcode/bedrock.py +27 -0
  10. randomcode/cache.py +72 -0
  11. randomcode/cohere.py +23 -0
  12. randomcode/databricks.py +23 -0
  13. randomcode/env.py +17 -0
  14. randomcode/ernie.py +23 -0
  15. randomcode/everlyai.py +23 -0
  16. randomcode/example_generator.py +5 -0
  17. randomcode/fake.py +30 -0
  18. randomcode/fireworks.py +23 -0
  19. randomcode/formatting.py +5 -0
  20. randomcode/gigachat.py +23 -0
  21. randomcode/google_palm.py +30 -0
  22. randomcode/human.py +23 -0
  23. randomcode/hunyuan.py +23 -0
  24. randomcode/input.py +15 -0
  25. randomcode/javelin_ai_gateway.py +30 -0
  26. randomcode/jinachat.py +23 -0
  27. randomcode/konko.py +23 -0
  28. randomcode/litellm.py +30 -0
  29. randomcode/meta.py +25 -0
  30. randomcode/minimax.py +23 -0
  31. randomcode/mlflow.py +23 -0
  32. randomcode/mlflow_ai_gateway.py +30 -0
  33. randomcode/ollama.py +23 -0
  34. randomcode/openai.py +23 -0
  35. randomcode/pai_eas_endpoint.py +25 -0
  36. randomcode/promptlayer_openai.py +25 -0
  37. randomcode/python.py +19 -0
  38. randomcode/requests.py +35 -0
  39. randomcode/s1.py +28 -0
  40. randomcode/s10.py +56 -0
  41. randomcode/s2.py +49 -0
  42. randomcode/s3.py +37 -0
  43. randomcode/s4.py +19 -0
  44. randomcode/s5.py +28 -0
  45. randomcode/s6.py +44 -0
  46. randomcode/s7.py +46 -0
  47. randomcode/s8.py +53 -0
  48. randomcode/s9.py +45 -0
  49. randomcode/serpapi.py +25 -0
  50. randomcode/sql_database.py +25 -0
  51. randomcode/tongyi.py +23 -0
  52. randomcode/vertexai.py +23 -0
  53. randomcode/volcengine_maas.py +30 -0
  54. randomcode/yandex.py +23 -0
  55. randomcode-0.1.0.dist-info/METADATA +84 -0
  56. randomcode-0.1.0.dist-info/RECORD +59 -0
  57. randomcode-0.1.0.dist-info/WHEEL +5 -0
  58. randomcode-0.1.0.dist-info/licenses/LICENSE.txt +7 -0
  59. randomcode-0.1.0.dist-info/top_level.txt +1 -0
randomcode/litellm.py ADDED
@@ -0,0 +1,30 @@
1
+ from typing import TYPE_CHECKING, Any
2
+
3
+ from langchain._api import create_importer
4
+
5
+ if TYPE_CHECKING:
6
+ from langchain_community.chat_models.litellm import (
7
+ ChatLiteLLM,
8
+ ChatLiteLLMException,
9
+ )
10
+
11
+ # Create a way to dynamically look up deprecated imports.
12
+ # Used to consolidate logic for raising deprecation warnings and
13
+ # handling optional imports.
14
+ DEPRECATED_LOOKUP = {
15
+ "ChatLiteLLM": "langchain_community.chat_models.litellm",
16
+ "ChatLiteLLMException": "langchain_community.chat_models.litellm",
17
+ }
18
+
19
+ _import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
20
+
21
+
22
+ def __getattr__(name: str) -> Any:
23
+ """Look up attributes dynamically."""
24
+ return _import_attribute(name)
25
+
26
+
27
+ __all__ = [
28
+ "ChatLiteLLM",
29
+ "ChatLiteLLMException",
30
+ ]
randomcode/meta.py ADDED
@@ -0,0 +1,25 @@
1
+ from typing import TYPE_CHECKING, Any
2
+
3
+ from langchain._api import create_importer
4
+
5
+ if TYPE_CHECKING:
6
+ from langchain_community.chat_models.meta import convert_messages_to_prompt_llama
7
+
8
+ # Create a way to dynamically look up deprecated imports.
9
+ # Used to consolidate logic for raising deprecation warnings and
10
+ # handling optional imports.
11
+ DEPRECATED_LOOKUP = {
12
+ "convert_messages_to_prompt_llama": "langchain_community.chat_models.meta",
13
+ }
14
+
15
+ _import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
16
+
17
+
18
+ def __getattr__(name: str) -> Any:
19
+ """Look up attributes dynamically."""
20
+ return _import_attribute(name)
21
+
22
+
23
+ __all__ = [
24
+ "convert_messages_to_prompt_llama",
25
+ ]
randomcode/minimax.py ADDED
@@ -0,0 +1,23 @@
1
+ from typing import TYPE_CHECKING, Any
2
+
3
+ from langchain._api import create_importer
4
+
5
+ if TYPE_CHECKING:
6
+ from langchain_community.chat_models.minimax import MiniMaxChat
7
+
8
+ # Create a way to dynamically look up deprecated imports.
9
+ # Used to consolidate logic for raising deprecation warnings and
10
+ # handling optional imports.
11
+ DEPRECATED_LOOKUP = {"MiniMaxChat": "langchain_community.chat_models.minimax"}
12
+
13
+ _import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
14
+
15
+
16
+ def __getattr__(name: str) -> Any:
17
+ """Look up attributes dynamically."""
18
+ return _import_attribute(name)
19
+
20
+
21
+ __all__ = [
22
+ "MiniMaxChat",
23
+ ]
randomcode/mlflow.py ADDED
@@ -0,0 +1,23 @@
1
+ from typing import TYPE_CHECKING, Any
2
+
3
+ from langchain._api import create_importer
4
+
5
+ if TYPE_CHECKING:
6
+ from langchain_community.chat_models.mlflow import ChatMlflow
7
+
8
+ # Create a way to dynamically look up deprecated imports.
9
+ # Used to consolidate logic for raising deprecation warnings and
10
+ # handling optional imports.
11
+ DEPRECATED_LOOKUP = {"ChatMlflow": "langchain_community.chat_models.mlflow"}
12
+
13
+ _import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
14
+
15
+
16
+ def __getattr__(name: str) -> Any:
17
+ """Look up attributes dynamically."""
18
+ return _import_attribute(name)
19
+
20
+
21
+ __all__ = [
22
+ "ChatMlflow",
23
+ ]
@@ -0,0 +1,30 @@
1
+ from typing import TYPE_CHECKING, Any
2
+
3
+ from langchain._api import create_importer
4
+
5
+ if TYPE_CHECKING:
6
+ from langchain_community.chat_models.mlflow_ai_gateway import (
7
+ ChatMLflowAIGateway,
8
+ ChatParams,
9
+ )
10
+
11
+ # Create a way to dynamically look up deprecated imports.
12
+ # Used to consolidate logic for raising deprecation warnings and
13
+ # handling optional imports.
14
+ DEPRECATED_LOOKUP = {
15
+ "ChatMLflowAIGateway": "langchain_community.chat_models.mlflow_ai_gateway",
16
+ "ChatParams": "langchain_community.chat_models.mlflow_ai_gateway",
17
+ }
18
+
19
+ _import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
20
+
21
+
22
+ def __getattr__(name: str) -> Any:
23
+ """Look up attributes dynamically."""
24
+ return _import_attribute(name)
25
+
26
+
27
+ __all__ = [
28
+ "ChatMLflowAIGateway",
29
+ "ChatParams",
30
+ ]
randomcode/ollama.py ADDED
@@ -0,0 +1,23 @@
1
+ from typing import TYPE_CHECKING, Any
2
+
3
+ from langchain._api import create_importer
4
+
5
+ if TYPE_CHECKING:
6
+ from langchain_community.chat_models.ollama import ChatOllama
7
+
8
+ # Create a way to dynamically look up deprecated imports.
9
+ # Used to consolidate logic for raising deprecation warnings and
10
+ # handling optional imports.
11
+ DEPRECATED_LOOKUP = {"ChatOllama": "langchain_community.chat_models.ollama"}
12
+
13
+ _import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
14
+
15
+
16
+ def __getattr__(name: str) -> Any:
17
+ """Look up attributes dynamically."""
18
+ return _import_attribute(name)
19
+
20
+
21
+ __all__ = [
22
+ "ChatOllama",
23
+ ]
randomcode/openai.py ADDED
@@ -0,0 +1,23 @@
1
+ from typing import TYPE_CHECKING, Any
2
+
3
+ from langchain._api import create_importer
4
+
5
+ if TYPE_CHECKING:
6
+ from langchain_community.chat_models.openai import ChatOpenAI
7
+
8
+ # Create a way to dynamically look up deprecated imports.
9
+ # Used to consolidate logic for raising deprecation warnings and
10
+ # handling optional imports.
11
+ DEPRECATED_LOOKUP = {"ChatOpenAI": "langchain_community.chat_models.openai"}
12
+
13
+ _import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
14
+
15
+
16
+ def __getattr__(name: str) -> Any:
17
+ """Look up attributes dynamically."""
18
+ return _import_attribute(name)
19
+
20
+
21
+ __all__ = [
22
+ "ChatOpenAI",
23
+ ]
@@ -0,0 +1,25 @@
1
+ from typing import TYPE_CHECKING, Any
2
+
3
+ from langchain._api import create_importer
4
+
5
+ if TYPE_CHECKING:
6
+ from langchain_community.chat_models.pai_eas_endpoint import PaiEasChatEndpoint
7
+
8
+ # Create a way to dynamically look up deprecated imports.
9
+ # Used to consolidate logic for raising deprecation warnings and
10
+ # handling optional imports.
11
+ DEPRECATED_LOOKUP = {
12
+ "PaiEasChatEndpoint": "langchain_community.chat_models.pai_eas_endpoint",
13
+ }
14
+
15
+ _import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
16
+
17
+
18
+ def __getattr__(name: str) -> Any:
19
+ """Look up attributes dynamically."""
20
+ return _import_attribute(name)
21
+
22
+
23
+ __all__ = [
24
+ "PaiEasChatEndpoint",
25
+ ]
@@ -0,0 +1,25 @@
1
+ from typing import TYPE_CHECKING, Any
2
+
3
+ from langchain._api import create_importer
4
+
5
+ if TYPE_CHECKING:
6
+ from langchain_community.chat_models.promptlayer_openai import PromptLayerChatOpenAI
7
+
8
+ # Create a way to dynamically look up deprecated imports.
9
+ # Used to consolidate logic for raising deprecation warnings and
10
+ # handling optional imports.
11
+ DEPRECATED_LOOKUP = {
12
+ "PromptLayerChatOpenAI": "langchain_community.chat_models.promptlayer_openai",
13
+ }
14
+
15
+ _import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
16
+
17
+
18
+ def __getattr__(name: str) -> Any:
19
+ """Look up attributes dynamically."""
20
+ return _import_attribute(name)
21
+
22
+
23
+ __all__ = [
24
+ "PromptLayerChatOpenAI",
25
+ ]
randomcode/python.py ADDED
@@ -0,0 +1,19 @@
1
+ """For backwards compatibility."""
2
+
3
+ from typing import Any
4
+
5
+ from langchain._api import create_importer
6
+
7
+ # Code has been removed from the community package as well.
8
+ # We'll proxy to community package, which will raise an appropriate exception,
9
+ # but we'll not include this in __all__, so it won't be listed as importable.
10
+
11
+ _importer = create_importer(
12
+ __package__,
13
+ deprecated_lookups={"PythonREPL": "langchain_community.utilities.python"},
14
+ )
15
+
16
+
17
+ def __getattr__(name: str) -> Any:
18
+ """Look up attributes dynamically."""
19
+ return _importer(name)
randomcode/requests.py ADDED
@@ -0,0 +1,35 @@
1
+ """DEPRECATED: Kept for backwards compatibility."""
2
+
3
+ from typing import TYPE_CHECKING, Any
4
+
5
+ from langchain._api import create_importer
6
+
7
+ if TYPE_CHECKING:
8
+ from langchain_community.utilities import (
9
+ Requests,
10
+ RequestsWrapper,
11
+ TextRequestsWrapper,
12
+ )
13
+
14
+ # Create a way to dynamically look up deprecated imports.
15
+ # Used to consolidate logic for raising deprecation warnings and
16
+ # handling optional imports.
17
+ DEPRECATED_LOOKUP = {
18
+ "Requests": "langchain_community.utilities",
19
+ "RequestsWrapper": "langchain_community.utilities",
20
+ "TextRequestsWrapper": "langchain_community.utilities",
21
+ }
22
+
23
+ _import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
24
+
25
+
26
+ def __getattr__(name: str) -> Any:
27
+ """Look up attributes dynamically."""
28
+ return _import_attribute(name)
29
+
30
+
31
+ __all__ = [
32
+ "Requests",
33
+ "RequestsWrapper",
34
+ "TextRequestsWrapper",
35
+ ]
randomcode/s1.py ADDED
@@ -0,0 +1,28 @@
1
+ %Performing Union, Intersection and Complement Operations
2
+
3
+ clc;
4
+ clear;
5
+
6
+ u = input('Enter the membership values of First Fuzzy set: ');
7
+ v = input('Enter the membership values of Second Fuzzy set: ');
8
+
9
+ if length(u) ~= length(v)
10
+ error('Both fuzzy sets must have the same number');
11
+ end
12
+
13
+ w = max(u, v);
14
+ p = min(u, v);
15
+ q1 = 1 - u;
16
+ q2 = 1 - v;
17
+
18
+ disp('Union of Two Fuzzy sets:');
19
+ disp(w);
20
+
21
+ disp('Intersection of Two Fuzzy sets:');
22
+ disp(p);
23
+
24
+ disp('Complement of First Fuzzy set:');
25
+ disp(q1);
26
+
27
+ disp('Complement of Second Fuzzy set:');
28
+ disp(q2);
randomcode/s10.py ADDED
@@ -0,0 +1,56 @@
1
+ # Genetic Algorithm – II
2
+
3
+ import random
4
+
5
+ weights = [2, 3, 4, 5]
6
+ values = [6, 10, 12, 13]
7
+ capacity = 8
8
+
9
+ POP_SIZE = 6
10
+ GENES = len(weights)
11
+ GENERATIONS = 15
12
+ MUT_RATE = 0.1
13
+
14
+ population = [[random.randint(0, 1) for _ in range(GENES)]
15
+ for _ in range(POP_SIZE)]
16
+
17
+ def fitness(chrom):
18
+ total_weight = 0
19
+ total_value = 0
20
+ for i in range(GENES):
21
+ if chrom[i] == 1:
22
+ total_weight += weights[i]
23
+ total_value += values[i]
24
+ if total_weight > capacity:
25
+ return 0
26
+ return total_value
27
+
28
+ for gen in range(GENERATIONS):
29
+
30
+ fit_vals = [fitness(c) for c in population]
31
+ best_fit = max(fit_vals)
32
+ best_idx = fit_vals.index(best_fit)
33
+
34
+ print("Gen", gen+1,
35
+ "Best =", population[best_idx],
36
+ "Value =", best_fit)
37
+
38
+ new_pop = []
39
+
40
+ for _ in range(POP_SIZE):
41
+ a, b = random.sample(range(POP_SIZE), 2)
42
+ winner = population[a] if fit_vals[a] > fit_vals[b] else population[b]
43
+ new_pop.append(winner[:])
44
+
45
+ for i in range(0, POP_SIZE, 2):
46
+ if random.random() < 0.8:
47
+ cp = random.randint(1, GENES - 1)
48
+ new_pop[i][:cp], new_pop[i+1][:cp] = \
49
+ new_pop[i+1][:cp], new_pop[i][:cp]
50
+
51
+ for i in range(POP_SIZE):
52
+ for j in range(GENES):
53
+ if random.random() < MUT_RATE:
54
+ new_pop[i][j] ^= 1
55
+
56
+ population = new_pop
randomcode/s2.py ADDED
@@ -0,0 +1,49 @@
1
+ %Implementation of De Morgan’s Law
2
+
3
+ clc;
4
+ clear;
5
+
6
+ u = input('Enter the membership values of first fuzzy set: ');
7
+ v = input('Enter the membership values of second fuzzy set: ');
8
+
9
+ if length(u) ~= length(v)
10
+ error('Both fuzzy sets must have the same number');
11
+ end
12
+
13
+ w = max(u, v);
14
+ p = min(u, v);
15
+ q1 = 1 - u;
16
+ q2 = 1 - v;
17
+
18
+ x1 = 1 - w;
19
+ x2 = min(q1, q2);
20
+
21
+ y1 = 1 - p;
22
+ y2 = max(q1, q2);
23
+
24
+ disp('Union of two fuzzy sets (max operation)');
25
+ disp(w);
26
+
27
+ disp('Intersection of two fuzzy sets (min operation)');
28
+ disp(p);
29
+
30
+ disp('Complement of first fuzzy set');
31
+ disp(q1);
32
+
33
+ disp('Complement of second fuzzy set');
34
+ disp(q2);
35
+
36
+ disp('De Morgan Law Verification');
37
+
38
+ disp('1) Complement of Maximum = Minimum of Complements');
39
+ disp('LHS:');
40
+ disp(x1);
41
+ disp('RHS:');
42
+ disp(x2);
43
+
44
+ disp('2) Complement of Minimum = Maximum of Complements');
45
+ disp('LHS:');
46
+ disp(y1);
47
+ disp('RHS:');
48
+ disp(y2);
49
+
randomcode/s3.py ADDED
@@ -0,0 +1,37 @@
1
+ % Plotting Various Membership Functions
2
+
3
+ clc;
4
+ clear;
5
+ close all;
6
+
7
+ figure;
8
+
9
+ x = 0:1:10;
10
+ y1 = trimf(x, [1 3 5]);
11
+
12
+ subplot(3,1,1);
13
+ plot(x, y1, 'LineWidth', 2);
14
+ title('Triangular Membership Function');
15
+ xlabel('x');
16
+ ylabel('Membership Value');
17
+ grid on;
18
+
19
+ x = 0:1:10;
20
+ y2 = trapmf(x, [1 3 5 7]);
21
+
22
+ subplot(3,1,2);
23
+ plot(x, y2, 'LineWidth', 2);
24
+ title('Trapezoidal Membership Function');
25
+ xlabel('x');
26
+ ylabel('Membership Value');
27
+ grid on;
28
+
29
+ x = 0:0.2:10;
30
+ y3 = gbellmf(x, [3 5 7]);
31
+
32
+ subplot(3,1,3);
33
+ plot(x, y3, 'LineWidth', 2);
34
+ title('Bell Shaped Membership Function');
35
+ xlabel('x');
36
+ ylabel('Membership Value');
37
+ grid on;
randomcode/s4.py ADDED
@@ -0,0 +1,19 @@
1
+ % Using Fuzzy toolbox to model tips value
2
+
3
+ Quality: {not good, satisfying, delightful}
4
+ Service: {poor, average, good}
5
+
6
+
7
+ Type fuzzy in MATLAB to open FIS Editor.
8
+
9
+ Add two inputs:
10
+ Quality: not_good, satisfied, delicious
11
+ Service: poor, average, good
12
+
13
+ Add one output:
14
+
15
+ Tip: less, medium, high (Range 10–100)
16
+ Assign triangular (trimf) membership functions for all variables.
17
+ Create rules in Rules Editor.
18
+ View results in Rule Viewer and test the system.
19
+ Save and exit.
randomcode/s5.py ADDED
@@ -0,0 +1,28 @@
1
+ % Implementation of Fuzzy Inference System
2
+
3
+ # INPUTS
4
+
5
+ Temperature: {Freeze, Cool, Warm and Hot}
6
+ Cloud Cover: {Sunny, Partly Cloudy and Overcast}
7
+
8
+ #rules
9
+
10
+ Sunny (Cover) and Warm (Temp) -> Fast (Speed)
11
+ Cloudy (Cover) and Cool (Temp) -> Slow (Speed)
12
+
13
+
14
+ Type fuzzy in MATLAB.
15
+
16
+ Add inputs:
17
+ Temperature: Freezing, Cool, Warm, Hot
18
+ Cloud Cover: Sunny, Partly Cloudy, Overcast
19
+
20
+ Add output:
21
+ Speed: Slow, Fast
22
+
23
+ Assign appropriate trimf/trapmf membership functions.
24
+ Add rules:
25
+
26
+ Sunny & Warm → Fast
27
+ Overcast & Cool → Slow
28
+ View in Rule Viewer and save.
randomcode/s6.py ADDED
@@ -0,0 +1,44 @@
1
+ % Simple Fuzzy Set Operations
2
+
3
+ clc;
4
+ clear;
5
+
6
+ a = input('Enter the fuzzy set A: ');
7
+ b = input('Enter the fuzzy set B: ');
8
+
9
+ if length(a) ~= length(b)
10
+ error('Both fuzzy sets must have the same number of elements');
11
+ end
12
+
13
+ c = a + b;
14
+ d = a .* b;
15
+
16
+ as = c - d;
17
+ e = 1 - b;
18
+ ad = a .* e;
19
+
20
+ f = a - b;
21
+
22
+ bs = min(1, c);
23
+ bd = max(0, f);
24
+
25
+ g = c - 1;
26
+ bp = max(0, g);
27
+
28
+ disp('The algebraic sum:');
29
+ disp(as);
30
+
31
+ disp('The algebraic difference:');
32
+ disp(ad);
33
+
34
+ disp('The algebraic product:');
35
+ disp(d);
36
+
37
+ disp('The bounded sum:');
38
+ disp(bs);
39
+
40
+ disp('The bounded difference:');
41
+ disp(bd);
42
+
43
+ disp('The bounded product:');
44
+ disp(bp);
randomcode/s7.py ADDED
@@ -0,0 +1,46 @@
1
+ % Generation of ANDNOT function using McCulloch-Pitts neural net
2
+
3
+ clc;
4
+ clear;
5
+
6
+ disp('Enter weights');
7
+ w1 = input('w1 = ');
8
+ w2 = input('w2 = ');
9
+
10
+ disp('Enter threshold');
11
+ theta = input('theta = ');
12
+
13
+ x1 = [0 0 1 1];
14
+ x2 = [0 1 0 1];
15
+ target = [0 0 1 0];
16
+
17
+ while 1
18
+ zin = x1*w1 + x2*w2;
19
+ y = zeros(1,4);
20
+
21
+ for i = 1:4
22
+ if zin(i) >= theta
23
+ y(i) = 1;
24
+ else
25
+ y(i) = 0;
26
+ end
27
+ end
28
+
29
+ disp('Output = ');
30
+ disp(y);
31
+
32
+ if isequal(y, target)
33
+ break;
34
+ else
35
+ disp('Wrong weights. Enter again.');
36
+ w1 = input('w1 = ');
37
+ w2 = input('w2 = ');
38
+ theta = input('theta = ');
39
+ end
40
+ end
41
+
42
+ disp('McCulloch Pitts Net for ANDNOT');
43
+ disp('Weights:');
44
+ disp([w1 w2]);
45
+ disp('Threshold:');
46
+ disp(theta);
randomcode/s8.py ADDED
@@ -0,0 +1,53 @@
1
+ % Perceptron neural network
2
+
3
+ clc;
4
+ clear;
5
+
6
+ x = [ 1 1 -1 -1;
7
+ 1 -1 1 -1 ];
8
+
9
+ t = [1 -1 -1 -1];
10
+
11
+ w = [0 0];
12
+ b = 0;
13
+
14
+ alpha = input('Enter learning rate = ');
15
+ theta = input('Enter threshold = ');
16
+
17
+ epoch = 0;
18
+
19
+ while true
20
+ error_flag = 0;
21
+
22
+ for i = 1:4
23
+ yin = b + w * x(:,i);
24
+
25
+ if yin > theta
26
+ y = 1;
27
+ elseif yin < -theta
28
+ y = -1;
29
+ else
30
+ y = 0;
31
+ end
32
+
33
+ if y ~= t(i)
34
+ w = w + alpha * t(i) * x(:,i)';
35
+ b = b + alpha * t(i);
36
+ error_flag = 1;
37
+ end
38
+ end
39
+
40
+ epoch = epoch + 1;
41
+
42
+ if error_flag == 0
43
+ break;
44
+ end
45
+ end
46
+
47
+ disp('Perceptron for AND Function');
48
+ disp('Final Weights:');
49
+ disp(w);
50
+ disp('Final Bias:');
51
+ disp(b);
52
+ disp('Epochs:');
53
+ disp(epoch);