Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
donald-pinckney committed May 13, 2019
1 parent caa6265 commit f7789ae
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 73 deletions.
10 changes: 10 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"default": true,
"MD025": false,
"MD013": false,
"MD033": false,
"MD009": false,
"MD034": false,
"MD040": false,
"MD026": {"punctuation": ".,;:!"}
}
2 changes: 1 addition & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<!-- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface"> -->

{% if page.runOrEdit == true %}
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500" rel="stylesheet" type="text/css">
<link href="{{ site.baseurl }}/public/book_deps/fonts/SourceCodePro/source-code-pro.css" rel="stylesheet" type="text/css">

<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" href="{{ site.baseurl }}/public/book_deps/css/highlight.css">
Expand Down
2 changes: 1 addition & 1 deletion _includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h1>

<a class="horizontal-item sidebar-nav-item{% if page.url == blog_bu or page.layout == 'post' or page.layout == 'bookpost' %} active{% endif %}" href="{{ site.baseurl }}/blog/">Blog Posts</a>

<a class="horizontal-item sidebar-nav-item" href="{{ site.baseurl }}/books/tensorflow/book/">TensorFlow Guide</a>
<a class="horizontal-item sidebar-nav-item" href="{{ site.baseurl }}/books/tensorflow/book/ch1-setup/intro.html">TensorFlow Guide</a>

<div class="horizontal-item">
</div>
Expand Down
68 changes: 68 additions & 0 deletions _plugins/Runnable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@
require "rouge"
require "rouge/plugins/redcarpet"

class String
# colorization
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end

def red
colorize(31)
end

def green
colorize(32)
end

def yellow
colorize(33)
end

def blue
colorize(34)
end

def pink
colorize(35)
end

def light_blue
colorize(36)
end
end

class Runnable < Redcarpet::Render::HTML
include Rouge::Plugins::Redcarpet
# def image(link, title, alt)
Expand All @@ -13,6 +44,43 @@ class Runnable < Redcarpet::Render::HTML
# return "<figure>#{figure}#{caption}</figure>"
# end

def postprocess(doc)
# puts doc
if doc.include? "```"
raise "\nERROR: fenced code block not properly parsed!"
# return nil
end
return doc
end

def generate_id(str)
gen_id = basic_generate_id(str)
gen_id = 'section' if gen_id.empty?
@used_ids ||= {}
if @used_ids.key?(gen_id)
gen_id += "-#{@used_ids[gen_id] += 1}"
else
@used_ids[gen_id] = 0
end
return gen_id
end

# The basic version of the ID generator, without any special provisions for empty or unique
# IDs.
def basic_generate_id(str)
gen_id = str.gsub(/^[^a-zA-Z]+/, '')
gen_id.tr!('^a-zA-Z0-9 -', '')
gen_id.tr!(' ', '-')
gen_id.downcase!
gen_id
end

def header(text, level)
theId = generate_id(text)
tag = "h#{level}"
"<#{tag} id=\"#{theId}\">#{text}</#{tag}>"
end

RE_PATH = %r{path=(?<path>[^,]+)}
RE_SLICE = %r{slice=(?<slice>\d+)}

Expand Down
2 changes: 1 addition & 1 deletion _posts/idris/2019-03-26-idris-serverless.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ For details type :warranty.

## Exporting the Function to JavaScript

This is great, but we need a way to run this code on Google Cloud Functions. Fortunately, Idris provides a built-in compiler to JavaScript, so we can compile our Idris function above into JavaScript code, which Google Cloud Functions directly supports. However, we still need a way to access the incomming HTTP request object, and write a string to the response. Since both the request and response are actual JavaScript objects, the most convenient thing to do is write some wrapper JavaScript which calls our `hello` function.
This is great, but we need a way to run this code on Google Cloud Functions. Fortunately, Idris provides a built-in compiler to JavaScript, so we can compile our Idris function above into JavaScript code, which Google Cloud Functions directly supports. However, we still need a way to access the incoming HTTP request object, and write a string to the response. Since both the request and response are actual JavaScript objects, the most convenient thing to do is write some wrapper JavaScript which calls our `hello` function.

