Algorithms. Physics. Mathematics. Machine Learning.
258 subscribers
131 photos
9 videos
1 file
60 links
DIY projects, fun with 3d, electronics, programming, vibe coding, math, ML algorithms.
Download Telegram
Vibe Coding Guide

I’m monitoring a few resources with good vibe-coding and agentic programming practices, and I try to apply this stuff in my everyday work.

There’s a manual with some best vibe-coding practices. I’m going to read it and share the ideas that clicked for me here.
🔥32
Slightly improved MapReduce sunflowers

I just realized that in the post I promised to share a new version of map-reduce sunflowers with a small improvement for watering cells with tall sunflowers.

There are no 10 fire flags, but 4 flags is good enough for me, I really appreciate it.

So, small improvement: the whole code

Exact line - we check if the sunflower is a tallest possible one, and if it is, we provide it with water.

Different logic for coordinates: for each height we store a list of points

A little bit different merge stage.
To those, who want to understand agents properly

There is a post (in Russian) from a guy I really respect. Formally, it’s an advertisement for Yet Another Agent’s channel — but this time it’s not about news or hype. It’s about fundamentals.

What I especially like: the post contains a curated list of publications worth reading first, before drowning in frameworks, tools, and buzzwords.
From uplift to logit

Where we are
In the previous post we started to build a bridge from uplift to a score, which lets us solve binary classification problem. What we achieved:
⚗️ calculated probabilities for all combinations of binary feature f and target L
⚗️ wrote a score expression for S as logarithm of conditional probabilities fraction

Notation
⚗️ L - a binary target, 0 or 1 values (l in picture)
⚗️ r - a binary feature, 0 or 1 values
⚗️ α = P(L=1) - probability of target to be 1 or average value of target
⚗️ ϐ = P(f=1) - coverage, probability of feature to be equal 1, or average value of feature
⚗️ γ = P(L=1|f=1)/P(l=1) - uplift, gain in target we have when selected subset with f = 1
⚗️ S - score for ideal model to predict target

Problem statement
For given α, ϐ, γ:
🦐 create a dataset with non-stationary uplift γ
🦐 create baseline S for target prediction

Increment
For me these conditional probabilities are terra incognita. I don't have solid intuition, what is right and what is wrong. So, I was wanted a small sanity check for all this complex for me math. And test is quite simple: γ=1 means that factor doesn't give new information about target. In this case weights for this factor should become 0. In the previous attempt it wasn't obvious at all.

This time I slightly changed notation and used conditional probabilities instead of absolute one. And it is totally obvious now that when γ=1, expressions under logarithms become 1, logarithms are equal to 0 and therefore, expressions with N and M (number of ones and zeroes in sets of factors) goes away. It means that factors are not important, exactly what we assumed taking γ=1. Now I'm quite confident in this result, so let's dive deeper.

Outcomes
🦐 we have watertight expressions for dataset generation for arbitrary γ
🦐 there is an expression for the optimal model S
🦐 case γ=1 checked and S behave as it expected
🦐 expression for S is a bridge from probabilities to logistic regression model
🦐 it’s a universal approach — we can try it in the wild
Titanic - Machine Learning from Disaster

I want to close my gestalt. I invented a new ML method, I'm working as ML engineer for 9 years, I taught ML in GoTo school and in Russian Armenian University. But I have never submitted Titanic from Kaggle. Let's try to build our own approach. I think it's always interesting to start from scratch, build your own solution and only then read work of others.

Kaggle
It's a famous platform for machine learning. There is plethora of datasets for different tasks. You can find datasets for regression, classification, ranking, whatever. Kaggle provides free GPU resources for training your models, it allows you to check the quality of your solutions, compete with best ML geeks of our planet. "Grandmaster of Kaggle" is the title you want to have in your CV. So, not a bad place to hang around.

Titanic
13 years ago (what a number!) The Competition was published. Nowadays it's a good tradition to start ML lessons with this dataset. Why? Because:
🛳 It's a binary classification task
🛳 you can train your grasp of precision, accuracy, recall, ROC, ROC AUC
🛳 a lot of missing values
🛳 multimodal data (strings + numbers)

Data
On the data page one can check dataset's structure. It's split on two parts: training part and test part. You are to train model on your data, then apply the model to test data and submit it. Platform will check your results and give you feedback. Let's check fields:

target
☠️ survived - target field, 1 for survived (38%), 0 otherwise.

