# TeV Solar Gamma Rays as a probe for the Solar Internetwork Magnetic Fields

Kenny C.Y. Ng  0000-0001-8016-2170<EMAIL_ADDRESS>Department of Physics,
The Chinese University of Hong Kong, Shatin, New Territories, Hong Kong, China
Andrew Hillier  0000-0002-0851-5362<EMAIL_ADDRESS>Department of
Mathematics and Statistics, University of Exeter, Exeter, EX4 4QF UK
Shin’ichiro Ando  0000-0001-6231-7693<EMAIL_ADDRESS>GRAPPA Institute,
University of Amsterdam, 1098 XH Amsterdam, The Netherlands  Kavli Institute
for the Physics and Mathematics of the Universe, University of Tokyo, Chiba
277-8583, Japan

( May 27, 2024)

###### Abstract

The magnetic fields that emerge from beneath the solar surface and permeate
the solar atmosphere are the key drivers of space weather and, thus,
understanding them is important to human society. Direct observations, used to
measure magnetic fields, can only probe the magnetic fields in the photosphere
and above, far from the regions the magnetic fields are being enhanced by the
solar dynamo. Solar gamma rays produced by cosmic rays interacting with the
solar atmosphere have been detected from GeV to TeV energy range, and revealed
that they are significantly affected by solar magnetic fields. However, much
of the observations are yet to be explained by a physical model. Using a semi-
analytic model, we show that magnetic fields at and below the photosphere with
a large horizontal component could explain the $\sim$1 TeV solar gamma rays
observed by HAWC. This could allow high-energy solar gamma rays to be a novel
probe for magnetic fields below the photosphere.

##  I Introduction

It has long been theorised that cosmic rays impacting the Sun would produce
high-energy gamma rays through hadronic interactions Seckel:1991ffa
(hereafter SSG). The pioneering work by SSG considered cosmic-ray reflection
by magnetic flux tubes, which significantly enhanced the solar gamma-ray flux
compared to the case where the magnetic fields are ignored Zhou:2016ljf .

Solar atmospheric gamma rays were first detected by EGRET Orlando:2008uk , but
precision observation was only made possible by the Fermi space gamma-ray
telescope. Ref. Abdo:2011xn  showed that the observed flux is much higher than
the SSG prediction Seckel:1991ffa  in the 0.1–10 GeV energy range. Later,
Refs. Ng:2015gya ; Tang:2018wqp ; Linden:2018exo ; Linden:2020lvz  confirmed
this up to around 100 GeV. Furthermore, solar gamma rays also exhibit a hard
spectrum, large time variation that anticorrelates with solar activity
Ng:2015gya ; Tang:2018wqp ; Linden:2020lvz , a spectral dip in the energy
spectrum Tang:2018wqp , and nontrivial time-dependent gamma-ray morphology
Linden:2020lvz ; Arsioli:2024scu . Recently, solar gamma rays were detected
for the first time by HAWC HAWC:2022khj  in the TeV range with a soft spectral
index of about $-3.6$.

In terms of modeling efforts, Refs. Mazziotta:2020uey ; Li:2020gch
implemented the PFSS Schatten:1969 ; Altschuler:1969SoPh ; Hoeksema:1984PhDT ;
Wang:1992ApJ  corona magnetic field model in particle propagation and
interaction simulation suites to compute the solar gamma-ray flux. While both
calculations showed that corona magnetic fields can significantly affect
gamma-ray production and could plausibly account for most of the observed flux
below 10 GeV, the observed flux above 100 GeV remains unexplained. Ref.
Gutierrez:2019fna ; Gutierrez:2022mor  connected the cosmic-ray Sun shadow and
the cosmic-ray induced solar emissions. Ref. Banik:2023shc  hypothesized that
the Sun could be a TeVatron to explain the high-energy emission. Using 3D MHD
simulations, Ref. Hudson2020MNRAS.491.4852H  suggested a pressure-magnetic
field relation for computing the cosmic-ray interaction in the solar
atmosphere. Most recently, Ref. Li:2023twp  considered magnetic flux tubes and
flux sheets, showing an impressive agreement in flux and spectral shape with
data from $\sim 10$ GeV to $\sim 1$ TeV, though the flux at TeV falls short by
a factor of a few under the chosen set of fixed parameters.

Despite all these efforts, there is a lack of concrete theoretical
understanding on the production of solar gamma rays. Given the complexity of
solar magnetic fields and the vast cosmic-ray energy scale involved (from sub-
GeV to beyond TeV), a complete description of solar gamma-ray production may
seem daunting without investing significant effort into detailed simulations
and modeling. However, as we argue in this work, given a set of reasonable
assumptions, we can identify the dominant effect responsible for the gamma-ray
production at the high-energy limit. In particular, we show that horizontal
sub-photospheric internetwork magnetic fields are likely responsible for the
observed $\sim$TeV solar gamma rays.

##  II The need for strong fields

In this work we exclusively discuss steady solar gamma-ray emission; transient
emission, such as those associated with solar flares Ramaty1975SSRv…18..341R ;
Murphy1987ApJS…63..721M ; Kozlovsky2002ApJS..141..523K ; Omodei:2018uni ;
Share:2018kqt , has only been observed up to a few GeV Fermi-
LAT:2013vao_flares  and are all removed for Fermi solar gamma-ray analyses
(E.g., Refs Ng:2015gya ; Tang:2018wqp ; Linden:2018exo ; Linden:2020lvz .)
There are also leptonic components, such as inverse Compton Orlando:2006zs ;
Moskalenko:2006ta ; Orlando:2008uk ; Zhou:2016ljf ; Orlando:2020ezh ;
Lai:2022qif ; Yang:2023res  and synchrotron Petrosian:2022bxr ;
Orlando:2022xsm  emission by cosmic-ray electrons interacting with Sunlight or
solar magnetic fields, but they have completely different morphology and thus
can be easily distinguished from the hadronic disk component.

Solar atmospheric gamma rays (also called the disk component) are produced
dominantly through hadronic channels, when secondary particles (such as
neutral pions) decay into gamma rays. Typically, the produced gamma rays have
energy about 10% of that of the primary cosmic rays, $E_{\gamma}\sim
0.1E_{p}$. The fact that HAWC observed TeV solar gamma rays implies that
cosmic rays up to 10 TeV must be strongly affected by solar magnetic fields.
Considering the Larmor radius ($L$) versus energy,

$\frac{E}{20\,\rm TeV}\simeq\frac{L}{R_{\odot}}\frac{B}{\rm
G}\simeq\frac{L}{10^{3}\,\rm km}\frac{B}{\rm kG}\,,$ (1)

one can see that at least 1 kG field strength is needed in order to affect
$\sim$10 TeV cosmic rays while confining the physical scale to be around
$10^{3}$ km.

To give some context for this $10^{3}\,{\rm km}$ length scale, Figure 1 shows
the matter density as a function of _depth_ Baker:1966 ; 1973ApJ…184..605V ,
defined to be zero at the photosphere and increases towards the center of the
Sun. Given the density profile, one can estimate the gamma-ray production
efficiency by computing the vertical optical depth toward the center of the
Sun $\tau_{v}=\int\frac{\rho}{m_{p}}\sigma dr$, where $\rho$ and $m_{p}$ are
the matter density and proton mass, respectively. In this work, we take the
proton-proton cross section, $\sigma$, to be about 31 mb Kelner:2006tc , and
we ignore the modest increase of the cross section toward high energy. In
addition, as depth increases, it is increasingly more difficult for the gamma
rays to escape the Sun. The combined gamma-ray production and escape
efficiency can then be approximated by $\tau_{v}e^{-\tau_{v}}$, as the
exponential factor approximates the parent particle’s attenuation and the
escape probability of the produced gamma rays. This approximation is justified
as the photon radiation length Workman:2022ynf  is only slightly longer than
the proton interaction length. Both $\tau_{v}$ and $\tau_{v}e^{-\tau_{v}}$ are
shown with the right axis of Figure. 1. We can see that the $10^{2}$–$10^{3}$
km depth scale mentioned above corresponds to the peak of the
$\tau_{v}e^{-\tau_{v}}$, which highlights the typical depth required for
maximal gamma-ray production efficiency. Incidentally, this length scale is
also approximately the size of a granule, the convective cell at the solar
surface.

Figure 1: Solar density model from Baker Baker:1966  and Vernazza
1973ApJ…184..605V  (blue solid line). We note that these two models and the
density solution by Ref. Unno:1985PASJ  (red dashed line) overlaps just below
the photosphere and agree excellently with each other. In orange lines, we
also show the vertical optical depths, showing that a few hundred km below the
photosphere is the most optimal depth for producing solar gamma rays (see text
for details).

