Demonstrate the basic usage of our hironaka repo.
License: MIT
ubuntu2004
Overview
This is a brief notebook explaining what the package hironaka can do with examples.
Note: We require Python version >= 3.8
Summary
Local resolution of singularity can be transformed into a double-agent game (Hironaka's polyhedral game). Variations of the game have applications in various other problems like singularity theories.
Our purpose is to facilitate the computations around Hironaka's game including a support of machine learning techniques like reinforcement learning.
Quick-start
The definition of the game
The original Hironaka game is a game consisting of 2 players. They operate in a non-symmetric fashion. To emphasize the difference, let us call player 1 the "host", player 2 the "agent". For every turn the game has a state, the host makes a move, and the agents makes a move. Their moves change the state and the game goes into the next turn.
A state is represented by a set of points who are the vertices of the Newton polytope itself.
Every turn,
The host chooses a subset such that .
The agent chooses a number .
together changes the state to the next according to the following linear change of variables: for points . We subsequently apply Newton polytope to the transformed points and only keep the vertices.
A state is terminal if it consists of one single point. In this case, the game will not continue and the host wins. As a result, the host wants to reduce the number of as quickly as possible, but the agent wants to keep the number of for as long as possible.
The codes
Points is a wrapper that aims to showcase the basic usage of core classes. Its objects record a set of points in space.
The points are represented by nested lists. All points sit in the same Euclidean space.
One can add
distinguished_pointparameter to specify the index of a distinguished point. It will be tracked when going through all operations.Once the
Pointsobject is created, one can call.step()to take actions. The two parameters arehost_coordinates,agent_coordinates. They are demonstrated in lines ahead.
Different Hosts and Agents
There are a few implemented hosts and agents. The usage is demonstrated below.
Note: for normal usage, please make sure to set ignore_batch_dimension=True. If batch dimension is utilized, the game will be dealing with multiple separate games as a batch, and Agent, Host takes an extra dimension in the input.
Remember that Points is merely a wrapper for ListPoints that simplifies some APIs. When the usage gets more and more involved, it is recommended to switch to ListPoints and an extra batch dimension must be added outside. For now, Points still does the work.
For a host to make a move, feed it with the Points or ListPoints object. For an agent to make a move, feed it with the Points or ListPoints object plus the host's choice.
Once Agent.move(...) is called, if inplace=False is not specified, the state of the Points or ListPoints object will be modified. Otherwise, only the action will be returned.
You can pitch them against each other like the following.
Working with neural networks
Everybody wants to do machine learning nowadays, including us. In our project, we work with PyTorch.
Hosts and Agents who make decisions based on neural networks (nn.Module) should use the classes PolicyHost, PolicyAgentand their subclasses. They take in Policy as a parameter when constructing.
One can apply all kinds of creativity to the training of these models. But let us leave the training part to you smart folks and demonstrate how to use neural network players we just defined. They have exactly the same API as before as they are just subclasses of Host and Agent.
Going further
What we present here (Points, Agent, Host, Game, etc) is merely a facade that demonstrates the mathematical part of the project. They only support very basic usages. Admittedly, the structure of the repo has A LOT of rooms to improve. From here, the path branches out to the wilderness of the engineering world. We would like to guide the users to the corresponding modules:
For gym environment support, please take a look at
gym_envTensorPointssaves points in the form oftorch.Tensor. Operations are fully vectorized and use only matrix manipulations provided by Pytorch. It does NOT support single-step game wrappers (Agent,Host,Game) as it can simulate a collection of games at the same time (useful in GPU training)util.FusedGamegoes around gym and tries to fuse the host/agent decisions together and directly talking to GPU. It works withTensorPoints.Custom MCTS and DQN modules are in-progress.