Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,9 @@
* Forecasting
* [Run](machine_learning/forecasting/run.py)
* [Frequent Pattern Growth](machine_learning/frequent_pattern_growth.py)
* [Gaussian Naive Bayes](machine_learning/gaussian_naive_bayes.py)
* [Gradient Boosting Classifier](machine_learning/gradient_boosting_classifier.py)
* [Gradient Boosting Regressor](machine_learning/gradient_boosting_regressor.py)
* [Gradient Descent](machine_learning/gradient_descent.py)
* [K Means Clust](machine_learning/k_means_clust.py)
* [K Nearest Neighbours](machine_learning/k_nearest_neighbours.py)
Expand All @@ -685,6 +687,8 @@
* [Multilayer Perceptron Classifier](machine_learning/multilayer_perceptron_classifier.py)
* [Polynomial Regression](machine_learning/polynomial_regression.py)
* [Principle Component Analysis](machine_learning/principle_component_analysis.py)
* [Random Forest Classifier](machine_learning/random_forest_classifier.py)
* [Random Forest Regressor](machine_learning/random_forest_regressor.py)
* [Scoring Functions](machine_learning/scoring_functions.py)
* [Self Organizing Map](machine_learning/self_organizing_map.py)
* [Sequential Minimum Optimization](machine_learning/sequential_minimum_optimization.py)
Expand Down Expand Up @@ -923,6 +927,7 @@
* [Back Propagation Neural Network](neural_network/back_propagation_neural_network.py)
* [Convolution Neural Network](neural_network/convolution_neural_network.py)
* [Input Data](neural_network/input_data.py)
* [Perceptron](neural_network/perceptron.py)
* [Simple Neural Network](neural_network/simple_neural_network.py)
* [Two Hidden Layers Neural Network](neural_network/two_hidden_layers_neural_network.py)

Expand Down Expand Up @@ -975,6 +980,7 @@
* [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py)
* [Malus Law](physics/malus_law.py)
* [Mass Energy Equivalence](physics/mass_energy_equivalence.py)
* [Maxwells Equations](physics/maxwells_equations.py)
* [Mirror Formulae](physics/mirror_formulae.py)
* [N Body Simulation](physics/n_body_simulation.py)
* [Newtons Law Of Gravitation](physics/newtons_law_of_gravitation.py)
Expand Down
1 change: 1 addition & 0 deletions cellular_automata/conways_game_of_life.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def generate_images(cells: list[list[int]], frames: int) -> list[Image.Image]:
# Create output image
img = Image.new("RGB", (len(cells[0]), len(cells)))
pixels = img.load()
assert pixels is not None

# Save cells to image
for x in range(len(cells)):
Expand Down
1 change: 1 addition & 0 deletions cellular_automata/one_dimensional.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def generate_image(cells: list[list[int]]) -> Image.Image:
# Create the output image
img = Image.new("RGB", (len(cells[0]), len(cells)))
pixels = img.load()
assert pixels is not None
# Generates image
for w in range(img.width):
for h in range(img.height):
Expand Down
5 changes: 2 additions & 3 deletions data_structures/binary_tree/non_recursive_segment_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from __future__ import annotations

from collections.abc import Callable
from typing import Any, TypeVar
from typing import Any, TypeVar, cast

Check failure on line 42 in data_structures/binary_tree/non_recursive_segment_tree.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F401)

data_structures/binary_tree/non_recursive_segment_tree.py:42:20: F401 `typing.Any` imported but unused help: Remove unused import: `typing.Any`

Check failure on line 42 in data_structures/binary_tree/non_recursive_segment_tree.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F401)

data_structures/binary_tree/non_recursive_segment_tree.py:42:20: F401 `typing.Any` imported but unused help: Remove unused import: `typing.Any`

T = TypeVar("T")

Expand All @@ -57,10 +57,9 @@
... lambda a, b: (a[0] + b[0], a[1] + b[1])).query(0, 2)
(6, 9)
"""
any_type: Any | T = None

self.N: int = len(arr)
self.st: list[T] = [any_type for _ in range(self.N)] + arr
self.st: list[T] = [cast(T,None) for _ in range(self.N)] + arr
self.fn = fnc
self.build()

Expand Down
2 changes: 2 additions & 0 deletions data_structures/heap/binomial_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def insert(self, val):
if val < self.min_node.val:
self.min_node = new_node
# Put new_node as a bottom_root in heap
assert self.bottom_root is not None
self.bottom_root.left = new_node
new_node.parent = self.bottom_root
self.bottom_root = new_node
Expand Down Expand Up @@ -283,6 +284,7 @@ def delete_min(self):

# Update bottom root
self.bottom_root = self.bottom_root.parent
assert self.bottom_root is not None
self.bottom_root.left = None

# Update min_node
Expand Down
29 changes: 24 additions & 5 deletions data_structures/linked_list/doubly_linked_list.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
"""
https://en.wikipedia.org/wiki/Doubly_linked_list
"""
from __future__ import annotations

from typing import Any


class Node:
def __init__(self, data):
def __init__(self, data: Any):
self.data = data
self.previous = None
self.next = None
self.previous: Node | None = None
self.next: Node | None = None

def __str__(self):
return f"{self.data}"


class DoublyLinkedList:
def __init__(self):
self.head = None
self.tail = None
self.head: Node | None = None
self.tail: Node | None = None

def __iter__(self):
"""
Expand Down Expand Up @@ -93,13 +96,18 @@ def insert_at_nth(self, index: int, data):
new_node.next = self.head
self.head = new_node
elif index == length:
assert self.tail is not None
self.tail.next = new_node
assert self.tail is not None
new_node.previous = self.tail
self.tail = new_node
else:
temp = self.head
assert temp is not None
for _ in range(index):
temp = temp.next
assert temp is not None
assert temp.previous is not None
temp.previous.next = new_node
new_node.previous = temp.previous
new_node.next = temp
Expand Down Expand Up @@ -141,23 +149,32 @@ def delete_at_nth(self, index: int):
if length == 1:
self.head = self.tail = None
elif index == 0:
assert self.head is not None
self.head = self.head.next
assert self.head is not None
self.head.previous = None
elif index == length - 1:
assert self.tail is not None
delete_node = self.tail
self.tail = self.tail.previous
assert self.tail is not None
self.tail.next = None
else:
temp = self.head
assert temp is not None
for _ in range(index):
temp = temp.next
assert temp is not None
delete_node = temp
assert temp.next is not None
assert temp.previous is not None
temp.next.previous = temp.previous
temp.previous.next = temp.next
return delete_node.data

