Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e20f47b
simplex_met
MarksmanM Oct 19, 2019
b751379
simplex_met
MarksmanM Oct 19, 2019
5f985d8
simplex_method
MarksmanM Oct 19, 2019
53c9091
simplex_method
MarksmanM Oct 19, 2019
6620e9e
simplex_method
MarksmanM Oct 19, 2019
9fd78dd
simplex_method
MarksmanM Oct 19, 2019
8a6e557
simplex_method
MarksmanM Oct 19, 2019
7c21cc1
simplex_method
MarksmanM Oct 19, 2019
484df7e
simplex_method
MarksmanM Oct 19, 2019
3b8e6dd
simplex_method
MarksmanM Oct 19, 2019
c3541f4
simplex_method
MarksmanM Oct 19, 2019
babc60c
simplex_method
MarksmanM Oct 19, 2019
bf8df79
simplex_method
MarksmanM Oct 19, 2019
7160490
simplex_method
MarksmanM Oct 19, 2019
39bb9fb
simplex_method
MarksmanM Oct 19, 2019
a940328
simplex_method
MarksmanM Oct 19, 2019
638154d
simplex_method
MarksmanM Oct 19, 2019
8d05b9e
simplex_method
MarksmanM Oct 19, 2019
f050f85
simplex_method
MarksmanM Oct 19, 2019
b56fbc7
simplex_method_mb_done
MarksmanM Oct 19, 2019
b5f6638
simplex_method_done
MarksmanM Oct 19, 2019
b8686d8
simplex_method_done_fix
MarksmanM Oct 19, 2019
1a745f2
sat
MarksmanM Oct 20, 2019
8cc7d6c
Mon
MarksmanM Oct 24, 2019
05fd6b5
Wen
MarksmanM Oct 24, 2019
b71c816
Thu
MarksmanM Oct 24, 2019
a16dfd1
Delete Exercises_with_solutions.ipynb
MarksmanM Oct 24, 2019
c18ed66
Delete Exercises_with_solutions.ipynb
MarksmanM Oct 24, 2019
b5566bd
hw
MarksmanM Oct 31, 2019
2cc21d3
Merge branch 'homework_05_ml' of https://github.com/MarksmanM/Applied…
MarksmanM Oct 31, 2019
165ead0
hw_5_pls
MarksmanM Oct 31, 2019
ae9fbbd
wat
MarksmanM Oct 31, 2019
a11cbea
fixed
MarksmanM Nov 1, 2019
8a54345
fixed
MarksmanM Nov 1, 2019
a54be1e
fixed
MarksmanM Nov 1, 2019
7bb8f87
fixed
MarksmanM Nov 1, 2019
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
58 changes: 56 additions & 2 deletions homeworks/homework_05_ml/simplex_method.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!#!/usr/bin/env python
# coding: utf-8

import numpy as np
Expand All @@ -20,4 +20,58 @@ def simplex_method(a, b, c):
:param c: np.array, shape=(1, m)
:return x: np.array, shape=(1, m)
"""
raise NotImplementedError
n, m = a.shape
# Создадим симплекс-таблицу
# где кол-во строк это кол-во неравенств n + строка c взятая с противоположным знаком,
# а кол-во столбцов это кол-во переменных m + кол-во строк n + 2 столбца
sim_tab = np.zeros((n+1, m+n+2))
result = [0 for i in range(m)]
sim_tab[:-1, :m] = a
sim_tab[:, m+1:] = np.eye(n+1)
sim_tab[:-1, -1] = b
sim_tab[-1, : m] = c[:]*(-1)
dct = {}
while is_negative(sim_tab, m):
# Найдем индекс столбца, в последней строке которого хранится
# наибольший отрицательный элемент
piv_col = most_negative(sim_tab, m)
# Найдем индекс строки, где результат деления последнего столбца на
# элемент с индексом piv_col минимален
piv_row = smallest_quotient(sim_tab, piv_col)
dct[piv_row] = piv_col
sim_tab[piv_row][:] = sim_tab[piv_row] / sim_tab[piv_row][piv_col]
for i in range(n+1):
if i != piv_row:
sim_tab[i][:] = sim_tab[i][:] - sim_tab[piv_row][:]*sim_tab[i][piv_col]
for key, value in dct.items():
result[value] = sim_tab[key][-1]
return np.array(result)


def is_negative(sim_tab, m):
for i in range(m):
if sim_tab[-1][i] < 0:
return True
else:
return False


def most_negative(sim_tab, m):
p = 1
ind = -1
for i in range(m):
if sim_tab[-1][i] < p:
ind = i
p = sim_tab[-1][i]
return ind


def smallest_quotient(sim_tab, piv_col):
p = np.sum(sim_tab[:-1][-1])*100
ind = -1
for i in range(sim_tab.shape[0]-1):
k = sim_tab[i][sim_tab.shape[1]-1]/sim_tab[i][piv_col]
if k < p:
ind = i
p = k
return ind
32,562 changes: 32,562 additions & 0 deletions homeworks/homework_05_ml/Вторник/adult.data

Large diffs are not rendered by default.

577 changes: 577 additions & 0 deletions homeworks/homework_05_ml/Вторник/Вторник.ipynb

Large diffs are not rendered by default.

Loading