haotianblog
Blog
Search
Ask the AI

Blog

Blog Articles

This page collects the main technical articles on haotianblog, with emphasis on machine learning, algorithm implementation, deep learning math, network protocols, AI security, and battery modeling. The goal is to publish explanations with context, implementation details, code, or experiment output rather than short summaries.

If this is your first visit, start by topic. The machine learning route begins with data and evaluation. The algorithm route begins with eight queens and K-means. The networking route moves from DNS, TCP, and TLS into proxies and caching. The AI security route starts from threat modeling and safe toy labs.

Current reading routes

How to evaluate an article here

The site is trying to avoid pages that are only concept summaries or link lists. A useful technical article should state the question, show the input, explain the implementation, preserve evidence, and describe the boundary of the result. For algorithms and machine learning, that evidence may be intermediate state, metrics, error cases, source code, or downloadable files. For network protocols, it may be headers, status codes, cache state, timing phases, and reproduction commands.

If a page is only a route, index, or tool surface, it should point clearly to the stronger article that carries the explanation. That keeps the site easier to evaluate: a reader can tell whether a page is a learning route, an experiment entry, a resource page, or a complete tutorial.

Content Type and Evidence Standard

Content type Question it should answer Evidence the page should keep visible
Machine learning implementation How does data enter the model, and why should the metric be trusted? Split strategy, baseline, run command, error cases, and metric definition.
Algorithm and C/Python code Which state changes, and where are the boundary cases? Input format, loop invariant, complexity, output example, and failing input.
Network protocol debugging Is the issue in DNS, TLS, proxying, caching, or the application layer? Headers, status codes, timing sequence, cache state, and reproduction commands.
AI security experiment What does the demo prove, and what does it not prove? Authorization boundary, toy-lab setup, metric, mitigation, and misuse limits.

Current maintenance focus

New and revised articles will continue to emphasize reproducibility and explanation. Machine learning pages should include split strategy, baselines, error analysis, and experiment notes. Network pages should show layered evidence from browser, CDN, Nginx, and application behavior. AI security pages should keep authorization boundaries, toy-lab limits, and defensive review methods visible.

Older articles are revised against actual reproduction results. Broken commands need replacements, dependency changes need versions, and conclusion-only passages need derivations or run evidence. A reader should be able to tell whether a claim comes from an equation, program output, protocol response, or controlled experiment.

Article index

The index below is generated from the current site categories. Tool, survey, and share pages are not treated as core articles; readers should prioritize posts with complete body text, code, and experiment notes.

Categorized blog

Read by project

Posts are grouped into networking, battery modeling, AI, 2D animation, algorithm implementation, and site-building projects, with level, reading time, and stack metadata.

Series

Deep Learning Math Visualized

Five posts move from matrix calculus, backpropagation, optimizers, convolution, and attention, each with hand calculation, code, figures, and animation.

5 posts

Matrix Calculus for Neural Networks

Derive dL/dW for y = Wx + b and verify it with finite differences.

Level: Intermediate Reading time: 13 min
  • Matrix Calculus
  • NumPy
  • Gradient Check

Backpropagation as a Computation Graph

Trace local gradients through ReLU and softmax cross-entropy in a two-layer MLP.

Level: Intermediate Reading time: 14 min
  • Backpropagation
  • Computation Graph
  • Softmax

Gradient Descent and Optimizer Geometry

Compare gradient descent, momentum, and Adam on a visible quadratic loss surface.

Level: Intermediate Reading time: 13 min
  • Gradient Descent
  • Momentum
  • Adam
  • Loss Surface

Convolution and Receptive Field Math

Compute convolution output size, receptive fields, channel mixing, and im2col layout.

Level: Intermediate Reading time: 13 min
  • Convolution
  • Receptive Field
  • im2col

Transformer Attention Math

Hand-calculate Q/K/V scores, softmax weights, masks, multi-head structure, and KV cache.

Level: Intermediate Reading time: 14 min
  • Transformer
  • Attention
  • QKV
  • KV Cache

Project category

Network Fundamentals

A reproducible route through DNS, TCP, TLS, HTTP/3, proxy tunnels, load balancing, and shared caches with code and figures.

14 posts

Sharing a Secret Is Easy; Sharing State Is Not: Six Traps in Cross-Machine SSO

Extending a single-machine login gate into SSO across subdomains makes key distribution the easy part — state is the hard one. This records the problems from running one gate on three machines: why replay protection became per-site, how a second copy of the key produced "gate passes, application returns 401", how an allowlist preservation rule in a deploy script silently switched login off, and why comparing generated codes manufactures phantom failures.

Reading time: 13 min
  • TOTP
  • HMAC
  • auth_request
  • nginx

Authenticated Is Not Protected: Auditing an Authorisation Boundary