One potential site for finding the 1 kG fields is sunspots. However, at a
given time, sunspots only occupy a small fraction of the solar surface, thus
unlikely to affect solar gamma-ray production at a great capacity. At much
smaller scales, kG fields can form in the quiet Sun in intergranular lanes.
Recently, the effect of the vertical network fields in flux tubes and
intergranular lanes were investigated in Ref. Li:2023twp  by assuming that
cosmic rays follow the open field lines high in the atmosphere into these
structures and considering the cosmic rays reflected by the magnetic bottle
effect. With a fixed choice of parameters, the flux and the spectral shape
agrees well with the data, though it falls below the HAWC observation at TeV
by a factor of a few. This indicates that network fields are likely important
for the gamma-ray production for a wide energy range.

In this work, we look at a completely different magnetic field configuration
by turning our eyes to another potential source of kG fields: _horizontal_
internetwork fields below the photosphere.

##  III The role of solar internetwork magnetic fields

The atmosphere of the Sun (photosphere, chromosphere, and Corona) shows a
diverse range of magnetic phenomena Wedemeyer-Bohm:2008tpk ; Wiegelmann2014 ;
Solanki2006RPPh…69..563S . In the photosphere, it can be divided into active
and _Quiet_ regions. Active regions famously host strong magnetic fields
features, e.g., in Sunspots. The quiet regions, though once thought to be non-
magnetic, is now known to be fully magnetic Almeida:2011talk  (the so-called
Quiet Revolution), and could even dominate the magnetic energy of the Sun
TrujilloBueno:2004re .

The magnetic fields in the quiet regions come from network and internetwork
regions (see Ref. Rubio2019LRSP ; Rempel2023SSRv  for reviews). The network
regions outline the shape of the granular and supergranular cells, while the
internetwork regions represent the cell interiors. The internetwork fields,
which have typical field strength of ${\cal O}(100)$ G at the solar surface,
have a large horizontal component TrujilloBueno:2004re ;
Lites1996ApJ…460.1019L ; Suarez:2007pp ; Lites2008ApJ…672.1237L ;
Rubio2019LRSP  and are suggested to be caused by local dynamo from the
ubiquitous convective motion Schuessler:2008si ; Steiner2008ApJ…680L..85S ;
Steiner2010ASSP…19..166S ; Rempel2023SSRv . Given the large coverage of the
internetwork regions and that the convective motions below the surface could
produce similar fields (but at strengths determined by the local energy
equipartition between kinetic and magnetic energy), we consider their role in
gamma-ray production.

For solar gamma-ray production, horizontal fields are likely to be _efficient_
, as cosmic rays can be reflected as long as they stay in the coherent field
region, then observable gamma rays can be produced when cosmic rays interact
after they are reflected.

As we limit our attention to the TeV gamma rays, we can also safely ignore the
processes that affect mostly lower energy cosmic rays or are expected to be
subdominant. For example, the interplanetary magnetic fields affect how cosmic
rays propagate from interstellar space to the surface of the Sun
Potgieter:2013pdj , but only affect gamma rays around and below 10 GeV
Abdo:2011xn ; Li:2022zio . Typical corona magnetic fields Wang:1992ApJ , as
shown in Ref. Mazziotta:2020uey ; Li:2020gch , are not strong enough to
significantly affect $>$TeV cosmic rays.

###  III.1 A toy model of the horizontal internetwork fields

We use a simplified model to investigate the effect of horizontal internetwork
magnetic fields on solar gamma-ray production. At the solar surface, the
typical ${\cal O}(100)$ G horizontal field strength TrujilloBueno:2004re ;
Lites1996ApJ…460.1019L ; Suarez:2007pp ; Lites2008ApJ…672.1237L ;
Rubio2019LRSP  is comparable to the kinetic energy density of the fluid. For
reference, with density around $3\times 10^{-7}\,{\rm g/cm^{3}}$ and flow
speed around $3\,{\rm km/s}$, the equiparition field is around 580 G. We thus
model horizontal field strength below the photosphere following this
assumption,

$|\vec{B}(r)|=f\sqrt{4\pi\rho(r)x(r)^{2}}\,,$ (2)

where $\rho$ is the density, $r$ is the radial distance, $x$ is the flow
speed, and we consider $f$ a free parameter in this model, with $f^{2}$ being
the fraction of the kinetic energy over to magnetic energy ($f=1$ represents
the equipartition case). Though we consider $f\leq 1$ as an physically
reasonable representation of the field strengths obtainable by local dynamo
action (e.g. Rempel:2014ApJ…789..132R ), we also investigate some larger
values to mimic the rise of magnetic field from lower depths of the convection
zone to inject field into the sub-photospheric region.

The speed amplitude can be estimated by convection models Unno:1985PASJ ;
Deng_2006ApJ…643..426D ; Xiong:2021FrASS…7…95X , inferred from simulations
Stein_1998ApJ…499..914S , or indirectly probed through surface observation and
helioseismology Hotta_2023SSRv..219…77H . For our toy magnetic field model, we
obtain the speed amplitude as a function of depth from Unno, Kondo, and Xiong
Unno:1985PASJ . Fig. 2 right axis shows the velocity amplitude from this
model, which is consistent with that from global and local simulations (see
Fig. 4 of Ref. Miesch:2012ApJ…757..128M ).

Figure 2: (Left axis) Magnetic field models used in this calculation. The
photosphere is located at a depth of 1250 km. Above the photosphere, the
$\left|B(-1250)\right|=1\,{\rm G}$ case extrapolates the field to 1 G, while
the $\left|B(<0)\right|=0$ case sets the field to be zero. (Right axis) The
flow speed model used in this work from Ref. Unno:1985PASJ .

Figure 2 shows the magnitude of the magnetic fields we used in our horizontal
field model, following Eq. (2). Above the photosphere, the magnetic fields get
weaker and become more complicated. In the spirit of this paper, we consider
two cases to estimate the uncertainties associated with magnetic fields above
the photosphere. One is that we extrapolate the field strength linearly to 1 G
at 1250 km above the photosphere while keeping the field direction (labeled as
$\left|B(-1250)\right|=1\,{\rm G}$, dashed lines in Fig. 2); the second case
is that we ignore the fields completely above the photosphere (labeled as
$\left|B(<0)\right|=0$). These two models roughly bracket the two extreme
effects of magnetic fields above the photosphere: one suppresses cosmic rays
from reaching the photosphere and one have no effect on that.

###  III.2 Cosmic ray orbit simulation

Once the magnetic field model is specified, we can solve for trajectories of
particles that go into the Sun, which is necessary for calculating the
interaction probabilities of these particles and hence the gamma-ray
production efficiencies. We solve the particle trajectories using the Lorentz
force with the following assumptions: (1) The horizontal fields are coherent
within the convection cell, and the cell is always large enough to contain our
cosmic-ray particles; (2) particle trajectories are not affected by other
factors, such as interactions; and (3) the cosmic rays are made of protons
only. (The effect of nuclei on the flux is estimated separately below.)

Figure 3: An example of the orbit simulation, showing 15 of the 368 tracks
used for the calculation for the $\left|B(-1250)\right|=1\,{\rm G}$ case with
$f=1$ and 10 TeV proton energy. The dashed lines are the tracks projected to
the $z=-2.5\times 10^{3}$ km plane.

The protons are injected at 1250 km above the photosphere, and is assumed to
be isotropic. This is in part justified as Refs. Mazziotta:2020uey ;
Li:2020gch  show that corona fields have a small effect on the gamma-ray
production at TeV. At the injection point, a set of downgoing trajectories are
simulated, assuming equal probability in pointing directions. In practice,
only the hemisphere towards the Sun is needed, as the other half will simply
escape. The anisotropy induced by the corona field may affect the gamma-ray
production when coupled to the sub-photospheric fields, however. We defer this
to future studies.

Figure 3 shows the particle trajectories obtained following the above
assumptions, and by solving the equation of motion:

$\frac{d\vec{p}}{dt}=q(\vec{\beta}\times\vec{B})\,,$ (3)

where $\vec{p}$ is the particle momentum, $\vec{\beta}$ is the particle
velocity in unit of speed of light, and $q$ is the particle charge. The
$\left|B(-1250)\right|=1\,{\rm G}$ model is used with $f=1$ and the particles
have an energy of 10 TeV. A total of 368 down-going trajectories are solved
for each energies, prescribed using the healpy package with Nside = 8. This
corresponds to 368 equal-solid angle sky areas, each covers a sky area of
about $(7.3\,{\rm deg})^{2}$. For each trajectory, labeled by the solid angle
$\Omega$, we obtain its total optical depth along the track,
$\tau(E_{p},\Omega)=\int\frac{\rho}{m_{p}}\sigma d\ell$, where $\ell$ is the
track length element.

