No actual code this week as I was mainly reading through various materials on multiple instance learning and coming up with an appropriate method for the problem. Right now the solution I've settled on is to use the expectation-maximisation (EM) algorithm. The reason I feel like this fits the problem, is that there are two interdependent unknown variables, the true position of the point and the underlying habitat labels in each bag. In addition the output is both the habitat classifier as well as probability distribution about the predicted true location of occurrence.

To go into more detail about how I will implement this I'll use the following notation.

$\pi_{bi}$ - the prior probability that the point associated with bag $b$ is actually from pixel $i$

$A_i$ - The square region of pixel $i$

$A_b$ - The region of uncertainty of bag $b$

$B_b$ - The set of pixels in bag $b$ (those overlapping $A_b$)

$x_i$ - Tessera embedding at pixel $i$

$\theta^{(t)}$ - Classifier parameters at iteration $t$

$\alpha_{bi}^{(t)}$ - Weight of pixel $i$ from bag $b$ at iteration $t$ / Predicted probability after $t$ iterations of true point from bag $b$ being in pixel $i$

$y_b$ - Label of bag $b$

First the weight of the point is uniformly distributed over all the pixels in its uncertainty area. This reflects the prior belief that the point is equally likely to come from anywhere in the region (This can easily be substituted with a different distribution such as Gaussian depending on what I think the underlying distribution of GPS error actually is). It also takes into consideration the geometry of the pixels, so pixels which only partially lie within the uncertainty region are weighted less.

$$ \pi_{bi} = \frac{|A_i \cap A_b|}{|A_b|} $$

Initially the weight of the pixel in each bag is set to the prior probability.

$$ \alpha_{bi}^{(0)} = \pi_{bi} $$

The next step is to train a logistic regression model based on minimising the weighted cross-entropy of the probability that a pixel's predicted label is the same as the label of the bag given the pixel's embedding.

$$ \theta^{(t)} = \operatorname*{argmin}_\theta \left( - \sum_b \sum_{i \in B_b} \alpha_{bi}^{(t)} \log P_\theta (y = y_b | x_i) \right) $$

This classifier can then be used to recalculate the probabilities that each pixel's true label matches the label of the bag.

$$ p_{bi}^{(t)} = P_{\theta^{(t)}}(y = y_b | x_i) $$

This represents the main loop of the algorithm as you can see the improved weights will improve the model and the improved model creates better weights. However, using $p_{bi}^{(t)}$ directly for $\alpha_{bi}^{(t+1)}$ can lead to the total weight of a bag exceeding 1 and will overweight larger bags. In addition it breaks the interpretation that $\alpha_{bi}^{(t)}$ is the probability that the bag's true location is within pixel $A_i$. Therefore, every pixel will be normalised within each bag, as well as being scaled by the prior to keep the geometric weighting accurate.

$$ \alpha_{bi}^{(t+1)} = \frac{\pi_{bi}\, p_{bi}^{(t)}}{\sum_{j \in B_b} \pi_{bj}\, p_{bj}^{(t)}} $$

Now with the normalised weights the algorithm can be iterated on to refine the classifier and the weights. How many iterations of EM is something I will have to assess and look into more later as the more iterations I perform the danger of overfitting increases.

After working through the mathematics of the algorithm I realised this would be a good place for me to make use of a side project I've been working on which uses LLMs to write procedural code for animation. So as an AI disclaimer, the animation below, while iterated on and prompted in great detail by myself, was entirely procedurally generated with an LLM. I know that a lot of people object to any AI generated resources, however I believe that it can be used to greatly benefit scientific communication when used correctly, and I think the video below does a good job of visualising the algorithm.