<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="https://www.kentonk.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://www.kentonk.com/" rel="alternate" type="text/html" /><updated>2026-01-29T17:01:40+00:00</updated><id>https://www.kentonk.com/feed.xml</id><title type="html">Kenton Kwok</title><subtitle>Hello! I am a computer vision engineer and physicist. Nice to meet you!</subtitle><author><name>{&quot;name&quot;=&gt;nil, &quot;avatar&quot;=&gt;&quot;/files/head.jpg&quot;, &quot;bio&quot;=&gt;&quot;Scientist-engineer, traveller, photographer &amp; science communicator-- cause why not?&quot;, &quot;location&quot;=&gt;&quot;Cambridge, UK&quot;, &quot;email&quot;=&gt;&quot;me@kentonk.com&quot;, &quot;bitbucket&quot;=&gt;nil, &quot;codepen&quot;=&gt;nil, &quot;dribbble&quot;=&gt;nil, &quot;flickr&quot;=&gt;nil, &quot;facebook&quot;=&gt;nil, &quot;foursquare&quot;=&gt;nil, &quot;github&quot;=&gt;&quot;kwokkenton&quot;, &quot;google_plus&quot;=&gt;nil, &quot;keybase&quot;=&gt;nil, &quot;instagram&quot;=&gt;&quot;fizzyphys&quot;, &quot;lastfm&quot;=&gt;nil, &quot;linkedin&quot;=&gt;&quot;kentonkwok&quot;, &quot;pinterest&quot;=&gt;nil, &quot;soundcloud&quot;=&gt;nil, &quot;stackoverflow&quot;=&gt;nil, &quot;steam&quot;=&gt;nil, &quot;tumblr&quot;=&gt;nil, &quot;twitter&quot;=&gt;nil, &quot;vine&quot;=&gt;nil, &quot;weibo&quot;=&gt;nil, &quot;xing&quot;=&gt;nil, &quot;youtube&quot;=&gt;nil}</name><email>me@kentonk.com</email></author><entry><title type="html">Salsa and Bachata scene in Cambridge</title><link href="https://www.kentonk.com/2026/01/29/salsa.html" rel="alternate" type="text/html" title="Salsa and Bachata scene in Cambridge" /><published>2026-01-29T12:00:00+00:00</published><updated>2026-01-29T12:00:00+00:00</updated><id>https://www.kentonk.com/2026/01/29/salsa</id><content type="html" xml:base="https://www.kentonk.com/2026/01/29/salsa.html">&lt;p&gt;&lt;img src=&quot;https://images.unsplash.com/photo-1504609813442-a8924e83f76e?q=80&amp;amp;w=1740&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;ixlib=rb-4.1.0&amp;amp;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Surprise! After a few months of searching, I’ve discovered the existence of a Salsa/ Bachata scene in Cambridge (UK)! It’s mostly Cuban salsa and Bachata, but I’ve managed to find a nice bunch dancing crossbody.&lt;/p&gt;

&lt;p&gt;Just wanted to share this online in case anyone else finds it useful.&lt;/p&gt;

&lt;h2 id=&quot;salsa&quot;&gt;Salsa&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Monday is Cambridge University Cuban Salsa Society at Revs with Randy Despaigne and other teachers. There are usually 3 levels at the class 20:00-21:00 and the social lasts until 22:00.&lt;/li&gt;
  &lt;li&gt;Tuesday is Darwin Cuban Salsa at Downing Place starting at 20:30 with Randy Despaigne, Verónica del Tono and other teachers. There are 4 levels followed by a social. &lt;a href=&quot;https://www.trybooking.com/uk/FXME&quot;&gt;Tickets&lt;/a&gt; are released Sundays at 1900. Members of Darwin College Cambridge get a discount.&lt;/li&gt;
  &lt;li&gt;Wednesday is Cuban Salsa and Bachata classes followed by a social, at Downing Place, with &lt;a href=&quot;https://leandrocharanga100dancer.co.uk&quot;&gt;Leandro Charanga&lt;/a&gt; starting at 1930&lt;/li&gt;
  &lt;li&gt;Thursday is &lt;a href=&quot;https://www.cambridgesalsa.co.uk/&quot;&gt;Cambridge Cuban Salsa&lt;/a&gt; with Sacha from 1930 at the Meadows Community Centre, 299 Arbury Rd, Cambridge CB4 2JL.&lt;/li&gt;
  &lt;li&gt;Friday &amp;amp; Mondays are salsa classes with &lt;a href=&quot;https://club-salsa.co.uk/&quot;&gt;Club Salsa&lt;/a&gt; (LA on 1 style, not Cuban) at St Andrews Baptist Church at 2000 then a social until midnight. Salsa and Bachata are played.&lt;/li&gt;
  &lt;li&gt;Sunday is Cambridge Cuban Salsa with Sacha from 1930 at at Adélie Studios, 121 Chesterton Road, CB4 3AT.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bachata&quot;&gt;Bachata&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Mondays at Cambourne Church Center and Tuesdays in Hidden Rooms with Veronica and team at &lt;a href=&quot;https://www.facebook.com/groups/295912874125184/?locale=en_GB&quot;&gt;Bachata Cambridge&lt;/a&gt;. Bachata sensual is the main style.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;other-dance&quot;&gt;Other dance&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;For University students, there unfortunately isn’t a Salsa/ Bachata team, but the Cambridge University Dancesports society does offer classes and does organise competitions! https://www.cambridgedancers.org/teams/cudt/&lt;/li&gt;
&lt;/ul&gt;</content><author><name>{&quot;name&quot;=&gt;nil, &quot;avatar&quot;=&gt;&quot;/files/head.jpg&quot;, &quot;bio&quot;=&gt;&quot;Scientist-engineer, traveller, photographer &amp; science communicator-- cause why not?&quot;, &quot;location&quot;=&gt;&quot;Cambridge, UK&quot;, &quot;email&quot;=&gt;&quot;me@kentonk.com&quot;, &quot;bitbucket&quot;=&gt;nil, &quot;codepen&quot;=&gt;nil, &quot;dribbble&quot;=&gt;nil, &quot;flickr&quot;=&gt;nil, &quot;facebook&quot;=&gt;nil, &quot;foursquare&quot;=&gt;nil, &quot;github&quot;=&gt;&quot;kwokkenton&quot;, &quot;google_plus&quot;=&gt;nil, &quot;keybase&quot;=&gt;nil, &quot;instagram&quot;=&gt;&quot;fizzyphys&quot;, &quot;lastfm&quot;=&gt;nil, &quot;linkedin&quot;=&gt;&quot;kentonkwok&quot;, &quot;pinterest&quot;=&gt;nil, &quot;soundcloud&quot;=&gt;nil, &quot;stackoverflow&quot;=&gt;nil, &quot;steam&quot;=&gt;nil, &quot;tumblr&quot;=&gt;nil, &quot;twitter&quot;=&gt;nil, &quot;vine&quot;=&gt;nil, &quot;weibo&quot;=&gt;nil, &quot;xing&quot;=&gt;nil, &quot;youtube&quot;=&gt;nil}</name><email>me@kentonk.com</email></author><summary type="html">In case anyone finds this useful!</summary></entry><entry><title type="html">Technical Note: Beer Lambert Law for Oxygenation Extraction</title><link href="https://www.kentonk.com/science/2026/01/07/oxy_modelling.html" rel="alternate" type="text/html" title="Technical Note: Beer Lambert Law for Oxygenation Extraction" /><published>2026-01-07T12:00:00+00:00</published><updated>2026-01-07T12:00:00+00:00</updated><id>https://www.kentonk.com/science/2026/01/07/oxy_modelling</id><content type="html" xml:base="https://www.kentonk.com/science/2026/01/07/oxy_modelling.html">&lt;p&gt;The most common approach in the literature for extracting oxygenation from multispectral or hyperspectral images, based on diffuse reflectance spectroscopy, is to use the Beer Lambert law.&lt;/p&gt;

&lt;p&gt;Although the model is technically incorrect, it can give results that make sense.&lt;/p&gt;

&lt;h2 id=&quot;forward-model-the-beer-lambert-law&quot;&gt;Forward model– the Beer Lambert Law&lt;/h2&gt;

&lt;p&gt;This is a physics-based law (also used in atmospheric physics, metrology), that comes from summing together infinitesimal absorptions over distance. It describes the resultant intensity of light \(I_T\) after passing through a medium (in transmission), basically saying that a unit increase in absorbance will be amplified exponentially as it continuously interacts with the medium over a distance.&lt;/p&gt;