Figure 4 shows gamma-ray efficiency factor for the tracks of the
$\left|B(-1250)\right|=1\,{\rm G}$ and $\left|B(<0)\right|=0$ cases,
respectively. The efficiency factor is defined as by

${\cal T}(E_{p},\Omega)=\tau(E_{p},\Omega)e^{-\tau(E_{p},\Omega)}\,$ (4)

using the optical depth solutions obtained from particle trajectories above.
Given the field geometry, the particles will always be reflected and hence
contribute to the gamma ray production. We leave subtle cases, such as
particles interacting before reflection, etc, for future numerical follow ups.
The exponential factor in Eq. 4 approximates the effectiveness of particle
attenuation in high-optical depth scenarios.

The solid lines in Fig. 4 are the zenith-weighted sum $\int\cos\theta\tau
e^{-\tau}d\Omega$. Here we can see the main differences between the two
magnetic field models. For the $\left|B(-1250)\right|=1\,{\rm G}$ case, the
efficiency is suppressed at low energies as cosmic rays can be reflected off
the Sun before reaching sufficient column density to interact. This
suppression is especially significant for particles with small inclination
angles.

The efficiency also drops off at high energies due to the $e^{-\tau}$ factor.
The efficiency peak ($1/e$) is located at higher energies for the less
inclined trajectories as they transverse the shallower part of the atmosphere.
For the $\left|B(<0)\right|=0$ case, as the particles only experience the
magnetic fields after they enter the photosphere, even low energy particles
could accumulate sufficient column density in the high density atmosphere. And
similarly, less inclined particles contributes to the efficiency at higher
energies.

Figure 4: Colored lines show the efficiency factor ${\cal T}=\tau e^{-\tau}$
as a function of cosmic-ray proton energies for different downgoing
trajectories. The black solid line is the zenith-weighted sum of the
efficiencies $\int\cos\theta{\cal T}d\Omega$. The top panel represents the
$\left|B(-1250)\right|=1\,{\rm G}$ case, and the bottom panel corresponds to
the $\left|B(<0)\right|=0$ case.

##  IV  Gamma-ray flux production

Given the orbit information, we can estimate the gamma-ray production semi-
analytically. We first write down the emissivity following the delta function
approximation from Ref. Kelner:2006tc . The emissivity here is the number of
photons produced per energy per surface area per incoming solid angle,

$\displaystyle\frac{dN}{dE_{\gamma}d\Omega dA}(E_{p},\Omega)$ $\displaystyle=$
$\displaystyle N_{\rm nuc}\frac{2c}{K_{\pi}}\int_{E_{\rm min}}dE_{\pi}{\cal
T}(\tilde{E},\Omega)$ (5)
$\displaystyle\times\frac{\Phi_{p}(\tilde{E})}{\sqrt{E_{\pi}^{2}-m_{\pi}^{2}}}\,,$

where $N_{\rm nuc}$ is the nuclear enhancement factor, $K_{\pi}=0.17$, $E_{\rm
min}=E_{\gamma}+{m_{\pi}^{2}}/{4E_{\gamma}}$,
$\tilde{E}=m_{p}+{E_{\pi}}/{K_{\pi}}$, and $\Phi_{p}(E_{p})$ is the cosmic-ray
proton flux, for which we use the analytic double break expression from Ref.
Lipari:2019jmk , which is a fit of cosmic-ray data from 0.1 TeV to 100 TeV at
Earth position. At this energy, we expect the effect of cosmic-ray modulation
to be negligible Li:2022zio . The nuclear enhancement factor $N_{\rm nuc}$
takes into account the enhanced gamma-ray production due to the presence of
nuclei in the cosmic rays and the target Mori:2009te ; Kachelriess:2014mga .
The only relevant species to be considered is Helium, which is $<10$% in both
cases. We follow Ref. Zhou:2016ljf  and take the enhancement factor as a
constant of 1.8.

The total photon flux is then obtained by integrating Eq. (5) over the solid
angle and the surface area, $4\pi R^{2}$, divided by $4\pi D^{2}$, hence,

$\frac{dF}{dE}=F_{\rm sur}\frac{R^{2}}{D^{2}}\int
d\Omega\cos\theta\frac{dN}{dE_{\gamma}d\Omega dA}(E_{p},\Omega)\,,$ (6)

where $F_{\rm sur}$ is the surface fraction that the cosmic rays would
encounter the internetwork fields, and $\cos\theta$ takes the projection
effect between the surface area element and the cosmic-ray incoming angle into
account. Here we have taken the cosmic-ray flux to be isotropic at 1250 km
above the photosphere.

Figure 5 shows the computed solar gamma-ray spectra for $f=0.3$, 0.7, and 1.5,
and $F_{\rm sur}=0.3$. Considering the $\left|B(-1250)\right|=1\,{\rm G}$
case, at lower energies, the gamma-ray production are suppressed compared to
the $\left|B(<0)\right|=0$ case. At higher energies, the additional magnetic
fields provides extra deflections that shift the efficiency factor towards
higher energies, thus making the $\left|B(-1250)\right|=1\,{\rm G}$ case
higher.

From Fig. 5, we can see that horizontal internetwork magnetic fields could
explain the HAWC 6-yr observations with a reasonable choice of parameters
$f\simeq 0.7$ and $F_{\rm sur}\simeq 0.3$. We note that these two parameters
are somewhat degenerate if only considering the results above 1 TeV.

Figure 5: Gamma ray flux produced by cosmic rays reflecting on the horizontal
internetwork fields, for $f=0.3$, 0.7, and 1.5. The flux is directly
proportional to the surface fraction $F_{surf}$ [Eq. (6)], which is taken to
be $1$ in this figure. Dotted lines and solid lines correspond to the
$\left|B(<0)\right|=0$and $\left|B(-1250)\right|=1\,{\rm G}$cases,
respectively. The Fermi-LAT data at the solar minimum (2008-2010) and 9-year
(2008-2017) averaged flux data Tang:2018wqp  are shown for comparison. The
recent HAWC results HAWC:2022khj  are shown in thick boxes, with black solid
line being the 6-year (2014-2021) combined result, blue dashed line correspond
to solar max. (2014-2017), and red dashed line correspond to the solar min.
(2018-2021) It can be seen that our model could reasonably explain the HAWC
data, e.g., with $f\simeq 0.7$ and $F_{sur}\simeq 0.3$.

##  V  Conclusion and Discussion

In this work, we provide the first physical model that can fully explain the
HAWC TeV solar observation. We show that horizontal sub-photospheric
internetwork fields, an extension of those seen at the photosphere, could be
strong and ubiquitous enough to reflect $\sim$TeV cosmic rays and generate the
observed solar gamma rays. Our model is simple and has few parameters, as the
magnetic field strength can be reasonably connected to the kinetic energy of
the fluid through the scaling parameter $f$. Another parameter is the fraction
of the Sun that are covered by the horizontal fields, $F_{\rm sur}$. A
reasonable choice of parameters $f\simeq 0.7$ and $F_{\rm sur}\simeq 0.3$
could explain the HAWC 6-yr observations, for instance.

Nevertheless, our model has some shortcomings that likely can only be
addressed with detailed numerical investigations with more realistic setup.
For instance, we assume that the particles traverse the same convection cell
with the coherent field direction, which is probably a good assumption for
nearly vertical trajectories, but less so for the ones with small incident
angles that could travel across cells. Particles traveling across cells may
encounter vertical fields in cell boundaries and different horizontal field
orientations in other cells, which would likely prolong the time the particle
stays in the photosphere, and could soften the spectrum at high energies. A
more realistic convection cell model with different sizes and magnetic field
orientations would be needed to address this. In addition, the details of
particle shower development in the Sun under magnetic fields can only be
tackled in a numerical setup, which could affect the gamma-ray production
yield at lower energies substantially.

We focus on the TeV energy range, which allows us to ignore effects from
weaker magnetic fields. To fully explain the solar gamma-ray observation from
TeV down to the GeV energy range, a comprehensive model that includes solar
modulations, corona magnetic fields, and network magnetic fields is likely
necessary. Notably, Sun shadow observations might be used to isolate the
effect of large scale magnetic fields (e.g., from the corona)
Amenomori:2013own ; Tibet:2018PhRvL.120c1101A ; sunshadowAartsen:2018zrl ;
sunshadowBeckerTjus:2019rqu ; sunshadowAartsen:2020hzn .