But to do this we need to make sure that JavaScript code can call our `hello` function. To do this we just need to add an `FFI_Export` declaration to the Idris code:

Expand Down
14 changes: 9 additions & 5 deletions _posts/metal/2018-07-05-metal-intro-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ subscribeName: Metal
---

# What is Metal, and why use it?

[Metal][metal website] is a powerful new GPU programming API designed by Apple. Originally it was announced in 2014 for iOS and claimed significant performance benefits over [OpenGL][opengl website], the standard 3D graphics API, and since 2014 it has gained the ability for general purpose GPU computation, cross-platform support between iOS and macOS, and other features. But what exactly is it, and how does it compare to OpenGL?

Both Metal and OpenGL are low-level APIs that provide programmable access to GPU hardware for 3D graphics. Both allow you to write code that will execute on the GPU to customize how 3D objects are rendered. However, OpenGL tends to hide the communication between the CPU and the GPU, whereas Metal requires you to explicitly program this communication.
Both Metal and OpenGL are low-level APIs that provide programmable access to GPU hardware for 3D graphics. Both allow you to write code that will execute on the GPU to customize how 3D objects are rendered. However, OpenGL tends to hide the communication between the CPU and the GPU, whereas Metal requires you to explicitly program this communication.

This gives us two advantages: first, it allows for greater efficiency in terms of CPU and GPU communication; and second it provides an excellent learning opportunity to understand how this low-level communication works. But don't let this scare you: while this might sound horribly complicated, it's actually quite elegant and enjoyable code to write.

Expand All @@ -22,6 +23,7 @@ Rendering a 2D multi-colored triangle is the hello world program for graphics, a
![End Goal Screenshot][screen1]

# Rough Sketch of Graphics Pipelines

3D graphics are generally described by geometry, which is usually specified by the **vertices** of triangles. These vertices are generated by code on the CPU, and then need to be sent over to the GPU for rendering. The vertex data will then be fed through a GPU pipeline, eventually resulting in a final image being rendered, which can then be displayed on screen:

![Basic GPU Pipeline][basic_pipeline]
Expand All @@ -31,13 +33,15 @@ In short, a **pipeline** is a series of pre-configured steps that the GPU hardwa
# Basic Setup and Clearing the Screen

## Creating a one window macOS app

