# Learning a threshold from a matrix

I have a 2D matrix, and I want to learn a threshold from this matrix. All items in the matrix bigger than the threshold will become 1s, and all smaller than the threshold will become 0s. Then, I have a differentiable loss function to evaluate the resulting 0-1 matrix. What methods are typically used to learn the threshold? Do we put the matrix across a network, or are there any non-neural-network methods?

You have some kind of loss function $$L(y,\hat y)$$ that takes in some kind of truth value, $$y$$, and the $$0/1$$ values from your matrix, $$\hat y$$.

Implicitly, this is a function of the truth values, $$y$$, of the threshold, $$t$$, and of the original, unrounded values in your matrix, $$m$$.

Your goal is to minimize the loss, so minimize $$L(y, t, m)$$. Depending on the complexity, you might choose to do this by hand (calculus) or perhaps on a computer by looping over possible thresholds. If the matrix values all are between $$0$$ and $$1$$, for instance, you might calculate the loss at every $$0.01$$ increment.

This is a fairly straightforward computation, since the loss function really only depends on one variable, $$t$$, as the truth labels $$y$$ and unrounded values $$m$$ are fixed.

The hierarchy of methods for thresholds are:

1. Hand-coded thresholds
2. Learned thresholds with a decision tree
3. Learned thresholds with an ensemble of trees (e.g., Random Forest or XGBoost)
4. Learned thresholds with neural networks