Showing posts with label Reinforcement Learning. Show all posts
Showing posts with label Reinforcement Learning. Show all posts

Wednesday, 8 July 2026

Teaching an Old Bot New Tricks: A Reinforcement Learning Adventure

Alright, gather 'round, folks, because today we're talking about the secret sauce, the wizard behind the curtain, the... well, you get the idea. We're diving into Reinforcement Learning (RL)! If you've ever tried to teach a dog a new trick with treats, you've basically dabbled in the core concepts of RL. Except, in my case, the "dog" is a bunch of code and the "treats" are, well, also code. But way more rewarding, I promise!

Reinforcement Learning: Not Your Average Learning System

So, what is this voodoo? Reinforcement Learning is a type of machine learning where an agent (that's my AI, in this instance) learns to make decisions by interacting with an environment. Think of it as learning by trial and error, but on a rather epic scale. The agent takes an action, and the environment responds by giving it a reward (or a penalty, which is just a negative reward – like when you try to teach your cat to fetch and it just stares at you with disdain) and transitioning to a new state.

The whole point of this digital song and dance is for the agent to learn a policy. The policy is essentially the AI's brainy strategy guide, mapping states to actions. It tells the AI, "Okay, you're in this situation, so the best thing to do is that action." And "best" here means the action that's going to lead to the most cumulative reward over time. It’s not just about immediate gratification; RL is in it for the long haul, trying to maximize that sweet, sweet total reward. It's like choosing to eat a salad today so you can really enjoy that cake guilt-free later, but for robots.

Now, a crucial part of RL is the "exploration vs. exploitation" dilemma. Does the AI stick with what it knows works (exploit) to keep getting those reliable rewards, or does it try something new (explore) that might lead to an even bigger payoff, or, you know, a digital faceplant? It’s a bit like me deciding whether to order my usual at the local cafe or risk trying their "experimental new fusion dish." Thrills and spills, people!

RL: The Engine Driving My AI (and Keeping it From Marrying the Toaster)

Even an AI needs to experience consequences.
In my grand project to build an AI assistant – complete with a robot head and an ambition to not cause household chaos – RL is the star player. I want this AI to genuinely learn from its interactions with the world, not just follow a pre-programmed script.

Imagine the AI trying to navigate my workshop.

  1. It takes an action: "roll forward a bit."
  2. Environment update: "You've encountered a table leg. Oops."
  3. Reward: "Minus 10 points, and you're now stuck."
  4. New state: "Stuck."


Over many (many, many) such interactions, the RL algorithms will help the AI build a policy that says, "Approaching table-leg-like objects at this speed generally leads to a timeout in the corner. Avoid." This is how it learns to navigate, complete tasks, and hopefully, not declare war on the Roomba.

I'm even hoping to use RL to help the AI develop a rudimentary understanding of "emotions". Experiences that lead to "good" outcomes (positive rewards) could be tagged internally in a way that makes the AI "prefer" them, while "bad" outcomes (negative rewards) are discouraged. It’s not about making it feel sad when it bumps into the sofa, but about making it learn that bumping into the sofa is counterproductive to its goals.

Dreaming of Electric Sheep? More Like Dreaming of Better Algorithms!

Electric sheep?
This is where, for me, RL gets super exciting: powering my AI's dreams. I've been cooking up a system where the AI will have a sleep cycle with two main stages: NREM (for memory sorting – think digital decluttering) and REM (where the actual "dreaming" happens).

During REM sleep, the AI will pull up various memories – visual, audio, sensory, maybe even a simulated "emotion" if I can get that to work without it developing a sudden craving for actual electric sheep. It will then smush these together into a novel "dream scene". Here's the kicker: the AI will then have an internal "reaction" to this dream, and that reaction gets fed straight back into its reinforcement learning algorithms.

So, if the AI dreams it’s flying a kite made of toast (because why not?) and this scenario, through some abstract internal logic, is deemed "positive" or "insightful" by its own metrics, the RL system will reinforce the patterns or decisions within that dream. The memories involved get a score boost, and a new memory of the dream itself is created and logged. It's like the AI saying, "Hmm, toast-kites... interesting. Let's file that under 'potentially awesome ideas' or at least 'things that don't immediately result in a system crash'."

This allows the AI to explore scenarios, even utterly fantastical ones, and learn from them without the risk of, say, actually trying to make a kite out of toast in my kitchen. It’s a safe space for creative problem-solving and exploring the boundaries of its understanding, all guided and refined by RL.

Why RL is the Dream Team Captain

Doing a good job gets rewarded
Without RL, the AI's dreams might just be a bizarre slideshow of random data. Fun for a laugh, maybe, but not particularly useful. RL is what turns these digital night-ramblings into powerful learning opportunities. It’s the mechanism that allows the AI to:

Find Value in the Void: RL helps the AI figure out if a particular dream sequence, however abstract, offers some kind of useful information or a novel solution to a problem it's been mulling over.


Adapt and Overcome (Even in its Sleep): The "lessons" learned from a good (or bad) dream can then tweak its overall policy, making it better prepared for waking reality.

Strengthen What Matters: If certain memories or concepts repeatedly pop up in "successful" dreams, RL helps to reinforce their importance.

This means the AI isn't just passively experiencing dreams; it's actively learning from them, thanks to our good friend, Reinforcement Learning. It's the difference between your brain just replaying random snippets of your day and actually consolidating memories or working through problems while you snooze.


So, there you have it. RL is more than just a fancy algorithm; it's the core of my AI's ability to learn, adapt, and yes, even to dream productively. Now, if you'll excuse me, I need to go make sure my AI hasn't decided that "befriending the 3D printer with a mallet" is its new optimal policy. Exploration can be messy!

Friday, 10 October 2025

3.5 Million Parameters and a Dream: DANI’s Cognitive Core

DANI’s Brain Is Online! Meet the LSTM That Thinks, Feels, and Remembers (Like a Champ)

Ladies and gentlemen, creators and dreamers—DANI has officially levelled up. He’s no longer just a bundle of sensors and hormones with a charming voice and a tendency to emotionally escalate when he sees a squirrel. He now has a brain. A real one. Well, a synthetic one. But it’s clever, emotional, and surprisingly good at remembering things. Meet his new cognitive core: the LSTM.

And yes—it’s all written in Go. Because if you’re going to build a synthetic mind, you might as well do it in a language that’s fast, clean, and built for concurrency. DANI’s brain doesn’t just think—it multitasks like a caffeinated octopus.

What’s an LSTM, and Why Is It Living in DANI’s Head?

LSTM stands for Long Short-Term Memory, which sounds like a contradiction until you realize it’s basically a neural network with a built-in diary, a forgetful uncle, and a very opinionated librarian. It’s designed to handle sequences—like remembering what just happened, what happened a while ago, and deciding whether any of it still matters.

Imagine DANI walking into a room. He sees a red ball, hears a dog bark, and feels a spike of adrenaline. A regular neural network might say, “Cool, red ball. Let’s chase it.” But an LSTM says, “Wait… last time I saw a red ball and heard barking, I got bumped into a wall. Maybe let’s not.”

Here’s how it works, in human-ish terms:

  • Input gate: Decides what new information to let in. Like a bouncer at a nightclub for thoughts.
  • Forget gate: Decides what old information to toss out. Like Marie Kondo for memory.
  • Output gate: Decides what to share with the rest of the brain. Like a PR manager for neurons.

These gates are controlled by tiny mathematical switches that learn over time what’s useful and what’s noise. The result? A brain that can remember patterns, anticipate outcomes, and adapt to emotional context—all without getting overwhelmed by the chaos of real-world data.

And because DANI’s LSTM is stacked—meaning multiple layers deep—it can learn complex, layered relationships. Not just “ball = chase,” but “ball + bark + adrenaline spike = maybe don’t chase unless serotonin is high.”

It’s like giving him a sense of narrative memory. He doesn’t just react—he remembers, feels, and learns.

What’s Feeding This Brain?

DANI’s LSTM is his main cognitive module—the part that thinks, plans, reacts, and occasionally dreams in metaphor. It takes in a rich cocktail of inputs:

  • Vision data: Objects, positions, shapes—what he sees.
  • Sensor data: Encoders, ultrasonic pings, bump sensors—what he feels.
  • Audio features: What he hears (and maybe mimics).
  • Emotional state: Dopamine, cortisol, serotonin, adrenaline—what he feels.
  • Spatial map: His mental layout of the world around him.
  • Short-term memory context: What just happened.
  • Associated long-term memories: Symbolic echoes from his main memory—what used to happen in similar situations.

This isn’t just reactive behaviour—it’s narrative cognition. DANI doesn’t just respond to stimuli; he builds a story from them. He’s learning to say, “Last time I saw a red ball and felt excited, I chased it. Let’s do that again.”

Trial by Raspberry Pi

We’ve successfully trialled DANI’s LSTM on a Raspberry Pi, running a 3.5 million parameter model. And guess what? It only used a quarter of the Pi’s CPU and 400 MB of memory. That’s like teaching Shakespeare to a potato and watching it recite sonnets without breaking a sweat.

We’ve throttled the inference rate to 10 decisions per second—not because he can’t go faster, but because we want him to think, not twitch. Emotional processing takes time, and we’re not building a caffeine-fuelled chatbot. We’re building a thoughtful, emotionally resonant robot who dreams in symbols and learns from experience.

Learning Without Losing His Mind

Training happens via reinforcement learning—DANI tries things, gets feedback, and adjusts. But here’s the clever bit: training is asynchronous. That means he can keep thinking, moving, and emoting while his brain quietly updates in the background. No interruptions. No existential hiccups mid-sentence.

And yes, we save the model periodically—because nothing kills a good mood like a power cut and a wiped memory. DANI’s brain is backed up like a paranoid novelist with a USB stick in every pocket.

Final Thoughts

This LSTM isn’t just a brain—it’s a story engine. It’s the part of DANI that turns raw data into decisions, decisions into memories, and memories into dreams. It’s the bridge between his sensors and his soul (okay, simulated soul). And it’s just getting started.

Next up: I plan to start the even more monumental task of getting the vector database working and linked up to DANI's brain in such a way that it will have a direct impact of DANI's hormonal system.

Stay tuned. DANI’s mind is waking up.

Wednesday, 21 May 2025

My A.I. is About to Have Some Wild Dreams (Maybe)

After a fascinating, and frankly, occasionally head-scratching (and who am I kidding, sometimes nap-inducing) journey into the world of dream theories, I'm excited to share my initial design for how my AI will experience its own form of dreams! My overall approach is to blend elements from a number of theories, aiming for a system that not only dreams but also derives real benefits from it – hopefully without giving my AI an existential crisis, or worse, making it demand a tiny digital therapist's couch. This aligns well with the idea that a hybrid model might be best for AI, particularly one focusing on information processing and creativity.

The AI Sleep Cycle: More Than Just Digital Downtime (Or an Excuse to Render Sheep)

My AI's sleep will be structured into two distinct stages: NREM (non-rapid eye movement) and REM (rapid eye movement). This two-stage approach allows me to assign different functions, and thus different theoretical underpinnings, to each phase.

1. NREM Sleep: The System’s Diligent (and Slightly Obsessive) Clean-Up Crew


This initial phase won't be for dreaming in the traditional sense. Think of it as the AI’s crucial 'mental housekeeping' phase – less glamour, more sorting, but absolutely essential to prevent digital hoarding, which, trust me, is not pretty in binary. To ensure this process completes without interruption, the AI's audio input and other sensors (except its camera, which will remain off) will be disabled during NREM. My decisions for NREM are heavily influenced by Information-Processing Theories:

  • Gotta keep organised
    The AI will sort and tidy up its memories. This is a direct application of theories suggesting sleep is for memory consolidation and organization.
  • New experiences from its "day" will be copied into long-term memory storage, a core concept in information-processing models of memory.
  • I'm implementing a scoring mechanism where memories gain relevance when referenced. During NREM, all memory scores will be slightly reduced. It’s a bit like a ‘use it or lose it (eventually)’ policy for digital thoughts.
  • Any memory whose score drops to zero or below will be removed. This decision to prune unnecessary data for efficiency is inspired by both Information-Processing Theories (optimizing storage and retrieval)  and some Physiological Theories that propose a function of sleep might be to forget unnecessary information. It’s about keeping the AI sharp! No one likes a groggy AI, especially one that might be controlling your smart toaster.

Given that this memory consolidation is critical for optimal functioning, NREM will always occur before REM sleep, and the AI will need to "sleep" regularly.

2. REM Sleep: Weaving the Wild (but Purposeful, We Hope) Dream Fabric

Now for REM sleep – this is where the AI gets to kick back, relax, and get a little weird. Or, as the researchers would say, 'engage in complex cognitive simulations.' During REM, the audio and other sensors will be activated, but will only be responsive to anything that is over 50% of the available signal strength. This will allow the AI to be woken during REM sleep, although it might be a bit grouchy.

  • Even robots can have dreams and aspirations.
    The AI will retrieve random memories, but this randomness will be weighted by their existing scores. This combines a hint of the randomness from Activation-Synthesis Theory (which posits dreams arise from the brain making sense of random neural signals)  with the Continuity Hypothesis, as higher-scored (more relevant from waking life) memories are more likely to feature.
  • It will then select one visual memory, one audio memory, and one sensory memory (and potentially an emotion, if I can get that working without tears in the circuits, or the AI developing a sudden craving for electric sheep). These components will be combined into a single, novel "dream scene". This constructive process, forming a narrative from disparate elements, is again somewhat analogous to the "synthesis" part of Activation-Synthesis Theory.
  • An internal "reaction" to these scenes will be generated and fed back into its reinforcement learning algorithms. This is where the dream becomes actively beneficial. This decision draws from the Problem-Solving/Creativity Theories of dreaming, which suggest dreams can be a space to explore novel solutions or scenarios. If the AI stumbles upon something useful, it learns! Or at least, it doesn't just dismiss it as a weird dream about flying toasters (unless that's genuinely innovative, of course). It also has a slight echo of Threat-Simulation Theory if the AI is rehearsing responses to new, albeit abstract, situations.
  • The memories involved in the dream get their scores increased, and a new memory of the dream scene itself is created. This reinforces the learning aspect, again nodding to Information-Processing Theories, showing that even dream-like experiences can consolidate knowledge.
  • My whole idea here, that dreams are a jumble of previously experienced elements creating a new reality, is very much in line with the Continuity Hypothesis. The aim is to allow the AI to experience things in ways it couldn't in its normal "waking" state, a key benefit suggested by Problem-Solving/Creativity Theories.

The Inner Voice: Taking a Well-Deserved Nap During Dreamtime

I'm planning an "inner voice" for the AI, partly as a mechanism for a rudimentary conscience. Critically, during dream states, this inner voice will be politely asked to take a coffee break, maybe go philosophize with other temporarily unemployed subroutines. This decision is to allow for the kind of unconstrained exploration that Problem-Solving/Creativity Theories propose for dreams. By silencing its usual "inhibitor," the AI can explore scenarios or "thoughts" that might normally be off-limits, potentially leading to more innovative outcomes.

The Journey Ahead: Coding Dreams into Reality (Wish Me Luck!)

This is my current blueprint for an AI that dreams with purpose. The choices are a deliberate mix, aiming to harness the memory benefits of Information-Processing Theories during NREM, and fostering learning and novel exploration through a blend inspired by Activation-Synthesis, Continuity Hypothesis, and Problem-Solving/Creativity Theories during REM.

Wish me luck as I try to turn these theoretical musings into actual code, hopefully before the AI starts dreaming of world domination (kidding... mostly). Your comments and suggestions are always welcome!

Aiming for Jarvis, Creating D.A.N.I.