&lt;p&gt;This makes sense, as if there is a constant interaction probability per distance, this will be amplified with a thicker medium.&lt;/p&gt;

\[I_T(z) = I_0 \exp\bigg(-\int_0^z\mu_a(z&apos;) dz&apos;\bigg)\]

&lt;p&gt;To make it useful for us in diffuse reflectance, we assume that&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;light is attenuated by tissue according to the Beer lambert law, over an interaction distance $l$&lt;/li&gt;
  &lt;li&gt;all non-attenuated light is therefore backscattered and forms part of the &lt;strong&gt;diffuse&lt;/strong&gt; &lt;strong&gt;reflectance&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;This is equivalent to saying, incorrectly, that so we can directly use Beer Lambert by assuming the transmitted light is the reflected light $I_T = I_R$&lt;/li&gt;
  &lt;li&gt;it is super incorrect but it is useful&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can make the assumptions, with non-interacting chromophores, that that the absorption coefficient is a linear combination of chromophores&lt;/p&gt;

&lt;p&gt;The integral inside the bracket is the absorbance $a$&lt;/p&gt;

\[a(\lambda) = -\ln[I_{R}(\lambda)/I_{0}(\lambda)]=\sum_{i}\varepsilon_i (\lambda) c_{i}l+U\]

&lt;p&gt;where&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$a$ is the absorbance (dimensionless)&lt;/li&gt;
  &lt;li&gt;absorbers indexed by $i$&lt;/li&gt;
  &lt;li&gt;$\mu_a$ is the absorbance [cm-1]&lt;/li&gt;
  &lt;li&gt;(mean) path length $l$ [cm],
    &lt;ul&gt;
      &lt;li&gt;$\varepsilon$ is the molar absorption coefficient [L mol-1 cm-1]&lt;/li&gt;
      &lt;li&gt;$c$ is the molar concentration [mol L-1]&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;$U$ is a wavelength-independent ‘fudge factor’ that captures other losses&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Assuming there are two dominant chromophores, oxy and deoxyhaemoglobin, we can proceed with our analysis. This is the molar extinction coefficient of oxy and deoxyhaemoglobin in water, compiled by Scott Prahl (Oregon Institute of Technology). This can be found &lt;a href=&quot;https://omlc.org/spectra/hemoglobin/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/files/blog/2026-01-oxy/image-19.png&quot; alt=&quot;alt text&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Graphs showing the molar extinction coefficients on a linear and logarithmic scale&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Notes&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A high extinction coefficient means that more light is absorbed in that wavelength&lt;/li&gt;
  &lt;li&gt;Deoxyhaemoglobin absorbs more in the reds by a (few) orders of magnitude, whilst oxyhaemoglobin absorbs slightly more in the greens&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;simulation&quot;&gt;Simulation&lt;/h3&gt;

&lt;p&gt;We can put this all in a simulation to observe how changing the various parameters changes the resultant reflectance spectrum. We define the oxygenation as the fraction of oxygenated to deoxyhaemoglobin in&lt;/p&gt;

\[S_{O_2} = \frac{c_{HbO_2}}{c_{HbO_2 }+c_{HbO }}\]

&lt;iframe src=&quot;/files/blog/2026-01-oxy/blood_oxygenation.html&quot; width=&quot;100%&quot; height=&quot;550&quot; style=&quot;border:none;&quot;&gt;
&lt;/iframe&gt;

&lt;p&gt;&lt;em&gt;Interactive plot showing the effects of varying different model parameters&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;inverse-retrieval&quot;&gt;Inverse: retrieval&lt;/h2&gt;

&lt;p&gt;By doing model-based retrieval, we mean to solve for the mixing coefficients (or the concentrations). By using a least squares solver, we obtain a point estimates of the quantities $(c_{HbO_2 }, c_{HbO }, U)$. Unless $l$ is fixed, it is absorbed into the concentrations.&lt;/p&gt;

&lt;p&gt;We can observe several potential failure modes of the retrieval algorithm by playing around with the simulation.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;When the path length is high, most of the useful signal is in the wavelengths above 600 nm. Increasing the scattering term has the same effect on the reflectance as reducing the oxygenation saturation.&lt;/li&gt;
  &lt;li&gt;Increasing the path length for a high oxygenation sample has the same effects as a reduction in the oxygenation saturation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;p&gt;[1] N. T. Clancy, G. Jones, L. Maier-Hein, D. S. Elson, and D. Stoyanov, ‘Surgical spectral imaging’, Medical Image Analysis, vol. 63, p. 101699, Jul. 2020, doi: 10.1016/j.media.2020.101699.&lt;/p&gt;</content><author><name>{&quot;name&quot;=&gt;nil, &quot;avatar&quot;=&gt;&quot;/files/head.jpg&quot;, &quot;bio&quot;=&gt;&quot;Scientist-engineer, traveller, photographer &amp; science communicator-- cause why not?&quot;, &quot;location&quot;=&gt;&quot;Cambridge, UK&quot;, &quot;email&quot;=&gt;&quot;me@kentonk.com&quot;, &quot;bitbucket&quot;=&gt;nil, &quot;codepen&quot;=&gt;nil, &quot;dribbble&quot;=&gt;nil, &quot;flickr&quot;=&gt;nil, &quot;facebook&quot;=&gt;nil, &quot;foursquare&quot;=&gt;nil, &quot;github&quot;=&gt;&quot;kwokkenton&quot;, &quot;google_plus&quot;=&gt;nil, &quot;keybase&quot;=&gt;nil, &quot;instagram&quot;=&gt;&quot;fizzyphys&quot;, &quot;lastfm&quot;=&gt;nil, &quot;linkedin&quot;=&gt;&quot;kentonkwok&quot;, &quot;pinterest&quot;=&gt;nil, &quot;soundcloud&quot;=&gt;nil, &quot;stackoverflow&quot;=&gt;nil, &quot;steam&quot;=&gt;nil, &quot;tumblr&quot;=&gt;nil, &quot;twitter&quot;=&gt;nil, &quot;vine&quot;=&gt;nil, &quot;weibo&quot;=&gt;nil, &quot;xing&quot;=&gt;nil, &quot;youtube&quot;=&gt;nil}</name><email>me@kentonk.com</email></author><category term="science" /><summary type="html">The most common approach in the literature for extracting oxygenation from multispectral or hyperspectral images, based on diffuse reflectance spectroscopy, is to use the Beer Lambert law.</summary></entry><entry><title type="html">Travelling abroad for work!</title><link href="https://www.kentonk.com/science/2025/08/30/travelling.html" rel="alternate" type="text/html" title="Travelling abroad for work!" /><published>2025-08-30T12:00:00+00:00</published><updated>2025-08-30T12:00:00+00:00</updated><id>https://www.kentonk.com/science/2025/08/30/travelling</id><content type="html" xml:base="https://www.kentonk.com/science/2025/08/30/travelling.html">&lt;p&gt;Travel is eye opening and you can learn an awful deal just by getting out of a day-to-day routine.&lt;/p&gt;

&lt;p&gt;I used to think that scientists/ engineers are only good in the lab or working behind a desk. This is far from the case! A lot of scientists do field work/ experimental collaborations abroad and attend meetings internationally. For me, I moved around different cities for jobs and in my previous role in industry I attended 2 trade shows (London, Birminhgam) and 2 conferences (Stuttgart, Helsinki) on behalf of the company and learnt a lot from it. Others on my team got sent to San Francisco for Photonics West, which is the largest photonics symposium, and ECCV, which is the largest computer vision event in Europe. It did help that I was a customer-facing engineer but these are some tips if you spot an event you want to attend.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://images.unsplash.com/photo-1477281765962-ef34e8bb0967?q=80&amp;amp;w=1466&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;ixlib=rb-4.1.0&amp;amp;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The first thing you must do if you want to take on these opportunities, especially if you’re young, is to establish yourself as a competent, eloquent and trusted team member. Your line manager should feel comfortable to send you out externally knowing that you can represent the group/ company and make a good impression on others. It took around 6-9 months for me to get to this stage after doing some internal presentations, client calls and reports. After that, you should start noting down events you’d like to attend and start asking!&lt;/p&gt;

&lt;p&gt;One great mentor at my previous company said the most stupid thing you can do is not asking!&lt;/p&gt;

