Skip to content

Commit

Permalink
Chapter 4, README updates
Browse files Browse the repository at this point in the history
  • Loading branch information
SethHWeidman committed Sep 16, 2019
1 parent 24f38eb commit 6e6fa2a
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 451 deletions.
364 changes: 266 additions & 98 deletions 04_extensions/Code.ipynb

Large diffs are not rendered by default.

414 changes: 65 additions & 349 deletions 04_extensions/Math.ipynb

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file removed 04_extensions/img/Log_loss_vs_MSE_y_eq_0.png
Binary file not shown.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ It was mostly for me to keep the code I was writing for the book organized, but
## Structure

Each chapter has two notebooks: a `Code` notebook and a `Math` notebook. Each `Code` notebook contains the Python code for corresponding chapter and can be run start to finish to generate the results from the chapters. The `Math` notebooks were just for me to store the LaTeX equations used in the book, taking advantage of Jupyter's LaTeX rendering functionality.

## `lincoln`

In the notebooks in the Chapters 4 and 5 folder, I import classes from `lincoln`, rather than putting those classes in the Jupyter Notebook itself. `lincoln` is not currently a `pip` installable library; th way I'd recommend to be able to `import` it and run these notebooks is to add a line like the following your `.bashrc` file:

```bash
export PYTHONPATH=$PYTHONPATH:/Users/seth/development/DLFS_code/lincoln
```

This will cause Python to search this path for a module called `lincoln` when you run the `import` command (of course, you'll have to replace the path above with the relevant path on your machine once you clone this repo). Then, simply `source` your `.bashrc` file before running the `jupyter notebook` command and you should be good to go.
3 changes: 1 addition & 2 deletions lincoln/lincoln/conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ def _output(self,

patches = self._get_image_patches(self.input_)

import pdb; pdb.set_trace()
patches_reshaped = (patches
.transpose(1, 0, 2, 3, 4)
.reshape(batch_size, img_size, -1))

param_reshaped = (self.param
.transpose(0, 2, 3, 1)
.reshape(patch_size, -1))
# import pdb; pdb.set_trace()

output_reshaped = (
np.matmul(patches_reshaped, param_reshaped)
.reshape(batch_size, img_height, img_height, -1)
Expand Down
6 changes: 4 additions & 2 deletions lincoln/lincoln/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ def _output(self) -> float:
self.softmax_preds = np.clip(softmax_preds, self.eps, 1 - self.eps)

# actual loss computation
softmax_cross_entropy_loss = -1.0 * self.target * np.log(self.softmax_preds) - \
(1.0 - self.target) * np.log(1 - self.softmax_preds)
softmax_cross_entropy_loss = (
-1.0 * self.target * np.log(self.softmax_preds) - \
(1.0 - self.target) * np.log(1 - self.softmax_preds)
)

return np.sum(softmax_cross_entropy_loss) / self.prediction.shape[0]

Expand Down

0 comments on commit 6e6fa2a

Please sign in to comment.