features
🛂 PassengerId — Unique identifier for each passenger. Not used as a predictor.
🏛Pclass — Ticket class: 1 = 1st (upper), 2 = 2nd (middle), 3 = 3rd (lower). Proxy for socio-economic status.
👺Name — Passenger name. Can be used to extract title (Mr, Mrs, Miss, etc.) or family.
👧🏻 Sex — Biological sex (male / female). Strong predictor of survival (“women and children first”).
🧙🏿‍♂️ Age — Age in years. Fractional if under 1. Has missing values.
👩‍❤️‍👨 SibSp — Number of siblings or spouses aboard (Sibling + Spouse). Discrete count (0–8).
👨‍👩‍👦 Parch — Number of parents or children aboard (Parent + Child). Discrete count (0–6).
🎫 Ticket — Ticket number. Often alphanumeric; can be messy for modeling.
💲 Fare — Passenger fare paid. Continuous; may correlate with Pclass and Cabin.
🏡 Cabin — Cabin number. Heavily missing; when present, deck/position may be informative.
🧳 Embarked — Port of embarkation: C = Cherbourg, Q = Queenstown, S = Southampton.

EDA

It's always a good idea to check your data. You can understand, how full they are and how informative they are.

🏛Pclass

No missing values, three values with frequencies:
1 216
2 184
3 491

We can calculate average survival rate for all three classes:
1 63%
2 47%
3 24%

Now we can recall that average survival rate is 38%. So, first class highly votes for the survival, second class slightly votes for survival and third class highly votes against survival.

👺Name

It's a good quiestion, whether name contains some information for survival at all. Let's check. I want to use hash trick technique and figure out. Experiment with hash trick demonstrated that Name feature contains information and gives 62% ROC AUC. So I dove into this field deeper. It turned out that it has format like
Futrelle, Mrs. Jacques Heath (Lily May Peel)

I checked distribution of survived for different titles and it is a good feature:

Master 0.575000 40
Miss 0.702703 185
Mr 0.156673 517
Other 0.724832 149

👧🏻 Sex
definitely a strong feature, it is on the picture

🧳 Embarked — Port of embarkation: C = Cherbourg, Q = Queenstown, S = Southampton.
Three different values, strong uplift => valueable feature

I'm going to continue this exploration. I would like to see that this topic is interesting. Please vote with 🔥 if you like it.

Jupyter Lab
github: eda
🔥61
Old but gold

Let's discuss a programming task. You have a bunch of numeric pairs like 5, 5, 7, 7, 2, 2 and one unique number, like 13. You mix everything into one array and shuffle it. Now you have something like [7, 2, 13, 5, 2, 7, 5]. Let n be the number of elements and let it be huge, like 100000000. Numbers are 32- or 64-bit wide. The task is to find the unique number. In our case it would be 13.

Feel free to share in comments time and memory complexities of your approach to this problem. It would be like T=O(...); M=O(...)

I think it would be fun to collect options for a few days and then compare algorithms.
🤷‍♂1
Old but gold

There seems to be two different problems. But really, it's the same problem.

1. Find the repeating and non-repeating parts of the decimal expansion of 1/n.
1/3 = 0.(3)
1/6 = 0.1(6)
2. For a singly linked list, check whether it contains a cycle.

Share your thoughts and ideas in the comments. Use the “spoiler” feature wisely. I’ll publish the canonical approach in 3 days, if needed.
👀2
The Deleted Photo

A long long time ago my colleague lent me a short-focused lens for my camera. I tested it for a week and this is my favorite shot from that week.

Just after I took this shot, it turned out the place was a police station and one of the police officers decided to teach my friend and me a lesson. He told us that it was forbidden to take photos of a strategically important facility and made us stay there for about two hours. It wasn't too bad because we were in the middle of some programming discussion and time flew by. Then the police officer asked me to show him the photos, without touching the camera and told me to delete this one. Then he let us go.

I was totally pissed off, because even from the preview screen I liked this shot very much. I turned off the camera and didn't touch it until I got home. Then I dove into photo recovery techniques. It was like "make an image of flash card onto my computer's drive; install a program that can recover files from a memory card image; start the recovery process ..." It wasn't easy, but I succeeded.

Enjoy the result!
🔥43
Periods in digits and remainders

I'm preparing a post with a solution for the first problem in the post . And there is a small question which has irked me for a while.

When we calculate digits of 1/n, there is a function which gives a digit from the remainder. So a cycle in the remainders leads to a period in digits, therefore period of digits can't be longer than period of the remainders. But why can't it be shorter?

I think that I have a glimpse of the idea, how to explain this. But if you have a good explanation, please share it.
👍1
Table with leaves

Who would guess that these wooden foldable panels on the sides of a table are "leaves"?
Not only decision trees and bushes have them.
Element of 2D sort

I don't have a fully cooked idea today, so let's discuss half-baked.

In The Farmer Was Replaced game there is a subgame where you plant cacti. Quite a complex description of game rules boils down to quite a simple idea: in order to make cacti harvest efficient, you are to sort 2D matrix of cacti heights. I.e. cacti become bigger when you move upward or to the right.

