Performing symbolic math steps is often related to pattern recognition. In theory, ChatGPT could be doing a good job here. I wanted to find the inverse of \[f(x) = {\mathrm{sign}}(x) \log(1+|x|)\] This function is a form of a signed logarithmic scaling. So, let's see what ChatGPT is telling us:
Yet Another Math Programming Consultant
I am a full-time consultant and provide services related to the design, implementation and deployment of mathematical programming, optimization and data-science applications. I also teach courses and workshops. Usually I cannot blog about projects I am doing, but there are many technical notes I'd like to share. Not in the least so I have an easy way to search and find them again myself. You can reach me at erwin@amsterdamoptimization.com.
Wednesday, September 27, 2023
Wednesday, September 20, 2023
Julia vs Python
![]() |
Simulation with n=1000 |
Monday, September 4, 2023
Critiquing a GAMS Model
It is always interesting to read GAMS models written by someone else. There are probably three things one can observe:
- A nice formulation or concept that is useful to learn about.
- A bad implementation: something that really should not be done that way.
- A piece of code that is correct and defensible, but I would write it differently. This includes things like style, layout, formatting, etc.
Tuesday, August 29, 2023
Three-level Matrix Balancing
Matrix balancing: introduction
Matrix Balancing Models are often used in economic modeling exercises: they create consistent data sets from data originating from different, conflicting data sources. A standard example is updating a matrix subject to given row and column sums. An example can look like:
Update orange cells subject to row/column sums |
The empty cells are zero, and they should remain zero. In other words, we need to preserve sparsity. Often, we have non-negativity restrictions on the values. The mathematical model can look like this:
Friday, August 4, 2023
Some TSP MTZ experiments
In [1], a question was posed about a TSP model using the MTZ (Miller-Tucker-Zemlin) subtour elimination constraints. The results with Julia/glpk were disappointing. With \(n=58\) cities, things were taken so long that the solver seemed to hang. Here I want to see how a precise formulation with a good MIP solver can do better. As seeing is believing, let's do some experiments.
The standard MTZ formulation[1] can be derived easily. We use the binary variables \[\color{darkred}x_{i,j}=\begin{cases}1 & \text{if city $j$ is visited directly after going to city $i$}\\ 0 & \text{otherwise}\end{cases}\]
Wednesday, July 12, 2023
Coloring edges of a grid
Given an m * n grid, each edge must be colored. However, there are 2 constraints:
- Entire grid must use only 3 unique colors
- Each square in the grid must be colored using exactly 2 colors (2 edges per color)
Thursday, July 6, 2023
A Julia thingy
In Julia, we can write 2x instead of 2*x. Not the most earth-shattering. But a bit special nonetheless.
The expression in the last cell is interpreted as a function call.
Sunday, July 2, 2023
Some confusion here
Sometimes you end up visiting strange sites. This is a question & answer site. The question is:
Obviously, this is not a good question. It is something like "what is the difference between a ham sandwich and butter?".
The answers are not so good either.
Tuesday, June 27, 2023
CVXPY DCP errors
Objective | CVXPY code | Result | Notes |
---|---|---|---|
\[\color{darkred}x^T \color{darkred}x\] | x.T@x | DCP error | print shows minimize x@x, i.e. transpose is dropped |
\[\color{darkred}x^T \color{darkred}x\] | x@x | DCP error | |
\[\color{darkred}x^T \color{darkred}x\] | cp.sum_squares(x) | transformed into quad_over_lin(x, 1.0) | |
\[\color{darkred}x^T \color{darkblue}Q \color{darkred}x\] | x.T@Q@x | transformed into QuadForm(x,Q) | |
\[\color{darkred}y:=\color{darkred}x-\color{darkblue}p\]\[\color{darkred}x^T \color{darkblue}Q \color{darkred}y\] | y=x-p x.T@Q@y | DCP error | |
\[\color{darkred}x^T \color{darkblue}Q \color{darkred}x - \color{darkred}x^T \color{darkblue}Q \color{darkblue}p\] | x.T@Q@x - x.T@Q@p | first term transformed into QuadForm(x,Q) |
Wednesday, May 10, 2023
Generate all solutions that sum up to one
In a post, the following question was posed:
We can select unique values \(\displaystyle\frac{1}{i}\) for \(i=1,\dots,n\). Find all combinations that add up to 1.
A complete enumeration scheme was slow even for \(n=10\). Can we use a MIP model for this or something related?
A single solution is easily found using the model:
Mathematical Model |
---|
\[ \begin{align} & \sum_{i=1}^n \frac{1}{i} \cdot \color{darkred}x_i = 1 \\ & \color{darkred}x_i \in \{0,1\} \end{align}\] |