Skip to content

Commit 4708b84

Browse files
committed
merge.
2 parents ee1c3a0 + 3e202df commit 4708b84

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
lines changed

.flake8

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@
44
#########################
55
[flake8]
66
ignore =
7-
S101 # asserts are ok when testing.
8-
S301 # pickle
9-
S403 # pickle
7+
# asserts are ok when testing.
8+
S101
9+
# pickle
10+
S301
11+
# pickle
12+
S403
1013
S404
1114
S603
12-
W503 # Line break before binary operator (flake8 is wrong)
13-
E203 # Ignore the spaces black puts before columns.
14-
E402 # allow path extensions for testing.
15+
# Line break before binary operator (flake8 is wrong)
16+
W503
17+
# Ignore the spaces black puts before columns.
18+
E203
19+
# allow path extensions for testing.
20+
E402
1521
DAR101
1622
DAR201
17-
N400 # flake and pylance disagree on linebreaks in strings.
23+
# flake and pylance disagree on linebreaks in strings.
24+
N400
1825
exclude =
1926
.tox,
2027
.git,
@@ -34,4 +41,4 @@ max-complexity = 20
3441
import-order-style = pycharm
3542
application-import-names =
3643
seleqt
37-
tests
44+
tests

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The problem is illustrated below:
1616
![parabola_task](./figures/parabola_task.png)
1717

1818

19-
- Next we consider a paraboloid, $\cdot$ denots the scalar product,
19+
- Next we consider a paraboloid, $\cdot$ denotes the scalar product,
2020

2121
$$ \min_{\mathbf{x}} \mathbf{x} \cdot \mathbf{x}, \text{ with } \mathbf{x_0} = (2.9, -2.9) .$$
2222

@@ -27,7 +27,7 @@ Once more the problem is illustrated below:
2727
![paraboloid_task](./figures/paraboloid_task.png)
2828

2929

30-
- Additionally we consider a bumpy paraboloid, $\cdot$ denots the scalar product,
30+
- Additionally we consider a bumpy paraboloid, $\cdot$ denotes the scalar product,
3131

3232
$$ \min_{\mathbf{x}} \mathbf{x} \cdot \mathbf{x} + \cos(2 \pi x_0) + \sin(2 \pi x_1 ), \text{ with } \mathbf{x_0} = (2.9, -2.9) .$$
3333

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
nox
22
numpy
33
matplotlib
4-
torch
4+
torch

src/optimize_2d_momentum_bumpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def bumpy_grad(pos: np.ndarray) -> np.ndarray:
6464
step_total = 1 # TODO: Choose the total number of steps.
6565

6666
pos_list = [start_pos]
67-
grad = np.array((0.0, 0.0))
67+
velocity_vec = np.array((0.0, 0.0))
6868
# TODO implement gradient descent with momentum.
6969

7070
for pos in pos_list:

src/optimize_2d_momentum_bumpy_torch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def bumpy_function(pos: th.Tensor) -> th.Tensor:
5757
step_total = 100
5858

5959
pos_list = [start_pos]
60-
grad = np.array((0.0, 0.0))
60+
velocity_vec = np.array((0.0, 0.0))
6161
# TODO: Implement gradient descent with momentum.
6262

6363
for pos in pos_list:

src/util.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,19 @@ def write_movie(
2626
name (str, optional): The name of the movie file. Defaults to "grad_movie".
2727
xlim (int, optional): Largest x value in the data. Defaults to 3.
2828
ylim (int, optional): Largest y value in the data. Defaults to 3.
29+
30+
Raises:
31+
RuntimeError: If conda ffmpeg package is not installed.
2932
"""
30-
ffmpeg_writer = manimation.writers["ffmpeg"]
33+
try:
34+
ffmpeg_writer = manimation.writers["ffmpeg"]
35+
except RuntimeError:
36+
raise RuntimeError(
37+
"RuntimeError: If you are using anaconda or miniconda there might "
38+
"be a missing package named ffmpeg. Try installing it with "
39+
"'conda install -c conda-forge ffmpeg' in your terminal."
40+
)
41+
3142
metadata = dict(
3243
title="Gradient descent", artist="Matplotlib", comment="Minimization movie!"
3344
)

tests/test_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_grad_parabola(pos):
7070
np.array((2.9, 2.9)),
7171
),
7272
)
73-
def test_gard_paraboloid(pos):
73+
def test_grad_paraboloid(pos):
7474
"""Test the paraboloid gradient."""
7575
nabla_x = grad_paraboloid(pos)
7676
fd_nabla_x = finite_difference(paraboloid, pos)

0 commit comments

Comments
 (0)