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
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
DIY. Physics laboratory

We started a small educational project. A short ride to the Vernisage flea market brought us:
⚗️ Holder for chemistry experiments
⚗️ 5 springs
⚗️ old Soviet set of weights

In a chat session with ChatGPT we explained that we aim at a worldwide site on which one can start the camera, point it at an oscillating object, get the time dependence of its displacement, extract frequencies from the signal and track experiment results. Iron Friend gave unexpected comment that putting a bright spot on the oscillating object can save us tons of work.

After some adjustments we finally got the result on the photos. Program detects the red spot on the picture, creates a mask (on the right) and writes the dependence of the vertical coordinate for the center of mass versus time. Lower image - the recorded curve.

Next steps:
📟 Calculate frequencies of components (Prony's algorithm)
📈 Track frequency change versus mass change

In general, I want to use this setup to cover the following topics:
✒️ frequency dependence on mass for elastic restoring force
✒️ frequency dependence on pendulum length
✒️ expressions for effective spring constant for series and parallel spring connections

The current state of the project
🔥3
Mystery code

Later I'm going to explain in detail, what is going on. For now I'm curious whether this subject is trivial. If you can, feel free to answer the following questions in the comments:

How come that the guessed highlighted numbers in the beginning of the post match restored at the end?
What's the connection with the previous post ?
What physics can be connected to this math?
3
How to survive in the new reality

Probably the best explanation "How to stop worrying and love agents."

In order to succeed you have to:
🟢 Hone your expertise
🟢 Use LLMs as chat, agents, tools - whatever helps you move faster

There is no silver bullet. You buy this AI fluency only by paying with hundreds of hours of trial and error.

Stolen from here (russian)
I'm not totally original

While I was digging into this area on my own, with heavy help from ChatGPT, of course, I never expected that I have a completely new result.

On Monday my colleagues and I discussed how a linear model drops out of Bayesian probability formulas and the book from the attachment was mentioned. It turns out "my" expressions are in there too - see the references in the picture.
Tiny math problem anniversary

Ten years ago I accidentally invented an easy but funny mathematical problem. Let a long decimal number be "a". We permute digits and get "b". Is (a - b) divisible by 9?

The answer is obvious. But I saw some advanced contest-level math students, for whom it wasn't easy at all to come up with a strict explanation, why.
11
Titanic. Age.

We started talking about the Titanic dataset. Let's discuss the Age factor. We saw that Sex, Pclass and Embarked are strong features and to study them we used that these features are categorical with low cardinality. Age is different. It's a continuous value from 0 to 80 with missing values. I tried the following approaches to figure out its signal:

👁 ROC with age as the score and survival as the target: 47% ROC AUC, no clean picture although some age ranges seem to carry signal
👁 Train CatBoost with age as the only feature, survival as the target and logloss as the loss function. Not bad on train, but random on eval
👁 In the spirit of Bayesian analysis, compare the age distribution of survivors and not-survivors. It seems the most promising exercise. There is a 0-10 range with higher density in the survival distribution, while 18-28 is more prominent among those who died. Naive model which just gives 1 to the 0-10 range and so on gives 57% ROC AUC, it seems decent
👁 Age field is filled for 80.1% of cases
👁 Survival rate is 40.6% (slightly more) for passengers with known age and 29.4% (significantly less) for passengers with missing age

All in all, age feature seems to be weak, but useful.
126 and 01239

👉 The sets 1, 2, 6 and 0, 1, 2, 3, 9 are fun because their arithmetic mean is an integer. And 01239 is slightly more fun: both median and mean are inside the set.

📖 A well known fact: if you look for a point that minimizes the total distance Σ |xᵢ − a|you end up with the median. The explanation is also intuitive. Imagine these numbers are coordinates of houses, and you want to place a transformer station. You want to minimize the total length of wires. (I like a transformer station more than the legendary postman: a postman who can carry only one package at a time feels… suspicious.) If there are more houses on the right, it’s profitable to move the station to the right; if more on the left — move left. Equilibrium happens when the counts on both sides are equal. That’s the median.

But the “sum of squares” story always felt less obvious to me: Σ (xᵢ − b)²

🦴 Straight physical system is a net of springs which connect a nail (what?!!) with all houses. In this case physics is quite trivial — this mythic nail would be placed in the position where all forces are in an equilibrium and, by definition of forces through potential energy, sum of squared distances is minimized.


⚛️ This model looks totally awkward to me now. When I was young this analogy looked great. But now it stopped clicking. Springs have finite length and it's hard imagine nail connected with houses by springs. Probabilities are totally different thing. We all want to live in an universe with high probability. It's a respectable place in the middle of multiverse. So, if x1, ..., xn are samples and you want a single “most representative” number, you can assume the source distribution is Gaussian. Then maximizing likelihood is the same as minimizing the sum of squared errors — and the answer becomes the mean. Much more natural than a city-wide spring spiderweb.
👍1
Agentic RAG Legal Challenge

Why am I doing it? I'm reading a lot about agents, llms and other quite popular nowadays hot stuff. But, besides my project on work, I have no hands-on experience with all these technologies. So, I decided to take part in this competition. I don't think I will win any prize, but hope to get some experience and slightly deeper understanding of all these RAG-like buzzwords.

Informal contest description. The main idea is to create a system, which can take as input a bunch of PDF files, preprocess them and then answer questions. It's important to track telemetry - how fast the first token was generated, which chunk was retrieved from the RAG system, total amount of burned tokens.

If you want to read more, feel free to check:
📖 participant guide
⚗️ short version of QA session

Please, react with fire (🔥), if you want to read more about this competition.
🔥31👏1
The Farmer Was Replaced — navigation

🛸 From time to time I write about the game The Farmer Was Replaced.

Unexpectedly it turned into a nice playground for experimenting with algorithms, navigation on toroidal grids, and even small distributed systems.

👇👇👇 Below is a collection of posts about TFWR.

If you want to start quickly

These five posts contain most of the ideas.

52 — The Farmer Was Replaced tg web_en web_ru
59 — Torus navigation tg web_en web_ru
67 — TFWR. Labyrinth tg web_en web_ru
71 — TFWR. Spawn drones tg web_en web_ru
91 — Sunflowers. MapReduce tg web_en web_ru

Full list
💣 Introduction

52 — The Farmer Was Replaced tg web_en web_ru
54 — TFWR. Navigation tg web_en web_ru

🧭 Navigation on the field

59 — Torus navigation tg web_en web_ru

🌽 Labyrinth and maze traversal 🌽

67 — TFWR. Labyrinth tg web_en web_ru
117 — Left hand rule in The Farmer Was Replaced tg web_en web_ru
119 — TFWR. Left hand maze traversal tg web_en web_ru

🏋️ Sorting tasks 🏋️

70 — Bubble sort of one cacti column in TFWR tg web_en web_ru
115 — 2D sort tg web_en web_ru
116 — 2D insertion sort. Implementation tg web_en web_ru

✈️ Drones and distributed programming ✈️

71 — TFWR. Spawn drones tg web_en web_ru
78 — TFWR. Drone coordination tg web_en web_ru

🗺 MapReduce experiments 🗺

86 — MapReduce in The Farmer Was Replaced. Part I tg web_en web_ru
90 — MapReduce in The Farmer Was Replaced. Part II tg web_en web_ru
91 — Sunflowers. MapReduce tg web_en web_ru

🧙‍♂️ Small optimization trick 🧙‍♂️

122 — Dict vs % tg web_en web_ru

📢 Discussion 📢

110 — For TFWR solutions discussions tg web_en web_ru
3
A fleeting moment of joy. Vibe analytics.

Thank you very much for the supportive reactions to the previous post about the RAG competition.

A few words about the progress. On Sunday I spent quite a solid piece of time playing with the available data.

The idea of the competition is that you have an initial portion of data: 30 PDF documents and 100 questions. You are to prepare a pipeline which can digest these documents and prepare system to quickly answer questions.

I started with the questions. The prompt "figure out groups of questions with minimal size so questions in each group are as similar as possible" gave me 7 groups of questions.

Then "analyze these questions and figure out a relational scheme which allows us to address them in the most efficient way" gave me quite a complex relation scheme which was implemented in SQLite. Definitely it is not an architecture to win the contest, but it is a solid basis to create a golden set of answers with which we can compare answers of our quick RAG system.

Then "work without interruptions, create and check hypotheses, evaluate them, find proper answers to all questions in the contest, save explanations" gave me 100 answers. Short review of a few cases showed me that references to documents are quite solid and it totally makes sense to try this approach as the first submission.

There are several categories of questions. Some of them require a precise answer (number or list or name or boolean), some - free text. We have 1.0 score on precise answers and the nice value 0.693 on freeform answers.

I think it's a big step for our team and it's very rewarding to get 7th place in one day of work. Out of 144 members with some non-zero submissions and 300 registered teams.
6
Media is too big
VIEW IN TELEGRAM
TFWR. Simple pumpkin harvest

The goal of this post is not to give you a ready polished and optimized pumpkin harvester in the TFWR game. I want to show you the simplest possible harvester, as I know it and explain step-by-step how it works.

def best_move(d1, d2, n1, n2):
d, n = ((d1, n1), (d2, n2))[n2 < n1]
for _ in range(n):
move(d)

def nav(x2, y2):
x1, y1 = get_pos_x(), get_pos_y()
n = get_world_size()
best_move(East, West, (x2 - x1)%n, (x1 - x2)%n)
best_move(North, South, (y2 - y1)%n, (y1 - y2)%n)


My favorite navigation. Why it works is written here.

n = 12
set_world_size(n)


Just for the sake of the video let our farm be 12 cells long. If you don't have this function yet, you can measure your farm with

n = get_world_size()


Let's start with tilling the whole farm.

for y in range(n):
for x in range(n):
nav(x,y)
if get_ground_type() == Grounds.Grassland:
till()


Two loops allow us to visit every cell on the farm. It's a good idea to check the ground type because without this check the script will always change the ground type to the opposite.

Now let's plan our pumpkin endeavor.

plan = []
for y in range(n):
for x in range(n):
plan.append((x, y))


We created an array of tuples with all cells in which we want to have mature pumpkins.

while plan:
x, y = plan.pop(0)
nav(x, y)
if not can_harvest():
plant(Entities.Pumpkin)
plan.append((x, y))


while plan

is quite an interesting construction. It executes a piece of code while there is something in the list 'plan'. You can re-write this condition as len(plan) > 0, but while plan is more pythonic.

Then we get a pair of coordinates from the beginning of the list and go to the (x, y) place. Now the most tricky, at least for me, part starts.

A pumpkin can be grown up, in this case can_harvest() is True. But if it is not, there are two options: the pumpkin is OK, but it is growing and the pumpkin can be rotten. This code elegantly handles all these options. It tries to plant a pumpkin. If it is growing already, plant does nothing. If it is rotten, plant replaces it with a new one. In all these cases it makes sense to check the pumpkin again, so we append the tuple of coordinates to the end of our list.

If we are outside the loop, our plan is empty, it means that all pumpkins are grown up and we can harvest them.

Last but not least, we need to make an infinite loop to continue the harvest.

Code on github
👍1🎃1
6*6 to a really round number

One more number I can't leave unnoticed. It is not a true round number, but I can see a few interesting facts here.

First of all, it's the voltage of household outlets. I can't help but mention the joke "By using this outlet you have a 160V bonus"

I'm really waiting for 100000000₂, and there are only 6*6 subscribers left to this rooooound number.

Due to vector algebra, three-phase symmetry, and the properties of complex numbers, √3​⋅220≈1.73⋅220≈380
4
This media is not supported in your browser
VIEW IN TELEGRAM
Simple wood farm

It's a simple wood farm for the beginning of the game.

def best_move(d1, n1, d2, n2):
d, n = ((d1, n1), (d2, n2))[n2 < n1]
for _ in range(n):
move(d)

def nav(x2, y2):
x1, y1 = get_pos_x(), get_pos_y()
n = get_world_size()
best_move(East, (x2 - x1) % n, West, (x1 - x2) % n)
best_move(North, (y2 - y1) % n, South, (y1 - y2) % n)

n = 6
set_world_size(n)
while True:
for y in range(n):
for x in range(n):
nav(x, y)
p = Entities.Tree
if (x + y) % 2:
p = Entities.Bush
if can_harvest():
harvest()
plant(p)


Let's check some interesting moments.

First of all, I like nav function a lot. It allows to write a clean and concise code. Write once, use forever. Until you need a heavy optimization, but it's a different story.

n = 6
set_world_size(n)


I have quite an advanced farm, these lines shrink it back into the "beginning of the game" state. In the beginning of the game you had better use

n = get_world_size()


while True:

Let's repeat our harvesting.

  for y in range(n):
for x in range(n):
nav(x, y)

We traverse the whole board.

      p = Entities.Tree
if (x + y) % 2:
p = Entities.Bush


a chessboard pattern for bushes and trees. Allows trees to grow fast.

      if can_harvest():
harvest()

quite an important trick. Prevents young trees from being chopped down. Without this "if" one can chop a tree without getting a reward for it.

plant(p)

plant the plant again.

Happy woodchopping!!!
👍1