<?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 René-Jean Corneille on Medium]]></title>
        <description><![CDATA[Stories by René-Jean Corneille on Medium]]></description>
        <link>https://medium.com/@airejie?source=rss-197173de4b30------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bbvotKumcLRoWGBwz-wzmA@2x.jpeg</url>
            <title>Stories by René-Jean Corneille on Medium</title>
            <link>https://medium.com/@airejie?source=rss-197173de4b30------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 15:00:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@airejie/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[The Modern Data Platform Design: a tool agnostic approach]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/the-modern-data-platform-design-a-tool-agnostic-approach-250ebe4a0a5?source=rss-197173de4b30------2"><img src="https://cdn-images-1.medium.com/max/860/1*-BbuImhfvEiaroQJgZWbtw.png" width="860"></a></p><p class="medium-feed-snippet">The big data echosystem is still too big! There I said it. I still remember seeing this post years ago and as a young and upcoming data&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/swlh/the-modern-data-platform-design-a-tool-agnostic-approach-250ebe4a0a5?source=rss-197173de4b30------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/the-modern-data-platform-design-a-tool-agnostic-approach-250ebe4a0a5?source=rss-197173de4b30------2</link>
            <guid isPermaLink="false">https://medium.com/p/250ebe4a0a5</guid>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[big-data-platform]]></category>
            <category><![CDATA[analytics-engineering]]></category>
            <dc:creator><![CDATA[René-Jean Corneille]]></dc:creator>
            <pubDate>Sun, 07 Aug 2022 14:40:05 GMT</pubDate>
            <atom:updated>2022-08-12T15:10:58.311Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[CI/CD Pipelines for Python Packages With Circle CI and CodeClimate]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/ci-cd-pipelines-for-python-packages-with-circle-ci-and-codeclimate-ecb0c9e460ec?source=rss-197173de4b30------2"><img src="https://cdn-images-1.medium.com/max/2600/1*OegG1bf_3BsjtmWINRNSUg.jpeg" width="4852"></a></p><p class="medium-feed-snippet">In software engineering, continuous deployment and integration is a growing trend consisting of frequently updating and releasing code via&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/swlh/ci-cd-pipelines-for-python-packages-with-circle-ci-and-codeclimate-ecb0c9e460ec?source=rss-197173de4b30------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/ci-cd-pipelines-for-python-packages-with-circle-ci-and-codeclimate-ecb0c9e460ec?source=rss-197173de4b30------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecb0c9e460ec</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[René-Jean Corneille]]></dc:creator>
            <pubDate>Sun, 24 Jan 2021 15:03:29 GMT</pubDate>
            <atom:updated>2021-02-20T15:10:25.270Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[PySpark on macOS: installation and use]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/pyspark-on-macos-installation-and-use-31f84ca61400?source=rss-197173de4b30------2"><img src="https://cdn-images-1.medium.com/max/2600/1*fMXJN-4dt9f1-Gs3epj4ow.jpeg" width="6720"></a></p><p class="medium-feed-snippet">Spark is a very popular framework for data processing. It has slowly taken over the use of Hadoop for data analytics. In memory processing&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/swlh/pyspark-on-macos-installation-and-use-31f84ca61400?source=rss-197173de4b30------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/pyspark-on-macos-installation-and-use-31f84ca61400?source=rss-197173de4b30------2</link>
            <guid isPermaLink="false">https://medium.com/p/31f84ca61400</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[René-Jean Corneille]]></dc:creator>
            <pubDate>Mon, 21 Oct 2019 17:58:20 GMT</pubDate>
            <atom:updated>2019-10-22T11:35:37.458Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Docker: a Primer]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://airejie.medium.com/docker-a-primer-95bff4ae16a9?source=rss-197173de4b30------2"><img src="https://cdn-images-1.medium.com/max/2600/1*9bdap4DPRFtvBd7paVwN6Q.png" width="2880"></a></p><p class="medium-feed-snippet">Docker is an application allowing to manage Linux containers on top of an existing OS. It provides a virtualisation layer (the Docker&#x2026;</p><p class="medium-feed-link"><a href="https://airejie.medium.com/docker-a-primer-95bff4ae16a9?source=rss-197173de4b30------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://airejie.medium.com/docker-a-primer-95bff4ae16a9?source=rss-197173de4b30------2</link>
            <guid isPermaLink="false">https://medium.com/p/95bff4ae16a9</guid>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[René-Jean Corneille]]></dc:creator>
            <pubDate>Tue, 05 Mar 2019 23:22:39 GMT</pubDate>
            <atom:updated>2019-03-11T20:52:38.423Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to setup an AWS EC2 instance]]></title>
            <link>https://airejie.medium.com/how-to-setup-an-aws-ec2-instance-51d968812f89?source=rss-197173de4b30------2</link>
            <guid isPermaLink="false">https://medium.com/p/51d968812f89</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[René-Jean Corneille]]></dc:creator>
            <pubDate>Mon, 28 May 2018 07:01:01 GMT</pubDate>
            <atom:updated>2018-05-29T15:55:07.018Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3UjWJ4T_tgy8USNCcSFeNg.jpeg" /></figure><p>The recent developement in data storage and processing have been motivated by the increasing amount and complexity of data available to individuals and companies. Most of these recent advancements require sophisticated and powerful hardware. Aspiring data scientists must be able to understand and master these new tools.</p><p>For instance, given the computer power required to carry out training of algorithms, these are usually carried out “on the cloud” (i.e. by remote access to a virtual machine) which avoid to buy and maintain very expensive hardware especially if the peak usage is only occasional. Cloud computing allow to perform these very intensive tasks and must now be part of the toolbox of any data scientist.</p><p>One of the most popular service provider is Amazon which provide an IaaS (infrastructure as a service) with AWS. I have to admit that the AWS interface is dauting and might be very offputting for a beginner. I started using AWS back in 2012 to run Monte Carlo simulations because back then I had a cheap computer and I followed classes on two campuses and the one with the powerful computers I would go to only every other week. I recently stumbled upon my notes when I was trying to figure out how to launch an AWS instance and realized how much the interface had changed since then. I thus decided to update them and in the process to make them available to anyone starting out with AWS.</p><p>I assume that the reader already has an AWS account and has a basic knowledge of the Linux terminal commands. If not, here is a quick <a href="https://www.youtube.com/watch?v=WviHsoz8yHk">tutorial</a>. Setting up an EC2 (Elastic Cloud Compute) is a matter of 5 steps:</p><h4><strong>1. generate a key pair</strong></h4><p>As I said before, since the computing resource is in the cloud, we need to access it remotely, in order to do so securely, we use an ssh connection that will require a key pair. You can generate one by going into the AWS EC2 dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OqFC56Cq_BNqF-72RxRVrw.png" /><figcaption><strong>1–1. AWS services dashboard (select EC2)</strong></figcaption></figure><p>And then you need to select the <strong>Key Pairs</strong> tab:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h4xAshFd-Guv1OMZsWE9uQ.png" /><figcaption><strong>1–2. EC2 Dashboard (select Key Pairs)</strong></figcaption></figure><p>You can now create a key pair:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3LNgHJqU07pYA6T9pdW0w.png" /><figcaption><strong>1–3. Key pairs list</strong></figcaption></figure><p>You only need to give the key pair a name:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ueHqQ3ba0PU-VQ2Di2p9GQ.png" /><figcaption><strong>1–4. Create new key pair</strong></figcaption></figure><p>This will download the key pair in a .pem file. It is not possible to connect to the instance without this file so do not lose it. I repeat: DO. NOT. LOSE. IT. You can still retrieve your instance in this case, AWS provides some information <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html">here</a>. Some additional precautions must be taken to ensure that only the administrator can read this file by using this command in the terminal (after a cd in the directory where the file was downloaded):</p><pre>chmod 400 myec2instance.pem</pre><h4>2. create a new user (optional but recommended)</h4><p>Now that you have you key pair, you need to create a new user. This step is not required if only one user connects to the instance, but necessary if the connection is shared (setup access rights). To do so, one need to go to the IAM (Identity and Access Management) section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3IRHcXDgllI85JNiEHhkA.png" /><figcaption><strong>2–1. Services (IAM)</strong></figcaption></figure><p>Then add a new user:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RDcgylqjGboBZFmj61QHlQ.png" /><figcaption><strong>2–2. Users list</strong></figcaption></figure><p>the new user name must be completed and its access (programmatic and/or through the AWS console):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QzlnrOeZBZMPBniT2w5uPg.png" /><figcaption><strong>2–3. Add user</strong></figcaption></figure><p>When all of this is chosen, the user permission must be chosen (this is the most important step). Here since we have only one user, we setup administrator rights:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*St1mWCHWBWtSL70sglbd0Q.png" /><figcaption><strong>2–4. Set permission</strong></figcaption></figure><p>Then you can download the user access IDs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8waqtuh-CODeVEpc9Ms6Q.jpeg" /><figcaption><strong>2–5. New user created</strong></figcaption></figure><p>Now that the new user is created, it is possible to access the AWS plateform with the link provided in the downloaded csv:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*inXgMbbPp1ivwVF02pj8wQ.jpeg" /><figcaption><strong>2–5. Login</strong></figcaption></figure><p>New users do not have root access, only the original account has. In any case, I would advise against using the root access for doing this tutorial: it is just best practice not to get to know the interface with a root access.</p><h4>3. create billing alert (optional but strongly recommended)</h4><p>Not only this is best practice, it is in your best interest to set up a billing alert. This is no joke. I have seen plenty of horror stories on reddit on this subject matter. It only takes 5 minutes and it can save you some headaches. You first need to go to <strong>CloudWatch US East (N. Virginia) region</strong> where the billing alerts are handled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jt80xlYSVmGp0CM_jQjG4A.png" /><figcaption><strong>3–1. CloudWatch US East (N. Virginia) region</strong></figcaption></figure><p>Then type <em>billing</em> in the metric search bar and select <em>Total Estimated Charge</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*545ZiiPvFvyXu2ijszcTag.png" /><figcaption><strong>3–2. Select Metric</strong></figcaption></figure><p>Then select the <em>EstimatedCharges </em>metric in the “All Metric” tab:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pEUcDe76JxoPFsBID9Hn7g.png" /><figcaption><strong>3–3. Select the metric</strong></figcaption></figure><p>And then in the “Graphed Metric” tab we can now set an alarm:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*25p0HDfjCc_OexhCPWXbsA.png" /><figcaption><strong>3–4. Setup alarm</strong></figcaption></figure><p>Then it is possible to choose the threshold amount and the email address to contact when the estimated cost reaches this level:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m4ZgMwiKQ2GGah-QwfF29g.png" /><figcaption><strong>3–5. Set up alarm level and notification list</strong></figcaption></figure><h4>4. create a new instance</h4><p>Now that we have created an alert, we can dive in. Virtual machines can be intanciated in then EC2 Dashboard. It can be accessed as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3xTbFulQC8v7I3F8NazAoQ.png" /><figcaption><strong>4–1. EC2 service</strong></figcaption></figure><p>Back to the EC2 dashboard, and in the “Instances” select “Launch Instance”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KJ59oNMM5eKPeS3RiMCNCg.png" /><figcaption><strong>4–2. Launch Instance</strong></figcaption></figure><p>The new instance OS is chosen among the available images on AWS (here I choose <a href="https://www.ubuntu.com/download/server">Ubuntu Server 16.04 LTS</a>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UJ3L-HoGRSaMe7La_rigcA.png" /><figcaption><strong>4–3. Choose AMI (Ubuntu Server 16.04 LTS)</strong></figcaption></figure><p>Following this, the computing power of the instance must be chosen. There are many options. For a test, it is better to choose a small, general purpose configuration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E0SIzRsBgv05upPxZ0jSgw.png" /><figcaption><strong>4–4. Choose Instance Type</strong></figcaption></figure><p>Before launching the virtual machine, the last step is to choose the key pair associated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lVfEagoPCHqlmwRbyWOEQQ.png" /><figcaption><strong>4–5. Choose Key Pair</strong></figcaption></figure><h4>5. connect remotely to instance</h4><p>After a few minutes, the new instance should be running. It is possible to check in the EC2 dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YA7DyYd9UQ2gLEO5aPpJKQ.png" /><figcaption><strong>5–1. EC2 Running instances</strong></figcaption></figure><p>By clicking on the <em>1 Running Instances</em> link, we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pb1_VIYrwUaKkqvXNjt-hw.png" /><figcaption><strong>5–2 Instance Description</strong></figcaption></figure><p>Now, in order to connect to the instance remotely, we need to do it through an SSH client, the key pair will allow us to securely connect to the server:</p><pre>ssh -i myec2instance.pem ubuntu@[EC2 Public DNS]</pre><p>And you are all set. Some of my upcoming posts (Docker, API with Flask,…) will require to setup an EC2 instance, then this tutorial will come in handy if you still follow me then.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51d968812f89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Classification with OpenCV3 C++ (2/2)]]></title>
            <link>https://airejie.medium.com/classification-with-opencv3-c-2-2-9ac7aca3ec57?source=rss-197173de4b30------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ac7aca3ec57</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[René-Jean Corneille]]></dc:creator>
            <pubDate>Mon, 07 May 2018 15:06:48 GMT</pubDate>
            <atom:updated>2018-05-07T15:06:48.035Z</atom:updated>
            <content:encoded><![CDATA[<h3>Large data set with low variance:</h3><h4>original dataset:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4NvOLjioc-bo97pGy0RKeg.png" /></figure><h4>k-nearest neighbours:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vYpJOQaMWYbzCQDPJEgbaQ.png" /></figure><h4>decision tree:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WPISrcYKLIVM_1iWM8lHqQ.png" /></figure><h4>boosting:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IuWCZwaxNLAM4R1RwDlXWQ.png" /></figure><h4>random forest:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a704HGW6-uo6H8wn7M8Iiw.png" /></figure><h4>linear SVM:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HXbdJWnfBbRt4ndkHTNh1A.png" /></figure><h4>rbf SVM:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SlPxdAkrkLsyH8HRgEpPig.png" /></figure><h4>sigmoid SVM:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C8t-UM8nKbWFYdnVjW_51w.png" /></figure><h3>Large data set with high variance:</h3><h4>original dataset:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C4U9Et9nO_VWrRP6yNqjCg.png" /></figure><h4>k-nearest neighbours:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G4ivKIwg-3f2jmijcW3x3g.png" /></figure><h4>decision tree:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r6e_sEk7o76REvcd68ID1w.png" /></figure><h4>boosting:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CJUrWKyQ0To2C_7-cZX6Aw.png" /></figure><h4>random forest:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yDtEuUEVIEYJuspop-Bx8g.png" /></figure><h4>linear SVM:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v5rAHFtWG_JvIPgjpzf7XA.png" /></figure><h4>rbf SVM:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*raW50-cfOKXbzAx-WiezRQ.png" /></figure><h4>sigmoid SVM:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wR1RGfyt8FQGIl56HWrDIQ.png" /></figure><h3>Small data set with low variance:</h3><h4>original dataset:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aSnIcot5CdfBi4IyjCamMg.png" /></figure><h4>k-nearest neighbours:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fa5xdhx6HM1TOwGFoRJRPA.png" /></figure><h4>decision tree:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pbcg-M5HvFsBiDcadCSbYw.png" /></figure><h4>boosting:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AjmFhHDWDaesyCZrz9PU3g.png" /></figure><h4>random forest:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JlikvAIMPkSSA3KREwKblA.png" /></figure><h4>linear SVM:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sWXp_oh-oL_SQOdOQnQynQ.png" /></figure><h4>rbf SVM:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D47LT_RUoKuyMEw9CuUQLw.png" /></figure><h4>sigmoid SVM:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H8umSKAFsLkNzjdeTImL8w.png" /></figure><h3>Small data set with high variance:</h3><h4>original dataset:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VcWiLYk1kO51F72y9_BM1A.png" /></figure><h4>k-nearest neighbours:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*69XkXLSn22M724hYbKg5_Q.png" /></figure><h4>decision tree:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lTik_iBdR9eVxt28uFCr0w.png" /></figure><h4>boosting:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Lp90vcJDxaPnkmcAMIBrQ.png" /></figure><h4>random forest:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uG20Jwk5rrDS18HC8H34uA.png" /></figure><h4>linear SVM:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3zhg4rboy_BX1BPOdeJiuA.png" /></figure><h4>rbf SVM:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UAxKldAMiyA40OiXzfhEMw.png" /></figure><h4>sigmoid SVM:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mRWoGsmGNNGem9zwIaf7oQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ac7aca3ec57" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Classification with OpenCV3 C++ (1/2)]]></title>
            <link>https://airejie.medium.com/classification-with-opencv3-c-1-2-6e677689c366?source=rss-197173de4b30------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e677689c366</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[opencv]]></category>
            <dc:creator><![CDATA[René-Jean Corneille]]></dc:creator>
            <pubDate>Mon, 07 May 2018 15:06:18 GMT</pubDate>
            <atom:updated>2018-05-21T20:58:09.882Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rf__8xWSTniXUDcGvnC3Hw.jpeg" /></figure><p>OpenCV is an open source C++ library focusing on computer vision launched in 1999 by Intel research. It is written in C++ but bindings in Python and Matlab are available. The project has been supported by Willow Garage since 2008 and is under active development. OpenCV provides tools for many computer vision applications such as image/gesture recognition, motion tracking, mobile robotics… Computer vision is closely related to machine learning thus OpenCV has a module that implements many traditional algorithms. And more recently, OpenCV 3 added support for deep learning algorithms.</p><p>I decided to do some experiments quite close to the ones performed by Kolanovic [2] since I find that it allows to do some catch up on traditional ML while getting a little bit more familiar with the OpenCV C++ API. After finishing my experiments I decided to publish these results, they might be useful to anyone starting out with OpenCV C++. I personally prefer working with Opencv in C++, here is a <a href="https://www.learnopencv.com/opencv-c-vs-python-vs-matlab-for-computer-vision/">post</a> weighting the pros and cons of each interface available ( C++, Matlab or python).</p><h4><strong>Installing OpenCV3</strong></h4><p>I strongly recommend the macOS package manager Homebrew which makes life much easier and provides a clean, simple interface to build libraries, though some are not available (such as caffe). Some would argue that this gives the false impression that coding is simple, however, for beginners and people that are more scientists than programmers, and ideally would want to focus on the actual prototyping/experimenting phase than the actual setting up phase, Homebrew is perfect. For a C++11 installation with python binding and contrib modules the following command is needed:</p><pre>brew install opencv3 --c++11 --with-python3 --with-contrib</pre><p>The contrib modules are extensions to OpenCV built-in classes. There seems to be a problem with installing OpenCV3 with the python3 binding, this <a href="http://www.pyimagesearch.com/2017/05/15/resolving-macos-opencv-homebrew-install-errors/">blog post</a> deals with this issue (it seems to has been fixed in recent commits but just in case).</p><h4><strong>Data</strong></h4><p>I use dummy data generated by scikit-learn. Actually, everything except the training and prediction will be done with python, i.e. generating the data with sklearn, then training the OpenCV C++ models, perform some cross validation with the test data. Then back to python to finally display the results with seaboarn. This make preparation and analysis of the results quicker and thus I can spend more time on the actual machine learning part. Doing these with C++ would have been a bit more painful.</p><p>This gives some dummy data generators to work with:</p><pre>from sklearn.datasets import make_moons, make_circles, make_blobs</pre><p>The data are from 3 different generators, either with a small (400) or large (4000) sample size and with low (5%) or large (30%) standard deviation (in red class 0 and in blue class 1):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yKfRRxTlokIoX4iZJhpRGQ.png" /><figcaption><strong>large samples with low variance (top: data set 1, middle: data set 2 and bottom: data set 3)</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IM8vnVky8U9zQOq6r3azAg.png" /><figcaption><strong>large samples with high variance (top: data set 1, middle: data set 2 and bottom: data set 3)</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nn3AUC7_DjBARcoirV8bUQ.png" /><figcaption><strong>small samples with low variance (top: data set 1, middle: data set 2 and bottom: data set 3)</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F2dGtf9pHzOEf5qlc-XiKA.png" /><figcaption><strong>small samples with high variance (top: data set 1, middle: data set 2 and bottom: data set 3)</strong></figcaption></figure><p>The data can then easily be saved to csv with pandas. You can find the notebook I used for visualisation <a href="https://github.com/RonsenbergVI/classification_opencv">here</a>.</p><h4><strong>OpenCV containers</strong></h4><p>OpenCV has its own containers that are the input for their machine learning algorithms. Thus I only present the ones needed for this tutorial but the library has a rich collection of containers that are curated for computer vision applications.</p><p>The simplest container is the <strong>Mat</strong> data type that can be instantiated as follows:</p><pre>auto array = cv::<strong>Mat</strong>::ones(1, 20, CV_32F);</pre><p>Here a row vector with 20 columns is created with 1 as initial values for each element with a 32 bits precision. There are other functions allowing to initialise the matrix values:</p><pre>auto zer = cv::<strong>Mat</strong>::zeros(1, 20, CV_32F); // zero matrix<br>auto id = cv::<strong>Mat</strong>::eye(20, 20, CV_32F); // identity matrix</pre><p>More generally, the matrix type is defined as follows for one channel matrices:</p><pre>CV_&lt;bit_depth&gt;&lt;type&gt;</pre><p>The type can either be S for signed int, U for unsigned int and F for float. The bit depth can be 8, 16 32 or 64. <a href="http://docs.opencv.org/trunk/d6/d6d/tutorial_mat_the_basic_image_container.html">OpenCV also allows for multi channel matrices that are designed to contain image pixels</a>.</p><p>Inputs for machine learning algorithms in OpenCV are instances of the class <strong>TrainData</strong>. This class is quite useful because it has an internal train/test split logic thus the algorithm trained only the data only accesses the elements marked as trained and the remaining are discarded and used for testing. A set of sample data can be created as follows:</p><pre>auto X = cv::<strong>Mat</strong>::zeros(400,2,CV_32F); // dummy features matrix<br>auto Y= cv::<strong>Mat</strong>::zeros(400,1,CV_32U); // dummy label matrix<br>cv::<strong>Ptr</strong>&lt;cv::ml::<strong>TrainData</strong>&gt; data=cv::ml::<strong>TrainData</strong>::create(X,0,Y);</pre><p>where X is the instance cv::<strong>Mat</strong> with the observed features and Y a cv::<strong>Mat</strong> instance with the labels, both fed with the data generated by sklearn. The second parameter is 0 to signal that one observation is a row vector with the features as columns. If the value is 1 then one observation is a column vector. In order to set the train/test split ratio, the following member function is handy:</p><pre>data-&gt;setTrainTestSplitRatio(0.2,true);</pre><p>The first parameter defines the percentage set aside for testing and the functions performs a shuffle split is the second input value is true.</p><h4>Binary classification</h4><p>OpenCV C++ has a machine learning module wrapped in the cv::ml:: namespace. All the models implemented are derived class of the cv::ml::<strong>StatModel</strong> which declares training and prediction member functions for its instances. It<strong> </strong>is a pure virtual class and methods are accessed through pointers of the base class (dynamic polymorphism):</p><pre>cv::ml::Ptr&lt;<strong>StatModel</strong>&gt; model = cv::ml::<strong>StatModel</strong>::create();</pre><p>Thus the pointer of the base class StatModel allows to reference any of the model we want. The models can thus be trained nicely using the same member function:</p><pre>model-&gt;train(data);</pre><p>We can check at any moment whether a model was trained as follows:</p><pre>model-&gt;isTrained();</pre><p>When the model is trained, the generalisation error can be computed as follows:</p><pre>model-&gt;calcError(data, true, y);</pre><p>the first parameter takes as input the data set, the error is computed over the test set if the second parameter is true (generalisation error), otherwise the train set (training error). The last parameters outputs the labels predicted by the model for the set used. Instead of directly computing the error, it is also possible to compute prediction of a given set of features:</p><pre>model-&gt;predict(x_test);</pre><p>which returns a vector with the predicted classes.</p><p>Each model has its own parameter sets. So I go over the parameters I chose for the experiments. Some models have a grid search allowing to find the parameter set optimising the test classification accuracy. For the others, I just tweaked the parameters until I got to satisfying results.</p><p>Once the model is instantiated, its parameters needs to be set by the user, here are the parameters chosen for the following algorithms (I assume that these traditional algorithms are known by the reader):</p><p><a href="https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm"><strong>- k nearest neighbours</strong></a><strong>:</strong></p><pre>kNearest-&gt;setDefaultK(5);<br>kNearest-&gt;setIsClassifier(true);</pre><ul><li><strong>setDefaultK: </strong>sets the number of nearest neighbours.</li><li><strong>setIsClassifier: </strong>if false, the algorithm fitted is a regression (i.e. continuous output) if true it is a classifier.</li></ul><p><a href="https://en.wikipedia.org/wiki/Decision_tree"><strong>decision tree</strong></a><strong>:</strong></p><pre>decisionTree-&gt;setMaxDepth(3000);<br>decisionTree-&gt;setMinSampleCount(1);<br>decisionTree-&gt;setUse1SERule(false);<br>decisionTree-&gt;setUseSurrogates(false);<br>decisionTree-&gt;setPriors(cv::Mat());<br>decisionTree-&gt;setCVFolds(1);</pre><ul><li><strong>setMaxDepth: </strong>sets the maximum depth of the tree.</li><li><strong>setMinSampleCount: </strong>sets the minimum number of observation in each leaf.</li><li><strong>setUse1SERule:</strong> is true algorithm performs a more aggressive pruning of the tree which reduces its variance.</li><li><strong>setUseSurrogates:</strong> only useful if there are missing input values.</li><li><strong>setPriors: </strong>skews penalty for miss-classification for certain classes.</li><li><strong>setCVFolds:</strong> sets the <a href="https://en.wikipedia.org/wiki/Cross-validation_(statistics)#k-fold_cross-validation">cross validation procedure order</a> for pruning the tree.</li></ul><p>I go into more details on decision trees in openCV C++ in an upcoming post.</p><p><a href="https://en.wikipedia.org/wiki/Random_forest"><strong>random forest</strong></a></p><pre>randomForest-&gt;setMaxCategories(2);<br>randomForest-&gt;setMaxDepth(3000);<br>randomForest-&gt;setMinSampleCount(1);<br>randomForest-&gt;setTruncatePrunedTree(false);<br>randomForest-&gt;setUse1SERule(false);<br>randomForest-&gt;setUseSurrogates(false);<br>randomForest-&gt;setPriors(cv::Mat());<br>randomForest-&gt;setTermCriteria(criterRamdomF);<br>randomForest-&gt;setCVFolds(1);</pre><ul><li><strong>setTermCriteria:</strong> sets the convergence criteria by choosing when the algorithm stops (either when a given precision is reached <strong>CV_TERMCRIT_EPS</strong>, or when a number of iteration is reached <strong>CV_TERMCRIT_ITER</strong>). Then the value of each criteria must be set.</li></ul><pre><strong>auto</strong> criterRamdomF = cv::<strong>TermCriteria</strong>();<br>criterRamdomF.type = CV_TERMCRIT_EPS + CV_TERMCRIT_ITER;<br>criterRamdomF.epsilon = 1e-8;<br>criterRamdomF.maxCount = 5000;</pre><p><a href="https://en.wikipedia.org/wiki/Boosting_(machine_learning)"><strong>boost</strong></a></p><pre>boost-&gt;setBoostType(cv::ml::Boost::DISCRETE);<br>boost-&gt;setWeakCount(100);<br>boost-&gt;setMaxDepth(2000);<br>boost-&gt;setUseSurrogates(false);<br>boost-&gt;setPriors(cv::Mat());</pre><ul><li><strong>setBoostType: </strong>selects the type of boosting algorithm used (options are AdaBoost or Logit).</li><li><strong>setWeakCount: </strong>sets the number of weak classifiers used.</li></ul><p><a href="https://en.wikipedia.org/wiki/Support_vector_machine#Linear_SVM"><strong>linear SVM</strong></a></p><pre>linearSvm-&gt;setC(100);<br>linearSvm-&gt;setKernel(linearSvm-&gt;LINEAR);;<br>linearSvm-&gt;setTermCriteria(criterSvm);<br>linearSvm-&gt;setType(linearSvm-&gt;C_SVC);</pre><ul><li><strong>setKernel: </strong>sets the kernel function.</li><li><strong>setC: </strong>sets the regularization hyperparameter.</li></ul><p><a href="https://en.wikipedia.org/wiki/Radial_basis_function_kernel"><strong>rbf SVM</strong></a></p><pre>rbfSvm-&gt;setC(1000);<br>rbfSvm-&gt;setTermCriteria(criterRbf);<br>rbfSvm-&gt;setCoef0(0.3);<br>rbfSvm-&gt;setKernel(rbfSvm-&gt;RBF);<br>rbfSvm-&gt;setGamma(0.9);<br>rbfSvm-&gt;setType(rbfSvm-&gt;C_SVC);</pre><ul><li><strong>setGamma: </strong>hyperparameter of the sigmoid kernel function.</li><li><strong>setCoef0: </strong>hyperparameter of the sigmoid kernel function.</li></ul><p><strong>sigmoid SVM</strong></p><pre>sigmoidSvm-&gt;setC(1000);<br>sigmoidSvm-&gt;setTermCriteria(criterSigmoid);<br>sigmoidSvm-&gt;setCoef0(0.3);<br>sigmoidSvm-&gt;setGamma(0.9);<br>sigmoidSvm-&gt;setKernel(sigmoidSvm-&gt;SIGMOID);<br>sigmoidSvm-&gt;setType(sigmoidSvm-&gt;C_SVC);</pre><p>I also visit further Support Vector Machines in Open CV C++in an upcoming post.</p><h4>Results:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*jGdM7xAobAkaRbJ4wDGKEw.png" /><figcaption><strong>classification performance for large samples</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*Zr-UxFVRiLF3n0PA5_oH6Q.png" /><figcaption><strong>classification performance for small samples</strong></figcaption></figure><p>The code used for this post can be found <a href="https://github.com/RonsenbergVI/classification_opencv">here</a>. Mode detailed results can also be found <a href="https://medium.com/@airejie/classification-with-opencv3-c-2-2-9ac7aca3ec57">here</a>.</p><h4>References:</h4><p><a href="https://docs.opencv.org/3.0-beta/modules/ml/doc/ml.html">[1]</a>. OpenCV3 Machine Learning API Documentation</p><p>[2]. Big Data and AI Strategies, <em>Machine Learning and Alternative Data Approach to Investing, </em>Kolanovic Marco, Krishnamachar Rajesh T. (2017)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e677689c366" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Xcode for C++ projects]]></title>
            <link>https://airejie.medium.com/setting-up-xcode-for-c-projects-17531c3c3941?source=rss-197173de4b30------2</link>
            <guid isPermaLink="false">https://medium.com/p/17531c3c3941</guid>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[René-Jean Corneille]]></dc:creator>
            <pubDate>Mon, 14 Aug 2017 15:58:00 GMT</pubDate>
            <atom:updated>2017-08-18T03:33:57.182Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MXoIYWrgxZjakP528wtuFQ.jpeg" /></figure><p>When I first started using Xcode for my C++ projects I was a bit overwhelmed by the settings interface; sure I had used Xcode heavily for Objective-C and then Swift project but most of the Build Settings are already set up to run any iOS/macOS app. For C++ however, it gets a bit trickier. Here is a solution I found works for C++ libraries built with cmake, make or Homebrew. I hope it turns out to be useful for anyone coding in C++ with Xcode.</p><p>Setting up Xcode for C++ projects is a four step process:</p><p><strong>a. defining the build location:</strong></p><p>This is mostly for convenience so this step can be skipped. Selecting “Legacy” as Build Location allows to store the build data in the same folder as the project. More information about the other choices can be found <a href="https://pewpewthespells.com/blog/managing_xcode.html#builddirs">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ylUs8PRTU6IWv341nRQCyA.png" /><figcaption>Build location setting</figcaption></figure><p><strong>b. providing the header search path:</strong></p><p>In order to call a library API, the macro <strong><em>#include</em></strong> must be called. But Xcode needs to know where the projects header must be found (on macOS, these are usually in /usr/local/include). If you build the library with a package manager, you should look into the default folder or the one you set up at build. For example with Homebrew the default directory is /usr/local/Cellar/&lt;library-name&gt;/../include.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N2YxzEAwQF-CTgH5YdD8rw.png" /><figcaption>Adding header search paths</figcaption></figure><p><strong>c. providing the libraries search location:</strong></p><p>The C++ linker needs to know where to find the third party (dynamic ) libraries. They usually have the .dylib extension and are located by default on macOS in the folder /usr/local/lib or /usr/local/Cellar/&lt;library-name&gt;/../lib for a library built with Homebrew.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_kchbAtx9CHGTUa-kIkP7g.png" /><figcaption>Adding library search path</figcaption></figure><p><strong>d. adding the linker flags</strong></p><p>And finally the linker flags tell Xcode which library are actually used in the project. The format is -l&lt;l-name&gt; and the library named ‘l-name’ will be searched in the library search path (provided in c.) when linking. More informations on linking can be found in the <a href="https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html">gcc documentation</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-bFimJDdIOmj_E81-LDouA.png" /><figcaption>Adding linker flags</figcaption></figure><p>Now Xcode is ready to work with any C++ library installed with Homebrew or build with cmake.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17531c3c3941" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Une introduction à Armadillo]]></title>
            <link>https://airejie.medium.com/une-introduction-%C3%A0-armadillo-327d2509f29e?source=rss-197173de4b30------2</link>
            <guid isPermaLink="false">https://medium.com/p/327d2509f29e</guid>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[tutoriel]]></category>
            <category><![CDATA[programmation]]></category>
            <category><![CDATA[calcul-matriciel]]></category>
            <dc:creator><![CDATA[René-Jean Corneille]]></dc:creator>
            <pubDate>Sun, 09 Jul 2017 07:52:00 GMT</pubDate>
            <atom:updated>2017-08-18T03:34:17.542Z</atom:updated>
            <content:encoded><![CDATA[<p>Armadillo est une librarie template C++ avec une interface très complete pour le calcul matriciel et l’algèbre linéaire. Elle permet de rapidement obtenir un code fonctionel sans compromis sur la performance du language.</p><p>Ce tutoriel couvre l’installation de cette librarie (sur macOS seulement pour le moment), l’execution de simple code et un tour de sa riche interface. Une alternative à Armadillo est <a href="http://eigen.tuxfamily.org/index.php?title=Main_Page">Eigen</a>.</p><p><a href="http://arma.sourceforge.net/">Armadillo</a> est developpé et maintenu par la NITCA (<em>National Information and Communications Technology of Australia</em>). Leur but était de fournir une interface aussi facile d’utilisation que celle de Matlab pour les utilisateurs du language de bas-niveau qu’est C++. Nombreuses sont les librairies qui dépendent de Armadillo comme <a href="http://www.mlpack.org/">MLPACK</a> (pour l’apprentissage statistique) et <a href="http://sigpack.sourceforge.net/">SigPack</a> (pour le traitement du signal).</p><p>Armadillo utilise BLAS et LAPACK; BLAS est un ensemble d’operations de bases d’albgèbre linéaire écrites en Fortran et est à la base de nombreuses libraries de calcul matriciel tel que Numpy et de languages comme Matlab. LAPACK fut lancée en 1992 et est une librarie Fortran offrant des solutions à une variété de problèmes d’analyse numérique.</p><p>Armadillo est couvert sous la licence Apache 2.0, donc libre au lecteur de l’utiliser dans ses projets.</p><h3><strong>Installation</strong></h3><p>Je recommande d’installer Armadillo avec le gestionnaire de paquets de macOS <a href="https://brew.sh/">Homebrew</a>. C’est l’un des gestionnaires les plus utilisés pour le système d’exploitation de Apple du fait de sa facilité d’utilisation et de son interface integrée dans le terminal. Si Homebrew n’est pas encore installé dans votre système, copiez cette commande dans votre terminal:</p><pre>$ /usr/bin/ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;</pre><p>Maintenant que Hombrew est installé nous pouvons maintenant installer Armadillo:</p><pre>$ brew install armadillo --c++11</pre><p>Une autre methode pour installer Armadillo est d’utiliser un autre gestionnaire CMake qui est cependant plus difficile d’utilisation et qui permet une installation ‘sur-mesure’ que nous ne couvrons pas ici.</p><h3>Compilation</h3><p>Pour utiliser Armadillo dans un fichier C++ il faut d’abord importer la librairie:</p><pre>#include &lt;armadillo&gt;</pre><p>Pour compiler et executer du code C++ depuis le terminal, il faut d’abord se déplacer dans le dossier où se situe ce ficher (en utilisant la commande ‘cd’) et ensuite préciser au compilateur (g++ a été utiliser pour développer ce tutorial) où se trouve la librairie lorsque l’on compile le fichier source avec la commande:</p><pre>$ g++ main.cc -o main.o -O2 -larmadillo</pre><p>Pour utiliser la librairie dans Xcode, il suffit d’ajouter à la liste des ‘Other C++ Flags’:</p><pre>-l/usr/local/opt/armadillo/include</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*99K0Jb87jB57f3KMe_D6_Q.png" /></figure><h3>Premiers pas</h3><p>Armadillo permet la manipulation de tableaux de 1, 2 ou 3 dimensions et définit de nombreux opérateurs classiques ce qui permet d’écrire un code compact et lisible. Nous nous limitons ici aux tableaux de 1 ou 2 dimensions.</p><p>Les classes de tableaux sont les suivantes:</p><ul><li>matrices (MxN);</li><li>vecteurs; qui peuventêtre définis comme ligne (Nx1) ou colonne(1xN) et sont des sous-classes de matrices;</li></ul><p>Les classes de la librarie sont écrites utilisant le principe du polymorphisme statique. Ainsi pour créer une matrice par example il faut préciser au compilateur le type de donnée que notre matrice va contenir; par exemple pour créer une matrice de <em>doubles</em>, il faut procéder comme suit:</p><pre>arma::<strong>Mat</strong>&lt;<strong>double</strong>&gt; A = arma::<strong>Mat</strong>&lt;<strong>double</strong>&gt;(); <br>arma::<strong>mat</strong> B = arma::<strong>mat</strong>(); // both are equivalent</pre><p>Afin d’éviter d’avoir à utiliser le namespace “arma” il faut juste ajouter la ligne de code:</p><pre>using namespace arma;</pre><p>Des types classiques ont été créées par convénience; pour les <em>doubles </em>par exemple:</p><pre>arma::<strong>mat</strong> A = arma::<strong>mat</strong>(); // matrix of doubles<br>arma::<strong>vec</strong> A = arma::<strong>vec</strong>(); vector of doubles</pre><p>pour créer des tableaux d’entier naturels positifs:</p><pre>arma::<strong>umat</strong> A = arma::<strong>mat</strong>(); // matrix of unsigned int<br>arma::<strong>uvec</strong> A = arma::<strong>vec</strong>(); vector of unsigned int</pre><p>Il y a plusieurs types de constructeurs disponibles pour créer des tableaux données. Je recommande personnellement d’éviter les constructeurs par défauts et au lieu d’utiliser le constructeur permettant de définir la valeur de tous les elements à zero:</p><p>Le code suivant:</p><pre>arma::<strong>mat</strong> M1 = arma::<strong>mat</strong>(5,10,arma::fill::zero);<br>arma::<strong>mat</strong> M2 = arma::<strong>mat</strong>(size(M1),arma::fill::randu);<br>arma::<strong>mat</strong> M3 = arma::<strong>mat</strong>(size(M1),arma::fill::ones);</pre><pre>std::cout &lt;&lt; M1.n_rows &lt;&lt; &quot;\n&quot;; // returns &#39;5&#39;<br>std::cout &lt;&lt; M1.n_cols &lt;&lt; &quot;\n&quot;; // returns &#39;10&#39;<br>std::cout &lt;&lt; M1.n_nonzero &lt;&lt; &quot;\n&quot;; // returns &#39;0&#39;<br>std::cout &lt;&lt; M3.n_nonzero &lt;&lt; &quot;\n&quot;; // returns &#39;50&#39;</pre><p>crée une matrice “M1” avec 5 lignes et 10 colonnes dont les éléments sont égaux à zéro, une matrice “M2” de la même taille que “M1” dont les éléments sont des réalisations indépendantes de la loi uniforme sur l’intervalle [0,1] et enfin une matrice “M3” de même taille que “M1” dont tous les éléments sont égaux à 1. Les options de “remplissage” sont les suivantes:</p><ul><li><strong>arma::fill::zero</strong>: initialise tous les éléments à 0;</li><li><strong>arma::fill::ones</strong>: initialise tous les éléments à 1;</li><li><strong>arma::fill::eye</strong>: initialise les éléments de la diagonale à 1 et les autres éléments à 0;</li><li><strong>arma::fill::randu</strong>: initialise les éléments comme réalisations indépendantes de la loi uniforme sur l’intervalle [0,1];</li><li><strong>arma::fill::randn</strong>: initialise les éléments comme réalisations indépendantes de la loi normale centrée réduite;</li><li><strong>arma::fill::none</strong>: ne modifie aucun élément;</li></ul><p>Une méthode assez conveniente pour créer une matrice est à partir d’une chaîne de caractères. Chaque élément doit être séparé par un espace et chaque ligne par un point-virgule:</p><pre>arma::mat fromString arma::mat(&quot;1 9;-1 3&quot;);</pre><p>Si le format n’est pas respecté alors une erreur fera arrêter la compilation.</p><p>Armadillo traite les scalaires comme des matrices de taille (1,1) ou des vecteurs de taille 1; par ailleurs certaines constantes utiles sont définies dans la librairie:</p><pre>arma::datum::pi; // pi<br>arma::datum::inf; // infinite<br>arma::datum::nan; // not a number</pre><p><strong><em>Accéder aux éléments</em></strong></p><p>Les éléments des matrices peuvent être accédés utilisant l’indexation par numéro de ligne et/ou colonne grâce aux opérateurs (), [] ou de la fonction <strong>.at()</strong>.</p><p>L’opérateur recommandé en phase de développement est () qui est moins performant mais qui vérifie que l’indice demandé est à l’intérieur des bornes de la matrice en question, sinon une exception est signalée par le compilateur. Ce n’est pas le cas des opérateurs [] ou .at() qui ne signaleront rien d’où l’importance de ne les utiliser que lorsque le code est testé puisqu’ils amélioront la performance.</p><pre>fromString(0,0); // extrait &#39;1&#39;<br>fromString(30,30); // erreur !<br>fromString[1,0]; // extrait &#39;9&#39;<br>fromString[10,0]; // ??</pre><p>Il est aussi possible d’extraire une ligne/colonne donnée d’une matrice en utilisant les fonctions membres <strong>.col()</strong> et <strong>.row()</strong>:</p><pre><strong>vec</strong> x = <strong>vec</strong>();<br><strong>colvec</strong> y = <strong>colvec</strong>();</pre><pre>x = fromString.row(0);  // x = [1,9] <br>y = fromString.col(0);  // x = [1;-1]</pre><p>Une méthode plus avancée est l’extraction de sous-matrices grâce à la méthode <strong>.submat(); </strong>cette opérateur fournit un accées lecture/écritude de la sous-matrice ce qui est particulièrement intéressant pour modifier des parties choisies d’une matrice:</p><pre><strong>int</strong> firstR(2),lastR(3),firstC(3),lastC(4);</pre><pre>// -- 1 --<br>arma::<strong>mat</strong> X = arma::<strong>mat</strong>(10,10,arma::fill::ones); </pre><pre>arma::<strong>mat</strong> Y = X.submat(firstR,lastR,firstC,lastC);</pre><pre>std::cout &lt;&lt; Y.n_rows &lt;&lt; &quot;\n&quot;; <br>std::cout &lt;&lt; Y.n_cols &lt;&lt; &quot;\n&quot;; </pre><pre>// -- 2 -- <br>X.submat(firstR,lastR,firstC,lastC) = mat(size(Y),arma::fill::zeros)</pre><p>La première partie de ces quelques lignes de code permet de crée une matrice carrée de taille 10 “X” dont ls éléments sont tous égaux à 1, ensuite crée une matrice “Y” qui est une sous-matrice de taille 2 “X” (ligne 2 à ligne 3 et colonne 3 à colonne 4) et ensuite affiche le nombre de lignes et le nombre de colonnes de “Y”;</p><p>La deuxième partie du code modifie la sous-matrice de “X”, plus précisément definit X(2,3), X(2,4), X(3,3) et X(3,4) tous égaux à 0.</p><p><strong><em>Vérifier les propriétés de matrices</em></strong></p><ul><li><strong>in_range() </strong>vérifie qu’un indice est valide, c’est-à-dire que si on essaye d’y accéder avec l’opérateur () une exception ne sera pas lancée.</li></ul><pre>arma::<strong>mat</strong> X = arma::<strong>mat</strong>(4,4,arma::fill:randu);</pre><pre>std::cout &lt;&lt; X.in_range(2,3) &lt;&lt; &quot;\n&quot;; // returns True<br>std::cout &lt;&lt; X.in_range(1,4) &lt;&lt; &quot;\n&quot;; // returns False<br>std::cout &lt;&lt; X.in_range(5,0) &lt;&lt; &quot;\n&quot;; // returns False<br>std::cout &lt;&lt; X.in_range(10,100) &lt;&lt; &quot;\n&quot;; // returns False</pre><ul><li><strong>is_empty()</strong> vérifie qu’une matrice est “vide”. Cette function membre renvoie la valeur True pour les matrices pour lesquelles la méthode <strong>.reset() </strong>a été appliquée ou pour les éléments initialisés avec le constructeur par défaut.</li></ul><pre>arma::<strong>mat</strong> X = arma::<strong>mat()</strong>;<strong><br></strong>std::cout &lt;&lt; X.is_empty() &lt;&lt; &quot;\n&quot;; returns True;</pre><pre>X(0,0) = <strong>double</strong>(0.5);<br>std::cout &lt;&lt; X.is_empty() &lt;&lt; &quot;\n&quot;; returns False;</pre><pre>X.reset();<br>std::cout &lt;&lt; X.is_empty() &lt;&lt; &quot;\n&quot;; returns True;</pre><ul><li><strong>is_finite()</strong> vérifie que tous les éléments d’une matrice sont finis (i.e. différent de inf ou de nan)</li></ul><pre>arma::<strong>mat</strong> X = arma::<strong>mat</strong>(3,10,arma::fill::ones);<br>std::cout &lt;&lt; X.is_finite() &lt;&lt; &quot;\n&quot;; returns True;</pre><pre>X(1,1) = arma::datum::inf;<br>std::cout &lt;&lt; X.is_finite() &lt;&lt; &quot;\n&quot;; returns False;</pre><pre>X(1,1) = <strong>double</strong>(0.0);<br>X(1,1) = arma::datum::inf;<br>std::cout &lt;&lt; X.is_finite() &lt;&lt; &quot;\n&quot;; returns False;</pre><ul><li><strong>is_square()</strong> vérifie que la matrice est carrée (nombre de lignes égal au nombre de colonnes):</li></ul><pre>arma::<strong>mat</strong> X = arma::<strong>mat</strong>(3,10,arma::fill::ones);<br>std::cout &lt;&lt; X.is_square() &lt;&lt; &quot;\n&quot;; returns False;</pre><pre>arma::<strong>mat</strong> Y = arma::<strong>mat</strong>(3,3,arma::fill::eye);<br>std::cout &lt;&lt; Y.is_square() &lt;&lt; &quot;\n&quot;; returns True;</pre><ul><li><strong>is_vec()</strong> vérifie si l’un des composants de la taille de la matrice est égal à 1 (i.e. s’il s’agit d’un vecteur ligne ou colone);</li></ul><pre>arma::<strong>mat</strong> a = arma::<strong>mat</strong>(3,10,arma::fill::ones);<br>std::cout &lt;&lt; a.is_vec() &lt;&lt; &quot;\n&quot;; returns False;</pre><pre>arma::<strong>mat</strong> b = arma::<strong>mat</strong>(1,3,arma::fill::zeros);<br>std::cout &lt;&lt; b.is_vec() &lt;&lt; &quot;\n&quot;; returns True;</pre><pre>arma::<strong>mat</strong> c = arma::<strong>mat</strong>(3,1,arma::fill::randu);<br>std::cout &lt;&lt; c.is_vec() &lt;&lt; &quot;\n&quot;; returns True;</pre><pre>arma::<strong>vec</strong> d = arma::<strong>vec</strong>(4,arma::fill::randu);<br>std::cout &lt;&lt; d.is_vec() &lt;&lt; &quot;\n&quot;; returns True;</pre><pre>arma::<strong>colvec</strong> e = arma::<strong>colvec</strong>(3,arma::fill::randu);<br>std::cout &lt;&lt; e.is_vec() &lt;&lt; &quot;\n&quot;; returns True;</pre><ul><li><strong>has_inf() </strong>vérifie que les éléments de la matrice sont tous finis (i.e. différents de inf):</li></ul><pre>arma::vec r = arma::vec(100,arma::fill::zero);<br>std::cout &lt;&lt; r.has_inf() &lt;&lt; &quot;\n&quot;; returns False;</pre><pre>r(99) = arma::datum::nan;<br>std::cout &lt;&lt; r.has_inf() &lt;&lt; &quot;\n&quot;; returns False;</pre><pre>r(99) = arma::datum::inf;<br>std::cout &lt;&lt; r.has_inf() &lt;&lt; &quot;\n&quot;; returns True;</pre><ul><li><strong>has_nan() </strong>vérifie que les éléments de la matrice sont tous des nombres(i.e. différents de nan):</li></ul><pre>arma::vec r = arma::vec(100,arma::fill::zero);<br>std::cout &lt;&lt; r.has_nan() &lt;&lt; &quot;\n&quot;; returns False;</pre><pre>r(99) = arma::datum::inf;<br>std::cout &lt;&lt; r.has_nan() &lt;&lt; &quot;\n&quot;; returns False;</pre><pre>r(99) = arma::datum::nan;<br>std::cout &lt;&lt; r.has_nan() &lt;&lt; &quot;\n&quot;; returns True;</pre><p><strong><em>Calcul matriciel</em></strong></p><p>Armadillo redéfinit les opérateurs suivants :</p><ul><li><strong>q * A </strong>ou <strong>A * q </strong>: multiplication des éléments d’une matrice A par un scalaire q;</li><li><strong>A + B </strong>: addition élément par éléments d’une matrice (elles doivent avoir la même taille)<strong>;</strong></li><li><strong>A * B </strong>: multiplication classique de matrices (les tailles doivent être compatibles);</li><li><strong>A / B </strong>: division élément par élément de la matrice A par la matrice B (elles doivent être de même taille et B doit être une matrice dont tous les éléments sonts différents de zéro);</li><li><strong>A == B </strong>: revoie la valeur True si et seulement si les matrices sont de même taille et les éléments à la même position ont la même valeur<strong>;</strong></li><li><strong>A != B </strong>: revoie la valeur True si et seulement si<strong>A == B </strong>renvoie la valeur False;</li><li><strong>A % B </strong>: multiplicatio élément par élément de la matrice A par la matrice B (elles doivent être de même taille);</li></ul><p>Dans les prochaines publications nous nous concentrons l’accès d’éléments avec des méthodes plus avancées, les fonctions d’analyse numérique de la librarie et enfin les tableaux à 3 dimensions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=327d2509f29e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>