&lt;h2 id=&quot;tips-for-asking-your-boss-for-sponsorship-to-attend-conferences-summer-schools&quot;&gt;Tips for asking your boss for sponsorship to attend conferences/ summer schools&lt;/h2&gt;

&lt;p&gt;🤘🏼In case you are also a young professional working in industry, I think joining conferences and summer schools are a good way to learn about things outside your day-to-day and to meet interesting people. SIGGRAPH have a really good &lt;a href=&quot;https://s2025.siggraph.org/ask-your-boss/&quot;&gt;“Get your boss on-board” template article&lt;/a&gt; which you can use to persuade whoever is in charge. I am not too familiar with the process in academia, probably there is a formal application for funding from specific funding bodies, but I am sure that there are similarities!&lt;/p&gt;

&lt;p&gt;In summary you should mention&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;what the event is about? What is the field it is in? How big is it? Is is prestigious? Make sure it is of a decent size and actually relevant to your team/ company.&lt;/li&gt;
  &lt;li&gt;the value it brings to the company/ group &lt;strong&gt;(emphasise this)&lt;/strong&gt;
    &lt;ol&gt;
      &lt;li&gt;Marketing value: is there a poster you can present to the audience? Remember to include an estimate of how many people attend the event and the split (industry/ academia)&lt;/li&gt;
      &lt;li&gt;Practical value: what methods can you learn from the conference and bring back to the team? Is there a talk that you would like to attend?&lt;/li&gt;
      &lt;li&gt;Networking value: will this generate new leads/ start new collaborations?&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;that it’s also for your personal development&lt;/li&gt;
  &lt;li&gt;Also remember to give an estimate of the costs and a detailed breakdown (transport, accomodation, registration, food)&lt;/li&gt;
  &lt;li&gt;When is the decision deadline?&lt;/li&gt;
  &lt;li&gt;That you will write a report so other team members can learn from your experience&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;what-else-can-you-do&quot;&gt;What else can you do?&lt;/h2&gt;

&lt;p&gt;Some conferences have options to present industry insights/ posters/ conference papers. Even if you don’t work in a research team, some conference workshops have quite high acceptance rates so it’s always worth giving it a try.&lt;/p&gt;

&lt;p&gt;Your line-manager is not obliged to give you this opportunity, but there’s nothing stopping you from putting the best case forward!&lt;/p&gt;</content><author><name>{&quot;name&quot;=&gt;nil, &quot;avatar&quot;=&gt;&quot;/files/head.jpg&quot;, &quot;bio&quot;=&gt;&quot;Scientist-engineer, traveller, photographer &amp; science communicator-- cause why not?&quot;, &quot;location&quot;=&gt;&quot;Cambridge, UK&quot;, &quot;email&quot;=&gt;&quot;me@kentonk.com&quot;, &quot;bitbucket&quot;=&gt;nil, &quot;codepen&quot;=&gt;nil, &quot;dribbble&quot;=&gt;nil, &quot;flickr&quot;=&gt;nil, &quot;facebook&quot;=&gt;nil, &quot;foursquare&quot;=&gt;nil, &quot;github&quot;=&gt;&quot;kwokkenton&quot;, &quot;google_plus&quot;=&gt;nil, &quot;keybase&quot;=&gt;nil, &quot;instagram&quot;=&gt;&quot;fizzyphys&quot;, &quot;lastfm&quot;=&gt;nil, &quot;linkedin&quot;=&gt;&quot;kentonkwok&quot;, &quot;pinterest&quot;=&gt;nil, &quot;soundcloud&quot;=&gt;nil, &quot;stackoverflow&quot;=&gt;nil, &quot;steam&quot;=&gt;nil, &quot;tumblr&quot;=&gt;nil, &quot;twitter&quot;=&gt;nil, &quot;vine&quot;=&gt;nil, &quot;weibo&quot;=&gt;nil, &quot;xing&quot;=&gt;nil, &quot;youtube&quot;=&gt;nil}</name><email>me@kentonk.com</email></author><category term="science" /><summary type="html">Travel is eye opening and you can learn an awful deal just by getting out of a day-to-day routine.</summary></entry><entry><title type="html">The Missing Semester- Tips for Scientists who code</title><link href="https://www.kentonk.com/science/2025/08/28/missing-semester.html" rel="alternate" type="text/html" title="The Missing Semester- Tips for Scientists who code" /><published>2025-08-28T12:00:00+00:00</published><updated>2025-08-28T12:00:00+00:00</updated><id>https://www.kentonk.com/science/2025/08/28/missing-semester</id><content type="html" xml:base="https://www.kentonk.com/science/2025/08/28/missing-semester.html">&lt;p&gt;&lt;img src=&quot;/files/circus.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This article/ series inspired by the &lt;a href=&quot;https://missing.csail.mit.edu/&quot;&gt;MIT Missing Semester&lt;/a&gt; course lectures, which I thought was oriented much more towards computer scientists and goes through the shell, build processes, remote access etc. These topics are important, but I thought there should be something more oriented towards the types of work scientists like myself do, which largely comprise of signal/ data processing, analysis and its automation. I started making some &lt;a href=&quot;https://www.instagram.com/fizzyphys&quot;&gt;reels&lt;/a&gt; on my own ‘Missing Semester’ and this is a longer written form of the same information.&lt;/p&gt;

&lt;p&gt;Most scientists now code in the Python programming language, which is a high level language that is now taught in many universities and practically standard in industry.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Unlike physics/ mathematics, a lot of these are just &lt;strong&gt;tools&lt;/strong&gt; that us humans have &lt;strong&gt;designed/ built&lt;/strong&gt; to make things easier/ more convenient.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There’s nothing fundamental about any specific programming language or a packager, and these guidelines and ‘best’ practices may be superceded in the future. It’s more important to understand WHY we do this, say for reproducibility, modularity, separation of concerns, hardware independence etc.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;We will move from setting up your environments to using AI for coding assistance&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;1-environments-and-conda&quot;&gt;1. Environments and Conda&lt;/h2&gt;

&lt;p&gt;Have you ever wondered why there are so many different Pythons on your computer? Each is a different Python &lt;strong&gt;interpreter&lt;/strong&gt;, which reads and runs your python file, line by line. Each interpreter has its own &lt;strong&gt;environment&lt;/strong&gt;, which gives access to libraries (code that other people have written).&lt;/p&gt;

&lt;p&gt;To find out which python interpreter you are using, you can do &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;which python&lt;/code&gt; in your terminal.&lt;/p&gt;

&lt;p&gt;As we want analysis work to be &lt;strong&gt;reproducible&lt;/strong&gt; and &lt;strong&gt;reusable&lt;/strong&gt;, it is important to specify what &lt;strong&gt;libraries and packages&lt;/strong&gt; the script requires, and also their versions. These are also called &lt;strong&gt;dependencies&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I use &lt;a href=&quot;https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html&quot;&gt;conda&lt;/a&gt;, which is a package manager. It’s super beginner friendly and you’ll see many repositories using this to specify dependencies using an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;environment.yml&lt;/code&gt; file. You then do &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;conda env create --file environment.yml&lt;/code&gt; to create an environment using that file.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/files/blog/2025-08-missing_semester/image.png&quot; alt=&quot;alt text&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The other way usually taught is to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;virtualenv&lt;/code&gt; with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;requirements.txt&lt;/code&gt; file, but it doesn’t manage version conflicts of packages.&lt;/p&gt;

&lt;p&gt;In short, you give recipe files to environment managers and specify what versions of Python and libraries your code should be run in so others can reproduce your findings.&lt;/p&gt;

&lt;h2 id=&quot;2-code-organisation-jupyter-vs-python&quot;&gt;2. Code organisation: Jupyter vs Python&lt;/h2&gt;

&lt;p&gt;I love &lt;a href=&quot;https://jupyter.org/install&quot;&gt;Jupyter notebooks&lt;/a&gt; for quick prototyping—plots stick around, and it’s super fast to experiment with. There’s even VSCode extension for it!&lt;/p&gt;

&lt;p&gt;But… analysis in notebooks is tough to reproduce, as code cells can be run in any order.&lt;/p&gt;

&lt;p&gt;So here’s my approach: whenever I create a reusable function, I refactor it into a Python package and install it in editable mode.&lt;/p&gt;