After putting a two-factor gate in front of a self-hosted file manager, I asked what the gate actually protected. It protected the interface, not the files — the same bytes were reachable by two URLs, and while verifying that I found the gate had never been in the request path at all. This covers the audit, two nginx traps in the patch, and the edge cache that kept serving for nearly a year after the origin was closed.

Reading time: 13 min
  • nginx
  • auth_request
  • TOTP
  • CDN

Does Inbound Actually Work? Probing a Home Line From the Outside

Every port looks open when you scan from the machine itself, and nothing outside can connect. This covers why local probing is guaranteed to mislead, why a control port is not optional, and a full measurement run: public IPv4 that is not CGNAT, ports 80 and 443 filtered rather than closed, a real IPv6 address with inbound entirely dropped, and why an AAAA record must not come from an echo service.

Reading time: 11 min
  • nc
  • CGNAT
  • hairpin NAT
  • IPv6
  • DNS-01

A Certificate Is Not HTTPS: Debugging a Subdomain Reported as “Uncertified”

Someone told me a subdomain had no SSL certificate. It did — a wildcard covered it. But the investigation surfaced something worse: that subdomain served its mail login page over plain HTTP, password field and all, with no redirect. Plus two things that sent me the wrong way: openssl failing on every target at once, and DNS enumeration being meaningless behind a transparent proxy.

Reading time: 9 min
  • TLS
  • SNI
  • nginx
  • HSTS

Project category

Battery Modeling for AI

A reproducible research path from PyBaMM, EIS, and aging simulation to AI labels and risk-controlled parameter identification.

6 posts

Fitting PyBaMM Parameters: Why the Optimiser’s Numbers May Mean Nothing

The top search result, pybamm-param, is deprecated; PyBOP just restructured its API; and identifiability means an optimiser handed fifty free parameters returns fifty meaningless numbers. Includes a protocol separating a fit from a decoration.

Level: PhD level Reading time: 14 min
  • PyBaMM
  • EIS
  • Battery Aging
  • AI Dataset

PyBaMM Solver Convergence Failures: Numerics or Physics

When a long degradation run dies at cycle 300, reaching for tolerances is usually wrong. Tell numerics from physics with an SPMe cross-check, plus every IDAKLU option default and one trap that fails silently.

Level: PhD level Reading time: 14 min
  • PyBaMM
  • EIS
  • Battery Aging
  • AI Dataset

Project category

AI Learning Project

A practical route from AI concepts to machine learning workflow, evaluation, neural networks, Python practice, handwritten digits, a CIFAR-10 CNN, adversarial traffic-defense notes, and AI security.

28 posts

AI Basics Learning Roadmap

Separate AI, machine learning, and deep learning before going into implementation details.

Level: Beginner Reading time: 8 min
  • AI
  • Machine Learning
  • Deep Learning

Machine Learning Workflow

Follow the practical path from data and features to training, prediction, and evaluation.

Level: Beginner Reading time: 9 min
  • Machine Learning
  • Features
  • scikit-learn

Model Training and Evaluation

Understand loss, overfitting, train/test splits, accuracy, recall, and F1.

Level: Beginner Reading time: 9 min
  • Model Training
  • Metrics
  • Evaluation

Neural Network Basics

Move from perceptrons to activation, forward propagation, backpropagation, and training loops.

Level: Intermediate Reading time: 8 min
  • Neural Networks
  • Backpropagation
  • Python

Matrix Calculus for Neural Networks

Derive dL/dW for y = Wx + b and verify it with finite differences.

Level: Intermediate Reading time: 13 min
  • Matrix Calculus
  • NumPy
  • Gradient Check

Backpropagation as a Computation Graph

Trace local gradients through ReLU and softmax cross-entropy in a two-layer MLP.

Level: Intermediate Reading time: 14 min
  • Backpropagation
  • Computation Graph
  • Softmax

Gradient Descent and Optimizer Geometry

Compare gradient descent, momentum, and Adam on a visible quadratic loss surface.

Level: Intermediate Reading time: 13 min
  • Gradient Descent
  • Momentum
  • Adam
  • Loss Surface

Convolution and Receptive Field Math

Compute convolution output size, receptive fields, channel mixing, and im2col layout.

Level: Intermediate Reading time: 13 min
  • Convolution
  • Receptive Field
  • im2col

Transformer Attention Math

Hand-calculate Q/K/V scores, softmax weights, masks, multi-head structure, and KV cache.

Level: Intermediate Reading time: 14 min
  • Transformer
  • Attention
  • QKV
  • KV Cache

Python AI Mini Practice

Run a small scikit-learn classification task and read the experiment output.

Level: Practice Reading time: 10 min
  • Python
  • scikit-learn
  • Classification

Handwritten Digit Dataset Basics

Read train.csv, test.csv, labels, and the flattened 28 by 28 pixel layout before training the classifier.

