Polymer Mechanics and Machine Learning
Introduction In this example I will use the Kaggle cats and dogs dataset to train a CNN to classify if an image is a cat or a dog.
The code below reads all images from a local PetImages folder and splits them into a training and a validation set. Before training, the images are preprocessed with simple data augmentation: random horizontal flips and small rotations are applied to make the model more robust, and the pixel values are rescaled to the range [0, 1].
[1 Input] + [1 Hidden Layer with N Perceptrons] + [1 Output] In this example I will extend my previous code to be able to handle a hidden layer with N perceptrons. As before, I will demonstrate the use of the neural network by fitting it to the following mathematical function: $y = 0.1 + 0.1 \cdot x^2$ over the range $x \in [0, 10]$. The C++ implementation for this example can be found in my github account.
[1 Input] + [1 Hidden Layer with 2 Perceptrons] + [1 Output] In this example I will create a simple neural network that has one input, one hidden layer with 2 perceptrons, and one output. I will then fit that neural network to the following mathematical function: $y = 0.1 + 0.1 \cdot x^2$ over the range $x \in [0,10]$.
C++ code to solve this problem is listed below:
// 2 Layers: 1 input, 2 hidden, 1 output #include <iostream> #include <fstream> #include <algorithm> #include <cassert> #include <vector> #include <cmath> #include <random> double activation(double x, int type) { if (type==1) return std::max(0.
One Network Layer with 1 Input and 1 Output The simplest neural network architecture consists of a single perceptron. This network has only one input and one output, making it a highly streamlined model. While suitable for theoretical understanding, it is insufficient for real-world applications due to its limited capacity. However, it serves as a fundamental building block for studying the principles of backpropagation and training neural networks.
Code Location You can find the source code for this example here.
Installation Learning how large language models (LLMs) like ChatGPT and Gemini work can be both fascinating and empowering. While using them through APIs is convenient, running one locally on your own computer unlocks deeper understanding and control. Fortunately, setting up your own LLM on Linux or Windows is surprisingly straightforward.
In this article, I will walk you through the simple steps to run a popular LLM like Transformers on your own computer.
Introduction In my previous articles in this series I have shown how to calculate how far spherical object will fly based on its initial velocity and angle. I used both physics and machine learning methods to solve the problem. In this article I will examine how much of this can be completely automated using a large language model like ChatGPT 4o.
Prompt: I am interested in predicting the distance as a function of the angle and velocity.