From Hobby to PhD, with R

A story of 2 years of making (many) mistakes, and about learning (some)

N. L. D., URJC

Intro

Day 0: the book, the hobby

After reading about J.H. Holland’s LCS algorithm in Melanie Mitchell’s book on “Complexity”…

  • I’m not great at math, maybe a bit better at algorithms
  • I do think of information as foundational of all things, and the “bit” as the elemental component.
  • Genetic Algorithms (for some reason) make sense to me (survival, pressured randomness, search & optimization)
  • It’s all super slow though

THE BEST INTRO to the LCS Algorithm out-there (hands down!) (12’ video)

How it started

Day 21: the functional version

Already, the thing “worked”.

A few months later, it was my first R package. The first LCS implementation in R (AFAICT, anyway…)

It’s all here: https://github.com/kaizen-R/RLCS

Visualizing the model (iris - simplified)


It had some simplifications. 2 years later, some of these persist and make it wrong (and in some ways better at the same time!).

Interlude: What is an “LCS”?

In the 80’s, “AI” was approached as “Expert Systems”: Humans would write rules to define some behaviour. A difficulty was how to come up with the best rules a good model would need. ~1976, John H. Holland proposed the “Learning Classifier System”, leveraging his Genetic Algorithms.


A “model”, a population of rules could look a bit like this:

Rule Interpretation
###1 -> Y if D (and the rest doesn’t matter) then Class=Y
10## -> X if A & NOT(B) then Class=X

An LCS tries to evolve the best possible rules using stochastic processes (i.e. the result is not “the” guaranteed best), using a mix of covering, genetic crossing & mutation, and selection with pressure towards general but accurate rules. This is automated search of solutions, “ML”.


An LCS model is traditionally a population of “human-readable” rules, which is good for mitigating bias(es) (in training data, at least) and increased trust (justifying decisions).

Variants of LCS have been applied to Reinforcement (notably XCS) and Supervised Learning (e.g. UCS).

Day ~670: the PhD

And I kept going, nights and weekends (mostly weekends :D)…

No particular objective in the beginning, and yet after almost 2 years of:

  • working on a slow ML algorithm, with a (rather) slow language (yes, I said it)

  • thinking about S shapes of technological progress, different approaches, coming up with ideas

  • mixing languages and HW (C++, Rust, but also Torch),

  • and mostly (way too many) wrong approximations, and repeating again, and again, and again, night-long parallel-processing training runs… (a bit of an obsession…)


I was officially accepted at URJC ~ October 8th, 2026.


Joyful time.


If you fancy having even less spare time. But we’ll get back to this later.

What happened in between?

Let’s talk about R a bit

Focus on speed

I didn’t buy a fresher Mac (Maybe I should have..)

Long running multi-Core process in passive cooled Macbook Air M1

(EDIT: Now this is false, but that changed literally two weeks ago…)

Some ideas upfront


  • Hyper-parameters. The key of the algorithm speed/accuracy balance. I learnt the hard way.
  • First version used all lists. It made conceptual sense. It worked. It was (especially) slow.

  • In the end I got rid of the lists altogether. Scary refactoring, but it worked out ok…

  • AFTER trying everything else… Try C++ (Rcpp)…

  • Packages: Run Cmd+Shift+T (testthat) often.

  • browser() is your best friend in the whole-wide-world

{profvis} & {microbenchmark}

Bottlenecks? {profvis}

Compare Runtimes? {microbenchmark}

Parallel processing

When you run several simulations (37h+…)

Parallel execution becomes a great ally. And I’ve tried a few combinations. I currently settle on {foreach}-{doParallel}. Sometimes, even {plumbeR}!

You could use {future.apply} or {mirai}. I also want to look into {mizu}, the new kid in town.

Save runtimes through parallel processing (beautiful!)

environment() & Zero Copy

Not as “functional”, but, like it or not, in some cases, faster. Much.

Passing references (environment()) instead of large variables…

Other ideas

Breaking the input data. Kinda works. Much faster. Not a great idea.

Bad idea, per Papert & Minsky’s “Perceptrons”…

Who says you HAVE to follow the pseudo code to the letter?

Moving calls around for speed

Elephant in the room: LLMs

LLMs for Code

  • Well yes, they’re here. They are incredible at code. Better than I am, no contest.
  • That does not mean we have to use them. At least not for a hobby.
  • Maybe learning isnot better when efficient?

LLM can model proteins

Why I think twice about using LLMs

  • Cybersecurity risks (e.g. prompt injection, but also hallucinations)
  • geopolitical (e.g. Europe vs US/China) dependency,
  • educational matters (how should we approach that),
  • economical/societal (in ~5 years, what happens if you can’t pay $200/month for a subscription? You own you calculator… You rent your thinking agent?),
  • job market issue (who hires juniors and compete? Who will be the seniors in 5 years),
  • philosophical questions (who decides what guardrails for a model? Mostly? Not you…),
  • intelectual property (of data used to feed the algorithms),
  • concerning financials (at loss service, circular feedback loops, RAM costs…),
  • zero-responsibility marketing stunt large-scale hacking (?!),
  • and of course environmental impacts (water, forests, energy)
  • It’s not a calculator issue. It goes straight into the thinking process. Delegation of (most) of the reasoning effort. Delegation of how to solve problems, how to search for solutions.