&lt;p&gt;Refactoring just means making the code flow better by shifting the code to another file/ restructuring it. These new modules can then be imported nicely inside another analysis notebook, following the ‘don’t repeat yourself’ (DRY) principle :)&lt;/p&gt;

&lt;p&gt;Say I’ve copy and pasted my code into My code is now&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;my_repository
|_ my_package
    |_ my_file.py
    |_ __init__.py
|_ notebooks
    |_ data_analysis.ipynb
|_ pyproject.toml
|_ setup.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You also need to create and a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pyproject.toml&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# pyproject.toml
[build-system]
requires = [&quot;setuptools&quot;, &quot;wheel&quot;]
build-backend = &quot;setuptools.build_meta&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setup.py&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# setup.py
from setuptools import find_packages, setup

setup(
    name=&quot;my_package&quot;,
    version=&quot;0.1.0&quot;,
    packages=find_packages(),
    install_requires=[],  # Add dependencies here
    author=&quot;&quot;,
    author_email=&quot;&quot;,
    description=&quot;A short description of your package&quot;,
    url=&quot;https://github.com/yourusername/your_package&quot;,
    classifiers=[
        &quot;Programming Language :: Python :: 3&quot;,
        &quot;Operating System :: OS Independent&quot;,
    ],
    python_requires=&quot;&amp;gt;=3.7&quot;,
)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I can now install my module in editable mode (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-e&lt;/code&gt;), which means that any code I change in my module will instantly have effect, and there’s no need to reinstall &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install -e name_of_module&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In my Jupyter notebook (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;data_analysis.ipynb&lt;/code&gt;), I also put these two lines at the top&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;%load_ext autoreload
%autoreload 2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;which ensures that any changes to my packages are instantly reflected in my Jupyter environment.&lt;/p&gt;

&lt;p&gt;In this way, I keep prototyping separate from real development—making my code modular, reproducible, and reusable.&lt;/p&gt;

&lt;p&gt;More info &lt;a href=&quot;https://python101.pythonlibrary.org/chapter36_creating_modules_and_packages.html&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;https://packaging.python.org/en/latest/overview/&quot;&gt;here&lt;/a&gt; for those who want deeper dives.&lt;/p&gt;

&lt;h2 id=&quot;3-git-vs-github&quot;&gt;3. Git vs GitHub&lt;/h2&gt;

&lt;p&gt;Don’t make this common mistake—Git and GitHub are not the same thing. So, what’s Git?&lt;/p&gt;

&lt;p&gt;Git is the standard version control system for programming projects. It tracks every line of change, lets you roll back if needed, and makes it possible for people to &lt;strong&gt;collaborate&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Version control systems track history&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Think of a repository as your project, and a commit as a snapshot update. You can branch off, experiment, and later merge changes back into the main branch. And here’s the cool part—you don’t even need the internet. Git lives in a hidden .git folder on your computer.&lt;/p&gt;

&lt;p&gt;Now, GitHub is different. It’s an online service built on top of Git—like Google Drive for code. It’s where you upload repositories to share, collaborate, and contribute with others. GitHub is just one of many platforms—others include GitLab and Bitbucket.&lt;/p&gt;

&lt;p&gt;If you’re working with yourself, I’d recommend setting up your (remote) project on GitHub and then cloning it on your local PC.&lt;/p&gt;

&lt;h2 id=&quot;dont-be-intimidated-by-the-terminal&quot;&gt;Don’t be intimidated by the terminal&lt;/h2&gt;

&lt;h2 id=&quot;what-is-a-programming-language&quot;&gt;What is a Programming language?&lt;/h2&gt;</content><author><name>{&quot;name&quot;=&gt;nil, &quot;avatar&quot;=&gt;&quot;/files/head.jpg&quot;, &quot;bio&quot;=&gt;&quot;Scientist-engineer, traveller, photographer &amp; science communicator-- cause why not?&quot;, &quot;location&quot;=&gt;&quot;Cambridge, UK&quot;, &quot;email&quot;=&gt;&quot;me@kentonk.com&quot;, &quot;bitbucket&quot;=&gt;nil, &quot;codepen&quot;=&gt;nil, &quot;dribbble&quot;=&gt;nil, &quot;flickr&quot;=&gt;nil, &quot;facebook&quot;=&gt;nil, &quot;foursquare&quot;=&gt;nil, &quot;github&quot;=&gt;&quot;kwokkenton&quot;, &quot;google_plus&quot;=&gt;nil, &quot;keybase&quot;=&gt;nil, &quot;instagram&quot;=&gt;&quot;fizzyphys&quot;, &quot;lastfm&quot;=&gt;nil, &quot;linkedin&quot;=&gt;&quot;kentonkwok&quot;, &quot;pinterest&quot;=&gt;nil, &quot;soundcloud&quot;=&gt;nil, &quot;stackoverflow&quot;=&gt;nil, &quot;steam&quot;=&gt;nil, &quot;tumblr&quot;=&gt;nil, &quot;twitter&quot;=&gt;nil, &quot;vine&quot;=&gt;nil, &quot;weibo&quot;=&gt;nil, &quot;xing&quot;=&gt;nil, &quot;youtube&quot;=&gt;nil}</name><email>me@kentonk.com</email></author><category term="science" /><summary type="html"></summary></entry><entry><title type="html">Atomic advice for young me</title><link href="https://www.kentonk.com/thoughts/2025/06/04/efficient.html" rel="alternate" type="text/html" title="Atomic advice for young me" /><published>2025-06-04T12:00:00+00:00</published><updated>2025-06-04T12:00:00+00:00</updated><id>https://www.kentonk.com/thoughts/2025/06/04/efficient</id><content type="html" xml:base="https://www.kentonk.com/thoughts/2025/06/04/efficient.html">&lt;p&gt;&lt;img src=&quot;https://images.unsplash.com/photo-1505159940484-eb2b9f2588e2?q=80&amp;amp;w=2070&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;ixlib=rb-4.0.3&amp;amp;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;/h2&gt;

&lt;p&gt;These are some notes I have shown to me every morning when I wake up, hopefully they resonate with you.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Treat people around you well and spend quality time with friends and family, because they will lift you up.&lt;/li&gt;
  &lt;li&gt;Believe in yourself, accept and love yourself and face yur imperfections. If you don’t, who will?&lt;/li&gt;
  &lt;li&gt;Live in the present, do what makes you feel alive and live intensely. Really really want things, but chill out cause everything it going to be okay.&lt;/li&gt;
  &lt;li&gt;Always produce, work really hard and lead your life well. Put yourself out there and good things will happen.&lt;/li&gt;
  &lt;li&gt;Don’t think that the world is efficient, nor perfect in its current state. There are always things to discover, problems to be solved and wrongs waited to be righted.&lt;/li&gt;
  &lt;li&gt;Everyone wants connection. Make small talk with people and listen to their story. Learn about people. We’re all on the same boat.&lt;/li&gt;
  &lt;li&gt;Protect your time. Hell yeah or no.&lt;/li&gt;
  &lt;li&gt;Be kind to others, without being asked to, and then good things will happen&lt;/li&gt;
  &lt;li&gt;Adopt skepticism, be curious, think if things are true. Form a strong view of the world and hope to be contradicted by others.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;quotes&quot;&gt;Quotes&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;“You don’t need to be great to get started, you just need to get started to be great.” 千里之行，始於足下。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;“The only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle.” Steve Jobs.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;“Let your hopes, not your hurts, shape your future.” Robert H Schuller&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;“Define success on your own terms, achieve it by your own rules, and build a life you’re proud to live.” Anne Sweeney&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;If you look at what you have in life, you always have more. If you look at what you don’t have in life, you’ll never have enough. This echoes 知足者常樂. Oprah Winfrey.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The privilege of a lifetime is being who you are. Joseph Campbell&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;It’s all about the people&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Be the change you wish to see in the world&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;You will eventually use everything you’ve ever learned.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Go where you’re celebrated, not tolerated&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Comparison is the thief of joy&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;If you cannot find peace within yourself, you will never find it anywhere else&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;We don’t read and write poetry because it’s cute. We read and write poetry because we are members of the human race. And the human race is filled with passion. And medicine, law, business, engineering, these are noble pursuits and necessary to sustain life. But poetry, beauty, romance, love, these are what we stay alive for.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Nothing is so fatiguing as the eternal hanging on of an uncompleted task.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;</content><author><name>{&quot;name&quot;=&gt;nil, &quot;avatar&quot;=&gt;&quot;/files/head.jpg&quot;, &quot;bio&quot;=&gt;&quot;Scientist-engineer, traveller, photographer &amp; science communicator-- cause why not?&quot;, &quot;location&quot;=&gt;&quot;Cambridge, UK&quot;, &quot;email&quot;=&gt;&quot;me@kentonk.com&quot;, &quot;bitbucket&quot;=&gt;nil, &quot;codepen&quot;=&gt;nil, &quot;dribbble&quot;=&gt;nil, &quot;flickr&quot;=&gt;nil, &quot;facebook&quot;=&gt;nil, &quot;foursquare&quot;=&gt;nil, &quot;github&quot;=&gt;&quot;kwokkenton&quot;, &quot;google_plus&quot;=&gt;nil, &quot;keybase&quot;=&gt;nil, &quot;instagram&quot;=&gt;&quot;fizzyphys&quot;, &quot;lastfm&quot;=&gt;nil, &quot;linkedin&quot;=&gt;&quot;kentonkwok&quot;, &quot;pinterest&quot;=&gt;nil, &quot;soundcloud&quot;=&gt;nil, &quot;stackoverflow&quot;=&gt;nil, &quot;steam&quot;=&gt;nil, &quot;tumblr&quot;=&gt;nil, &quot;twitter&quot;=&gt;nil, &quot;vine&quot;=&gt;nil, &quot;weibo&quot;=&gt;nil, &quot;xing&quot;=&gt;nil, &quot;youtube&quot;=&gt;nil}</name><email>me@kentonk.com</email></author><category term="thoughts" /><summary type="html">thoughts</summary></entry><entry><title type="html">My Research interests</title><link href="https://www.kentonk.com/thoughts/2025/06/04/research-interests.html" rel="alternate" type="text/html" title="My Research interests" /><published>2025-06-04T12:00:00+00:00</published><updated>2025-06-04T12:00:00+00:00</updated><id>https://www.kentonk.com/thoughts/2025/06/04/research-interests</id><content type="html" xml:base="https://www.kentonk.com/thoughts/2025/06/04/research-interests.html">&lt;blockquote&gt;
  &lt;p&gt;This is my attempt to understand some gaps in research that I currently find interesting in. At the moment they revolve around computer vision and machine learning in biology. Last updated: June 2025.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;computer-vision-world-models-and-3d&quot;&gt;Computer Vision: World models and 3D&lt;/h2&gt;

