Thomj-Dev / SEMBAS

GNU General Public License v3.0
0 stars 0 forks source link

Measuring uniqueness of performance #32

Open ThomJ130 opened 1 month ago

ThomJ130 commented 1 month ago

Given some behavior, $f_i$, and set of inputs into $f_i$ that fall within the performance mode envelope, $E_i$, if we update, modify, or change $f_i$ to a different behavior $f_j$, how distinct or similar are their performances, i.e. $E_i \cap E_j$?

This becomes most clearly relevant when considering samples from a Bayesian Neural Network (BNN). When we create an ensemble of NNs by sampling from a BNN, how distinct are their performance modes? By maximizing distinctness, can we improve performance?

ThomJ130 commented 1 month ago

This is related to #12. Both benefit from monte carlo volume estimation. However, instead of focusing on the intersection of the envelopes, let's focus on the transformation of one onto the other. In other words, how much does the first envelope need to be mutated (translated and scaled) in order to map onto the second? This is very difficult if they are not similar, so some liberties may need to be taken in order to make a simple solution.

We can use nearest neighbors to find candidate boundary points to map onto. Here are some potential steps:

  1. Find the Center of Mass for both envelopes, translate the boundary for $E_1$ by the displacement between the CoMs towards $E_2$. This may (or may not) help with the assumption that we can find for each boundary point in $E_1$ a corresponding boundary point in $E_2$ using nearest neighbor search.
  2. For each halfspace in $E_1$'s boundary, find the nearest neighbor within $E_2$ boundary.
  3. Use the displacement between neighbors ($s = hs2.b - hs1.b$) and the angle between halfspace surface directions ($\theta = hs1.n.angle(\&hs2.n)$) to get the $|s| \cos (\theta) = |s| hs1.n \cdot hs2.n$. This is the approximated necessary jump distance in order to expand or contract $E_1$ to map onto E2 at that specific boundary point. (Potential optimization opportunity*)
  4. Repeat step 2**-3 until $|s|$ is below the desired error, or until a max iteration count has been exceeded.

This is a first pass on the problem, but it's roughly the idea. Some more thought needs to go into the converging upon $E_2$. Maybe we treat $|s| \cos(\theta)$ as a starting displacement (maybe double it), and then use binary surface search to converge upon the boundary in the direction $hs1.n$.

*We could stand to benefit from using matrix operations, moving the data into a contiguous data structure like a DMatrix. We already have logic for this in boundary_tools. This would produce two matrices, one for the boundary points ($B$) and the other for surface direction ($S$). The displacement between the boundaries would be $B_2 - B_1$, and the jump distance vector should just be $\vec d = (B_2 - B_1).norm(axis=1) \cdot (S_2 \cdot S_1).\text{T}$. I am using pseudo code to describe norm, but we need the norm of the columns (i.e. the norm of the displacement vectors). Anyway, let's say we have everything we need, then we can get an update function that converts $B_1^(i), B_2$ into $B_1^(i+1)$, where $B_1^(0)$ is the original boundary matrix. $B_1^(i+1) = (B_2 - B_1^(i)) \cdot S \cdot \sin(\vec \theta)$.

**If we execute the classifier to check if $B^(i+1)$ has passed the boundary, then we won't need to redo step 2, since we will just be using ground truth (FUT classifier) to converge upon the boundary. Otherwise, we may need to