While our model could explain the TeV flux data, a slew of observational
features still need to be addressed, such as time-dependence Ng:2015gya ;
Tang:2018wqp ; Linden:2020lvz ; HAWC:2022khj  and surface morphology at the
Fermi energy range Linden:2018exo ; Arsioli:2024scu . For these observations,
one would require a better understanding on how the related magnetic fields
changes in time and surface distribution. The morphology also depends on the
angular distribution of the emitted photons after cosmic-ray reflection and
interaction, which can only be tracked with numerical simulation.

The understanding of TeV solar gamma rays is also important for predicting
solar atmospheric neutrino flux Ingelman:1996mj ; Ng:2017aur ;
Arguelles:2017eao ; Edsjo:2017kjk , which could be detectable in neutrino
telescopes Aartsen:2019avh_solaratmneutrino ; IceCube:2021koo_icrcsolar  and
has strong implications for new physics searches (e.g., see Ref.
Aartsen:2016zhm_darkmatter ; Leane:2017vag ; Niblaeus:2019gjk ).

In summary, we show that TeV gamma rays could be a novel probe for the
magnetic fields and the fluid dynamics just under the photosphere, which are
difficult to probe with traditional observational methods. This will be
enabled by continued monitoring of the Sun by HAWC, LHAASO, and SWGO
SWGO:2019ahw , as well as closer theory-data connection with future numerical
work on the solar gamma-ray production.

##  Acknowledgments

KCYN is supported by Croucher foundation, RGC grants (24302721, 14305822,
14308023), Joint NSFC/GRC grant (N CUHK456/22), and NSFC grant 12322517. AH is
supported by STFC Research Grant No. ST/V000659/1. The work of SA was
supported by JSPS/MEXT KAKENHI under grant numbers JP20H05850, JP20H05861, and
JP24K07039. AH would like to acknowledge conversations with Profs Oskar
Steiner and Hideyuki Hotta which helped with the generation of the magnetic
field model. KCYN would like to thank John Beacom, Hugh Hudson, Federico
Fraschetti, Ofer Cohen, Eleonora Puzzoni, Annika Peter, and Jung-Tsung Li for
helpful comments and discussions. For the purpose of open access, the author
has applied a ‘Creative Commons Attribution (CC BY) licence to any Author
Accepted Manuscript version arising.