&lt;p&gt;There has traditionally been a gap between the geometric reconstruction based side of computer vision with recognition/ reorganisation side which has shifted to neural network based. Transformer based architectures are now used to tackle the &lt;a href=&quot;https://arxiv.org/pdf/2503.11651&quot;&gt;geometry based problem (VGGT, 2025)&lt;/a&gt;, which is orders of magnitude quicker than other techniques such as structure from motion. Now this is present, it would be interested to tap into its embeddings to see what ‘understanding’ of the visual world it has.&lt;/p&gt;

&lt;p&gt;Other topics: Neural Radiance Fields, 3/4D Gaussian Splatting&lt;/p&gt;

&lt;p&gt;Groups: &lt;a href=&quot;https://www.robots.ox.ac.uk/~vgg/research/&quot;&gt;Visual Geometry Group, Oxford&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;computer-vision-for-science&quot;&gt;Computer Vision: For science&lt;/h2&gt;

&lt;p&gt;A large part of the computer vision community is focused on visual perception and reasoning.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.nature.com/articles/s41596-023-00840-9&quot;&gt;Cell painting (2016)&lt;/a&gt; is an imaging-based cellular assay based on morphology (size, shape) that can be used to quantify the effects of chemical or genetic ‘perturbations’ to the cells.&lt;/p&gt;

&lt;p&gt;Image processing/ analysis techniques are maturing now (at least in 2D), and research is focused on obtaining an &lt;strong&gt;understanding&lt;/strong&gt; of the objects in images themselves.&lt;/p&gt;

&lt;h2 id=&quot;computational-photography-and-imaging&quot;&gt;Computational Photography and Imaging&lt;/h2&gt;

&lt;p&gt;the joint design of optics and algorithms to get the result you want. Applications in cell microscopy and neuroscience. See Laura Waller, Na Ji.&lt;/p&gt;

&lt;h2 id=&quot;machine-learning-for-biology-and-medicine&quot;&gt;Machine Learning for biology and medicine&lt;/h2&gt;

&lt;p&gt;Human scientists can pose questions/ hypotheses, do experiments, get data and learn from the data. Machines and computers are getting to the point where it can do the same. Centres such as the CZ Biohub, and big pharma are are constructing high throughput profiling platforms for basic research as well as applied screening.&lt;/p&gt;

&lt;p&gt;Biological data is tricky as unlike internet images, many times the datasets are small, require expert annotation, and experiments are costly to run.&lt;/p&gt;

&lt;p&gt;The world is inherently multimodal. Part of this is learning a ‘joint representation’ and hence developing understanding of the phenomenon itself.&lt;/p&gt;

&lt;p&gt;Generative design of molecules. Graph neural networks lend naturally to molecules. How can it be applied in synthetic biology and therapeutics?&lt;/p&gt;

&lt;p&gt;Meetings&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://cvdd-cvpr25.github.io/&quot;&gt;Computer vision for drug discovery at CVPR&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.lmrl.org/&quot;&gt;Learning Meaningful Representations of Life (LMRL) at ICLR 2025&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name>{&quot;name&quot;=&gt;nil, &quot;avatar&quot;=&gt;&quot;/files/head.jpg&quot;, &quot;bio&quot;=&gt;&quot;Scientist-engineer, traveller, photographer &amp; science communicator-- cause why not?&quot;, &quot;location&quot;=&gt;&quot;Cambridge, UK&quot;, &quot;email&quot;=&gt;&quot;me@kentonk.com&quot;, &quot;bitbucket&quot;=&gt;nil, &quot;codepen&quot;=&gt;nil, &quot;dribbble&quot;=&gt;nil, &quot;flickr&quot;=&gt;nil, &quot;facebook&quot;=&gt;nil, &quot;foursquare&quot;=&gt;nil, &quot;github&quot;=&gt;&quot;kwokkenton&quot;, &quot;google_plus&quot;=&gt;nil, &quot;keybase&quot;=&gt;nil, &quot;instagram&quot;=&gt;&quot;fizzyphys&quot;, &quot;lastfm&quot;=&gt;nil, &quot;linkedin&quot;=&gt;&quot;kentonkwok&quot;, &quot;pinterest&quot;=&gt;nil, &quot;soundcloud&quot;=&gt;nil, &quot;stackoverflow&quot;=&gt;nil, &quot;steam&quot;=&gt;nil, &quot;tumblr&quot;=&gt;nil, &quot;twitter&quot;=&gt;nil, &quot;vine&quot;=&gt;nil, &quot;weibo&quot;=&gt;nil, &quot;xing&quot;=&gt;nil, &quot;youtube&quot;=&gt;nil}</name><email>me@kentonk.com</email></author><category term="thoughts" /><summary type="html">an evolving literature review based on my current research interests</summary></entry><entry><title type="html">Recent musings– podcasts and videos</title><link href="https://www.kentonk.com/lifestyle,/machine_learning/2025/04/18/podcasts.html" rel="alternate" type="text/html" title="Recent musings– podcasts and videos" /><published>2025-04-18T12:00:00+00:00</published><updated>2025-04-18T12:00:00+00:00</updated><id>https://www.kentonk.com/lifestyle,/machine_learning/2025/04/18/podcasts</id><content type="html" xml:base="https://www.kentonk.com/lifestyle,/machine_learning/2025/04/18/podcasts.html">&lt;p&gt;&lt;img src=&quot;https://images.unsplash.com/photo-1458560871784-56d23406c091?q=80&amp;amp;w=1548&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;ixlib=rb-4.0.3&amp;amp;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Recent podcasts I’ve been listening to&lt;/p&gt;

&lt;h2 id=&quot;machine-learning&quot;&gt;Machine Learning&lt;/h2&gt;

