The videos above were generated using the same script described in an earlier post.

The number of channels was changed from 1 to 3 to add color.

The resolution was changed to `4096×2160`

(with corresponding updates to `XLIM`

and `YLIM`

).

The first video uses a `RENDER_SEED`

of `338`

and the second video uses `45`

. Unlike the video in the earlier post, these videos were generated using a GPU. A fixed seed value will have different results on CPU and GPU.

RENDER_SEED = 338 ... DEVICE = "cuda" ... XRES = 4096 YRES = 2160 XLIM = np.array([-1.0, 1.0]) YLIM = XLIM * (float(YRES) / XRES) ... CHANNELS = 3]]>

The video above was generated using neuralart.

The neural network takes position coordinates, distance to origin, and a vector **z** as inputs, and outputs a corresponding pixel intensity. The weights are randomly initialized. This configuration is described in more detail in the following blog posts and pages from studio otoro.

- Neural Network Generative Art in Javascript
- Generating Abstract Patterns with TensorFlow
- Neurogram
- Interactive Neural Network Art

The video frames are generated by transitioning the **z** input. In an earlier experiment, I tried varying **z** by transitioning along a straight line. The corresponding video is included in an earlier post. I also tried using a random walk, but found that there was too much back-and-forth motion this way.

The video above transitions **z** by walking along randomly generated cubic Bézier curves. The curves are connected, and the first handle of each curve has the same slope as the last handle of the preceding curve, in order to achieve smooth transitions across curves. Binary search is used so that the distance of each step along the curve is approximately fixed.

Here’s the source code.

]]>It’s based on the following blog posts and pages from studio otoro.

- Neural Network Generative Art in Javascript
- Generating Abstract Patterns with TensorFlow
- Neurogram
- Interactive Neural Network Art

The package is available on PyPI, the Python Package Index. It can be installed with *pip*.

$ pip install neuralart

For example command line usage, see neuralart#example.

For example library usage, see example.py.

]]>*echo* is a Unix utility that prints its arguments to standard output.

*printenv* is a Unix utility that prints the environment to standard output.

The core functionality of these programs can be written in a few lines of C, where program arguments and the environment are passed as function arguments to *main*.

When a process is executed on Linux (or other Unix-like systems), its stack contains pointers to the program arguments and the environment, as shown below.

|--------------------------| Low 0(%esp) | Argument Count | Addresses |--------------------------| 4(%esp) | Argument Pointers | | ... | |--------------------------| | 0 | |--------------------------| | Environment Pointers | | ... | |--------------------------| | 0 | |--------------------------| | Additional Data | | ... | High |--------------------------| Addresses

The stack grows downward in memory. That is, the *top* of the stack has the lowest memory address. When a program is executed, the top of the process stack contains 1) the argument count (conventionally referred to as *argc* in source code), followed by 2) pointers to the argument strings, 3) zero, 4) pointers to the environment strings, 5) zero, and 6) additional data (including the data that the argument/environment pointers reference).

*echo* and *printenv* can be implemented in assembly language by traversing the stack and printing out the relevant strings.

Both assembly programs have a helper macro, *print*, for writing to standard output. They also share a helper function, *strlen*, which returns the length of a string.

The assembly code for *echo* iterates over the argument pointers on the stack, printing the string corresponding to each argument. The iteration starts at the second element on the stack (past the first element, *argument count*), and stops when reaching a zero.

The full source code for *echo*, including the *print* macro and *strlen* function, is available at https://gist.github.com/dstein64/890e02e8e277f17d931c8a250ceaaf44.

The assembly code for *printenv* is similar to the code above for *echo*, but starts iteration a few elements deeper into the stack, at the first environment variable pointer. It uses the *argument count* on the stack to jump past the argument pointers.

The full source code for *printenv*, including the *print* macro and *strlen* function, is available at https://gist.github.com/dstein64/a52146a3c6a12c8c0b84cfd4e084bb15.

https://dstein64.github.io/k-means-quantization-js/

The JavaScript source code is available on GitHub:

https://github.com/dstein64/k-means-quantization-js

Below are some examples of quantized images.

The originals are available on http://photos.dannyadam.com/.

]]>PyFactorizationMachines is a Theano-based Python implementation of factorization machines.

**Update 4/20/2017**: The library is now available on PyPI, the Python Package Index. It can be installed with *pip*.

$ pip install pyfms

For documentation, see documentation.md.

For example usage, see example.py.

]]>Cells can be selected/deselected by clicking and dragging your mouse. The interface and display were designed for use with a desktop/laptop computer, not a touchscreen mobile device. That is, cells can’t be selected by swiping (but tapping works).

The default selected cells spell my first name, *daniel*. After selecting cells, click *Start* to begin the *game of life*.

The source code is available here (use your browser’s *view source*).

