kyo-takano / alphacube

A powerful & flexible Rubik's Cube solver
https://alphacube.dev
MIT License
16 stars 1 forks source link

Symbolic Regression #5

Open m-a-t-h-e-u-s opened 2 months ago

m-a-t-h-e-u-s commented 2 months ago

Hi there!

It is me again...

First of all, thank you very much for listening to my ideas and being so patient and nice with me.

I'm attempting Symbolic Regression on your model. However, managing 54 entries and 18 outputs is quite overwhelming. I'm considering training another model to predict the number of moves required for the AlphaCube to solve a given scramble, possibly with a small beam width to expedite data collection (I remember you did something like this, but I'm unsure if you have the model saved). For every solution with a length N, I would generate N data points, capturing the state after the scramble and the number of moves required to solve from the start to the end of the solution. Then, I'll utilize it as an evaluation function, like chess engines, and proceed with symbolic regression on this model, which involves 54 entries and 1 output. My intuition suggests it might contain some information on solving a Rubik's Cube within its weights. Additionally, it would be interesting to observe from the Symbolic Regression whether redundancies emerge, such as knowing two colors of a corner piece being sufficient to determine the entire piece.

Thank you!

kyo-takano commented 2 months ago

It looks like you are trying to implement something similar or identical to DeepCubeA, which utilizes a DNN as a heuristic distance estimator.

However, AlphaCube uses a method to use a DNN as a probability-based heuristic function. Not as a distance estimator. This foundational method is informally named "EfficientCube". For a better understanding, please check out How It Works, and the original paper for more details.

[!NOTE] K. Takano. Self-Supervision is All You Need for Solving Rubik's Cube. Transactions on Machine Learning Research, ISSN 2835-8856, 2023. URL: https://openreview.net/forum?id=bnBeNFB27b.

While I wouldn't discourage you from exploring the distance heuristic approach, note that AlphaCube/EfficientCube is empirically more performant than DeepCubeA.

That being said, if you still insist on using a DNN as a distance estimator, you could compute the entropy of an output (probability distribution) as a proxy to estimate the distance. Here's a code snippet to get you started:

import torch
import alphacube

# model
alphacube.load()
model = alphacube.solver.model.eval()

# data sample (1024 random states per depth)
batch_size = 2 ** 10
dl = alphacube.env.get_dataloader(batch_size)
batch_x, _ = next(iter(dl))
print(f"{batch_x.shape=}")

# prediction
batch_p = model(batch_x).softmax(-1)
H = -(batch_p * torch.log(batch_p)).sum(-1)
print(f"{H.shape=}")

# Compute shannon entropy
H_by_depth = H.reshape(batch_size, 20).detach().numpy().mean(0)
print(f"{H_by_depth=}")

With H_by_depth being an reverse index, you could easily get a rough estimate of the distance of a given state.