def delete(self, data) -> str:
current = self.head
assert current is not None

while current.data != data: # Find the position to delete
if current.next:
Expand All @@ -172,6 +189,8 @@ def delete(self, data) -> str:
self.delete_tail()

else: # Before: 1 <--> 2(current) <--> 3
assert current.previous is not None
assert current.next is not None
current.previous.next = current.next # 1 --> 3
current.next.previous = current.previous # 1 <--> 3
return data
Expand Down
11 changes: 9 additions & 2 deletions data_structures/linked_list/singly_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self):
>>> linked_list.head is None
True
"""
self.head = None
self.head: Node | None = None

def __iter__(self) -> Iterator[Any]:
"""
Expand Down Expand Up @@ -153,8 +153,10 @@ def __setitem__(self, index: int, data: Any) -> None:
if not 0 <= index < len(self):
raise ValueError("list index out of range.")
current = self.head
assert current is not None
for _ in range(index):
current = current.next_node
assert current is not None
current.data = data

def insert_tail(self, data: Any) -> None:
Expand Down Expand Up @@ -215,8 +217,10 @@ def insert_nth(self, index: int, data: Any) -> None:
self.head = new_node
else:
temp = self.head
assert temp is not None
for _ in range(index - 1):
temp = temp.next_node
assert temp is not None
new_node.next_node = temp.next_node
temp.next_node = new_node

Expand Down Expand Up @@ -316,10 +320,13 @@ def delete_nth(self, index: int = 0) -> Any:
self.head = self.head.next_node
else:
temp = self.head
assert temp is not None
for _ in range(index - 1):
temp = temp.next_node
assert temp is not None
delete_node = temp.next_node
temp.next_node = temp.next_node.next_node
assert delete_node is not None
temp.next_node = delete_node.next_node
return delete_node.data

def is_empty(self) -> bool:
Expand Down
1 change: 1 addition & 0 deletions fractals/mandelbrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def get_image(
"""
img = Image.new("RGB", (image_width, image_height))
pixels = img.load()
assert pixels is not None

# loop through the image-coordinates
for image_x in range(image_width):
Expand Down
2 changes: 1 addition & 1 deletion machine_learning/automatic_differentiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
"""

# partial derivatives with respect to target
partial_deriv = defaultdict(lambda: 0)
partial_deriv: defaultdict[Variable, np.ndarray] = defaultdict(lambda: np.array(0))

Check failure on line 261 in machine_learning/automatic_differentiation.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E501)

machine_learning/automatic_differentiation.py:261:89: E501 Line too long (91 > 88)

Check failure on line 261 in machine_learning/automatic_differentiation.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E501)

machine_learning/automatic_differentiation.py:261:89: E501 Line too long (91 > 88)
partial_deriv[target] = np.ones_like(target.to_ndarray())

# iterating through each operations in the computation graph
Expand Down
2 changes: 1 addition & 1 deletion networking_flow/minimum_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def mincut(graph: list[list[int]], source: int, sink: int) -> list[tuple[int, in
parent = [-1] * (len(residual))
res = []
while bfs(residual, source, sink, parent):
path_flow = float("inf")
path_flow = max(max(row) for row in residual)
s = sink

while s != source:
Expand Down
1 change: 1 addition & 0 deletions neural_network/input_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import os
import typing
import urllib
import urllib.request

import numpy as np
from tensorflow.python.framework import dtypes, random_seed
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ environment.python-version = "3.14"
rules.call-non-callable = "ignore"
rules.deprecated = "ignore"
rules.invalid-argument-type = "ignore"
rules.invalid-assignment = "ignore"
rules.invalid-parameter-default = "ignore"
rules.invalid-return-type = "ignore"
rules.invalid-type-arguments = "ignore"
Expand Down
5 changes: 4 additions & 1 deletion scheduling/cpuschedulingalgorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,10 @@ def add_process(self) -> None:
def delete_process(self) -> None:
"""Deletes a selected process."""
if sel := self.tree.selection():
pid = self.tree.item(sel[0])["values"][0]
values = self.tree.item(sel[0])["values"]
if not values:
return
pid = values[0]
self.processes = [p for p in self.processes if p["pid"] != pid]
self.tree.delete(sel[0])

Expand Down
Loading