Level: Beginner Reading time: 8 min
  • Dataset
  • CSV
  • Image Classification

Handwritten Digit Softmax in C

Follow the C implementation from logits and softmax probabilities to confusion matrices and submission export.

Level: Practice Reading time: 11 min
  • C
  • Softmax
  • Classification

Handwritten Digit Playground Notes

See how the offline classifier was adapted into a browser demo with drawing input and probability output.

Level: Practice Reading time: 8 min
  • Browser Demo
  • Softmax
  • Visualization

CIFAR-10 Tiny CNN Tutorial in C

Build and train a small convolutional neural network for CIFAR-10 image classification, then read its loss and accuracy output.

Level: Intermediate Reading time: 13 min
  • C
  • CNN
  • CIFAR-10
  • Backpropagation

High-Entropy Traffic Defense Notes

Study encrypted metadata leaks, entropy, traffic classifiers, and a defensive Python chaffing prototype.

Level: Intermediate Reading time: 16 min
  • Python
  • Traffic Analysis
  • Adversarial ML
  • Networking

AI Security Threat Modeling

Build a defense map with NIST adversarial ML, MITRE ATLAS, and OWASP LLM risks.

Level: Professional Reading time: 12 min
  • AI Security
  • Threat Modeling
  • NIST
  • MITRE ATLAS
  • OWASP

Adversarial Examples and Robust Evaluation

Evaluate clean and perturbed accuracy with an FGSM-style digits experiment.

Level: Professional Reading time: 11 min
  • Adversarial Examples
  • FGSM
  • Robust Evaluation
  • scikit-learn

Data Poisoning and Backdoor Defense

Study poison rate, trigger behavior, attack success rate, and training pipeline controls.

Level: Professional Reading time: 11 min
  • Data Poisoning
  • Backdoor Defense
  • Training Pipeline
  • scikit-learn

Model Privacy and Extraction Defense

Measure membership inference signal and surrogate fidelity against a local toy model.

Level: Professional Reading time: 12 min
  • Model Privacy
  • Membership Inference
  • Model Extraction
  • Prediction API

LLM, RAG, and Agent Security

Separate instructions from data and enforce tool permissions against indirect prompt injection.

Level: Professional Reading time: 12 min
  • LLM Security
  • RAG
  • Agent Tools
  • Prompt Injection

Large Language Models From a Developer’s Angle: Word Association at Scale

What an LLM is doing underneath the marketing: next-token prediction driven by the Transformer. Covers the architectural workflow, running an 8B model locally in Python, the hardware pitfalls encountered on the way, and what actually matters for developers building on top of these models.

Level: Beginner Reading time: 8 min
  • AI
  • Machine Learning
  • Python
  • scikit-learn

Multimodal LLM Architecture: How Vision Gets Aligned With Language

The crux of multimodal models is modality alignment. Covers the end-to-end architecture, the mathematics behind Q-Former and cross-attention, an MLP projection layer implemented in PyTorch, and why a linear projection and a two-layer MLP behave differently in production.

Level: Beginner Reading time: 8 min
  • AI
  • Machine Learning
  • Python
  • scikit-learn

KV Cache VRAM Explosion When Deploying Multimodal LLMs

Deploying LLaVA, Qwen-VL or InternVL runs into the same wall: KV cache memory. Covers the derivation of KV cache consumption, how AnyRes and dynamic resolution mitigate visual token explosion, 4-bit quantised inference with llama.cpp, and the engineering traps behind each.

Level: Beginner Reading time: 8 min
  • AI
  • Machine Learning
  • Python
  • scikit-learn

Visual Instruction Tuning: Where the Loss Function Actually Applies

The mechanics of visual instruction tuning, focusing on loss construction. Covers multimodal auto-regressive next-token prediction, the data flow from JSON to masked labels, the PyTorch label-masking implementation, and the production pitfalls that follow from getting the mask wrong.

Level: Beginner Reading time: 8 min
  • AI
  • Machine Learning
  • Python
  • scikit-learn

Deep Learning Frameworks: Why You Stop Writing Backpropagation by Hand

Once you have written a small neural network from scratch, the question becomes whether you must hand-code matrix multiplication and backpropagation every time. Covers what frameworks actually provide, the two major camps and how they differ, which one suits a beginner, and the same simple layer defined in each.

Level: Beginner Reading time: 8 min
  • AI
  • Machine Learning
  • Python
  • scikit-learn

Project category

2D Animation Principles

A route from character segmentation and SVG assets through bone matrices, two-bone IK, skinning weights, seam repair, and keyframe interpolation.

11 posts

Modern 2D Skeletal Runtimes: Mesh Deformation, Draw Order, and Constraints

Linear blend skinning cannot express folds, draw order or follow-through. Why mesh deformation must be applied in bind space, why draw order is a discrete track, and how Live2D's parameter-driven keyforms produce pseudo-3D.

