Polymer Mechanics and Machine Learning
About this site
I have a PhD in computational mechanics from MIT. This site is where I work through machine
learning projects myself and write up what I learn — the theory, the dead ends, and the
results. Everything here is educational; all code is open source under the
MIT license and available on
GitHub.
Introduction In an earlier article I trained a small CNN to decide whether an axis-free stress-strain image came from a rubber or a thermoplastic. The headline number was about 98% validation accuracy. I also added a caveat: because many materials had several curves — different strain rates, loading directions, or cyclic tests — curves from the same material could end up in both the training and validation sets. That kind of leakage makes a model look better than it really is.
Introduction It is useful to have reference data with known deformation and strain fields when evaluating the accuracy of DIC (Digital Image Correlation) software. For this purpose, I wrote a small speckle pattern image generator called DicGen. This free open source software, which is the subject of this post, produces synthetic 2D speckle images in which the deformation is known exactly.
In my previous post I described a new 2D DIC pipeline written in Python, and how I drove it with an LLM agent on 1,000 frames from a laboratory tensile test.
Introduction When performing uniaxial tension experiments for material characterization it is useful to not only record the applied force and displacement as a function of time, but also apply a speckle pattern on the specimen and take photos at regular time intervals during the test. These images can then be post-processed to better understand the deformation and strain fields in the specimen during the test. This type of image analysis is called Digital Image Correlation (DIC).
Introduction I have a collected a handful of GGUF models sitting in ~/.cache/llama.cpp. I wanted a straight answer to the simple question: how good are these local models at recalling facts and doing simple reasoning?
So I built a small harness that runs my local models against the full MMLU test set (14,042 questions across 57 subjects) using llama.cpp, one model at a time, and records every single prediction.
This post covers what MMLU is, how to get the questions, how the benchmark works, the example questions, and the results.
In Part 1 I benchmarked eight local GGUF models on the full MMLU test set with reasoning switched off. That is, the local LLMs were force to respond with a single letter. In this follow-up article I am repeating the study using one of those models using reasoning on.
The question, and the trap Part 1 ended on a caveat: those scores measured the ability of a model to answer a question directly, with no room to deliberate, and a thinking-capable model would probably do better if you let it think.
Introduction In the previous article we built engine.py: a complete reverse-mode automatic differentiation engine in about 80 lines, built around a single Value class. That engine knows how to record arithmetic on scalars and hand back the gradient of the final result with respect to every scalar that fed into it.
This article builds the next layer on top: nn.py, a small neural-network library in roughly 60 lines (heres the repo).
Introduction In the first two articles of this series we built a reverse-mode autograd engine (engine.py) and a small neural-network library on top of it (nn.py). Together they are about 140 lines of pure Python with no numerical dependencies beyond the standard library.
This article puts them to work on a real problem: predicting whether a breast tumor is malignant from measurements taken from a digitized image. The script is cancer_prediction.
Introduction engine.py is a complete reverse-mode automatic differentiation engine in about 80 lines (heres the repo). It has a single class, Value, that wraps one scalar and remembers how that scalar was computed, so that calling .backward() fills in the derivative of the final value with respect to every value that fed into it.
It’s the same core idea as PyTorch’s autograd, just small enough to read in one sitting. The code is also strongly influenced by Karpathy’s micrograd repo.
Introduction A common way to learn how Convolutional Neural Networks (CNNs) work is to develop a tool that can classify whether an image is a cat or a dog (in this case all images are either of a cat or of a dog, no other options are allowed). I created an example that does just that.
Since my background is in polymer mechanics, I wanted a more interesting version of this classification task: given an image of a stress-strain curve, decide whether it comes from a rubber material or a thermoplastic.
Different Types of Neural Networks (NN) There are several types of neural networks designed to perform specific tasks or process different kinds of data. Here are some of the most popular basic types:
Feedforward Neural Networks (FFN) The simplest type of neural network, consisting of interconnected nodes. Convolutional Neural Networks (CNN) Primarily used for image and vision-related tasks such as object recognition. Reccurent Neural Networks (RRN) Designed to process sequential data, like time series, by maintaining internal state variables.