Skip to content

Commit e797fd8

Browse files
Initial commit
1 parent 6079a2e commit e797fd8

File tree

9 files changed

+134
-59
lines changed

9 files changed

+134
-59
lines changed

.github/workflows/classroom.yml

Lines changed: 0 additions & 59 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
solution.py

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
# Deep Learning In Python - Week 1
3+
4+
<img src="https://github.com/hannesrosenbusch/DLIP_Week1/blob/main/assets/uvalogo.svg.png?raw=true" width="125"> <img src="https://github.com/hannesrosenbusch/DLIP_Week1/blob/main/assets/pythonlogo.jpeg?raw=true" width="380">
5+
6+
7+
An introduction to Python can be seen here: <br>
8+
[Python for R users](https://youtube.com/playlist?list=PLq0cz82QvYapppmpXPYgS76VbHHKRIgbk)
9+
10+
# Steps for Completing the Assignment
11+
12+
## Step 1
13+
Make a github account if you don't have one already.
14+
15+
## Step 2:
16+
Clone this github repository onto your laptop via a terminal, or use google colab, or kaggle...anywhere where you can edit python code.
17+
There are plenty of online resources which demo how to clone a repo e.g. here: https://www.earthdatascience.org/workshops/intro-version-control-git/basic-git-commands.
18+
(Notice that you need to install python if you decide to work on your laptop)
19+
20+
## Step 3:
21+
Edit the tasks.py file by filling in your solution code.
22+
Run the file to see whether you have errors.
23+
You can also run the grading files to preview whether your solution passes, but you are not allowed to change these files.
24+
25+
## Step 4:
26+
Add this week's kaggle certificate(s) to the repository (course: https://www.kaggle.com/learn/python ; https://www.kaggle.com/learn/pandas). If you received more than one certificate for this week, combine them into one pdf before. Name the file `certificate.pdf`
27+
28+
29+
## Step 5:
30+
Push your changes to the repo back to github. The grading will occur automatically but might take a minute.
31+
Again, the add/commit/push workflow of github is explained in various places online: https://www.earthdatascience.org/workshops/intro-version-control-git/basic-git-commands)

assets/pythonlogo.jpeg

5.26 KB
Loading

assets/uvalogo.svg.png

49.6 KB
Loading

grade_task1.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import numpy as np
2+
from tasks import step
3+
4+
# Test cases for Task 1: step function
5+
def test_step_positive():
6+
assert step(5) == 1, "Failed on positive input"
7+
8+
def test_step_negative():
9+
assert step(-3) == -1, "Failed on negative input"
10+
11+
def test_step_zero():
12+
assert step(0) == -1, "Failed on zero input"

grade_task2.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import numpy as np
2+
from tasks import step, ReLU
3+
4+
5+
def test_relu_default_cutoff():
6+
array = np.array([-5, 0, 3, -2, 4])
7+
expected_output = np.array([0, 0, 3, 0, 4])
8+
np.testing.assert_array_equal(ReLu(array.copy()), expected_output, "Failed on default cutoff")
9+
10+
def test_relu_custom_cutoff():
11+
array = np.array([-5, 0, 3, -2, 4])
12+
expected_output = np.array([2, 2, 3, 2, 4])
13+
np.testing.assert_array_equal(ReLu(array.copy(), 2), expected_output, "Failed on custom cutoff")
14+
15+
def test_relu_empty_array():
16+
array = np.array([])
17+
expected_output = np.array([])
18+
np.testing.assert_array_equal(ReLu(array.copy()), expected_output, "Failed on empty array")
19+
20+

grade_task3.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import numpy as np
2+
from tasks import step, ReLu, neural_net_layer
3+
4+
def test_neural_net_layer_basic():
5+
inputs = np.array([[1, 2], [3, 4]])
6+
weights = np.array([1, -1])
7+
expected_output = np.array([0, 0]) # (1*1 + 2*(-1)) = -1 -> 0 (after ReLu), (3*1 + 4*(-1)) = -1 -> 0 (after ReLu)
8+
np.testing.assert_array_equal(neural_net_layer(inputs, weights), expected_output, "Failed on basic 2D array")
9+
10+
def test_neural_net_layer_custom():
11+
inputs = np.array([[2, 3], [1, 1]])
12+
weights = np.array([1, 2])
13+
expected_output = np.array([8, 3]) # (2*1 + 3*2) = 8, (1*1 + 1*2) = 3
14+
np.testing.assert_array_equal(neural_net_layer(inputs, weights), expected_output, "Failed on different inputs")
15+
16+
def test_neural_net_layer_with_negatives():
17+
inputs = np.array([[1, -1], [-2, 3]])
18+
weights = np.array([-2, 1])
19+
expected_output = np.array([0, 7]) # ReLu([-3, 7]) = [0, 7]
20+
np.testing.assert_array_equal(neural_net_layer(inputs, weights), expected_output, "Failed on negative matrix values")

tasks.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import numpy
2+
3+
# Follow the tasks below to practice basic Python concepts.
4+
# Write your code in between the dashed lines.
5+
# Don't import additional packages. Numpy suffices.
6+
7+
# Task 1:
8+
# Instructions:
9+
#Write a function that takes one numeric argument as input.
10+
#If the number is larger than zero, the function should return 1, otherwise is should return -1.
11+
#The name of the function should be step
12+
13+
# Your code here:
14+
# -----------------------------------------------
15+
16+
def step
17+
18+
19+
# -----------------------------------------------
20+
21+
22+
# Task 2:
23+
# Instructions:
24+
#Write a function that takes in two arguments: a numpy array, and an integer (call argument "cutoff" and set default to 0).
25+
#The function should return a numpy array of the same length, with all elements smaller than the cutoff being set to cutoff).
26+
#The name of the function should be ReLu
27+
28+
29+
# Your code here:
30+
# -----------------------------------------------
31+
def ReLu
32+
33+
34+
# -----------------------------------------------
35+
36+
37+
# Task 3:
38+
# Instructions:
39+
#Write a function that takes in a two-dimensional numpy array of size (n, p) and a one-dimensional numpy array of size p.
40+
#The function should start by multiplying the two numpy arrays (matrix multiplication).
41+
#Next, apply the ReLu function from above to the resulting matrix and return the result.
42+
#Name the function neural_net_layer
43+
44+
# Your code here:
45+
# -----------------------------------------------
46+
47+
def neural_net_layer
48+
49+
50+
# ------------------------------------------

0 commit comments

Comments
 (0)