Skip to content

Commit

Permalink
worked on venv
Browse files Browse the repository at this point in the history
  • Loading branch information
carmelgafa committed Oct 11, 2024
1 parent 00ac45a commit 6d4852e
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 72 deletions.
11 changes: 0 additions & 11 deletions ml_algorithms.egg-info/PKG-INFO

This file was deleted.

41 changes: 0 additions & 41 deletions ml_algorithms.egg-info/SOURCES.txt

This file was deleted.

1 change: 0 additions & 1 deletion ml_algorithms.egg-info/dependency_links.txt

This file was deleted.

2 changes: 0 additions & 2 deletions ml_algorithms.egg-info/top_level.txt

This file was deleted.

Binary file removed ml_algorithms/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions ml_algorithms/src/algorithms/cnn/cnn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def convolution2d(x, kernel, bias, stride=1, padding=0):
"""
Convolution 2D
"""



Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ def gradient_descent(

a0 = 130
a1 = 19

a0_prev = a0
a1_prev = a1

data_set = pd.read_csv(filename, delimiter=',', index_col=False)

m = len(data_set)
epoch = 0

previous_cost = sys.float_info.max
gd_data = []


while True:
# calculate the hypothesis function for all training data
Expand Down Expand Up @@ -75,7 +75,7 @@ def gradient_descent(
a0_range=(125,175,0.5),
a1_range=(18,22,0.5),
gd_points = gd_data
)
)
return a0, a1

if __name__ == '__main__':
Expand All @@ -87,6 +87,7 @@ def gradient_descent(
epochs_threshold = 100000
costdifference_threshold = 0.00001
plot = True

a0, a1 = gradient_descent(filename, alpha, epochs_threshold, costdifference_threshold, plot)
print(f'a0: {a0:.3f}, a1: {a1:.3f}')
print(f'a0: {a0:.3f}, a1: {a1:.3f}')

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pandas as pd
from sklearn.preprocessing import StandardScaler



data_path=os.path.join(os.path.dirname(__file__),'..', 'data_generation', 'data_1f.csv')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from operator import index
from typing_extensions import _AnnotatedAlias
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib import cm

def plot_univariate_gd_analysis(file:str, a0_range:tuple, a1_range:tuple, gd_points:list, plot_slices=False):
def plot_univariate_gd_analysis(
file:str,
a0_range:tuple,
a1_range:tuple,
gd_points:list,
plot_slices=False):
'''
plot the costs surface and the gradient descent points
'''

# read the data set
Expand All @@ -31,7 +36,6 @@ def plot_univariate_gd_analysis(file:str, a0_range:tuple, a1_range:tuple, gd_poi
cost_row.append(cost)
costs.append(cost_row)


if plot_slices:

a0_mincost_idx = np.where(np.round(a0[0,:], 1)==150)
Expand All @@ -43,7 +47,7 @@ def plot_univariate_gd_analysis(file:str, a0_range:tuple, a1_range:tuple, gd_poi
plt.plot(a1_mincost, costs_mincosts)
plt.xlabel(r'$a_1$')
plt.ylabel(r'$J(150,a_1$)')

plt.show()


Expand Down Expand Up @@ -71,7 +75,15 @@ def plot_univariate_gd_analysis(file:str, a0_range:tuple, a1_range:tuple, gd_poi
plt.rcParams['text.usetex'] = True
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_surface(a0, a1, np.array(costs), rstride=1, cstride=1, cmap='cividis', edgecolor='none', alpha=0.5)
ax.plot_surface(
a0,
a1,
np.array(costs),
rstride=1,
cstride=1,
cmap='cividis',
edgecolor='none',
alpha=0.5)
ax.contour(a0, a1, np.array(costs), zdir='z', offset=-0.5, cmap=cm.coolwarm)
ax.plot(xx, yy, zz, 'r.--', alpha=1)
ax.set_xlabel(r'$a_0$')
Expand All @@ -84,7 +96,7 @@ def plot_univariate_gd_analysis(file:str, a0_range:tuple, a1_range:tuple, gd_poi

plot_univariate_gd_analysis(
file=os.path.join(os.path.dirname(__file__), 'data_generation', 'data_1f.csv'),
a0_range=(125,175,0.2),
a1_range=(18,22,0.2),
a0_range=(125,175,0.2),
a1_range=(18,22,0.2),
gd_points= [],
plot_slices=True)
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@

a_1 = (n*sum_xy - sum_x*sum_y)/(n*sum_x_sq - sum_x**2)


print(f'a_0: {a_0}, a_1: {a_1}')
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import matplotlib.pyplot as plt
import h5py
import scipy
from scipy import ndimage


def sigmoid(z):
"""
Expand Down

0 comments on commit 6d4852e

Please sign in to comment.