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

Including code snippets in Markdown #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

TikhonJelvis
Copy link
Owner

I found a package called pandoc-include-code that, well, does exactly what it says it does.

With this package, we can define named snippets in a .py file:

# start snippet iterate
from typing import Callable, Iterator, TypeVar
X = TypeVar('X')


def iterate(step: Callable[[X], X], start: X) -> Iterator[X]:
    state = start

    while True:
        yield state
        state = step(state)
# end snippet iterate

then include them in .md files with the following syntax:

...an arbitrary domain $\mathcal{D}$.

```{.python include=./chapter4/__init__.py snippet=iterate}
```

The above function take...

This way, we can keep all the snippets for a chapter in an executable (and testable!) Python file, with updates to the code files automatically reflected in the generated PDF.

I did this to a couple of snippets in chapter4.py as an example. I'm not sure this is the best way to organize the code and tests, but it seems like a good start. We can always iterate on this as we go along, and I would be comfortable forking and editing the pandoc-include-code package if we want different or more complicated behavior.

We could even include snippets from the rl/*.py files directly, but I'm not sure that's a good idea—the code might need extra details and complexity over time that isn't needed in the book itself.

@TikhonJelvis
Copy link
Owner Author

Once this is merged, it should work from any new Nix shells you open for this project. The change depends on #60 (which I'm going to merge shortly), so the first time you do it, the Nix shell might take a while to start while it's downloading and installing packages in the background.

I haven't tested this on macOS, so there might be some bugs on your computer!

@@ -61,7 +61,7 @@ This jargon overload is due to the confluence of terms from Control Theory (emer

It is also important to recognize that Reinforcement Learning is considered to be a branch of Machine Learning. While there is no crisp definition for *Machine Learning* (ML), ML generally refers to the broad set of techniques to infer mathematical models/functions by acquiring ("learning") knowledge of patterns and properties in the presented data. In this regard, Reinforcement Learning does fit this definition. However, unlike the other branches of ML (Supervised Learning and Unsupervised Learning), Reinforcement Learning is a lot more ambitious - it not only learns the patterns and properties of the presented data (internally building a model of the data), it also learns about the appropriate behaviors to be exercised (appropriate decisions to be made) so as to drive towards the optimization objective. It is sometimes said that Supervised Learning and Unsupervised learning are about "minimization" (i.e., they minimize the fitting error of a model to the presented data), while Reinforcement Learning is about "maximization" (i.e., RL also identifies the suitable decisions to be made to maximize a well-defined objective). Figure \ref{fig:ml_branches} depicts the in-vogue classification of Machine Learning.

![Branches of Machine Learning \label{fig:ml_branches}](./chapter0/BranchesofML.jpg "Branches of Machine Learning")
![Branches of Machine Learning \label{fig:ml_branches}](./chapter0/BranchesOfML.jpg "Branches of Machine Learning")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed a typo here. It worked fine on your computer because macOS doesn't care about cases in filenames, but Linux is case sensitive so it caused an error for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant