<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <id>https://mjboos.github.io</id>
  <title>Moritz Boos</title>
  <updated>2026-08-22T14:12:05.219464+00:00</updated>
  <link href="https://mjboos.github.io"/>
  <link href="https://mjboos.github.io/posts/atom.xml" rel="self"/>
  <generator uri="https://ablog.readthedocs.io/" version="0.11.12">ABlog</generator>
  <entry>
    <id>https://mjboos.github.io/blog/2022/til-countplot-labels.html</id>
    <title>TIL: Making a seaborn count plot with hue and labels</title>
    <updated>2022-12-16T00:00:00+00:00</updated>
    <author>
      <name>Moritz Boos</name>
    </author>
    <content type="html">&lt;p class="ablog-post-excerpt"&gt;&lt;p&gt;It’s surprisingly hard to label bars in a seaborn &lt;a class="reference external" href="https://seaborn.pydata.org/generated/seaborn.countplot.html"&gt;countplot&lt;/a&gt;, especially if you use more than one column (e.g. when using &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;hue&lt;/span&gt;&lt;/code&gt;). The function below does the labeling even when using two columns for indexing.&lt;/p&gt;
&lt;p&gt;&lt;img alt="png" src="https://mjboos.github.io/_images/TIL-2022-12-16_output_2_0.png" /&gt;&lt;/p&gt;
&lt;img alt="png" src="https://mjboos.github.io/_images/TIL-2022-12-16_output_2_0.png" /&gt;&lt;/p&gt;
</content>
    <link href="https://mjboos.github.io/blog/2022/til-countplot-labels.html"/>
    <summary>It’s surprisingly hard to label bars in a seaborn countplot, especially if you use more than one column (e.g. when using hue). The function below does the labeling even when using two columns for indexing.pngpng</summary>
    <category term="python" label="python"/>
    <category term="seaborn" label="seaborn"/>
    <category term="snippets" label="snippets"/>
    <category term="til" label="til"/>
    <published>2022-12-16T00:00:00+00:00</published>
  </entry>
  <entry>
    <id>https://mjboos.github.io/blog/2022/deep-auditory-encoding-attention.html</id>
    <title>Deep auditory encoding model with self-attention to predict brain activity</title>
    <updated>2022-07-27T00:00:00+00:00</updated>
    <author>
      <name>Moritz Boos</name>
    </author>
    <content type="html">&lt;p class="ablog-post-excerpt"&gt;&lt;p&gt;Do you like deep learning-based auditory encoding models?
Always wanted to train a deep recurrent model to predict brain activity from an auditory stimulus (i.e. spectrogram) but vanilla GRU/LSTM/RNN immediately overfit?
Do you also care about which parts of the auditory stimulus matter most for predicting brain activity?&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="https://github.com/mjboos/selfattention_audio"&gt;This library&lt;/a&gt; allows you to train a recurrent DNN (a GRU) and learn a self-attention mechanism that weighs hidden states - the resulting weighted tensor is used to predict brain activity (or whatever you choose as a target).
It also contains many variations of this model type (shared attention between targets, multi-head attention etc) and some functions for visualizing the computed attention weights on a spectrogram.&lt;/p&gt;
&lt;img alt="Schematic of the GRU self-attention encoding model" src="https://mjboos.github.io/_images/gru_attention_model.png" /&gt;&lt;/p&gt;
</content>
    <link href="https://mjboos.github.io/blog/2022/deep-auditory-encoding-attention.html"/>
    <summary>Do you like deep learning-based auditory encoding models?
Always wanted to train a deep recurrent model to predict brain activity from an auditory stimulus (i.e. spectrogram) but vanilla GRU/LSTM/RNN immediately overfit?
Do you also care about which parts of the auditory stimulus matter most for predicting brain activity?This library allows you to train a recurrent DNN (a GRU) and learn a self-attention mechanism that weighs hidden states - the resulting weighted tensor is used to predict brain activity (or whatever you choose as a target).
It also contains many variations of this model type (shared attention between targets, multi-head attention etc) and some functions for visualizing the computed attention weights on a spectrogram.Schematic of the GRU self-attention encoding model</summary>
    <category term="deep-learning" label="deep-learning"/>
    <category term="neuroscience" label="neuroscience"/>
    <category term="python" label="python"/>
    <category term="pytorch" label="pytorch"/>
    <published>2022-07-27T00:00:00+00:00</published>
  </entry>
  <entry>
    <id>https://mjboos.github.io/blog/2021/unsupervised-typo-finder.html</id>
    <title>Finding misspelled names with dirty_cat and unsupervised learning</title>
    <updated>2021-11-13T00:00:00+00:00</updated>
    <author>
      <name>Moritz Boos</name>
    </author>
    <content type="html">&lt;p class="ablog-post-excerpt"&gt;&lt;p&gt;As a data scientist one often wants to group or analyze data conditional on a categorical variable.
However, outside the world of neatly curated data sets, I often encounter the case that there can be slight misspellings in the category names: This happens when, for example, data input &lt;em&gt;should&lt;/em&gt; use a drop down menu, but users are forced to input the category name by hand. Misspellings happen and analyzing the resulting data using a simple &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;GROUP&lt;/span&gt; &lt;span class="pre"&gt;BY&lt;/span&gt;&lt;/code&gt; is not possible anymore.&lt;/p&gt;
&lt;p&gt;This problem is however the perfect use case of &lt;em&gt;unsupervised learning&lt;/em&gt;, a category of various statical methods that find structure in data without providing explicit labels/categories of the data a-priori.
Specifically clustering of the distance between strings can be used to find clusters of strings that are similar to each other (e.g. differ only by a misspelling) and hence gives us an easy tool to flag potentially misspelled category names in an unsupervised manner.&lt;/p&gt;
&lt;img alt="" src="https://mjboos.github.io/_images/unsupervised_output_4_0.png" /&gt;&lt;/p&gt;
</content>
    <link href="https://mjboos.github.io/blog/2021/unsupervised-typo-finder.html"/>
    <summary>As a data scientist one often wants to group or analyze data conditional on a categorical variable.
However, outside the world of neatly curated data sets, I often encounter the case that there can be slight misspellings in the category names: This happens when, for example, data input should use a drop down menu, but users are forced to input the category name by hand. Misspellings happen and analyzing the resulting data using a simple GROUP BY is not possible anymore.This problem is however the perfect use case of unsupervised learning, a category of various statical methods that find structure in data without providing explicit labels/categories of the data a-priori.
Specifically clustering of the distance between strings can be used to find clusters of strings that are similar to each other (e.g. differ only by a misspelling) and hence gives us an easy tool to flag potentially misspelled category names in an unsupervised manner.</summary>
    <category term="data-cleaning" label="data-cleaning"/>
    <category term="machine-learning" label="machine-learning"/>
    <category term="python" label="python"/>
    <category term="snippets" label="snippets"/>
    <published>2021-11-13T00:00:00+00:00</published>
  </entry>
  <entry>
    <id>https://mjboos.github.io/blog/2020/voxelwise-encoding-bids.html</id>
    <title>An example workflow for voxel-wise encoding models using a BIDS app</title>
    <updated>2020-07-31T00:00:00+00:00</updated>
    <author>
      <name>Moritz Boos</name>
    </author>
    <content type="html">&lt;p class="ablog-post-excerpt"&gt;&lt;p&gt;This shows how to (for a BIDS compliant dataset) extract features, save them in BIDS format, and run a BIDS app for voxel-wise encoding models.
We are going to use &lt;a class="reference external" href="https://openneuro.org/datasets/ds002322/versions/1.0.4"&gt;this&lt;/a&gt; dataset.&lt;/p&gt;
&lt;p&gt;Non-consecutive header level increase; H1 to H4 [myst.header]&lt;/p&gt;
&lt;/p&gt;
</content>
    <link href="https://mjboos.github.io/blog/2020/voxelwise-encoding-bids.html"/>
    <summary>This shows how to (for a BIDS compliant dataset) extract features, save them in BIDS format, and run a BIDS app for voxel-wise encoding models.