And, of course, there are limitations. You can move agent (drone) and it can swap a cactus under it with neighboring cacti. This prevents long-distance swaps, typical for traditional sorting algorithms like quicksort or merge sort and gives time complexity of O(n³) for n, the side length of the square field.

There is a global leaderboard in the game and the first place is 17 seconds for 8x8 field. My best attempt so far is 24.3 s. It's a 2D modification of insertion sort, I posted in here some time ago.

And today I'm going to try the approach in the picture. C - is the current drone position. Other letters - are the neighbors. Idea I want to test:
* write a tiny optimal procedure which sorts the cross in the order
* scan the field, apply the algorithm to each cell
* run insertion sort

My intuition is that this "cross local optimization" can cheaply move cacti far both in horizontal and vertical direction and it should take part of the load off insertion sort.
How Codex is built

I'm actively using the "Codex" agent in my work and it has always intrigued me how it works. I even wanted to find a repository with the source code and read it. Fortunately, today I stumbled upon a link to a post, where this topic is discussed. It explains the architecture and the engineering choices behind Codex.

I would summarize it as:
🤖 Codex is written in Rust
🤖 OpenAI uses Codex to build Codex
🤖 OpenAI developers multitask heavily with Codex
🤖 Skills are worth learning
🤖 Codex runs in a secure sandbox
🤖 Codex is a ReAct agent
🔥1
RAG is dead, long live agentic retrieval

Video touches a question I keep bumping into lately: do I actually need to learn RAG?

Very roughly: RAG is a way to preprocess your data into embeddings — high-dimensional vectors tied to chunks of text. During inference you retrieve the nearest chunks and feed them to the model so it has the “right” facts in front of it. If you have a text database with things that really shouldn’t be distorted, this helps reduce hallucinations.

The idea is elegant. The reality is messy. There are a lot of moving parts and a lot of “policies”: how to chunk, how to clean, how to embed, how to index, how to re-rank, what to cache, how to evaluate… It quickly becomes a whole universe where it’s easy to get lost.

In my current project I went the other way: no RAG. I just gave the agent tools like grep, cat, and a couple of small Python helpers it wrote for itself. According to the video, for agents working with codebases this is basically the SOTA approach: don’t overbuild retrieval, give the agent strong, direct access to the source of truth.

Extremely short version of the video:

📀For codebases: give the agent tools.
📀For other domains: RAG is still very relevant.

P.S. The phrase on the screenshot is from Yandex’s video summarization. It’s unintentionally hilarious.
Baghramyan mystery

I made these three photos of an escalator steps of Baghramyan metro station in Yerevan. These black and white triangles in the middle of the step intrigue me.

After the third attempt ChatGPT gave me close to the right explanation of this phenomenon. Let's try to beat it in the comments.
Web mirror of phys_math_dev is alive!

It was… kinda terrible.

Not when Codex wrote the code. Not when I deployed it to GitHub. It started when I logged into Cloudflare and began clicking around in the GUI.

The real pain came when Codex said: “Now you need to type in a dozen secrets.” Why?!! Sure, now I understand: you have to establish trust between Cloudflare, GitHub, and Telegram. But it’s not obvious at all. You bounce between different websites, copy-paste keys, IDs, tokens, and whatever else. And that little Python script that asked for my Telegram phone number and some mysterious confirmation still makes me shiver.

But anyway — it’s done. The mirror is live

It’s not ideal yet, and it definitely needs updates, but it works!
Baghramyan mystery revealed

Previously, I posted three mysterious photos. Today, let's solve the puzzle.

These triangles are the result of a strange coincidence. Shadows of handrails intersect in the middle of the step. So you see three zones:
I - brightest, lit by two lamps
II - mid shadow: lit by one lamp
III - deepest shadow: both lamps are blocked

Finally, there is a long "lever arm" in geometry, so a small shift of the lamps moves the shadows boundaries a lot. Near the bottom the bright zone dominates, near the top - the deep-shadow zone does.
Reality check

Yesterday I posted a hand-drawn sketch of the metro station. But I totally forgot that you can just take a photo of the place. Today, on the way to the office, I took this shot. Now you can compare the sketch and the photo and see whether my sketch was accurate.
🔥1
Childhood memory

While my next brainy post is baking, let me share with you a picture from my childhood.

I took this photo just today in the morning on my way to the office. The thing is that in 2026 in the Yerevan metro you can see exactly the same metal plates and signage I saw in 1989 in Moscow. Probably, this metro car was built 37 years ago at the Mytishchi Metro Car Factory and has been in use in the Yerevan metro ever since.
1