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

Feedback #1

Open
wants to merge 4 commits into
base: feedback
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
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Open in Visual Studio Code](https://classroom.github.com/assets/open-in-vscode-2e0aaae1b6195c2367325f4f02e2d04e9abb55f0b24a779b69b11b9e10269abc.svg)](https://classroom.github.com/online_ide?assignment_repo_id=17425364&assignment_repo_type=AssignmentRepo)
# MiniTorch Module 0

<img src="https://minitorch.github.io/minitorch.svg" width="50%">
Expand Down
24 changes: 17 additions & 7 deletions minitorch/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,29 @@ def circle(N):


def spiral(N):

def x(t):
return t * math.cos(t) / 20.0

def y(t):
return t * math.sin(t) / 20.0
X = [(x(10.0 * (float(i) / (N // 2))) + 0.5, y(10.0 * (float(i) / (N //
2))) + 0.5) for i in range(5 + 0, 5 + N // 2)]
X = X + [(y(-10.0 * (float(i) / (N // 2))) + 0.5, x(-10.0 * (float(i) /
(N // 2))) + 0.5) for i in range(5 + 0, 5 + N // 2)]

X = [
(x(10.0 * (float(i) / (N // 2))) + 0.5, y(10.0 * (float(i) / (N // 2))) + 0.5)
for i in range(5 + 0, 5 + N // 2)
]
X = X + [
(y(-10.0 * (float(i) / (N // 2))) + 0.5, x(-10.0 * (float(i) / (N // 2))) + 0.5)
for i in range(5 + 0, 5 + N // 2)
]
y2 = [0] * (N // 2) + [1] * (N // 2)
return Graph(N, X, y2)


datasets = {'Simple': simple, 'Diag': diag, 'Split': split, 'Xor': xor,
'Circle': circle, 'Spiral': spiral}
datasets = {
"Simple": simple,
"Diag": diag,
"Split": split,
"Xor": xor,
"Circle": circle,
"Spiral": spiral,
}
88 changes: 87 additions & 1 deletion minitorch/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,98 @@
import math

# ## Task 0.1
from typing import Callable, Iterable

#
# Implementation of a prelude of elementary functions.


# Mathematical functions:
# - mul
def mul(x: float, y: float) -> float:
return x * y


# - id
def id(x: float) -> float:
return x


# - add
def add(x: float, y: float) -> float:
return x + y


# - neg
def neg(x: float) -> float:
return -x


# - lt
def lt(x: float, y: float) -> bool:
return x < y


# - eq
def eq(x: float, y: float) -> bool:
return x == y


# - max
def max(x: float, y: float) -> float:
return y if lt(x, y) else x


# - is_close
def is_close(x: float, y: float) -> bool:
return abs(x - y) <= 0.01


# - sigmoid
def sigmoid(x: float) -> float:
if x >= 0:
return 1.0 / (1.0 + math.e ** (-x))
else:
return math.e**x / (1.0 + math.e**x)


# - relu
def relu(x: float) -> float:
if x >= 0:
return x
else:
return 0


# - log
def log(x: float) -> float:
return math.log(x)


# - exp
def exp(x: float) -> float:
return math.e**x


# - log_back
def log_back(x: float, d: float) -> float:
return d * (1 / x)


# - inv
def inv(x: float) -> float:
return 1 / x


# - inv_back
def inv_back(x: float, d: float) -> float:
return -d / (x**2)


# - relu_back
def relu_back(x: float, d: float) -> float:
return d if x > 0 else 0


#
# For sigmoid calculate as:
# $f(x) = \frac{1.0}{(1.0 + e^{-x})}$ if x >=0 else $\frac{e^x}{(1.0 + e^{x})}$
Expand All @@ -44,11 +114,27 @@
# - zipWith
# - reduce
#


# Use these to implement
# - negList : negate a list
def negList(a: list) -> list:
return a


# - addLists : add two lists together
def addLists(a: list, b: list) -> list:
return a + b


# - sum: sum lists
def sum(a: list) -> float:
return a[0]


# - prod: take the product of lists
def prod(a: list) -> float:
return a[0]


# TODO: Implement for Task 0.3.
4 changes: 2 additions & 2 deletions requirements.extra.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
altair==4.2.2
datasets==2.4.0
embeddings==0.0.8
networkx==3.3
plotly==4.14.3
pydot==1.4.1
python-mnist
streamlit==1.12.0
streamlit-ace
torch
watchdog==1.0.2
altair==4.2.2
networkx==3.3
1 change: 0 additions & 1 deletion tests/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
prod,
relu,
relu_back,
sigmoid,
)

from .strategies import assert_close, small_floats
Expand Down