Open Xcode (make sure to install the latest version of Xcode from the Mac App Store), make a new Xcode project, choose "Cocoa App" under "macOS", and hit next. Then, fill in whatever you want for the Product Name (I'll use `MetalIntro1`), choose Swift for the language, make sure Use Storyboards is checked, and Create Document-Based Application is *not* checked. My settings look like this:

![Project Settings][xcode1]

Then, hit Next, and save it somewhere. If you run the app (&#8984;R) then a single blank window should appear. This blank window is where we want to display our 3D graphics. Before we can write actual Metal code, we need a way for the 3D graphics to even appear in our window.

## Setting Up a MetalKit View

Everything visual in `macOS` is represented by a *view*, which concretely is a subclass of `NSView`. We need a view in our window in which we can display the results of the Metal graphics rendering. Apple provides a prebuilt view just for this purpose, `MTKView`, which we will take advantage of.

First, we need to add a `MTKView` to the window by modifying the Storyboard file, and then we need to configure it via code. Open `Main.storyboard`, select the root view of the view controller, and in the inspector panel change the class from `NSView` to `MTKView`, as shown below.
Expand All @@ -50,7 +54,7 @@ Now to configure the `MTKView` we need to write some initialization code in the
import Metal
import MetalKit
```

First we want to save the `MTKView` in a convenient variable, so add the following instance variable to the view controller class:

```swift
Expand Down Expand Up @@ -469,8 +473,8 @@ As described above, vertex data just stores information about each vertex. In th
```swift
// Create our vertex data
let vertices = [Vertex(color: [1, 0, 0, 1], pos: [-1, -1]),
Vertex(color: [0, 1, 0, 1], pos: [0, 1]),
Vertex(color: [0, 0, 1, 1], pos: [1, -1])]
Vertex(color: [0, 1, 0, 1], pos: [0, 1]),
Vertex(color: [0, 0, 1, 1], pos: [1, -1])]
```

If you are unsure how this vertex data relates to our final goal of drawing a triangle with red, green, and blue vertices, then I suggest getting our a piece of paper and sketching the positions of these vertices, and their colors.
Expand Down Expand Up @@ -629,6 +633,7 @@ For reference the complete sample project is [available for download here][proje
# Concluding Remarks

This post covered a lot of material; to recap, we saw how to:

1. Setup a MetalKit view in a native macOS app.
2. Manage a `MTLCommandQueue` and `MTLCommandBuffer` objects to send commands to the GPU.
3. Configure rendering properties using `MTLRenderPassDescriptor`.
Expand Down Expand Up @@ -660,7 +665,6 @@ What's really great and fun about graphics programming is that it is easy to exp
[pipeline_sketch]: /public/post_assets/metal/metal-intro-1/pipeline.png
[buffer_sketch]: /public/post_assets/metal/metal-intro-1/buffer.png


[screen1]: /public/post_assets/metal/metal-intro-1/screen1.png
[screen2]: /public/post_assets/metal/metal-intro-1/screen2.png
[screen3]: /public/post_assets/metal/metal-intro-1/screen3.png
Expand Down
2 changes: 0 additions & 2 deletions _posts/metal/2018-07-29-metal-intro-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ The problem of enforcing synchronization between the CPU and GPU is not unique t

[semaphore]: https://en.wikipedia.org/wiki/Semaphore_(programming)



[old_screen1]: /public/post_assets/metal/metal-intro-1/screen1.png
[old_project_link]: /public/post_assets/metal/metal-intro-1/MetalIntro1.zip

Expand Down
4 changes: 0 additions & 4 deletions _posts/ml/2019-05-02-tda.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ date: 2019-05-02
<link rel="stylesheet" href="/public/post_assets/tda/playground.css">
<link rel="stylesheet" href="/public/post_assets/tda/post.css">


The overall goal of Topological Data Analysis (TDA) is to be able to analyze topological features of data sets, often through computations of topological properties such as homology or via visualization. Here I will focus on the former technique, known as **persistent homology**, but I will briefly touch on the visualization aspect. Before jumping into the mathematical aspects I'll first give an overview of some motivations for TDA by both offering it as an alternative to typical statistical tools as well as showing some of the unique capabilities of TDA.

<div>
Expand Down Expand Up @@ -101,7 +100,6 @@ There have been further results that partially address some of these issues, of

To get a better intuition for why &#268;ech Complexes of point clouds \\(D\\) sampled from a topological space \\(X\\) fail to be homotopy equivalent to \\(X\\), we can look at visualizations of &#268;ech Complexes on sample data sets. Since &#268;ech Complexes can be quite high dimensional, we only visualize the 2-skeleton of the &#268;ech Complex. Below you can interact with a variety of sample data sets, and vary the parameter \\(\varepsilon\\) to see how it affects \\(\C_\e(D)^{(2)}\\).


<div id="playground"><div id="playground-canvas"></div><div id="data-menu"></div><div id="data-details"><div id="data-controls"><div id="data-options"></div><div id="tsne-options"></div></div><div id="data-description"><span></span></div></div></div>
<script src="/public/post_assets/tda/playground.js"></script>

Expand Down Expand Up @@ -212,7 +210,6 @@ The action of \\(t\\) is simply to shift each element up one gradation level by
</div>
The intuition is that we use multiplication by \\(t\\) to keep track of the number of times an element of a module is mapped through the linear persistence maps.


## Classification Theorem for \\(\mathbb{N}\\)-Persistence Modules

Showing that persistence modules are in correspondence with graded modules over \\(R[t]\\) opens the door to applying well-know classification theorems of graded modules. Unfortunately there is no simple classification when \\(R\\) is not a field, but for \\(R = F\\) a field, there exists a nice result:
Expand Down Expand Up @@ -301,7 +298,6 @@ Running this code produces the following plots:

In particular it shows the correct computation of the Betti numbers \\(\beta_0 = 2, \beta_1 = 2\\).


# References

<!-- Hello!! -->
Expand Down
1 change: 0 additions & 1 deletion books/pl/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Summary


- [Test](test.md)
1 change: 1 addition & 0 deletions books/tensorflow/src/ch1-setup/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Qualitatively, humans do not seem to comprehend the breed of a dog by performing
## So what can machine learning accomplish?

Lots! Machine learning is finding applications nearly everywhere, and it's still growing. Machine learning is full of constantly evolving research with new and exciting results, such as:

1. Image Synthesis with Semantic Manipulation of Images: <iframe width="340" height="315" src="https://www.youtube-nocookie.com/embed/3AIpPlzM_qs?rel=0" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>
2. [Natural Language Translation](https://research.googleblog.com/2016/09/a-neural-network-for-machine.html)
3. [Magically Enhancing Image Resolution](https://blog.deepsense.ai/using-deep-learning-for-single-image-super-resolution/)
Expand Down
15 changes: 13 additions & 2 deletions books/tensorflow/src/ch1-setup/linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,37 @@ On Linux TensorFlow has the ability to run your machine learning models on a GPU
## Installing Pip and Virtualenv

First, we need to install `pip`, and `virtualenv`. This should be easy using `apt-get`:

```bash
sudo apt-get install python3-pip python3-dev python-virtualenv
```

## Installing TensorFlow and friends

Virtualenv is an extremely easy and convenient way to install Python packages in a local and contained manner. The recommended way to install TensorFlow is by using `virtualenv`, since this ensures that the installation will be self-contained, and will not affect the rest of your system. Now, we need to create a new virtualenv:

```bash
# In this command, ~/tensorflow is the destination directory where the virtualenv will be created.
# In this command, ~/tensorflow is the destination directory where the virtualenv will be created.
# You can choose a different location if you prefer, but the rest of the installation tutorial will assume ~/tensorflow
python3 -m venv --system-site-packages ~/tensorflow
```

Then, we need to activate the virtualenv so we can install things inside it:

* If you are using `bash, sh, ksh, zsh`:

```bash
source ~/tensorflow/bin/activate
```

* If you are using `csh, tcsh`:

```bash
source ~/tensorflow/bin/activate.csh
```

* If you are cool and use `fish`:

```bash
source ~/tensorflow/bin/activate.fish
```
Expand All @@ -56,7 +64,7 @@ pip3 install --upgrade tensorflow-gpu # If installing WITH GPU support
In addition, we also install a few other Python packages that are useful for machine learning:

```bash
pip3 install --upgrade numpy # Used for linear algebra. Essential for using TensorFlow
pip3 install --upgrade numpy # Used for linear algebra. Essential for using TensorFlow
pip3 install --upgrade matplotlib # Used for plotting data, which is very useful for machine learning
pip3 install --upgrade pandas # Used for loading data sets
```
Expand All @@ -66,6 +74,7 @@ Once everything is installed, you can exit the virtualenv using the command `dea
## Testing the installation

Let's just quickly test the installation, to verify everything is installed and ready to go! If it isn't currently activated, activate your virtualenv with the appropriate activate command from above. Then, run the `python` command, and type the following code into Python:

```python
import tensorflow as tf
import numpy as np
Expand All @@ -75,7 +84,9 @@ hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
```

If everything is installed correctly, you should see the output:

```
Hello, TensorFlow!
```
Expand Down
Loading

0 comments on commit f7789ae

Please sign in to comment.