## References

  * (1) D. Seckel, T. Stanev and T. K. Gaisser, _Signatures of cosmic-ray interactions on the solar surface_ , _Astrophys. J._ 382 (1991) 652–666.
  * (2) B. Zhou, K. C. Y. Ng, J. F. Beacom and A. H. G. Peter, _TeV Solar Gamma Rays From Cosmic-Ray Interactions_ , _Phys. Rev._ D96 (2017) 023015, [1612.02420].
  * (3) E. Orlando and A. W. Strong, _Gamma-ray emission from the solar halo and disk: a study with EGRET data_ , _Astron. Astrophys._ 480 (2008) 847, [0801.2178].
  * (4) Fermi-LAT collaboration, A. A. Abdo et al., _Fermi-LAT Observations of Two Gamma-Ray Emission Components from the Quiescent Sun_ , _Astrophys. J._ 734 (2011) 116, [1104.2093].
  * (5) K. C. Y. Ng, J. F. Beacom, A. H. G. Peter and C. Rott, _First Observation of Time Variation in the Solar-Disk Gamma-Ray Flux with Fermi_ , _Phys. Rev._ D94 (2016) 023004, [1508.06276].
  * (6) Q.-W. Tang, K. C. Y. Ng, T. Linden, B. Zhou, J. F. Beacom and A. H. G. Peter, _Unexpected dip in the solar gamma-ray spectrum_ , _Phys. Rev._ D98 (2018) 063019, [1804.06846].
  * (7) T. Linden, B. Zhou, J. F. Beacom, A. H. G. Peter, K. C. Y. Ng and Q.-W. Tang, _Evidence for a New Component of High-Energy Solar Gamma-Ray Production_ , _Phys. Rev. Lett._ 121 (2018) 131103, [1803.05436].
  * (8) T. Linden, J. F. Beacom, A. H. G. Peter, B. J. Buckman, B. Zhou and G. Zhu, _First observations of solar disk gamma rays over a full solar cycle_ , _Phys. Rev. D_ 105 (2022) 063013, [2012.04654].
  * (9) B. Arsioli and E. Orlando, _Yet Another Sunshine Mystery: Unexpected Asymmetry in GeV Emission from the Solar Disk_ , _Astrophys. J._ 962 (2024) 52, [2401.03466].
  * (10) HAWC collaboration, A. Albert et al., _Discovery of Gamma Rays from the Quiescent Sun with HAWC_ , _Phys. Rev. Lett._ 131 (2023) 051201, [2212.00815].
  * (11) M. N. Mazziotta, P. De La Torre Luque, L. Di Venere, A. Fassò, A. Ferrari, F. Loparco et al., _Cosmic-ray interactions with the Sun using the FLUKA code_ , _Phys. Rev. D_ 101 (2020) 083011, [2001.09933].
  * (12) Z. Li, K. C. Y. Ng, S. Chen, Y. Nan and H. He, _Simulating gamma-ray production from cosmic rays interacting with the solar atmosphere in the presence of coronal magnetic fields*_ , _Chin. Phys. C_ 48 (2024) 045101, [2009.03888].
  * (13) K. H. Schatten, J. M. Wilcox and N. F. Ness, _A model of interplanetary and coronal magnetic fields_ , _Sol Phys_ 6 (1969) 442.
  * (14) M. D. Altschuler and G. Newkirk, _Magnetic Fields and the Structure of the Solar Corona. I: Methods of Calculating Coronal Fields_ , _Sol. Phys._ 9 (Sept., 1969) 131–149.
  * (15) J. T. Hoeksema, _Structure and Evolution of the Large Scale Solar and Heliospheric Magnetic Fields._ PhD thesis, Stanford Univ., CA., Sept., 1984.
  * (16) Y. M. Wang and J. Sheeley, N. R., _On Potential Field Models of the Solar Corona_ , _Astrophys. J._ 392 (June, 1992) 310.
  * (17) M. Gutiérrez and M. Masip, _The Sun at TeV energies: gammas, neutrons, neutrinos and a cosmic ray shadow_ , _Astropart. Phys._ 119 (2020) 102440, [1911.07530].
  * (18) M. Gutiérrez, M. Masip and S. Muñoz, _The Solar Disk at High Energies_ , _Astrophys. J._ 941 (2022) 86, [2206.00964].
  * (19) P. Banik, A. Bhadra and S. K. Ghosh, _Sun as a cosmic ray TeVatron_ , 2305.17086.
  * (20) H. S. Hudson, A. MacKinnon, M. Szydlarski and M. Carlsson, _Cosmic ray interactions in the solar atmosphere_ , _MNRAS_ 491 (Feb., 2020) 4852–4856, [1910.01186].
  * (21) J.-T. Li, J. F. Beacom, S. Griffith and A. H. G. Peter, _Small-scale Magnetic Fields Are Critical to Shaping Solar Gamma-Ray Emission_ , _Astrophys. J._ 961 (2024) 167, [2307.08728].
  * (22) R. Ramaty, B. Kozlovsky and R. E. Lingenfelter, _Solar Gamma Rays_ , _Space Sci. Rev._ 18 (Dec., 1975) 341–388.
  * (23) R. J. Murphy, C. D. Dermer and R. Ramaty, _High-Energy Processes in Solar Flares_ , _ApJS_ 63 (Mar., 1987) 721.
  * (24) B. Kozlovsky, R. J. Murphy and R. Ramaty, _Nuclear Deexcitation Gamma-Ray Lines from Accelerated Particle Interactions_ , _ApJS_ 141 (Aug., 2002) 523–541.
  * (25) N. Omodei, M. Pesce-Rollins, F. Longo, A. Allafort and S. Krucker, _Fermi-LAT Observations of the 2017 September 10 Solar Flare_ , _Astrophys. J. Lett._ 865 (2018) L7, [1803.07654].
  * (26) G. H. Share, R. J. Murphy, S. M. White, A. K. Tolbert, B. R. Dennis, R. A. Schwartz et al., _Characteristics of Late-phase $>$100 MeV Gamma-Ray Emission in Solar Eruptive Events_, _Astrophys. J._ 869 (2018) 182.
  * (27) Fermi-LAT collaboration, M. Ackermann et al., _High-energy Gamma-Ray Emission from Solar Flares: Summary of Fermi Large Area Telescope Detections and Analysis of Two M-class Flares_ , _Astrophys. J._ 787 (2014) 15, [1304.3749].
  * (28) E. Orlando and A. Strong, _Gamma-rays from halos around stars and the Sun_ , _Astrophys. Space Sci._ 309 (2007) 359–363, [astro-ph/0607563].
  * (29) I. V. Moskalenko, T. A. Porter and S. W. Digel, _Inverse Compton scattering on solar photons, heliospheric modulation, and neutrino astrophysics_ , _Astrophys. J._ 652 (2006) L65–L68, [astro-ph/0607521].
  * (30) E. Orlando and A. Strong, _StellarICS: Inverse Compton Emission from the Quiet Sun and Stars from keV to TeV_ , _JCAP_ 04 (2021) 004, [2012.13126].
  * (31) A. C. M. Lai and K. C. Y. Ng, _Anisotropic photon and electron scattering without ultrarelativistic approximation_ , _Phys. Rev. D_ 107 (2023) 063026, [2211.15691].
  * (32) H.-G. Yang, Y. Gao, Y.-Z. Ma and R. M. Crocker, _Solar gamma ray probe of local cosmic ray electrons_ , _Phys. Rev. D_ 108 (2023) L061304, [2309.04784].
  * (33) V. Petrosian, E. Orlando and A. Strong, _Transport of Cosmic-Ray Electrons from 1 au to the Sun_ , _Astrophys. J._ 943 (2023) 21, [2212.00929].
  * (34) E. Orlando, V. Petrosian and A. Strong, _A New Component from the Quiet Sun from Radio to Gamma Rays: Synchrotron Radiation by Galactic Cosmic-Ray Electrons_ , _Astrophys. J._ 943 (2023) 173, [2212.01364].
  * (35) Norman H. Baker, Stefan Temesváry, _Tables of Convective Stellar Envelope Models_.  1966\.
  * (36) J. E. Vernazza, E. H. Avrett and R. Loeser, _Structure of the Solar Chromosphere. Basic Computations and Summary of the Results_ , _Astrophys. J._ 184 (Sept., 1973) 605–632.
  * (37) S. R. Kelner, F. A. Aharonian and V. V. Bugayov, _Energy spectra of gamma-rays, electrons and neutrinos produced at proton-proton interactions in the very high energy regime_ , _Phys. Rev. D_ 74 (2006) 034018, [astro-ph/0606058].
  * (38) Particle Data Group collaboration, R. L. Workman and Others, _Review of Particle Physics_ , _PTEP_ 2022 (2022) 083C01.
  * (39) W. Unno, M. A. Kondo and D. R. Xiong, _Solar convection zone given by nonlocal mixing-length theory_ , _PASJ_ 37 (Jan., 1985) 235–244.
  * (40) S. Wedemeyer-Bohm, A. Lagg and A. Nordlund, _Coupling from the photosphere to the chromosphere and the corona_ , _Space Sci. Rev._ 144 (2009) 317–350, [0809.0987].
  * (41) T. Wiegelmann, J. K. Thalmann and S. K. Solanki, _The magnetic field in the solar atmosphere_ , _Astronomy and Astrophysics Reviews_ 22 (Nov., 2014) 78, [1410.4214].
  * (42) S. K. Solanki, B. Inhester and M. Schüssler, _The solar magnetic field_ , _Reports on Progress in Physics_ 69 (Mar., 2006) 563–668, [1008.0771].
  * (43) J. Sánchez Almeida and M. Martínez González, _The Magnetic Fields of the Quiet Sun_ , in _Solar Polarization 6_ (J. R. Kuhn, D. M. Harrington, H. Lin, S. V. Berdyugina, J. Trujillo-Bueno, S. L. Keil et al., eds.), vol. 437 of _Astronomical Society of the Pacific Conference Series_ , p. 451, Apr., 2011\.  1105.0387.  DOI.
  * (44) J. Trujillo Bueno, N. Shchukina and A. Asensio Ramos, _A Substantial amount of hidden magnetic energy in the quiet Sun_ , _Nature_ 430 (2004) 326–329, [astro-ph/0409004].
  * (45) L. Bellot Rubio and D. Orozco Suárez, _Quiet Sun magnetic fields: an observational view_ , _Living Reviews in Solar Physics_ 16 (Feb., 2019) 1.
  * (46) M. Rempel, T. Bhatia, L. Bellot Rubio and M. J. Korpi-Lagg, _Small-Scale Dynamos: From Idealized Models to Solar and Stellar Applications_ , _Space Sci. Rev._ 219 (Aug., 2023) 36.
  * (47) B. W. Lites, K. D. Leka, A. Skumanich, V. Martinez Pillet and T. Shimizu, _Small-Scale Horizontal Magnetic Fields in the Solar Photosphere_ , _ApJ_ 460 (Apr., 1996) 1019.
  * (48) D. O. Suarez et al., _Quiet Sun internetwork magnetic fields from the inversion of Hinode measurements_ , _Astrophys. J. Lett._ 670 (2007) L61, [0710.1405].
  * (49) B. W. Lites, M. Kubo, H. Socas-Navarro, T. Berger, Z. Frank, R. Shine et al., _The Horizontal Magnetic Flux of the Quiet-Sun Internetwork as Observed with the Hinode Spectro-Polarimeter_ , _Astrophys. J._ 672 (Jan., 2008) 1237–1253.
  * (50) M. Schuessler and A. Voegler, _Strong horizontal photospheric magnetic field in a surface dynamo simulation_ , _Astron. Astrophys._ 481 (2008) L5, [0801.1250].
  * (51) O. Steiner, R. Rezaei, W. Schaffenberger and S. Wedemeyer-Böhm, _The Horizontal Internetwork Magnetic Field: Numerical Simulations in Comparison to Observations with Hinode_ , _ApjL_ 680 (June, 2008) L85, [0801.4915].
  * (52) O. Steiner, _Magnetic Coupling in the Quiet Solar Atmosphere_ , in _Magnetic Coupling between the Interior and Atmosphere of the Sun_ , vol. 19 of _Astrophysics and Space Science Proceedings_ , pp. 166–185, Jan., 2010.  0904.2026.  DOI.
  * (53) M. Potgieter, _Solar Modulation of Cosmic Rays_ , _Living Rev. Solar Phys._ 10 (2013) 3, [1306.4421].
  * (54) J.-T. Li, J. F. Beacom and A. H. G. Peter, _Galactic Cosmic-Ray Propagation in the Inner Heliosphere: Improved Force-field Model_ , _Astrophys. J._ 937 (2022) 27, [2206.14815].
  * (55) M. Rempel, _Numerical Simulations of Quiet Sun Magnetism: On the Contribution from a Small-scale Dynamo_ , _Astrophys. J._ 789 (July, 2014) 132, [1405.6814].
  * (56) L. Deng, D. R. Xiong and K. L. Chan, _An Anisotropic Nonlocal Convection Theory_ , _Astrophys. J._ 643 (May, 2006) 426–437.
  * (57) D.-r. Xiong, _Convection Theory and Relevant Problems in Stellar Structure, Evolution and Pulsation Stability Part I. Convection Theory and Structure of convection zone and stellar evolution_ , _Frontiers in Astronomy and Space Sciences_ 7 (May, 2021) 95.
  * (58) R. F. Stein and Å. Nordlund, _Simulations of Solar Granulation. I. General Properties_ , _Apj_ 499 (May, 1998) 914–933.
  * (59) H. Hotta, Y. Bekki, L. Gizon, Q. Noraz and M. Rast, _Dynamics of Large-Scale Solar Flows_ , _Space Sci. Rev._ 219 (Dec., 2023) 77, [2307.06481].
  * (60) M. S. Miesch, N. A. Featherstone, M. Rempel and R. Trampedach, _On the Amplitude of Convective Velocities in the Deep Solar Interior_ , _Astrophys. J._ 757 (Oct., 2012) 128, [1205.1530].
  * (61) P. Lipari and S. Vernetto, _The shape of the cosmic ray proton spectrum_ , _Astropart. Phys._ 120 (2020) 102441, [1911.01311].
  * (62) M. Mori, _Nuclear enhancement factor in calculation of Galactic diffuse gamma-rays: a new estimate with DPMJET-3_ , _Astropart. Phys._ 31 (2009) 341–343, [0903.3260].
  * (63) M. Kachelriess, I. V. Moskalenko and S. S. Ostapchenko, _Nuclear enhancement of the photon yield in cosmic ray interactions_ , _Astrophys. J._ 789 (2014) 136, [1406.0035].
  * (64) Tibet ASgamma collaboration, M. Amenomori et al., _Probe of the Solar Magnetic Field Using the “Cosmic-Ray Shadow” of the Sun_ , _Phys. Rev. Lett._ 111 (2013) 011101, [1306.3009].
  * (65) M. Amenomori, X. J. Bi, D. Chen, T. L. Chen, W. Y. Chen, S. W. Cui et al., _Evaluation of the Interplanetary Magnetic Field Strength Using the Cosmic-Ray Shadow of the Sun_ , _Phys. Rev. Lett._ 120 (Jan, 2018) 031101, [1801.06942].
  * (66) IceCube collaboration, M. Aartsen et al., _Detection of the Temporal Variation of the Sun’s Cosmic Ray Shadow with the IceCube Detector_ , _Astrophys. J._ 872 (2019) 133, [1811.02015].
  * (67) J. Becker Tjus, P. Desiati, N. Döpper, H. Fichtner, J. Kleimann, M. Kroll et al., _Cosmic-Ray Propagation Around the Sun - Investigating the Influence of the Solar Magnetic Field on the Cosmic-Ray Sun Shadow_ , _Astron. Astrophys._ 633 (2020) A83, [1903.12638].
  * (68) IceCube collaboration, M. G. Aartsen et al., _Measurements of the time-dependent cosmic-ray Sun shadow with seven years of IceCube data: Comparison with the Solar cycle and magnetic field models_ , _Phys. Rev. D_ 103 (2021) 042005, [2006.16298].
  * (69) G. Ingelman and M. Thunman, _High-energy neutrino production by cosmic ray interactions in the sun_ , _Phys. Rev._ D54 (1996) 4385–4392, [hep-ph/9604288].
  * (70) K. C. Y. Ng, J. F. Beacom, A. H. G. Peter and C. Rott, _Solar Atmospheric Neutrinos: A New Neutrino Floor for Dark Matter Searches_ , _Phys. Rev. D_ 96 (2017) 103006, [1703.10280].
  * (71) C. A. Argüelles, G. de Wasseige, A. Fedynitch and B. J. P. Jones, _Solar Atmospheric Neutrinos and the Sensitivity Floor for Solar Dark Matter Annihilation Searches_ , _JCAP_ 1707 (2017) 024, [1703.07798].
  * (72) J. Edsjo, J. Elevant, R. Enberg and C. Niblaeus, _Neutrinos from cosmic ray interactions in the Sun_ , _JCAP_ 1706 (2017) 033, [1704.02892].
  * (73) IceCube collaboration, M. Aartsen et al., _Searches for neutrinos from cosmic-ray interactions in the Sun using seven years of IceCube data_ , 1912.13135.
  * (74) IceCube collaboration, J. Villarreal et al., _Recent Progress in Solar Atmospheric Neutrino Searches with IceCube_ , _PoS_ ICRC2021 (2021) 1174, [2107.13696].
  * (75) IceCube collaboration, M. Aartsen et al., _Search for annihilating dark matter in the Sun with 3 years of IceCube data_ , _Eur. Phys. J. C_ 77 (2017) 146, [1612.05949].
  * (76) R. K. Leane, K. C. Y. Ng and J. F. Beacom, _Powerful Solar Signatures of Long-Lived Dark Mediators_ , _Phys. Rev. D_ 95 (2017) 123016, [1703.04629].
  * (77) C. Niblaeus, A. Beniwal and J. Edsjo, _Neutrinos and gamma rays from long-lived mediator decays in the Sun_ , _JCAP_ 11 (2019) 011, [1903.11363].
  * (78) P. Abreu et al., _The Southern Wide-Field Gamma-Ray Observatory (SWGO): A Next-Generation Ground-Based Survey Instrument for VHE Gamma-Ray Astronomy_ , 1907.07737.


