haotianblog
Blog
Search
Ask the AI

Blog

Find an article by topic

Choose a topic, or browse all articles by category below.

All articles

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

HTTP/2, HTTP/3, and CDN caching: a Python waterfall model

Run a deterministic Python teaching model to compare HTTP/2 and HTTP/3 with cache HIT/MISS. Inspect RTT, handshake, and origin assumptions in the CSV output and waterfall plot.

Level: Professional Reading time: 14 min
  • HTTP/2
  • HTTP/3
  • QUIC
  • CDN
  • Python

Proxy Cache Troubleshooting: ARC, Nginx Locks, and X-Fetch

Check ARC ghost lists, Nginx shared metadata and cache-fill locks. Derive the X-Fetch refresh probability and understand eBPF timing and HTTP cache observations.

Level: Professional Reading time: 13 min
  • HTTP Cache
  • ETag
  • Observability
  • Python

Project category

Battery Modeling for AI

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

17 posts

PyBaMM EIS Data Generation: Impedance Features and AI Labels

Generate small-signal impedance with EISSimulation; check surface form, SOC and temperature, interpret impedance features, and distinguish finite RC-fit residuals from a general KK test.

Level: PhD level Reading time: 13 min
  • PyBaMM
  • EISSimulation
  • Impedance
  • Labels

Generate Battery Aging and EIS AI Datasets with PyBaMM

Organize PyBaMM aging and impedance data with defined SOH, RUL, LLI and LAM labels, grouped splits, termination checks, and an audit of the downloadable example labels.

Level: PhD level Reading time: 15 min
  • PyBaMM
  • Battery Aging
  • SOH
  • RUL
  • Data Quality

Training a Battery AI Model with PyBaMM: Predicting SOH and RUL

A PyTorch Transformer and loss example for SOH and RUL, with sequence padding, quantile outputs and data splits; the downloadable random-forest surrogate baseline is identified separately.

Level: PhD level Reading time: 14 min
  • PyBaMM
  • scikit-learn
  • SOH
  • RUL
  • Group Split

Drive-Cycle Current in PyBaMM: Time Grids and a Charge Check

A 29-case PyBaMM experiment separates input resampling from output sampling. Equal 0.583333 Ah still gives a 100.3 mV voltage difference. Includes signed-charge, unit and sparse-output checks.

Level: Graduate level Reading time: 12 min
  • PyBaMM
  • Drive Cycle
  • SPMe
  • IDAKLU
  • Sampling

PyBaMM Solver Convergence Failures: Numerics or Physics

Diagnose IDAKLU convergence failures with state-domain checks, SPMe/DFN comparisons, initial consistency and solver options, including version-specific option-key and partial-return tests.

Level: PhD level Reading time: 11 min
  • PyBaMM
  • IDAKLU
  • CasADi
  • Solver Convergence

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.

25 posts

Zhenyan AI: Point a Phone at an Experiment and Let AI Show You the Physics

Run real physics experiments with a phone and a computer: AI helps track motion, analyze curves, find the equation of motion and explain results, and brings custom inquiry tasks, class assignments and teacher review into everyday teaching.

Level: Beginner Reading time: 6 min
  • Video Measurement
  • AI Tutor
  • Classroom Management

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

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 for Developers: Tokens, Context and Sampling

Explain autoregressive next-token prediction, how tokens relate to characters, context budgets, temperature and top_p, then estimate local memory from weights, KV cache and runtime conditions.

Level: Beginner Reading time: 10 min
  • LLM
  • Transformer
  • Tokenizer
  • llama.cpp

KV Cache VRAM Explosion When Deploying Multimodal LLMs

Calculate raw KV cache payload for multimodal prompts, count tokens after image preprocessing, and distinguish AnyRes tiling from compression. Includes GQA, MHA and MQA examples, versioned llama.cpp code, and separate prefill/decode checks.

Level: Intermediate Reading time: 9 min
  • MLLM
  • KV Cache
  • AnyRes
  • llama.cpp

Visual Instruction Tuning Loss: Label Masks, Causal Shift and Freezing

Build aligned labels for assistant-response supervision, count targets after causal shifting, and distinguish AdamW behavior for grad=None, zero gradients and stale gradients. Retain the original simplified code beside an independently tested correction.

Level: Intermediate Reading time: 11 min
  • MLLM
  • Instruction Tuning
  • Label Masking
  • PyTorch

