Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab0 1.3 Гусев НС #375

Open
wants to merge 23 commits into
base: lab0
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/pyad.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy scipy
pip install numpy scipy sklearn nltk surprise pickle pandas
- name: Run unittests
run: |
python -m unittest discover ${{ github.head_ref }}
50 changes: 42 additions & 8 deletions lab0/basic_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ def matrix_multiplication(matrix_a, matrix_b):
Задание 1. Функция для перемножения матриц с помощью списков и циклов.
Вернуть нужно матрицу в формате списка.
"""
# put your code here
pass
if len(matrix_a[0]) != len(matrix_b):
raise ValueError()

matrix_result = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))]

for i in range(len(matrix_a)):
for j in range(len(matrix_a[0])):
for k in range(len(matrix_b[0])):
matrix_result[i][k] += matrix_a[i][j] * matrix_b[j][k]
return matrix_result



def functions(a_1, a_2):
Expand All @@ -17,23 +26,48 @@ def functions(a_1, a_2):
Необходимо найти точки экстремума функции и определить, есть ли у функций общие решения.
Вернуть нужно координаты найденных решения списком, если они есть. None, если их бесконечно много.
"""
# put your code here
pass
if a_1 == a_2:
return None
a1, b1, c1 = map(int, a_1.split())
a2, b2, c2 = map(int, a_2.split())
a3, b3, c3 = (a1 - a2), (b1 - b2), (c1 - c2)

if a3 == 0:
if b3 == 0:
return []
x = -c3 / b3
return [(x, a3 * x ** 2 + b3 * x + c3)]
dis = b3 ** 2 - 4 * a3 * c3
if dis < 0:
return None
elif dis == 0:
x = -(b3 / (2 * a3))
return [int(x), int(a3 * x ** 2 + b3 * x + c3)]
sqrt_dis = int(math.sqrt(dis))
x_plus = int((-b3 + sqrt_dis) / (2 * a3))
x_minus = int((-b3 - sqrt_dis) / (2 * a3))
return [(x_plus, int(a1 * x_plus ** 2 + b1 * x_plus + c1)), (x_minus, int(a2 * x_minus ** 2 + b2 * x_minus + c2))]


def skew(x):
"""
Задание 3. Функция для расчета коэффициента асимметрии.
Необходимо вернуть значение коэффициента асимметрии, округленное до 2 знаков после запятой.
"""
# put your code here
pass
x_e = sum(x) / len(x)
sigma = (sum([(num - x_e) ** 2 for num in x]) / len(x)) ** 0.5
m_3 = sum([(num - x_e) ** 3 for num in x]) / len(x)
A_3 = m_3 / (sigma ** 3)
return round(A_3, 2)


def kurtosis(x):
"""
Задание 3. Функция для расчета коэффициента эксцесса.
Необходимо вернуть значение коэффициента эксцесса, округленное до 2 знаков после запятой.
"""
# put your code here
pass
x_e = sum(x) / len(x)
sigma = (sum([(num - x_e) ** 2 for num in x]) / len(x)) ** 0.5
m_4 = sum([(num - x_e) ** 4 for num in x]) / len(x)
E_4 = m_4 / (sigma ** 4) - 3
return round(E_4, 2)
4 changes: 2 additions & 2 deletions lab0/test_basic_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_skew(self):
x1 = [2,3,5,7,8]
x2 = [2,3,2,5,7,2,2,8]
self.assertEqual(basic_math.skew(x1), round(scipy.stats.skew(x1), 2))
self.assertEqual(basic_math.skew(x1), round(scipy.stats.skew(x2), 2))
self.assertEqual(basic_math.skew(x2), round(scipy.stats.skew(x2), 2))

random.seed(100)
random_floats = [random.random() for _ in range(10000)]
Expand All @@ -85,7 +85,7 @@ def test_kurtosis(self):
x1 = [2,3,5,7,8]
x2 = [2,3,2,5,7,2,2,8]
self.assertEqual(basic_math.kurtosis(x1), round(scipy.stats.kurtosis(x1), 2))
self.assertEqual(basic_math.kurtosis(x1), round(scipy.stats.kurtosis(x2), 2))
self.assertEqual(basic_math.kurtosis(x2), round(scipy.stats.kurtosis(x2), 2))

random.seed(100)
random_floats = [random.random() for _ in range(10000)]
Expand Down
Loading
Loading