&lt;p&gt;It’s really interesting learning about the lives of researchers too and also the &lt;strong&gt;process&lt;/strong&gt; of scientific research itself&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;a href=&quot;https://www.youtube.com/c/TheRobotBrainsPodcast&quot;&gt;Robot Brains Podcast&lt;/a&gt; by &lt;a href=&quot;https://people.eecs.berkeley.edu/~pabbeel/&quot;&gt;Pieter Abbeel&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;Biographic interviews on the greatest researchers in machine learning&lt;/li&gt;
      &lt;li&gt;Host is an expert on reinforcement learning and robotics&lt;/li&gt;
      &lt;li&gt;Favourite episodes: Fei-Fei Li, Andrej Kaparthy, Ilya Sutskyaver, Yann LeCunn&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://deepmind.google/discover/the-podcast/&quot;&gt;DeepMind Podcast&lt;/a&gt; hosted by Hannah Fry
    &lt;ul&gt;
      &lt;li&gt;Episodes about DeepMind’s research into artificial intelligence&lt;/li&gt;
      &lt;li&gt;Favourite episodes: Jeff Dean, Pushmeet Kohli, AI for science&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;computational-imaging&quot;&gt;Computational Imaging&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://scien.stanford.edu/index.php/events/scien-seminars/&quot;&gt;Scien Seminars&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;other-topics&quot;&gt;Other topics&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://open.spotify.com/show/0sBh58hSTReUQiK4axYUVx&quot;&gt;Empire&lt;/a&gt; by William Dalrymple and Anita Anand
    &lt;ul&gt;
      &lt;li&gt;Favourite episodes: USA’s hidden empire, Byzantium, Spain, Zheng He&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;</content><author><name>{&quot;name&quot;=&gt;nil, &quot;avatar&quot;=&gt;&quot;/files/head.jpg&quot;, &quot;bio&quot;=&gt;&quot;Scientist-engineer, traveller, photographer &amp; science communicator-- cause why not?&quot;, &quot;location&quot;=&gt;&quot;Cambridge, UK&quot;, &quot;email&quot;=&gt;&quot;me@kentonk.com&quot;, &quot;bitbucket&quot;=&gt;nil, &quot;codepen&quot;=&gt;nil, &quot;dribbble&quot;=&gt;nil, &quot;flickr&quot;=&gt;nil, &quot;facebook&quot;=&gt;nil, &quot;foursquare&quot;=&gt;nil, &quot;github&quot;=&gt;&quot;kwokkenton&quot;, &quot;google_plus&quot;=&gt;nil, &quot;keybase&quot;=&gt;nil, &quot;instagram&quot;=&gt;&quot;fizzyphys&quot;, &quot;lastfm&quot;=&gt;nil, &quot;linkedin&quot;=&gt;&quot;kentonkwok&quot;, &quot;pinterest&quot;=&gt;nil, &quot;soundcloud&quot;=&gt;nil, &quot;stackoverflow&quot;=&gt;nil, &quot;steam&quot;=&gt;nil, &quot;tumblr&quot;=&gt;nil, &quot;twitter&quot;=&gt;nil, &quot;vine&quot;=&gt;nil, &quot;weibo&quot;=&gt;nil, &quot;xing&quot;=&gt;nil, &quot;youtube&quot;=&gt;nil}</name><email>me@kentonk.com</email></author><category term="lifestyle," /><category term="machine_learning" /><summary type="html"></summary></entry><entry><title type="html">Don’t be intimidated. Starting again in ML.</title><link href="https://www.kentonk.com/science/2025/04/18/mlx.html" rel="alternate" type="text/html" title="Don’t be intimidated. Starting again in ML." /><published>2025-04-18T12:00:00+00:00</published><updated>2025-04-18T12:00:00+00:00</updated><id>https://www.kentonk.com/science/2025/04/18/mlx</id><content type="html" xml:base="https://www.kentonk.com/science/2025/04/18/mlx.html">&lt;h2 id=&quot;learnings&quot;&gt;Learnings&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;The first step is to not be intimidated&lt;/li&gt;
  &lt;li&gt;There’s an abundance of resources (papers, blog posts, frameworks) online and sometimes you just want a single source of truth
    &lt;ol&gt;
      &lt;li&gt;Choose uni lecture courses to see if your level matches (Stanford, Cambridge)&lt;/li&gt;
      &lt;li&gt;The heart of DL is mathematics, but you need to be able to build it with computational tools. Try to get to the bottom of it&lt;/li&gt;
      &lt;li&gt;Textbooks are good, until they go &lt;strong&gt;too deep&lt;/strong&gt;&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;“What I cannot create, I do not understand”– Richard Feynman.
    &lt;ol&gt;
      &lt;li&gt;Define a simple task, get the base dataset, and do it.&lt;/li&gt;
      &lt;li&gt;Focus on understanding the concept and then implementing &lt;strong&gt;a&lt;/strong&gt; working version of it&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;Find infra tools that help you (weights and biases)&lt;/li&gt;
  &lt;li&gt;ALWAYS validate on something that a human can intuitively understand. The loss, accuracy metrics can be deceptive&lt;/li&gt;
  &lt;li&gt;Talking through with others help a lot&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;resources-and-inspirations&quot;&gt;Resources and inspirations&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Andrej Kaparthy’s &lt;a href=&quot;https://karpathy.github.io/2019/04/25/recipe/&quot;&gt;Recipe for Training Neural Networks&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;Become one with the data&lt;/li&gt;
      &lt;li&gt;Set up the &lt;strong&gt;end-to-end&lt;/strong&gt; training/ evaluation skeleton + visualise EVERYTHING + get dumb baselines. &lt;em&gt;Even better if you deploy it (especially if you want to show people)&lt;/em&gt;&lt;/li&gt;
      &lt;li&gt;Overfit on the training set&lt;/li&gt;
      &lt;li&gt;Last step: Regularise, tune, ensemble&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;</content><author><name>{&quot;name&quot;=&gt;nil, &quot;avatar&quot;=&gt;&quot;/files/head.jpg&quot;, &quot;bio&quot;=&gt;&quot;Scientist-engineer, traveller, photographer &amp; science communicator-- cause why not?&quot;, &quot;location&quot;=&gt;&quot;Cambridge, UK&quot;, &quot;email&quot;=&gt;&quot;me@kentonk.com&quot;, &quot;bitbucket&quot;=&gt;nil, &quot;codepen&quot;=&gt;nil, &quot;dribbble&quot;=&gt;nil, &quot;flickr&quot;=&gt;nil, &quot;facebook&quot;=&gt;nil, &quot;foursquare&quot;=&gt;nil, &quot;github&quot;=&gt;&quot;kwokkenton&quot;, &quot;google_plus&quot;=&gt;nil, &quot;keybase&quot;=&gt;nil, &quot;instagram&quot;=&gt;&quot;fizzyphys&quot;, &quot;lastfm&quot;=&gt;nil, &quot;linkedin&quot;=&gt;&quot;kentonkwok&quot;, &quot;pinterest&quot;=&gt;nil, &quot;soundcloud&quot;=&gt;nil, &quot;stackoverflow&quot;=&gt;nil, &quot;steam&quot;=&gt;nil, &quot;tumblr&quot;=&gt;nil, &quot;twitter&quot;=&gt;nil, &quot;vine&quot;=&gt;nil, &quot;weibo&quot;=&gt;nil, &quot;xing&quot;=&gt;nil, &quot;youtube&quot;=&gt;nil}</name><email>me@kentonk.com</email></author><category term="science" /><summary type="html">Learnings</summary></entry><entry><title type="html">Backpropagation of the batch norm layer</title><link href="https://www.kentonk.com/thoughts/2025/04/01/learnings.html" rel="alternate" type="text/html" title="Backpropagation of the batch norm layer" /><published>2025-04-01T12:00:00+00:00</published><updated>2025-04-01T12:00:00+00:00</updated><id>https://www.kentonk.com/thoughts/2025/04/01/learnings</id><content type="html" xml:base="https://www.kentonk.com/thoughts/2025/04/01/learnings.html">&lt;blockquote&gt;
  &lt;p&gt;Assignment 2 of Stanford’s &lt;a href=&quot;https://cs231n.github.io/&quot;&gt;CS231n&lt;/a&gt; took me a while to wrap my head round. These are some notes so that I remember.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;backpropagation&quot;&gt;Backpropagation&lt;/h2&gt;

&lt;p&gt;A gradient estimation method using reverse mode differentiation!&lt;/p&gt;

&lt;p&gt;In learning algorithms, the gradient we most often require is the gradient of the cost function with respect to the parameters, \(\nabla_W L(W)\) where \(W\) are the weights and $L$ is the scalar loss function.&lt;/p&gt;