Level: Professional Reading time: 12 min
  • Spine
  • Live2D
  • Mesh Deformation
  • Constraints

Animate’s HTML5 Canvas Runtime: Display List, Repaint Cost, and Caching

Publishing compiles the timeline into a CreateJS display tree, and the canvas repaints entirely every frame. Why vectors pay rasterisation per frame, the three cache parameter traps, and why filters require caching.

Level: Intermediate Reading time: 10 min
  • CreateJS
  • Canvas
  • EaselJS
  • Performance

Secondary Motion: Damped Springs for Hair and Tails

The keyframes are dialled in and the character still reads as stiff, because secondary motion is missing — the parts dragged along by the primary action that arrive a beat late. This covers parameterising a damped spring as frequency and damping ratio, and five traps in wiring it into a 2D skeletal system: why explicit Euler is unconditionally unstable, frame-rate dependent results, root-to-tip chain ordering, springing angles rather than positions, and why teleports blow it up.

Level: Practical Reading time: 13 min
  • semi-implicit Euler
  • damping ratio
  • bone chain

Squash and Stretch: Why Non-Uniform Scale Cannot Pass Through a Rotation

Wire squash and stretch into a skeletal system and nearly all the difficulty comes from one fact: non-uniform scale does not propagate down a hierarchy as safely as rotation and translation. This covers area preservation in 2D and the two things it does not preserve, why the wrong pivot sinks a ball into the floor, and the core trap — a parent scale times a child rotation contains shear, so only the rotated parts come out skewed.

Level: Practical Reading time: 12 min
  • affine transform
  • shear
  • pivot
  • smear

Project category

Algorithm Implementation Project

Implementation-focused notes around backtracking, bit operations, clustering, code, diagrams, and downloads.

5 posts

A Contour Tracer’s Stopping Condition: Three Lines Out of Order, Twenty Times the Area

Jacob's stopping criterion for Moore-neighbourhood tracing requires position and direction to match. I checked before updating the direction, using the previous iteration's leftover value, so the condition almost never fired — the tracer looped until the iteration cap, and the shoelace formula then closed the unclosed point list straight across the region.

Level: Advanced Reading time: 7 min
  • Moore neighbourhood
  • Jacob's criterion
  • Shoelace

Project category

Site Building Project

Notes on the bilingual site structure, content sync, categories, comments, and deployment workflow.

6 posts

Auditing My Own Site’s Structure: A Metric That Was Wrong by 8x

Trying to quantify whether my articles all look the same, I first measured 92% and wrote it into my conclusions. That number counted the theme template as article structure; corrected, it is 12%. This is about the measurement: defining "shape", where I drew the boundary wrong, why one metric hides the real problem, and the accidental control that finally killed it.

Reading time: 10 min
  • curl
  • Python
  • entropy
  • WordPress

Moving an Entire Image Pipeline Into the Browser: It Saves More Than CPU

A tool that takes character images, cuts them out, separates layers and produces an SVG asset library — with nothing uploaded. The original motivation was a single-core origin that could not host server-side image processing; what it actually saved was storage, moderation, privacy obligations and concurrency. Covers the five-step implementation, the price of IndexedDB, replacing a compression library with ZIP stored mode, and the one unavoidable cost.

Level: Advanced Reading time: 11 min
  • Canvas
  • IndexedDB
  • ONNX Runtime Web
  • ZIP

Featured Image Set, og:image Empty: Yoast’s Stale Indexable Cache

I attached featured images to 19 posts. The admin looked right, the page source had no og:image — and the JSON-LD on the same page already pointed at the new cover. That pairing is the diagnosis: the two outputs travel different paths, one computed live and one read from a precomputed index table.

Reading time: 6 min
  • WordPress
  • Yoast
  • WP-CLI
  • Open Graph

Only 276 MB of 8.3 GB Was Unique: Forensics Before a Delete

The server hit 86% disk with deploy backups at 8280 MB. Before deleting anything I worked out how much was genuinely unique — 276 MB, with the rest being one set of files copied 228 times. A set-difference check run before the delete recovered seven files that existed only in historical snapshots.

Reading time: 9 min
  • rsync
  • tar
  • sha256
  • Cloudflare Tunnel

Read-Only Is Structural, Not a Discipline: Ten Traps in Wiring a Self-Hosted Mailbox to AI

Wiring a self-hosted mailbox into an AI assistant: the protocol half is easy, making read-only structural rather than a promise is not. Traps hit along the way -- a rejection letter whose boilerplate says has been accepted, a syntax check that passed while authentication became dead code, a shared failure latch that took every user down at once, and why a synthetic click cannot tell a dead button from a blocked popup.

Level: Overview Reading time: 4 min
  • WordPress
  • Cloudflare
  • Content Workflow
Scroll down