Deep Learning Frameworks: Why You Stop Writing Backpropagation by Hand

A reproducible CPU comparison of PyTorch and TensorFlow using one fixed linear layer. Align weight layouts, losses and gradients, then check SGD updates, microbatch weighting, target broadcasting and save/load behavior against explicit references.

Level: Intermediate Reading time: 15 min
  • PyTorch
  • TensorFlow
  • Keras
  • NumPy

Why Local LLM Streams Arrive All at Once: Proxy and Client Buffering

Twenty local requests with a fixed SSE schedule isolate proxy and client buffering. First content shifts from 166.3 ms to about 806 ms while total time stays near 0.8 s. Includes parser and EOF controls.

Level: Graduate level Reading time: 10 min
  • Python
  • SSE
  • HTTP
  • Streaming

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

Secondary Motion: Damped Springs for Hair and Tails

A damped-spring implementation for 2D secondary motion: natural frequency and damping ratio, damping-dependent Euler stability, fixed physics steps, bone-length constraints, IK priority, and teleport resets.

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

Squash and Stretch: Non-Uniform Scale and Rotation in Bone Hierarchies

Choose the space for 2D squash and stretch. Derive when non-uniform scale and rotation produce non-orthogonal axes, distinguish 90-degree orthogonality from commutation, and compare inheritance, whole-image deformation, and polar decomposition.

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

Project category

Site Building Project

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

12 posts

Two Different GPUs Reporting the Same Name

Trace a WSL2/JAX case reporting one model name for different GPUs. Check UUID/id/capacity mappings, CUDA packages, instance lifetime, scheduling, a stdin hang and networking modes.

Level: Advanced Reading time: 8 min
  • WSL2
  • JAX
  • CUDA
  • PowerShell

Eight Failures That Never Errored: The Fitter Quietly Returned My Initial Guess

Eight numerical and display problems in an impedance fitter: an LM sign error that returned the initial guess, weak identification of large R over a finite frequency window, termination-status errors and weighting-dependent recovery. Original failure values, trial summaries and code are retained.

Level: Advanced Reading time: 8 min
  • EIS
  • Levenberg-Marquardt
  • ZARC
  • Nyquist

Below Average Position 10, Tools and Interactive Directories Had 6.46x the CTR

The three-month page-level export recorded 12,491 impressions and 53 clicks. Below average position 10, tools and interactive directories had 4.76% CTR versus 0.74% for the remaining pages. This review retains the tables and code and checks cohort definitions and inference.

Level: Advanced Reading time: 11 min
  • Search Console
  • CTR
  • AI Overviews
  • Python

Project category

Local models and browser deployment

Model selection, memory estimates, inference services, knowledge bases and browser runtimes.

10 posts

Turning Three Known VRAM Traps Into a Working Estimator

Check weight residency, KV structure and empirical overhead in a VRAM estimator. Separate four-point calibration from extrapolation, and correct slope attribution and KV-head replication assumptions.

Reading time: 12 min
  • KV cache
  • tensor parallel
  • GGUF
  • nvidia-smi

ONNX Runtime Web Deployment Checks: Assets, MIME, Config Timing and Threads

Audit four ONNX deployment gates: complete assets, executable module types, configuration timing and threading conditions. Includes four HTTP 200 transfer controls, two real WASM model contract probes, complete output tensors and runnable source, with explicit limits on accuracy and timing claims.

Level: Advanced Reading time: 8 min
  • onnxruntime-web
  • WebAssembly
  • nginx
  • COOP/COEP

IoU in Quantisation Validation: Historical 0.98/0.30 Records and Mask Controls

Separate prediction agreement from labelled quality, and distinguish local debugging checks from proof of a unique cause. Includes five 4x4 mask controls, raw metric records and runnable threshold examples. Historical model numbers are retained with explicit reproduction limits.

Level: Advanced Reading time: 12 min
  • ONNX
  • Quantisation
  • onnxruntime-web
  • ISNet

Gemma 4 on an 8GB GPU: llama.cpp, context, and RAG debugging

Debug model loading, flash attention, context allocation, asymmetric routing, and Chinese retrieval in a Gemma 4 gateway on an 8GB GPU, with commands and run logs.

Level: Hands-on Reading time: 18 min
  • llama.cpp
  • Gemma 4
  • nginx
  • sqlite-vec
  • iptables
Scroll down