# Improving the Performance of the LSTM and HMM Model via Hybridization

Larkin Liu1, Yu-Chung Lin1, Joshua Reid 2
1University of Toronto
2University of Waterloo
1{larkin.liu<EMAIL_ADDRESS><EMAIL_ADDRESS>
###### Abstract

Language models based on deep neural networks and traditional stochastic
modelling have become both highly functional and effective in recent times. In
this work, a general survey into the two types of language modelling is
conducted. We investigate the effectiveness of the Hidden Markov Model (HMM),
and the Long Short-Term Memory Model (LSTM). We analyze the hidden state
structures common to both models, and present an analysis on structural
similarity of the hidden states, common to both HMM’s and LSTM’s. We compare
the LSTM’s predictive accuracy and hidden state output with respect to the HMM
for a varying number of hidden states. In this work, we justify that the less
complex HMM can serve as an appropriate approximation of the LSTM model.

## Introduction

Language modelling has been an integral part of providing an understanding of
the nature of language sequences. In order to improve the machine
understanding of language using sequential models, we seek to explore two
prominent areas of statistical language models, the Hidden Markov Model (HMM),
and a Recurrent Neural Network (RNN) architecture, known commonly as Long
Short-Term Memory (LSTM) Model. Under a discrete stochastic modelling
framework, HMM’s were first introduced in (?) to classify speech signals.
First used to automate AT&T’s voice activated call center, the revolutionary
technology allowed computers to robustly characterise speech, and form a basic
understanding of spoken words. HMM’s have since become a definitive benchmark
for the state-of-the-art for speech recognition, and text recognition
algorithms. Around the same period, RNN’s were introduced by (?), however, the
training complexity of the model was far too high and was not commensurate
with the hardware capabilities at the time. In the 21st century, with the
introduction of the more advanced hardware for deep learning, came a wave of
applications for the RNN for both voice, text recognition (?), (?), (?), and
machine translation (?). In parallel, an early form of neural language model
was developed in (?), displaying promising results in statistical language
modelling.

LSTM’s were first introduced in (?), specifically to combat the vanishing
gradient problem occurring in LSTM model training via Stochastic Gradient
Descent. Research has been performed to validate the effectiveness of the
LSTM, not only on its ability to ameliorate the vanishing/exploding gradient
problem, but also on its ability to capture long term dependencies in text,
allowing the model to keep long term explanatory observations to make
classifications and predictions in memory. We reference the work of (?) where
they presents promising results in hypothetically combining the HMM and LSTM
to increase the predictive accuracy of the models. (?) showed that both the
LSTM and the HMM are capable of identifying special occurrences in text, such
as punctuation marks, vowels, etc. In our work, the HMM model is compared with
the LSTM model. We compare model performance based on the validation cross-
entropy of each LSTM model, and examine the similarities between the HMM and
LSTM, in terms of hidden state probabilities.

### The Hidden Markov Model (HMM)

Discrete time Hidden Markov Models (HMM) are stochastic models which have a
wide range of applications for modelling stochastic processes for various
applications. Discrete time HMM’s are ideal for modelling discrete auto-
correlated processes, where the observed variables depend on an unobservable
hidden state, $S_{t}$ which obey the Markov property, indicating that the
conditional probability of the immediate next state depends only on the
present state. The observable symbols at the current time epoch, $t$, are
conditionally dependent only on the hidden state at the time $t-1$. HMM’s have
been applied in industry to many practical use-cases, most notably in the
field of speech recognition (?). However, HMM’s do extend to a variety of use
cases, such as text classification (?), fraud detection (?), and autonomous
driving (?).

Figure 1: Architecture of an HMM (?)

We denote the hidden state at time $t$, $S_{t}$, as a condition representing
some underlying state of the sequential text language. The relationship
between hidden states, $S_{t}$, follow a Markov Property, as stated in Eq.
(1).

$P(S_{t+1}|S_{1},...,S_{t})=P(S_{t+1}|S_{t})$ (1)

For $M$ observation symbols, and $N$ hidden states, the parameters of the HMM
include the transition probability between hidden states denoted as matrix
$\boldsymbol{A}=\\{a_{ij}\\}$. Also the emission matrix
$\boldsymbol{B}=\\{b_{n}(m)\\}$ for each hidden state, and the initial
probability distribution $\boldsymbol{\pi}=\pi(n_{0})$ at time $t=0$. In order
to estimate the parameters of the model we use the Forward-Backward Algorithm
outlined in (?). The forward probability $\alpha_{t}(j)$ is defined as the
probability of being at state $S_{t}=j$ while observing sequences $O_{0:t}$,
as referenced in Eq. (2). And the backward probability, $\beta_{t}(i)$ is
defined as the probability of observing the sequence into the future
$O_{t+1:T}$ while currently at state $S_{t}=i$, as demonstrated in Eq. (3).
The cannonical representation of the forward and backward probabilities are
expressed in Equations (2) and (3).

$\displaystyle\alpha_{t}({j})$
$\displaystyle=b_{j}(O_{t})\sum_{i=1}^{N}\alpha_{t-1}(i)a_{ij}$ (2)
$\displaystyle\beta_{t}(i)$
$\displaystyle=\sum_{i=1}^{N}\beta_{t+1}(j)b_{j}(O_{t+1})a_{ij}$ (3)

The parameters for multiple sequence HMM’s can be estimated using the Baum-
Welch Algorithm (?). It is possible to estimate the parameters
$\boldsymbol{A}$, $\boldsymbol{B}$ and $\boldsymbol{\pi}$, using the Baum-
Welch Algorithm for multiple sequences. We define $\gamma_{t}(i)$ as observing
the specific full sequence $O(0:T)$ provided the knowledge of the system being
in state $S_{t}=i$, as defined in Eq. (4) for $n_{h}$ hidden states.

$\gamma_{t}(i)=\frac{\alpha_{t}({i})\beta_{t}(i)}{\sum_{i=0}^{n_{h}}\alpha_{t}({i})\beta_{t}(i)}$
(4)

We define $\zeta_{t}(i,j)$ as the probability of $S_{t}=i$ transitioning to
$S_{t+1}=j$ given the sequence of observations $(O_{0:T})$, as defined in Eq.
(5).

$\zeta_{t}(i,j)=\frac{\alpha_{t}({i})a_{ij}b_{j}(S_{t+1})\beta_{t+1}(j)}{P(O_{0:T})}$
(5)

Using the Baum-Welch algorithm, iterating through 1 to c iterations, we
iterate until convergence for the HMM parameters
$\theta_{hmm}^{(c)}=(\pi^{(c)},A^{(c)},B^{(c)})$.

$\displaystyle\pi_{i}^{(c)}$ $\displaystyle=\gamma_{0}(i)$ (6) $\displaystyle
A_{ij}^{(c)}$
$\displaystyle=\frac{\sum_{t=0}^{T-1}\zeta_{t}(i,j)}{\sum_{t=0}^{T-1}\gamma_{t}(i)}$
(7) $\displaystyle B_{i}(k)^{(c)}$
$\displaystyle=\frac{\sum_{t=0}^{T}\textbf{1}(O_{t}=k)\gamma_{t}(i)}{\sum_{t=0}^{T}\gamma_{t}(i)}$
(8)

### Recurrent Neural Networks and Long Short-Term Memory Models (LSTM)

Recurrent Neural Networks (RNN) are a class of neural networks capable of
processing sequential data using internal memory cells to represent temporal
information. Theoretically, RNN’s keep track of artificial long-term
dependencies; however, back-propagated gradients often vanish or explode as
the lengths of sequences grow. Long Short-Term Memory (LSTM), a special
architecture of RNN, proposed by (?) was created to alleviate the vanishing
gradient problem and retrieve information over long time periods. A LSTM cell
consists of three gates: the input, output, and forget gates. The gates serve
as regulators that control flow of information within the cell. The core of
LSTM follows the equation, expressed in Eq. (9).

$c_{t}=f_{t}*c_{t-1}+i_{t}*g_{t}$ (9)

The cell state, $c_{t}$, serves as the memory of LSTM and enables the RNN to
keep track of long-term dependencies. The LSTM cell then chooses to retain a
portion of its previous cell state through the forget gate $f_{t}$,
illustrated in Eq. (10). Another crucial component, the input gate $i_{t}$,
dictates how much new information is incorporated into the updated cell state
from the previous cell output, as illustrated in Eq (11). Finally, $g_{t}$
represents the gate that contains information used to update $c_{t}$, while
$h_{t}$ serves as the output of the LSTM unit at time $t$, as stipulated in Eq
(13).

$\displaystyle f_{t}$
$\displaystyle=\sigma(W_{if}x_{t}+b_{if}+W_{hf}h_{t-1}+b_{hf})$ (10)
$\displaystyle i_{t}$
$\displaystyle=\sigma(W_{ii}x_{t}+b_{ii}+W_{hi}h_{t-1}+b_{hi})$ (11)
$\displaystyle g_{t}$
$\displaystyle=\tanh(W_{ig}x_{t}+b_{ig}+W_{hg}h_{t-1}+b_{hg})$ (12)
$\displaystyle h_{t}$
$\displaystyle=\sigma(W_{io}x_{t}+W_{ho}h_{t-1}+b_{o})*\tanh(c_{t-1})$ (13)

Contrary to the standard RNN architecture, an LSTM cell chooses how much
information to retain from previous cells and what to add to the current cell
state, $c_{t}$. As the gradient computations are connected to the forget gate
activations, the vanishing gradient problem is greatly alleviated by creating
a path for necessary information to flow through $f_{t}$. The ability to learn
additively enables LSTM cells to capture long-term dependencies much more
efficiently than standard RNN’s do. Since its inception, different flavours of
LSTM have been invented to improve upon its existing architectures. Peephole
LSTMs (?), which let gate layers borrow information from the cell state, was
invented in 2000 to help RNNs learn precise timings. With the rise of
computational power in the 2000s, LSTM’s achieved record performances in
neural language modelling (?). Although LSTM language models perform well,
training them on a large dataset is very time-consuming due to normalized
distributions of predicted words; forcing the model to consider every word in
the dictionary when computing gradients (?). This proven effectiveness and the
difficulty in training LSTM language models provide justification into using
them as a benchmark for character classification accuracy of this project.

In 2014, a dramatic variation of LSTM, the Gated Recurrent Unit (GRU), was
introduced by (?) to simplify the LSTM architecture. GRU removes the cell
state and requires fewer tensor operations to train, which speeds up the
training process and provides a viable alternative to LSTM’s. An application
of this modelling technique could fundamentally speed up our model training
period, and could be left to future exploration. Also in recent years,
attention-based LSTM’s (?), which allows for dependencies regardless of the
differences in input and output sequences, have achieved impressive model
performances in image classification and speaker verification tasks. In
particular, the Transformer(?), a specific type of the attention mechanism,
can dramatically speed up the training process and has achieved record-
breaking performances in machine translation tasks. Recent developments of
LSTM’s continue to shed new light on future advancements of RNN’s. These
advances in RNN architecture could enhance both the modelling accuracy and
model training period of our comparative study.

## Methodology

We compare the performance of the models on the Tiny Shakespeare Dataset (TS)
and the War and Peace English Corpus (WP). Each character undergoes one hot
encoding of $\nu$ possible alphanumeric characters. The corpus was structured
in the form of a sliding window $\boldsymbol{x}$, of $w$ sequential
characters, where $n_{h}$ is the number of hidden states. To be specific, for
each window of text, $\boldsymbol{x}$, $\boldsymbol{x}_{0:w-1}$ were selected
as the input data, and $\boldsymbol{x}_{1:w}$ as the target variable,
therefore providing a one-to-one mapping of a character to the character
immediately proceeding it within the sliding window. The recurrent neural
networks used in this work were implemented using PyTorch, and the HMM model
was implemented using the hmmlearn package in Python. The tests were run on a
computer with an AMD Ryzen 2600 CPU and an Nvidia GTX 1070 graphics card.

In this experiment, the HMM model was trained using the Baum-Welch Algorithm.
We apply the Viterbi Algorithm to compute the most likely hidden state
sequence corresponding to the input observation. Our objective is to compare
the vector structure of the hidden state probability distribution with that of
the LSTM’s counterpart forward pass, on $c_{t}$. Subsequently, on the same
text sequence, we train a corresponding LSTM model with $\nu$ hidden states.

## Experimental Results

The generation of the training data is completed via generating $m$ ”batches”,
(?) refers to this a ”mini-batch stochastic gradient descent”, and is shown to
have convergent behaviour for for convex or pseudo-convex loss functions (?).
We set the mini-batch size $m=64$ for both training and validation. Sampling
is performed to ensure that there is sufficient randomness in the data to make
the model training and evaluation robust and fast (?).

We measure the performance of the LSTM model based on its ability to
accurately predict the subsequent character. We define the $J(\theta)$ as the
cross-entropy loss of the model, as illustrated in Eq. (14). The log-
likelihood of a model, $\mathcal{L}(\theta)$, is simply the negative value of
the cross-entropy $\mathcal{L}(\theta)=-J(\theta)$.

$J(\theta)=-\sum_{i=1}^{m}\sum_{k=1}^{\nu}\textbf{1}\\{\boldsymbol{y}_{1:w}^{(i)}=k|\boldsymbol{x}_{0:w-1},\theta\\}$
(14)

(?) displayed an improvement to the traditional HMM model and LSTM model in
terms of predictive accuracy as measured by predictive log-likelihood of the
model, $\mathcal{L}(\theta)$. The LSTM improves its $J(\theta)$ as we increase
the complexity of the model by increasing $n_{h}$, as evidenced in 1.
Furthermore, we examined the models seperately and measured the similarity of
the hidden states with respect to their cosine distance,
$\Delta(\mathbf{\Psi_{H}},\mathbf{\Psi_{L}})$. Where $\mathbf{\Psi_{H}}$ and
$\mathbf{\Psi_{L}}$ corresponds to the probabilities of each of the $n_{h}$
hidden state vectors.

$\Delta(\mathbf{\Psi_{H}},\mathbf{\Psi_{L}})=\frac{\mathbf{\Psi_{H}}\cdot\mathbf{\Psi_{L}}}{\big{\|}\mathbf{\Psi_{H}}\big{\|}\big{\|}\mathbf{\Psi_{L}}\big{\|}}$
(15)

In reference to Table 1, it was observed that an increase in the number of
hidden states does not guarantee an increase the predictive accuracy of the
LSTM. We notice that the cosine similarity,
$\Delta(\mathbf{\Psi_{H}},\mathbf{\Psi_{L}})$ generally decreases as we
decrease the $n_{h}$. However, between the 15-35 hidden state range for more
complex corpora such as WP, there seems to be a subtle increase in the cosine
similarity. This indicates that the HMM shares some structural similarities
when compared the the LSTM, respective to their hidden state distributions.

$n_{s}$ | $\Delta_{TS}$ | $\Delta_{WP}$ | $J(\theta)_{TS}$ | $J(\theta)_{WP}$
---|---|---|---|---
5 | 0.792 | 0.741 | 3.724 | 3.950
10 | 0.801 | 0.657 | 3.476 | 3.831
15 | 0.816 | 0.613 | 3.581 | 3.678
25 | 0.715 | 0.674 | 3.246 | 3.497
35 | 0.691 | 0.671 | 3.034 | 3.359
50 | 0.697 | 0.640 | 3.003 | 3.268
Table 1: Effect of the number of Hidden States on $\mathcal{L}(\theta_{H})$.

Due to the relatively small number of neurons, it was found that training with
a GPU was slower than a CPU. This is due to GPU’s having a large number of
weaker processing units that are well suited for the calculation of high
amounts of many small operations, such as linear algebra, that can be highly
parallelized (?). Having few neurons in each layer means that there is little
parallelization that can be performed. This results in only small improvements
to model training speed when using a GPU versus a CPU.

## Conclusion

In this work, we provide a brief survey of the HMM, and LSTM, illustrating the
key aspects of stochastic modelling and deep learning for the purpose of
language modelling and text prediction. We further demonstrate the
effectiveness of each model seperately, and demonstrate the similarities of
the hidden state structure of the HMM and LSTM respectively. We observe that
there are structural similarity between the hidden states of the LSTM and HMM,
measuring the hidden state probability output vectors of both models. From the
measurement, we find that general similarities do exist, especially at lower
dimensionalities. However, in complex corpora such as the War and Peace
dataset, the cosine similarity may increase with an increase in hidden state
dimensionality. The results of this paper justify that the HMM can be used as
a suitable approximator for the LSTM, and using this similarity one can
develop a hybrid model which may simplify the model training behaviour of the
LSTM or increase its respective performance. Furthermore, an area of
improvement can to modify our GPU based code in order to improve the training
times of the model, and not rely on CPU based computation. In summary, this
work has advanced the understanding of stochastic and deep learning based
models aimed at classifying text patterns.

## References

  * [Bahdanau, Cho, and Bengio 2014] Bahdanau, D.; Cho, K.; and Bengio, Y.  2014\.  Neural machine translation by jointly learning to align and translate.  cite arxiv:1409.0473Comment: Accepted at ICLR 2015 as oral presentation.
  * [Bengio et al. 2003] Bengio, Y.; Ducharme, R.; Vincent, P.; and Janvin, C.  2003\.  A neural probabilistic language model.  J. Mach. Learn. Res. 3:1137–1155.
  * [Bottou 1998] Bottou, L.  1998\.  Online algorithms and stochastic approximations.  In Saad, D., ed., Online Learning and Neural Networks. Cambridge, UK: Cambridge University Press.  revised, oct 2012.
  * [Chen et al. 2018] Chen, M. X.; Firat, O.; Bapna, A.; Johnson, M.; Macherey, W.; Foster, G.; Jones, L.; Parmar, N.; Schuster, M.; Chen, Z.; Wu, Y.; and Hughes, M.  2018\.  The best of both worlds: Combining recent advances in neural machine translation.  CoRR abs/1804.09849.
  * [Cho et al. 2014] Cho, K.; van Merriënboer, B.; Gulcehre, C.; Bahdanau, D.; Bougares, F.; Schwenk, H.; and Bengio, Y.  2014\.  Learning phrase representations using RNN encoder–decoder for statistical machine translation.  In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP), 1724–1734.  Doha, Qatar: Association for Computational Linguistics.
  * [Gers and Schmidhuber 2000] Gers, and Schmidhuber.  2000\.  Recurrent nets that time and count.  In Proceedings of the IEEE-INNS-ENNS International Joint Conference on Neural Networks. IJCNN 2000. Neural Computing: New Challenges and Perspectives for the New Millennium, volume 3, 189–194 vol.3.  IEEE.
  * [Graves, Mohamed, and Hinton 2013] Graves, A.; Mohamed, A.-r.; and Hinton, G. E.  2013\.  Speech recognition with deep recurrent neural networks.  CoRR abs/1303.5778.
  * [Hinton 2010] Hinton, G.  2010\.  Overview of mini-batch gradient descent.  Lecture Notes CSC321.
  * [Hochreiter and Schmidhuber 1997] Hochreiter, S., and Schmidhuber, J.  1997\.  Long short-term memory.  Neural Comput. 9(8):1735–1780.
  * [Hughes and Mierle 2013] Hughes, T., and Mierle, K.  2013\.  Recurrent neural networks for voice activity detection.  In ICASSP, 7378–7382.
  * [Jing and Xu 2019] Jing, K., and Xu, J.  2019\.  A survey on neural network language models.  CoRR abs/1906.03591.
  * [Jozefowicz, Zaremba, and Sutskever 2015] Jozefowicz, R.; Zaremba, W.; and Sutskever, I.  2015\.  An empirical exploration of recurrent network architectures.  In Proceedings of the 32Nd International Conference on International Conference on Machine Learning - Volume 37, ICML’15, 2342–2350.  JMLR.org.
  * [Karpathy, Johnson, and Li 2015] Karpathy, A.; Johnson, J.; and Li, F.  2015\.  Visualizing and understanding recurrent networks.  CoRR abs/1506.02078.
  * [Krakovna and Doshi-Velez 2016] Krakovna, V., and Doshi-Velez, F.  2016\.  Increasing the interpretability of recurrent neural networks using hidden markov models.  arXiv:1606.05320.
  * [Lipton 2015] Lipton, Z. C.  2015\.  A critical review of recurrent neural networks for sequence learning.  CoRR abs/1506.00019.
  * [Liu et al. 2019] Liu, S.; Zheng, K.; Zhao, L.; and Fan, P.  2019\.  A driving intention prediction method based on hidden markov model for autonomous driving.  CoRR abs/1902.09068.
  * [Liu 2017] Liu, L.  2017\.  Comparative study between statistical fraud detection methods on ecommerce networks.
  * [Nadeau and Bengio 2003] Nadeau, C., and Bengio, Y.  2003\.  Inference for the generalization error.  Mach. Learn. 52(3):239–281.
  * [Oh and Jung 2004] Oh, K.-S., and Jung, K.  2004\.  Gpu implementation of neural networks.  Pattern Recognition 37(6):1311 – 1314.
  * [Rabiner 1989] Rabiner, L. R.  1989\.  A tutorial on hidden markov models and selected applications in speech recognition.  In PROCEEDINGS OF THE IEEE, 257–286.
  * [Rumelhart, Hinton, and Williams 1988] Rumelhart, D. E.; Hinton, G. E.; and Williams, R. J.  1988\.  Neurocomputing: Foundations of research.  Cambridge, MA, USA: MIT Press.  chapter Learning Representations by Back-propagating Errors, 696–699.
  * [Vaswani et al. 2017] Vaswani, A.; Shazeer, N.; Parmar, N.; Uszkoreit, J.; Jones, L.; Gomez, A. N.; Kaiser, Ł.; and Polosukhin, I.  2017\.  Attention is all you need.  In Advances in Neural Information Processing Systems, 5998–6008.