&lt;h3 id=&quot;batch-norm&quot;&gt;Batch Norm&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/files/blog/backprop/image.png&quot; alt=&quot;Batch Norm Algorithm&quot; /&gt;
&lt;em&gt;Algorithm from the original paper&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Forward pass&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Elementwise statistics, average over batch
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sample_mean&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sample_var&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;denom&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sqrt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sample_var&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# normalise
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x_corrected&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sample_mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;denom&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#xhat
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gamma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x_corrected&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#yi
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Track the statistics of the mean and variance for test time
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;running_mean&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;momentum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;running_mean&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;momentum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sample_mean&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;running_var&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;momentum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;running_var&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;momentum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sample_var&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;cache&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;x_hat&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x_corrected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&apos;mu&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sample_mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&apos;var&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sample_var&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&apos;denom&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;denom&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;gamma&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gamma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;beta&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;x&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;method-1-computational-graph&quot;&gt;Method 1: Computational Graph&lt;/h4&gt;

&lt;p&gt;We trace the computational graph backwards step by step. This was explained &lt;a href=&quot;https://kratzert.github.io/2016/02/12/understanding-the-gradient-flow-through-the-batch-normalization-layer.html&quot;&gt;here&lt;/a&gt; quite well!&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;dgammax&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dout&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# dL/d(gamma*x)
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dgamma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dgammax&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xhat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#dL/dgamma
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dxhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dgammax&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gamma&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# dL/dxhat
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dbeta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# dL/dbeta
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;dnom_1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dxhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;denom&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#dL/d(x-mu)
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ddenom&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dxhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nom&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;denom&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# dL/d(sqrt(var+eps))
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dvar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ddenom&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;denom&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#dL/dvar
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;dnom_2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dvar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#dL/d(x-mu)
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dnom&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dnom_1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dnom_2&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#dL/dnom
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dmu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dnom&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#dL/dmu
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dx_1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dmu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ones&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;dx_2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dnom&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;dx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dx_1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dx_2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;method-2-differentiation-from-first-principles&quot;&gt;Method 2: Differentiation from first principles&lt;/h4&gt;

&lt;p&gt;This is already well explained in &lt;a href=&quot;https://cthorey.github.io/blog/2016/backpropagation/&quot;&gt;this&lt;/a&gt; blogpost, but I’d just like to add some more intuition.&lt;/p&gt;

&lt;p&gt;Example 1: Say we have a zero-centering/ mean subtraction operation using statistics derived from a batch. So \(y = x - \mu\). We know that \(x\) and \(y\) have the same size \(x,y \in \mathbb{R}^{(N\times D)}\) where $N$ is the batch size and \(D\) is the number of dimensions in your training example. If we write all the entries of matrix \(y\) out this will be&lt;/p&gt;

\[y_{kl} = x_{kl}- \frac{1}{N}\sum_{i}^{n}x_{il}\]

&lt;p&gt;&lt;em&gt;Equation 1: mean shift operation.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;more verbosely, using the Kronecker delta notation, which explicitly tells you the rules of the transition from \(x\) to \(y\), and we label the indices \(i,j\) and \(k,l\) differently for matrices \(x\) and \(y\) for clarity.&lt;/p&gt;

\[y_{kl} =x_{ij}\delta_{ik}\delta_{jl} - \frac{1}{N}\sum_{i}^{n}x_{ij}\delta_{jl}\]

&lt;p&gt;&lt;em&gt;Equation 1: matrix entry view of batch mean subtraction. This tells you how each element in the training batch will affect the output.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Say we already measured how much \(y\) impacts the scalar loss \(L\). In other words, we know the &lt;strong&gt;upstream derivative&lt;/strong&gt;, a 2D matrix \(\frac{dL}{dy_{kl}}\), which is how much the loss \(L\) changes by as each entry in \(y_{kl}\) changes. However, we want to use backpropagation to compute the loss with respect to $x$. We use the chain rule and sum over the indices in \(y\).&lt;/p&gt;

\[\frac{dL}{dx_{ij}} = \sum_{kl}\frac{dL}{dy_{kl}} \frac{dy_{kl}}{dx_{ij}}\]

&lt;blockquote&gt;
  &lt;p&gt;The complicated thing here is that \(x\) and \(y\) are matrices/ tensors. This is explained away in the deep learning book.
&lt;img src=&quot;/files/blog/backprop/image-1.png&quot; alt=&quot;alt text&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The terms&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(\frac{dL}{dy_{kl}}\) as explained, a 2D matrix&lt;/li&gt;
  &lt;li&gt;\(\frac{dy_{kl}}{dx_{ij}}\) is called a &lt;strong&gt;Jacobian matrix&lt;/strong&gt; here (2x2 = 4D), which explains how much each element in matrix \(y\) changes as each element in matrix \(x\) changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We write down the Jacobian computing the derivative of Eq. 1&lt;/p&gt;

\[\frac{dy_{kl}}{d x_{ij}} = \delta_{ik}\delta_{jl}-\frac{1}{N}\delta_{jl}\]

&lt;p&gt;&lt;em&gt;Eq. 2: Jacobian of the mean shift operation&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now we compute the loss by subtituting Eq.2 into the sum&lt;/p&gt;

\[\frac{d L}{d x_{ij}} = \frac{dL}{d x_{ij}} - \frac{1}{N} \sum_k \frac{dL}{dy_{kj}}\]

&lt;p&gt;&lt;em&gt;Eq. 3 Backpropagated gradient wrt $x$ of the loss function.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;See that \(\delta_{jl}\) is in both terms, which means that the channels are taken to be independent in the mean shift, as expected :)&lt;/p&gt;

&lt;p&gt;Some additional interpretation: Consider the first term in Eq. 1, as \(x\) changes, the same amount is changed in \(y\). The second term is a bit trickier. Changing one entry of \(x\) affects the batch mean, and so affects the ‘zero point’ of the entire batch, affecting every entry in \(y\)! But by how much? In fact a change \(dx\) in \(x\) will result in the outcome of each entry of \(y\) to change by \(dy = 1/N\). However, we ultimately care about the effect on the loss, which is why we are summing over indices \(kl\). The insight here is that the term \(\mu\) means that each row of \(\frac{dL}{dx_{ij}}\) will have contributed to all \(y_{kl}\).&lt;/p&gt;

&lt;p&gt;Example 2: Say we have a variance operation. So \(Y = \frac{1}{N}\sum_i(X - \mu)^2\).&lt;/p&gt;

\[\frac{\partial \sigma^2_l}{\partial x_{ij}} = \frac{2}{N} (x_{ij} - \mu_l)\delta_{jl}\]

&lt;p&gt;Interpretation&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;each element \(x_{ij}\) only affects the variance in the dimension that its relevant in, due to the Kronecker delta&lt;/li&gt;
  &lt;li&gt;a change in the mean itself will not affect the variance if the values’ excess from the mean stays the same (think of the variance being the same when the entries are all shifted by a constant amount)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Full Solution to Batch Norm:&lt;/p&gt;

\[\frac{\partial L}{\partial x_{ij}} = \sum _{kl} \frac{\partial L}{\partial y_{kl}}\frac{\partial y_{kl}}{\partial x_{ij}}\]

&lt;p&gt;Use the product rule&lt;/p&gt;

\[\frac{\partial y_{kl}}{\partial x_{ij}} = \gamma_l \bigg [ \frac{\partial (x_{kl} - \mu_l)}{\partial x_{ij}}\cdot (\sigma^2_{l} + \epsilon)^{-\frac{1}{2}} + \frac{\partial (\sigma^2_{l} + \epsilon)^{-\frac{1}{2}} }{\partial x_{ij}}\cdot (x_{kl} - \mu_l) \bigg] \\ = \gamma_l \bigg[ (\delta_{ik}\delta_{jl} - \frac{1}{N}\delta_{jl}) \cdot(\sigma^2_{l} + \epsilon)^{-\frac{1}{2}} -\frac{1}{2} (\sigma^2_{l} + \epsilon)^{-\frac{3}{2}} \frac{2}{N} (x_{ij} - \mu_l)\delta_{jl}\cdot (x_{kl} - \mu_l) \bigg]\]