RLCS with LLM

On Friction & Learning

Coding (and reading) == “additional ponder time”

E.g. I came up, over two years, independently, with many ideas that (doing things “right”) prove not crazy as others came up with them too! (Also: Dopamine!)

And why a PhD?

At these very conferences: “AI could write my thesis”. Well, “AI” can write papers, indeed! But why do a PhD then?


Naive (and idealistic, and romantic) take:

It is about becoming an expert through thinking & making some scientific progress (even something minuscule). And maybe it’s one way to direct learning efforts.


Also I now get excellent feedback from experts (my Thesis Supervisors). I’m not alone anymore!


And my wife wouldn’t let me study another MSc. 😅

Did I use LLMs then?

  • Not for any code of RLCS. I didn’t have a time pressure. Coding is a satisfying experience.

  • I did not use them that much for learning…

    • I prioritized books. And (later) papers.

    • Which possibly was a mistake (as long as you check the sources)

Maybe not using AI is really a privilege?

  • Do I use them? Yes (more at work, day-to-day, for coding at times, but I focus mostly on understanding how to use agentic GenAI securely)
  • Here, mostly to help me find literature (semantic understanding is super helpful!)
  • and indeed, sometimes, to discuss my own ideas, as a “sparring opponent” (being aware the vendor will have access and train on such conversations)

Note: Ensure Authorship is clear. It’s a tool, yes, and you don’t need to mention Excel. But the code you push with an Agent, is not your thinking alone. So you’re not the (only) author of it.

Paradox?


I have a critical stance on the (incorrect) use of LLMs. Yet I study Machine Learning?


Yes. I think LLMs and agentic AI is extremly powerful. But I believe that they are over-used, for the wrong reasons, given the (mentioned) issues.


One big focus for me is how to use the machine to help me make choices/decisions.

  • Deep Learning is (mostly) a black box. LLMs make the reasoning and decisions for us.
  • I want ML and computers to help us. I want eXplainable/Interpretable AI. I chose the LCS algorithm in big part because of that, while I realize it’s no competition for a 200+ billion parameters transformer…

  • We shouldn’t aim to replace ourselves, but to improve & elevate ourselves.

Use Agentic AI to make important progress. Fight cancer, climate change. Of course! Go right ahead.

But given the trade-offs, maybe hold off on generating “AI Slop” videos?

Conclusions

It was never about the syntax. It was (and still is) about thinking through (programmatic) approaches to solving problems. And coding in R is just as good an option as any other for that.


We should still read books. We should still code (even if only from time to time and for fun). We should still make time to think, get bored. Maybe not at our day job, “because competition”. But this is precisely why we must make an effort to reserve space for our own “mental gym”.


But isn’t learning fun in-and-of-itself?


Taking our time to learn and understand is becoming a luxury.

More Resources

Thank you!

Bonus

The future: the PhD

General lines…

Phase 1: Validation

Working on… Status
State of the art (my code doesn’t respect preceding algorithms…), literature review Ongoing
train/validation/test, stratified 5-fold Coded
Fix issues (data leakage in encoding…) Done
Better ML metrics for (SL) evaluations Done
Repeatability (datasets, seeds, etc.) Done
Run (thousands?) configs & iterations in grid search of several algorithms? Next up.

Phase 1: Matrices matching

Secret Sauce! This is quite possibly my first original (as far as I can tell) contribution. It’s not a secret either & I can show I have “priority” ;) (Until proven wrong, of course…)


More on this when (if? Nah, when!) I publish my first PhD Paper ;)

Draft generated in R / Quarto :)

Phase 1: Encoding improvements


Don’t encode data points, encode information!


Better Encodings, regularization and its effects…

E.g. Gini/entropy to change encoding length? Things like that, there is a lot to be considered! Trees encoding, etc. Or maybe discard variables? Markov Blankets…

Note: PCA & al. might make the model less interpretable

Bit string length & Input compression

Basic numerical encoding

Images data compression before training

Phase 2: Active learning & Data Complexity

That’s how I came to know my then-future-Thesis-Supervisors.

  • After discovering the concept, I thought I could come up with new data complexity measures, specific to RLCS.

  • Then I could leverage those metrics for “active learning”

    • exposing (in training) to fewer overall samples

    • while maintaining classification quality

    • and hence reduce runtimes

Hopefully anyway :D

Phase 3: Interpretability & Credit Assignment

While inherently interpretable, the rule-set (RLCS Model) gets complex quickly.


For Reinforcement Learning settings, I believe there is a way to leverage subsumption steps during training to distill information (“consolidate”) into a separate hierarchy of RLCS models, for shorter input strings (faster training/inference) while maintaining learning capacity.


To Be Continued…