<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mustapha Ajeghrir on Medium]]></title>
        <description><![CDATA[Stories by Mustapha Ajeghrir on Medium]]></description>
        <link>https://medium.com/@mustapha-ajeghrir?source=rss-3733a5b03aa2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dnSwtO0lR25m7WI9mTAYAw.jpeg</url>
            <title>Stories by Mustapha Ajeghrir on Medium</title>
            <link>https://medium.com/@mustapha-ajeghrir?source=rss-3733a5b03aa2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 01:47:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mustapha-ajeghrir/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why should you learn linear programming right now?]]></title>
            <link>https://medium.com/@mustapha-ajeghrir/why-should-you-learn-linear-programming-right-now-71fb028e3f2?source=rss-3733a5b03aa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/71fb028e3f2</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[integer-programming]]></category>
            <category><![CDATA[linear-programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[problems]]></category>
            <dc:creator><![CDATA[Mustapha Ajeghrir]]></dc:creator>
            <pubDate>Sun, 22 May 2022 19:33:07 GMT</pubDate>
            <atom:updated>2022-05-22T19:38:05.289Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PtJOiuHL9caEc6cx" /><figcaption>Photo by <a href="https://unsplash.com/@antoine1003?utm_source=medium&amp;utm_medium=referral">Antoine Dautry</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Linear programming is not a new concept. But it is very efficient when used. As an engineer, I have encountered many problems that are solved using linear programming like graphs or simple real life problems.</p><h3>What is linear programming (LP)?</h3><p><strong>TL;DR : </strong>Optimizing a linear objective function subject to linear constraints as in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*kiuavpgAiXE7mxD7p82lIQ.png" /><figcaption>A simple linear program with 2 variables</figcaption></figure><p><strong>Long Answer </strong>: Let’s say you have a quantity you want to maximize or minimize… But you also have some constraints that you should respect.</p><p>For example, you have a group of machines, and you want to maximize their produced value. But you only have a limited human and material resources. A simple linear programming formulation for this example would be an <strong>objective function</strong> let’s say <strong>x-y</strong> (value produced minus cost of production) and some <strong>constraints</strong> <strong>x = 2y</strong> (the cost is half of the value produced), <strong>y &lt;= 20</strong> (we only have 20 resources). Then the linear program will be optimized to generate the best solution (x=40 and y=20).</p><p>A linear program is an objective <strong>linear </strong>function (aka, A function we want to maximize or minimize) subject to some linear constraints (aka, Conditions that should be respected). The meaning of linear is important, it means we only used linear operations such as <strong>addition</strong>, <strong>subtraction</strong>, or <strong>multiplication </strong>with a <strong>scalar </strong>number (Not a variable, otherwise it is quadratic). A formal definition using vectors would be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/171/1*VZqcKZ8SDai9k2L_eri6YA.png" /><figcaption>Linear programming</figcaption></figure><h3>What is an integral linear programming (ILP) ?</h3><p>It is a linear problem with integer variables instead of float variables. There is also something called mixed linear program (<strong>MLP</strong>), it is simply a mixture between float and integer variables. The formal representation using vectors is in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*sfU6R9XYXSAl44YRdddNRg.png" /><figcaption>Integral Linear programming</figcaption></figure><p>This kind of problems are way more difficult to solve than normal linear programming problems, they are classified as <strong>NP-Complete</strong>. Which means we can reduce all the NP problem into this problem. Read more about NP-Completeness <a href="https://en.wikipedia.org/wiki/NP-completeness"><strong><em>here</em></strong></a><strong><em>.</em></strong></p><h3>How to define my LP/ILP ?</h3><p><strong>(1)</strong> Identify the number of decision variables</p><p><strong>(2) </strong>Identify the constraints on the decision variables</p><p><strong>(3)</strong> Write the objective function as a linear equation</p><p><strong>(4)</strong> Write everything in a canonical format</p><p>It is good practice to perform a mathematical demonstration to <strong>prove </strong>that the written problem is the same as your original problem.</p><h3>What kind of problems can we solve with LP/ILP?</h3><p>The answer is simple, any problem that could be put into the linear programming formulation (with only 3 operations: <strong>addition</strong>, <strong>subtraction</strong>, and <strong>scalar multiplication</strong>) could be solved. However, if there are no possible solutions, the problem is named unfeasible (aka, your constraints are too hard and impossible to respect). For example, if constraint 1 imposes <strong>x_1&gt;=4</strong> and constraint 2 imposes <strong>x_1&lt;=2</strong>, there are no feasible solutions.</p><h3>Solving Your LP/ILP</h3><p><strong>Using Excel : </strong>Excel is good if you just want to test the concept of LP or if you are only working with simple problems. There is a lot of tutorials out there if you are interested.</p><p><strong>Using Python : </strong>In Python, there is a lot of possibilities. It is possible to use <strong>SciPy </strong>or <strong>PuLP</strong>… as an open-source solution. On the other hand, it is also possible to use proprietary libraries like <strong>Gurobi </strong>(its free for limited size problems). I have personally used all of these 3 libraries and I would recommend PuLP for lovers of open-source and Gurobi for applications where speed is important (yes Gurobi is faster and contains more tunable parameters). I also recommend this <a href="https://realpython.com/linear-programming-python/"><strong><em>tutorial</em></strong></a>.</p><h3>My projects on ILPs</h3><ul><li><a href="https://github.com/Mustapha-AJEGHRIR/projet_sys_decision"><strong>Inv-MR-Sort :</strong></a><strong> </strong>MR-Sort is a decision system that sorts the items into classes based on their evaluation on each criteria using some parameters. The goal of Inverse MR-Sort is to learn those parameters from decisions that have been made. <a href="https://github.com/Mustapha-AJEGHRIR/projet_sys_decision"><strong>GITHUB LINK</strong></a></li><li><a href="https://github.com/Mustapha-AJEGHRIR/algo_dominant_set"><strong>Minimum dominant set :</strong></a><strong> </strong>Find the dominant set (aka, a set of nodes connected to all other nodes) on a weighted graph. <a href="https://github.com/Mustapha-AJEGHRIR/algo_dominant_set"><strong>GITHUB LINK</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71fb028e3f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multimodal Emotion Recognition]]></title>
            <link>https://medium.com/@mustapha-ajeghrir/multimodal-emotion-recognition-456e4a73f9e8?source=rss-3733a5b03aa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/456e4a73f9e8</guid>
            <category><![CDATA[emotion-recognition]]></category>
            <category><![CDATA[multimodal-learning]]></category>
            <category><![CDATA[modality-fusion]]></category>
            <category><![CDATA[emotions]]></category>
            <category><![CDATA[embedding]]></category>
            <dc:creator><![CDATA[Mustapha Ajeghrir]]></dc:creator>
            <pubDate>Tue, 19 Apr 2022 09:19:48 GMT</pubDate>
            <atom:updated>2022-04-19T09:20:08.342Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Emotion recognition is a dynamic process that targets the emotional state of the person, which means that the emotions corresponding to each individual’s actions are different. Human beings, in general, communicate their feelings in different ways. To ensure meaningful communication, accurate interpretation of these emotions is important. However, emotional recognition in our everyday lives is important for social contact, and emotions play an important role in deciding human actions. The following video shows an application of Multimodal emotion recognition.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FqIlw36x7N6M%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqIlw36x7N6M&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FqIlw36x7N6M%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6697f831e305c1b3673cf091dea4c0db/href">https://medium.com/media/6697f831e305c1b3673cf091dea4c0db/href</a></iframe><p>The aim of this blog is to give some insight emotion recognition on videos, by exploiting all of the three modalities: video, audio and text (the video transcript).</p><h4>Why videos ?</h4><p>Unlike static images, videos capture dynamic visual scenes with temporal and audio signals. Neighboring frames serve as a form of natural data augmentation, providing various object (pose, appearance), camera (geometry), and scene (illumination, object placements) configurations. They also capture the chronological order of actions and events critical for temporal reasoning. In these ways, the time dimension provides critical information that can improve the robustness of computer vision systems. Furthermore, the audio track in video can contain both natural sounds and spoken language that can be transcribed into text. These multimodal (sound and text) signals provide complementary information that can aid learning visual representations.</p><h3>Unimodal architectures</h3><p>Before going deep into multimodal architectures, let’s first focus on unimodal ones :</p><h4>Audio modality :</h4><p>Let’s focus on 2 main models, Wav2vec2 and HuBERT. They are very similar:</p><ul><li><strong>Wav2vec2 </strong>uses a transformer based architecure. The corresponding feature exctractor works over 25ms audio samples strided by 20ms (means two continuous samples share 5ms), the sampling rate of the audio is 16kHz. At first the audio is passed over a CNN to extract the main features, then it is passed through a Context network (transformer encoder network) to get the context vectors. It possible to start from the pretrained checkpoint using HuggingFace. The figure below shows the architecture of Wav2vec2.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XVAxOVwm7IpMT2Lc.png" /><figcaption>Wav2Vec2 architecture</figcaption></figure><ul><li><strong>HuBERT</strong> is similar to Wav2vec except during training. It uses clustering with MFCC representations to determine training targets in a prior step instead of Gumbel softmax in Wav2Vec2. The figure below shows the the architecture, on the right we can see the architecture of Wav2vec2.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*LImkH7-aAQn26ODW.png" /></figure><ul><li><strong>Performance : </strong>The two base models contain around 95M parameters and 317M parameters for the Large models. HuBERT performs as or better than Wav2vec2 when fine tuned. With our own experiments over IEMOCAP, we found that HuBERT performs better than Wav2vec2. For the inference speed, the two models are exactly the same. Processing a 2 seconds 16kHz audio is similar (in time) to process a 170 token text with BERT base. the inference speed experiment could be found <a href="https://colab.research.google.com/drive/10H104X8yUHAwMBVu7XUX8mAv8BoDV8XV?usp=sharing">HERE</a></li></ul><h4>Text modality :</h4><p>Given the transcript of a conversation along with speaker information of each constituent utterance, the ERC (emotion recognition in conversations) task aims to identify the emotion of each utterance from several pre-defined emotions. Formally, given the input sequence of N number of utterances [(u1, p1), (u2, p2), . . . , (uN , pN )], where each utterance <strong>ui</strong> consists of T words ui,j and spoken by party <strong>pi</strong>, the task is to predict the emotion label <strong>ei</strong> of each utterance <strong>ui</strong>.</p><p>Let’s first focus on recognizing emotions with no conversation context (distilBert), then we move to a conversation aware model:</p><ul><li><strong>Distilbert</strong> is a reduced BERT with lower layers and attention heads, 40% smaller and 60% faster. This model encodes the text without conversation axis. This might cause problems when trying to catch long term semantics.</li><li><a href="https://github.com/declare-lab/conv-emotion/tree/master/TL-ERC"><strong><em>TL-ER</em>C</strong></a><strong> </strong>solves the memory problem by adding a super layer of recurrent neural network. A choice of datasets (in source task and target task) is possible, in this work, we tryed the model with the weights of cornell dataset, and we finetuned the model to the task of Emotion recognition on IEMOCAP dataset. The model takes into account the dynamism in a conversation. The performance on the test data is about 46% on accuracy.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P5oYfiwGbMgjoL8j.jpg" /></figure><h4>Image modality :</h4><p>For the image modality, it is recommended to use a pretrained face action unit detector. The action units are some descriptors of the face that are linked expression and emotion. We will use <strong>OpenFace</strong>, it is a free and open source. We have used it to predict 18 face action units that we feed to a BI-LSTM model as in the figure below. It is possible to learn more in this <a href="https://www.mdpi.com/2076-3417/12/1/327/htm">paper</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*oe26bMyO5ejgE8EaeEkcyQ.png" /></figure><h3>Bi-modal architectures</h3><p>In this <a href="https://www.mdpi.com/2076-3417/12/1/327/htm">paper</a>, 2 modalities have been used: Audio and OpenFace’s action units. For audio, Wav2Vec 1 have been used, it is fully possible to upgrade to Wav2Vec2.0. The audio and face embeddings are then concatenated and fed to a simple logistic regression model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7QpCiaq3bB92QG6CjTTzdQ.png" /></figure><h3>Tri-modal architectures</h3><p>For the 3 modalities, let’s focus on the model proposed in the MOSEI-UMONS <a href="https://arxiv.org/pdf/2006.15955.pdf">paper</a>. This model which is based on the Transformer model makes use of all three modalities (audio, text, video), where the linguistic modality to modulate the others using <a href="https://www.notion.so/Co-modulation-968fd790744c4b338b8e09e80b440970">Co-modulation</a>. The features which are the inputs of the transformer blocks are computed as the following:</p><ul><li>Accoustic: The mel-spectograms were extracted using the <a href="https://librosa.org/doc/main/index.html">librosa</a> library with 80 filter banks (the embedding size is therefore 80)</li><li>Visual: A R(2+1)D-152 model was used to extract the spatio-temporal features, which takes as input a clip of 32 RGB frames of the video. Each frame is scaled to the size of 128x171 and then cropped to a window of size 112x112. The features are extracted by taking the output of the spatiotemporal pooling. The feature vector for the entire video is obtained by sliding a window of 32 RGB frames with a stride of 8 frames. We chose not to crop out the face region of the video and keep the entire image as input to the network. Indeed, the video is already centered on the person and we expect that the movement of the body such as the hands can be a good indicator for the emotion recognition and sentiment analysis tasks.</li><li>Linguistic: Embed each word in a vector of 300 dimensions using GloVe, after tokenization and lowercasing.</li></ul><p>The model was trained and tested on the CMU-MOSEI dataset. (<a href="https://arxiv.org/pdf/2006.15955.pdf">See paper</a> for evaluation results)</p><h3>How to combine modalities ?</h3><p>When we finally end up with an embedding for each modality, it is important to have an efficient technique to combine those embeddings. We have just discussed 2 possible ways, concatenation (as discussed in the bi-modal example) And Co-modulation (which is used on the tri-modal example). This <a href="https://ai.googleblog.com/2022/03/multimodal-bottleneck-transformer-mbt.html">Google AI blog</a> demonstrates that the best way for cross-modal fusion is using Bottlenecks, which help to collate and condense information from each modality before sharing it with the other, while still allowing free attention flow within a modality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*lsagKanP-52BAn7k" /></figure><h4>Note :</h4><p>This article is condensed version of what my team have done in a Multimodal Emotion Recognition project. The members of the team :</p><ul><li>AJEGHRIR Mustapha (me :D)</li><li>TAZI Nouamane</li><li>KHALD Asmae</li><li>BOUKHARI Taha</li><li>IGUILIZ Salah-Eddine</li><li>MARTIN-CHIVICO Pierre-Louis</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=456e4a73f9e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Traffic forecasting, an amazing experience.]]></title>
            <link>https://medium.com/@mustapha-ajeghrir/traffic-forecasting-an-amazing-experience-c38dd3b4278c?source=rss-3733a5b03aa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c38dd3b4278c</guid>
            <category><![CDATA[time-series-forecasting]]></category>
            <category><![CDATA[traffic]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[advice]]></category>
            <category><![CDATA[competition]]></category>
            <dc:creator><![CDATA[Mustapha Ajeghrir]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 15:24:11 GMT</pubDate>
            <atom:updated>2021-12-29T15:24:11.179Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*woNchRdVZ-j2hH4307JSgg.jpeg" /></figure><p>I have worked recently in a competition organized by BCG Gamma for traffic forecasting in Paris. The goal was to predict the traffic for the next 5 days in 3 avenues to optimize delivery for a virtual company. We worked as teams of 5 students for 1 week to create the model, predict future traffic and simulate a business interview.</p><h4>Our models :</h4><p>Unfortunately, me and my team had very little time for this competition, so we used some <strong>unrecommended</strong> practices in Machine learning :</p><p><strong>1.</strong> We tested few models: since we didn’t have enough time, we simply ran into the most hyped models like:</p><ul><li>Facebook’s “Prophet” model.</li><li>Some statistical models like: ARIMA, Exponential Smoothing …</li><li>TFT: Temporal Fusion Transformers.</li><li>N-BEATS: neural basis expansion analysis for time series.</li></ul><p><strong>2. </strong>We only used 1 avenue for model selection: the models that we used take too much time for training (except “Prophet” and statistical models), so we only used 1 avenue as a dataset for training and testing (back-testing: train up to day T and predict future 5 days, restart the training on day T+5)</p><p><strong>3. </strong>We searched for bigger datasets: At the beginning, we only had 1 year time series for the 3 avenues, so we went to search for more data (archived data for the past 8 years), the problem was that in a limited time, it would have been better to improve the quality of our inputs by adding other useful data like weather, coronavirus cases… Instead of adding less important data (especially because of the pandemic behavior changed)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DMJcdIK4H3XotZ7IH3ugHw.jpeg" /></figure><h4>The results:</h4><p>As we have trained on 1 avenue only, we found that N-beats performed better than others, we were also surprised that TFT didn’t give good performance at all. So, we trained our final model on 8 years for the 3 avenues (took 3 hours in a google colab pro) and predicted the traffic at last moments of the deadline.</p><p>Six days latter we had a meeting with the BCG Gamma team to discover with all our surprise that we were poorly ranked with a high RMSE score. After some investigations, we found that indeed our score for the avenue 1 (the one we used for model selection) was very good, but for avenue 2 our RMSE was twice the average.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X-OI-Ldm7rOPKG6h3JPZfg.png" /><figcaption>Avenue 1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NX6-2N04T9OLJaKvc7rCJw.png" /><figcaption>Avenue 2</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jdAWde09Z1WfJz-gC4bvYw.png" /><figcaption>Avenue 3</figcaption></figure><p>Never use only 1 time series for model selection!</p><h4>What we could have done:</h4><p>The best team have used Catboost, which a simple machine learning model in comparison to our N-beats deep learning model. After the deadline, we had much more time to do some experimentations, so we tried LightGBM model which is a machine learning model that is extremely fast, it even performed better than Catboost. Once again, keep calm and keep it simple!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*83r2IoJLGNg8QyKv2Tgxrg.jpeg" /></figure><h4>To Remember:</h4><p>It is very important to start by using light and reliable models for your problem. Starting by classical machine learning models instead of the stronger and more powerful deep learning ones.</p><p>Never try to use one class/set/cluster (like 1 avenue) of data to do your model selection. Good practice is to use different models for each cluster of data or at least use diverse samples from the different clusters if you use 1 model.</p><h4>Usefull links:</h4><ul><li>Data is taken <a href="https://opendata.paris.fr/explore/dataset/comptages-routiers-permanents/export/?disjunctive.libelle&amp;disjunctive.etat_trafic&amp;disjunctive.libelle_nd_amont&amp;disjunctive.libelle_nd_aval&amp;sort=t_1h"><strong>here</strong></a>.</li><li>We used <a href="https://unit8co.github.io/darts/README.html"><strong>Darts</strong></a>(based on pytorch),I found it to be brilliant for any time series forecasting.</li><li>Our project in <a href="https://github.com/NouamaneTazi/paris-traffic-forecast"><strong>github</strong></a>, <em>sorry it was not meant to be easy to read by others.</em></li><li>N-beats paper <a href="https://arxiv.org/pdf/1905.10437.pdf"><strong>here</strong></a>.</li><li>TFT paper <a href="https://arxiv.org/pdf/1912.09363.pdf"><strong>here</strong></a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c38dd3b4278c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>