For an overview of matrix factorization, I recommend Albert Au Yeung’s tutorial. That post describes matrix factorization, motivates the problem with a ratings prediction task, derives the gradients used by stochastic gradient descent, and implements the algorithm in Python.

For exploratory work, it would be great if the algorithm could be implemented in such a way that the gradients could be automatically derived. With such an approach, gradients would not have to be re-derived when e.g., a change is made to the loss function (either the error term and/or the regularization term). In general, automatically derived gradients for machine learning problems facilitate increased exploration of ideas by removing a time-consuming step.

Theano is a Python library that allows users to specify their problem symbolically using NumPy-based syntax. The expressions are compiled to run efficiently on actual data. Theano’s webpage provides documentation and a tutorial.

The following code includes a Theano-based implementation of matrix factorization using batch gradient descent. The parameters are similar to those in the quuxlabs matrix factorization implementation. *D* is a second-order masked numpy.ndarray (e.g., a ratings matrix, where the mask indicates missing ratings), and *P* and *Q* are the initial matrix factors. The elements of *P* and *Q* are the parameters of the model, which are initialized by the function’s caller. The rank of the factorization is specified by the dimensions of *P* and *Q*. For a rank-*k* factorization, *P* must be and *Q* must be (where *D* is an matrix). Additional parameters specify the number of iterations, the learning rate, and the regularization importance.

The code doesn’t contain any derived gradients. It specifies the loss function and the parameters that the loss function will be minimized with respect to. Theano figures out the rest!

The preceding code is not completely analogous to the quuxlabs matrix factorization implementation, since their implementation uses stochastic gradient descent, and the preceding code uses batch gradient descent.

The Theano-based implementation below uses stochastic gradient descent. It retains automatically derived gradients, but in my opinion it’s less elegant than the code above.

Lastly, the code below runs the two Theano-based matrix factorization implementations and a modified version of the quuxlabs implementation (minor modifications were made for consistency with the code above). The input data is the same ratings matrix used in the quuxlabs post and a rank-2 approximation is used for the factorizations.

Here’s the output:

Ratings Matrix [[ 5 3 -- 1] [ 4 -- -- 1] [ 1 1 -- 5] [ 1 -- -- 4] [-- 1 5 5]] Theano Batch Gradient Descent [[ 5. 2.98 2.76 1. ] [ 3.98 2.38 2.38 1. ] [ 1.07 0.85 4.75 4.99] [ 0.97 0.74 3.84 3.99] [ 1.57 1.14 4.96 5.01]] Theano Stochastic Gradient Descent [[ 4.98 2.97 2.74 1. ] [ 3.97 2.38 2.36 1. ] [ 1.06 0.85 4.77 4.98] [ 0.97 0.75 3.86 3.98] [ 1.54 1.13 4.96 4.99]] quuxlabs [[ 4.98 2.97 2.74 1. ] [ 3.97 2.38 2.36 1. ] [ 1.06 0.85 4.77 4.98] [ 0.97 0.75 3.86 3.98] [ 1.54 1.13 4.96 4.99]]

*Theano Stochastic Gradient Descent* and *quuxlabs* factorizations produce the same approximation for the ratings matrix, as they both use stochastic gradient descent to learn the model parameters. The approximation from *Theano Batch Gradient Descent* is slightly different, given that each iteration of batch gradient descent uses all the ratings, making it inherently different than stochastic gradient descent, which uses a single rating for each iteration.

The full Python source code of this post is available at https://

Here’s a link to the extension:

https://

The source code is on GitHub:

https://

After installing the extension, a highlighter icon appears in the location bar. Clicking that icon highlights important content on the page.

The extension is based on a separate project that I was recently working on for an *adaptive information systems* course. For my project, I implemented a Chrome extension that learns a user model based on the sites a user visits. Then on new sites, content was highlighted based on the similarity to the user model. I called the project extension *Persightlight*, for “personalized highlighting”.

The personalization component still needs more work, and it added complexity to the code. *Auto Highlight* is based on *Persighlight*, but all the user modeling and personalization code has been removed. *Auto Highlight* uses a heuristic that gives higher weight to words that appear often, rather than depending on a user model. I’d like to improve *Auto Highlight*, adding ideas from recent NLP research.

*Persighlight* essentially did extraction-based automatic summarization, scoring sentences relative to a user model. The model was represented by a term frequency vector, as were sentence candidates. Candidates were scored based on their cosine similarity with the user model. I’d like to also continue work on *Persighlight*. It would be interesting to see how personalization with a user model can contribute to highlighting, and summarization more broadly.

https://

[1] Liu, Wei, Jun Wang, Sanjiv Kumar, and Shih-Fu Chang. 2011. “Hashing with Graphs.” In Proceedings of the 28th International Conference on Machine Learning (ICML-11), edited by Lise Getoor and Tobias Scheffer, 1–8. ICML ’11. New York, NY, USA: ACM.

]]>