Hunting Gravitational Lenses with Neural Networks

Milad Pourrahmani
Department of Physics & Astronomy
University of California, Irvine

Join the Conversation #WolframTechConf

Abstract

I will present my results on the identification of distant strong gravitationally lensed galaxies in large astronomical surveys by taking advantage of the deep learning functionalities of Mathematica.Gravitational lensing, a prediction of Einstein' s general theory of relativity, is observed when two galaxies are aligned along the same line of sight after which the gravitational field of the dark matter surrounding the foreground galaxy bends the light coming from the background source and magnifies its image.Lensing galaxies are extremely valuable in cosmological studies since they provide the ideal laboratories for studying the very distant universe by providing unprecedented details of distant sources for what otherwise would have been a few bright pixels on the most powerful telescopes.However, finding these natural telescopes among millions of galaxies (per square degree) can be a challenging task.I will discuss utilization of Mathematica in generating a training dataset by simulating gravitational lenses and by training convolutional neural networks to identify real lenses in large astronomical surveys.I will further demonstrate how Mathematica can be an alternative to Google' s TensorFlow and convey my experience using external GPUs to train deep learning algorithms on Mathematica.These results will be published in the Astrophysical Journal.

What are gravitational lenses?

Image Source: https://www.space.com/20265-gravitational-lensing-of-distant-star-forming-galaxies-space-wallpaper-schematic.html

β=θ-(((Subscript[θ, E])^2)/θ)

(((Subscript[θ, E])^2)/(arcsecond^2))=(M/((10^11.09)(Subscript[M, ☉])))×(Gpc/((Subscript[D, L])(Subscript[D, S])/(Subscript[D, LS])))

->    or     ->

(10^11)
(10^11)
(10^11)
8 foot straw
1°×1° -> 250k visible galaxies
41k°

Creating Datasets

Image Normalization

img0=;

Manipulate[
GraphicsGrid[{{EventHandler[adjustedImage=SetAlphaChannel[ImageAdjust[img0,{c,b,γ}],α],"MouseClicked":>Print[mouse]],
ImageHistogram[adjustedImage]}}],
{{c,0},-1,10,0.1},
{{b,0},-1,4,0.1},
{{γ,1.},0,1.5,0.025},
{{α,1.,"α"},0.,1.,0.1},
Button["Print {c, b, γ}",Print[{c,b,γ}]],
Button["Original", {c,b,γ}={0.,0.,1.}],
Button["Magic", {c,b,γ}={0.9,1.3,0.375}]
]

Lens Simulation

(*ClearAll["Global`*"]*)
imgSize=100;
u2={1,1};
tempHisto=HistogramDistribution@ImageAdjust[,{1.,.5,.3}];
blankSrc=Image[ConstantArray[0.,imgSize u2]];
foreground=ImageResize[,imgSize u2];

f[r_,R_,W_,B_]:= ((Sin[(π/((Sqrt[2])imgSize/2))r])^2)N[B PDF[NormalDistribution[R,W],r]];
generator[R_,W_,B_,foreground_]:=Module[{arc,sky},
arc=
ImageApplyIndexed[
arc=f[Norm[#2-ImageDimensions[foreground]/2],R,W,B]&,foreground
];

sky=ImageAdd[foreground,arc];


(*sky=HistogramTransform[sky,tempHisto];*)

sky
]

fgList={,,,};

gaussianCollage={};
i=1;
R min=10;
R max=imgSize/2;
W min=3;
W max=20;
B min=0.2;
B max=2.;

Manipulate[

Multicolumn[{sky=generator[R,W,B,foreground],Plot[f[r, R,W,B],{r,0.,(Sqrt[2])imgSize},PlotRange->{{0,imgSize/2},{0,1}}]}],

{{B,B max,"B"},B min,B max,.1},
{{W,4.,"W"},W min,W max,1.},
{{R,39.,"R"},R min,R max,1.},
Button["Randomize",R=RandomReal[{R min,R max}];W=RandomReal[{W min,W max}];B=RandomReal[{B min,B max}]],
Button["Append Conjugates",AppendTo[gaussianCollage,sky->"lens"];AppendTo[gaussianCollage,fgList[[i]]->"nonlens"];],
Button["Append as \"nonlens\"",AppendTo[gaussianCollage,fgList[[i]]->"nonlens"];],
Button["Next",i=i+1;foreground=ImageResize[fgList[[i]],imgSize u2];R=RandomReal[{R min,R max}];W=RandomReal[{W min,W max}];B=RandomReal[{B min,B max}]]
]

Dynamic[gaussianCollage]

Convolutional Neural Network

Image Source: https://www.mathworks.com/discovery/convolutional-neural-network.html

classesCIFAR2={"airplane","automobile"};
imageSize=100{1,1};
convolutionKernelSize=5;
nonlinearity=Tanh;

net=NetChain[

{ConvolutionLayer[30,convolutionKernelSize],
nonlinearity,
PoolingLayer[2,2],

ConvolutionLayer[60,convolutionKernelSize],
nonlinearity,
PoolingLayer[2,2],

ConvolutionLayer[90,convolutionKernelSize],
nonlinearity,
PoolingLayer[2,2],

FlattenLayer[],

1000,
Ramp,
DropoutLayer[0.5],

800,
Ramp,
DropoutLayer[0.5],

600,
Ramp,
DropoutLayer[0.5]}

~Join~

{Length[classesCIFAR2],SoftmaxLayer[]},

"Input"->NetEncoder[{"Image",ColorSpace->"Grayscale",imageSize}],
"Output"->NetDecoder[{"Class",classesCIFAR2}]
];

net//TraditionalForm

Recovered & Discovered Lenses

From 240,000 images, down to 1,200 images using ranking based on lens probability.

knownLenses={
{,"Lens01","known lens"},{,"Lens02","known lens"},{,"Lens03","known lens"},{,"Lens04","known lens"},{,"Lens05","known lens"},{,"Lens06","known lens"},{,"Lens07","known lens"},{,"Lens08","known lens"},{,"Lens09","known lens"},{,"Lens10","known lens"},{,"Lens12","known lens"},{,"Lens13","known lens"},{,"Lens14","known lens"},{,"Lens15","known lens"},{,"Lens16","known lens"},{,"Lens17","known lens"},{,"Lens18","known lens"},{,"Lens19","known lens"},{,"Lens20","known lens"}
};

Grid[Partition[knownLenses[[All,1]],5]]

Hardware and Software

My Experience with Mathematica and TensorFlow

External GPU vs CPU

GPUs are essential for using Neural Networks. My neural network runs 170 times faster on Titan Xp eGPU compared to Core i7 CPU.

We thank NVIDIA for donating an GeForce Titan Xp to our research Group.

First, you need to install the NVIDIA Driver for your external GPU.

Then find out if Mathematica recognizes your eGPU and what is its device number.

Needs["CUDALink`"]
(*SystemInformation[]*)

Thank you!

Financial support for this paper was provided by NSF grant AST-1213319 and GAANN P200A150121.