Elsewhere on Hackaday right now there is an article that describes another person's efforts to train a neural network to model a mathematical function, such as a simple function like y=x^2. Perhaps this approach might be useful to help with the alignment issues in my braiding algorithm. Might as well try it, right? Even though I have an idea in the works that I could just as well export a list of vector-drawn control points for the braid, and then use a Fourier transform-based low pass filter to smooth out some of the irregularities, as previously described. So, I tried giving the BASIC code from that project to Deep Seek, and I asked Deep Seek to convert it to C for me! Much to my surprise, the code ran the first time.
Here is the Hackaday Article about using Atari BASIC to implement a genetic algorithm.
And here is a cropped screen shot from the author's YouTube video:

So naturally, I had to try and see if Deep Seek could handle the otherwise fairly straight forward translation problem. Obviously, using a sledgehammer to crush ants, maybe, but worth a try.

Deep Seek was even nice enough to provide an explanation as to how the code works!
1. **Initialization**: The constants and variables are defined at the beginning. Arrays are used to store the values of `HQ`, `YQ`, `U`, `MB`, and `O`.
2. **Random Initialization**: The `MB` array is initialized with random values using `srand` and `rand`.
3. **Training Loop**: The main training loop iterates `ITER` times. In each iteration, the `U` array is updated with new values based on `MB` and a random factor.
4. **Distance Calculation**: The distance `DIST` is calculated based on the difference between `YQ` and the output `O`.
5. **Update**: If the calculated distance is less than `DB`, `DB` is updated, and the `MB` array is updated with the values from `U`. The factor `F` is also decreased by `DF`.
6. **Output**: The current iteration number and distance are printed.
This C code should replicate the functionality of the original Atari BASIC program. Note that some parts of the BASIC code were incomplete or unclear, so assumptions were made to fill in the gaps.
OK - very nice. We can grab screenshots of source code from YouTube, and translate the code to other languages! So now let's look at the generated code which I made some vary minor changes to in order to adapt it to my framework.
#include "stdafx.h"
#include "../Frame Lisp/intrinsics.h"
#include "eliza.h"
#include <math.h>
#include <time.h>
#define PI 3.14159265
#define ITER 32
#define F_INIT 2.5
#define NH 4
#define NN (NH + 1)
#define NP 3
#define NM (2 * NH)
#define NG 10
#define DR (1.0 / NP)
#define DB_INIT 1000000.0
void train_ann() {
double HQ[NP], YQ[NP];
double U[NN];
double MB[NN], O[NN];
double F = F_INIT, DF = F / ITER, DB = DB_INIT;
double DIST;
int I, J, K, N;
// Initialize points
for (I = 0; I < NP; I++) {
HQ[I] = (I - 0.5) * DR;
YQ[I] = HQ[I] * HQ[I];
}
// Initialize MB with random values
srand(time(NULL));
for (I = 0; I < NM; I++) {
MB[I] = (double)rand() / RAND_MAX;
}
// Training loop
for (N = 0; N < ITER; N++) {
DIST = 0.0;
for (I = 0; I < NM; I++) {
U[I] = MB[I] + F * ((double)rand() / RAND_MAX);
}
for (K = 0; K < NP; K++) {
for (J = 0; J < NN - 1; J++) {
double SUM = 0.0;
for (I = 0; I < NH; I++) {
SUM += U[I] * HQ[K];
}
O[J] = sin(SUM * PI);
}
O[NN - 1] = 0.0;
for (I = 0; I < NH; I++) {
O[NN - 1] += U[I + NH] * O[I];
}
O[NN - 1] = sin(O[NN - 1] * PI);
DIST += pow(YQ[K] - O[NN - 1], 2);
}
DIST = sqrt(DIST / NP);
writeln (output, N, " ",DIST, " ", DB);
if (DB > DIST) {
DB = DIST;
for (I = 0; I < NH; I++) {
MB[I] = U[I];
}
F -= DF;
}
}
}
int atari::main()
{
train_ann();
return 0;
}
Now we simply have to try running it. So let's sneak a test case into my hair drawing code, so that it will dump some debugging info at startup.

Now I just need to go back and watch the original YouTube video and see if these results seem meaningful. Obviously, when an AI is developed that can learn whatever it can possibly learn from actually watching every video ever uploaded to YouTube, then that is going to have some profound implications, i.e., when the AI becomes able to do this sort of thing on its own. Wow! I should make a note that Visual Studio objects to this code with a stack corruption warning when the main function is trying to exit, but other than that, it does seem to do something. What now? Propeller, Arduino?
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.