We are going to use this dataset.Non-consecutive header level increase; H1 to H4 [myst.header]</summary>
    <category term="machine-learning" label="machine-learning"/>
    <category term="neuroimaging" label="neuroimaging"/>
    <category term="python" label="python"/>
    <published>2020-07-31T00:00:00+00:00</published>
  </entry>
  <entry>
    <id>https://mjboos.github.io/blog/2020/nilearn-surface-contours.html</id>
    <title>Adding contours of a surface region to a statistical map in Nilearn</title>
    <updated>2020-01-23T00:00:00+00:00</updated>
    <author>
      <name>Moritz Boos</name>
    </author>
    <content type="html">&lt;p class="ablog-post-excerpt"&gt;&lt;p&gt;I often use Nilearn’s surface plotting to show a statistical map on the cortex - and wish that I could add the outlines of a region on top of the statistical map.
This is harder than it seems at the first thought, since matplotlib’s mesh plotting allows us to only edit the whole color of a mesh-face, hence we need to find all faces that correspond to the outside edge of a region.&lt;/p&gt;
&lt;p&gt;But here’s code that’s working for me.&lt;/p&gt;
&lt;img alt="png" src="https://mjboos.github.io/_images/Surface_Contours_1_1.png" /&gt;&lt;/p&gt;
</content>
    <link href="https://mjboos.github.io/blog/2020/nilearn-surface-contours.html"/>
    <summary>I often use Nilearn’s surface plotting to show a statistical map on the cortex - and wish that I could add the outlines of a region on top of the statistical map.
This is harder than it seems at the first thought, since matplotlib’s mesh plotting allows us to only edit the whole color of a mesh-face, hence we need to find all faces that correspond to the outside edge of a region.But here’s code that’s working for me.png</summary>
    <category term="neuroimaging" label="neuroimaging"/>
    <category term="nilearn" label="nilearn"/>
    <category term="python" label="python"/>
    <category term="snippets" label="snippets"/>
    <published>2020-01-23T00:00:00+00:00</published>
  </entry>
  <entry>
    <id>https://mjboos.github.io/blog/2020/gmm-autograd.html</id>
    <title>Probability density fitting of a Mixture of Gaussians via autograd</title>
    <updated>2020-01-17T00:00:00+00:00</updated>
    <author>
      <name>Moritz Boos</name>
    </author>
    <content type="html">&lt;p class="ablog-post-excerpt"&gt;&lt;p&gt;Recently I’ve had to fit a &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Mixture_model#Gaussian_mixture_model"&gt;Mixture of Gaussians&lt;/a&gt; to a target &lt;em&gt;density&lt;/em&gt; instead of individual samples drawn from this density.
Googling revealed that at least &lt;a class="reference external" href="https://stats.stackexchange.com/questions/226504/fit-gaussian-mixture-model-directly-to-the-mixture-density"&gt;one other person&lt;/a&gt; faced this particular problem too, but there was no code readily available.&lt;/p&gt;
&lt;p&gt;To be clear, the problem is the following: given a mixture of Gaussian probability density that is evaluated at $N$ points, we want to recover parameters of these Gaussians (i.e. mean $\mu_{i}$, standard deviation $\sigma_{i}$, and a set of mixture weights $\pi_{i}$ that are constrained to be [0, 1] and sum to 1).&lt;/p&gt;
&lt;img alt="" src="https://mjboos.github.io/_images/GMM_autograd_1_1.png" /&gt;&lt;/p&gt;
</content>
    <link href="https://mjboos.github.io/blog/2020/gmm-autograd.html"/>
    <summary>Recently I’ve had to fit a Mixture of Gaussians to a target density instead of individual samples drawn from this density.
Googling revealed that at least one other person faced this particular problem too, but there was no code readily available.To be clear, the problem is the following: given a mixture of Gaussian probability density that is evaluated at $N$ points, we want to recover parameters of these Gaussians (i.e. mean $\mu_{i}$, standard deviation $\sigma_{i}$, and a set of mixture weights $\pi_{i}$ that are constrained to be [0, 1] and sum to 1).</summary>
    <category term="machine-learning" label="machine-learning"/>
    <category term="python" label="python"/>
    <category term="snippets" label="snippets"/>
    <published>2020-01-17T00:00:00+00:00</published>
  </entry>
</feed>
