Metrics for Classification and Regression

deeplenstronomy is designed for the purpose of facilitating machine and deep-learning studies of strong gravitational lensing. Supervised problems in these fields are typically framed as either classification problems or regression problems. This notebook will illustrate how you might utilize the features of deeplenstronomy to aid the development of your classification and regression algorithms.

Let's start by simulating a dataset with the demo_distributions.yaml file, and we'll also utilize the solve_lens_equation and return_planes arguments of deeplenstronomy.makedataset():

Classification

A simple, straightforward approach

For classification tasks, we are trying to predict a discretely-valued variable. The simplest approach to do this in deeplenstronomy is to classify the images from one configuration against the images in another configuration, with the configuration label serving as your discrete variable. If you take that simple approach, structure each CONFIGURATION section in the GEOMETRY section to be one of the classes in your classification problem.

A classic approach

In strong lensing searches, the terminology of "quads" and "doubles" are often used to describe the type of lensing going on (refering to the number of images of the source galaxy produced by the lensing). If you would like to classify based on the number of images of the source object, you can use the solve_lens_equation argument of deeplenstronomy.makedataset() to your advantage.

Setting this argument to True will add several columns to your dataset's metadata:

There will be a column of num_source_images for each band you choose to simulate. Using these columns you can determine which images contain quads, doubles, or no lensing. There are also columns such as x_mins_g, y_mins_g, x_mins_r, etc. for each band. These columns contain the information of the locations of each of the found positions of the lensed source object in your images.

Regression

Traditionally, strong lensing has been treated as a classification problem. However, there exist corner cases of slightly aligned galaxies that may produce small amounts of lensing as opposed to magnificent arcs and multiple images. If these corner cases exist in your training dataset, your classification algorithm may struggle with them. Framing lens detection as a regression problem is an interesting solution where instead of asking "Is this a lens?" or "Is this a quad?" you ask "How lensy is this image?"

To make this type of approach possible, you need to define a continuous variable that reflects the amount of lensing in the system. A mathematical approach to this is by calculating a quantity called the "Strong Lensing Cross Section," and as an open source framework, you are welcome to submit a pull-request to add this calculation to deeplenstronomy.

Another option that is possible with the current implementation of deeplenstronomy is to utilize the light from the source plane separate from all other light. Naively, if there is a lot of lensing going on, there will be a lot of light in the source plane, and if there is only a small amount of lensing then one would also expect a small amount of light in the source plane. This argument has to be normalized by the un-lensed brightness of the objects in the source plane, but is still a useable metric.

You can access this information by setting the return_planes argument to True. When you use this setting, your dataset will gain a new attribute for each configuration:

The planes for each configuration will be a numpy array with the following dimension structure:

Specifically, the plane axis is ordered as ("Lens Plane", "Source Plane", "Point Sources", "Noise"). Thus you can access all the source planes like this:

From this point, you can define a metric of your choice to characterize the amount of lensing going on.

A simple example could be the number of pixels with brightness above a certain threshold in a single band (the $g$-band in this case):

Note that I did not perform any normalization of the pixel values by the brightness of the objects simulated, nor did I normalize the number of pixels above the threshold by the angular sizes of the objects simulated, but these quantities are present in the dataset.CONFIGURATION_1.metadata. If these other two properties of the simulated dat were accounted for, then this metric could potentially frame the problem of lens detection as a regression problem. The purpose of this specific example, though, was to display how to pull information out of the individual planes and present the general concept of approaching strong lens searches with regression.