&lt;p&gt;Now we sum over indices \(k,l\)
\(\frac{\partial L}{\partial x_{ij}}\)
&lt;img src=&quot;/files/blog/backprop/image-5.png&quot; alt=&quot;alt text&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In code, this is&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;D&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;gamma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;gamma&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;denom&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;denom&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# sqrt(var + eps)
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;mu&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;var&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;x&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;nom&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;xhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;x_hat&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# (x-mu)/denom
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;dgamma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xhat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#dL/dgamma
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dbeta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# dL/dbeta
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sum_dout_batch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#sum_k dL/dout_kj
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sum_doutnom_batch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nom&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#sum_k dL/dout_kj * xkj
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gamma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;denom&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sum_dout_batch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nom&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;denom&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sum_doutnom_batch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;which leads to a 1.6x speedup roughly.&lt;/p&gt;

&lt;h2 id=&quot;side-notes&quot;&gt;Side notes&lt;/h2&gt;

&lt;h3 id=&quot;kronecker-delta&quot;&gt;Kronecker delta&lt;/h3&gt;

&lt;p&gt;Physicists here will be reminded of their classes in general relativity (tensors), atomic physics (dipole matrix transition elements).&lt;/p&gt;

&lt;h3 id=&quot;differences-in-resources&quot;&gt;Differences in resources&lt;/h3&gt;

&lt;p&gt;The deep Learning book draws nodes as intermediary variables&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/files/blog/backprop/image-3.png&quot; alt=&quot;alt text&quot; /&gt;&lt;/p&gt;

&lt;p&gt;CS231n draws nodes as operations and treat nodes as ‘gates.’&lt;/p&gt;

&lt;p&gt;The PyTorch docs illustrate both albeit in different shapes.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/files/blog/backprop/image-4.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;additional-notes-on-backprop&quot;&gt;Additional notes on backprop&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;https://colah.github.io/posts/2015-08-Backprop/ (Good for understanding Computational graphs and why backprop matters)&lt;/li&gt;
  &lt;li&gt;Deep Learning book (Mathsy, as usual, good for a second pass once you’ve understood the material)&lt;/li&gt;
&lt;/ul&gt;</content><author><name>{&quot;name&quot;=&gt;nil, &quot;avatar&quot;=&gt;&quot;/files/head.jpg&quot;, &quot;bio&quot;=&gt;&quot;Scientist-engineer, traveller, photographer &amp; science communicator-- cause why not?&quot;, &quot;location&quot;=&gt;&quot;Cambridge, UK&quot;, &quot;email&quot;=&gt;&quot;me@kentonk.com&quot;, &quot;bitbucket&quot;=&gt;nil, &quot;codepen&quot;=&gt;nil, &quot;dribbble&quot;=&gt;nil, &quot;flickr&quot;=&gt;nil, &quot;facebook&quot;=&gt;nil, &quot;foursquare&quot;=&gt;nil, &quot;github&quot;=&gt;&quot;kwokkenton&quot;, &quot;google_plus&quot;=&gt;nil, &quot;keybase&quot;=&gt;nil, &quot;instagram&quot;=&gt;&quot;fizzyphys&quot;, &quot;lastfm&quot;=&gt;nil, &quot;linkedin&quot;=&gt;&quot;kentonkwok&quot;, &quot;pinterest&quot;=&gt;nil, &quot;soundcloud&quot;=&gt;nil, &quot;stackoverflow&quot;=&gt;nil, &quot;steam&quot;=&gt;nil, &quot;tumblr&quot;=&gt;nil, &quot;twitter&quot;=&gt;nil, &quot;vine&quot;=&gt;nil, &quot;weibo&quot;=&gt;nil, &quot;xing&quot;=&gt;nil, &quot;youtube&quot;=&gt;nil}</name><email>me@kentonk.com</email></author><category term="thoughts" /><summary type="html">some notes on backpropagating through the batch norm layer, explained by a physicist</summary></entry><entry><title type="html">A Taylor expansion of effort</title><link href="https://www.kentonk.com/thoughts/2024/11/29/climate.html" rel="alternate" type="text/html" title="A Taylor expansion of effort" /><published>2024-11-29T12:00:00+00:00</published><updated>2024-11-29T12:00:00+00:00</updated><id>https://www.kentonk.com/thoughts/2024/11/29/climate</id><content type="html" xml:base="https://www.kentonk.com/thoughts/2024/11/29/climate.html">&lt;p&gt;I’ve recently been reading Greta Thunberg’s ‘&lt;a href=&quot;https://www.penguin.co.uk/books/446610/the-climate-book-by-thunberg-greta/9780141999043&quot;&gt;The Climate Book&lt;/a&gt;,’ a collection of articles by climate experts and also Thunberg herself on the climate crisis and what we can do to help.&lt;/p&gt;

&lt;p&gt;My existing view is that the world is heading on a a collision course towards disaster, the warming across the globe that leads to an increase in natural disasters, which will destroy homes and habitats for people and animals. It sometimes seems that what I can do, as an individual, is completely imperceptible, compared to the corporations and institutions that control the world, its energy supply, and the systems that people live in.&lt;/p&gt;

&lt;p&gt;It’s like how our habits as a consumer, is controlled by what’s on discount, what’s shown to us on ads, and what the norm is.&lt;/p&gt;

&lt;p&gt;What makes this book powerful is that it acknowledges this fact, that individual action is miniscule, but states that some individuals tend to have more power than others in shaping the future.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/files/blog/planet_b.jpg&quot; alt=&quot;person holding there is no planet b poster&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As a person living the global North, who gets on a plane for quite a few times each year, my ‘carbon footprint’ is already disproportionately larger than billions of people around the world. This means that my choices as a consumer already have a markedly bigger impact than maybe 90% of the world’s population.&lt;/p&gt;

&lt;p&gt;Above that, as a physicist, I can contribute to the technology needed to produce renewables, capture carbon or replace materials with high carbon emissions.&lt;/p&gt;

&lt;p&gt;As a person with a voice who’s not living in a cave, I can influence the people around me to adopt better practices.&lt;/p&gt;

&lt;p&gt;And if enough people do this, there’s bound to be a person sufficiently connected to me in a position of power, whose actions can truly shape the environment.&lt;/p&gt;

&lt;p&gt;If we expand a person’s (positive) impact \(I\) as a function of effort \(E\), it’s clear that consumer actions lead to a linear impact. However, building useful technologies, doing useful research, adding to the climate discussion, contributing to education and advocacy, can have lead to superlinear effects.&lt;/p&gt;

\[\text{Impact} = \frac{dI}{dE}\Delta E + \frac{d^2I}{dE^2}(\Delta E)^2 + \frac{d^3I}{dE^3}(\Delta E)^3 + \text{higher order terms}\]

&lt;p&gt;This perspective was empowering to hear.&lt;/p&gt;</content><author><name>{&quot;name&quot;=&gt;nil, &quot;avatar&quot;=&gt;&quot;/files/head.jpg&quot;, &quot;bio&quot;=&gt;&quot;Scientist-engineer, traveller, photographer &amp; science communicator-- cause why not?&quot;, &quot;location&quot;=&gt;&quot;Cambridge, UK&quot;, &quot;email&quot;=&gt;&quot;me@kentonk.com&quot;, &quot;bitbucket&quot;=&gt;nil, &quot;codepen&quot;=&gt;nil, &quot;dribbble&quot;=&gt;nil, &quot;flickr&quot;=&gt;nil, &quot;facebook&quot;=&gt;nil, &quot;foursquare&quot;=&gt;nil, &quot;github&quot;=&gt;&quot;kwokkenton&quot;, &quot;google_plus&quot;=&gt;nil, &quot;keybase&quot;=&gt;nil, &quot;instagram&quot;=&gt;&quot;fizzyphys&quot;, &quot;lastfm&quot;=&gt;nil, &quot;linkedin&quot;=&gt;&quot;kentonkwok&quot;, &quot;pinterest&quot;=&gt;nil, &quot;soundcloud&quot;=&gt;nil, &quot;stackoverflow&quot;=&gt;nil, &quot;steam&quot;=&gt;nil, &quot;tumblr&quot;=&gt;nil, &quot;twitter&quot;=&gt;nil, &quot;vine&quot;=&gt;nil, &quot;weibo&quot;=&gt;nil, &quot;xing&quot;=&gt;nil, &quot;youtube&quot;=&gt;nil}</name><email>me@kentonk.com</email></author><category term="thoughts" /><summary type="html">I’ve recently been reading Greta Thunberg’s ‘The Climate Book,’ a collection of articles by climate experts and also Thunberg herself on the climate crisis and what we can do to help.</summary></entry></feed>