<?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 Ed Duarte on Medium]]></title>
        <description><![CDATA[Stories by Ed Duarte on Medium]]></description>
        <link>https://medium.com/@EdDuarte?source=rss-de7fec41027------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Ed Duarte on Medium</title>
            <link>https://medium.com/@EdDuarte?source=rss-de7fec41027------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 14:41:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@EdDuarte/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[Living Globe: Tridimensional interactive visualization of world demographic data]]></title>
            <link>https://medium.com/@EdDuarte/living-globe-tridimensional-interactive-visualization-of-world-demographic-data-c3eeb1845c51?source=rss-de7fec41027------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3eeb1845c51</guid>
            <category><![CDATA[webgl]]></category>
            <category><![CDATA[information-visualization]]></category>
            <category><![CDATA[paper]]></category>
            <category><![CDATA[spatial-analysis]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Ed Duarte]]></dc:creator>
            <pubDate>Mon, 14 Aug 2017 17:49:49 GMT</pubDate>
            <atom:updated>2019-05-20T02:13:00.546Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V9O6AHzqONcneKfxi0QfLw.png" /></figure><p>Living Globe is a WebGL application for tri-dimensional worldwide data visualization. It allows the simultaneous representation of multiple indicators as spatial structures (bars and other objects located in a specific latitude-longitude on the globe). The mapping of data to the provided visual structures is configurable by the user, introducing an aspect of customization which encourages a more immediate, visual-only interpretation of the data. Additionally, the represented data is normalized within an adjustable scale. This can be used to filter out extremely high or extremely low samples, uniforming the remaining data and improving its visibility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*7lgEvxvC_Be_LGNg20vDpQ.png" /><figcaption>Current prototype of Living Globe, showing population growth mapped to the bars/pilars height, total life expectancy at birth to bar color, and birth/death ratio to country color.</figcaption></figure><p>Our prototype was developed with demographic data in mind, like total population, density, population-growth, life expectancy, net migration, crude birth rate, crude death rate and the ratio between the last two. However, today it actually allows the visual exploration of the any kind of numerical data structured in JSON by year and by country. We provide two example input files: “input.json” (containing demographic data between the years 1960 and 2014) and “input_alt.json” (containing miscellaneous data regarding finance, demography and employment between the years 1960 and 2014).</p><p>While offering inexperienced users a default mapping of these data variables into visual variables, Living Globe allows more advanced users to select the mapping they intend to use. This means that users can control over an earlier stage of the visualization reference model (Riccardo Mazza. Introduction to information visualization. Springer-Verlag London, 1, 2009) making Living Globe a more flexible tool than other similar tools.</p><p>In order to support this feature, three visual variables may be selected to map a data type:</p><ul><li>height of vertical bars (directly proportional to the data value);</li><li>color of vertical bars (in a color scale ranging from blue to yellow);</li><li>color of the countries on the globe (in a scale ranging from red to green).</li></ul><p>An adequate selection of the data variables and their mapping to the visual variables may help the identification and study of potential relations among data variables. The time interval can be changed through a slider.</p><p>Living Globe also offers the following functionality: i) textual search, with dynamic suggestion of the countries names; ii) country selection; and iii) configuration of minimum and maximum data values; This last feature, which filters out countries that do not match the minimum and maximum values and normalizes the remaining data set, can potentially lead to improvements in the interpretation of data in countries with small samples (eg. Portugal) by filtering out countries with large samples (e.g. China).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*8epuqwb50JpbZgWqzimi1w.png" /><figcaption>Living Globe showing total population mapped to the country color: the data from all countries is displayed on the left, and filtering out large population countries (such as China and India) on the right (resulting in a representation with much more diverse and distinguishing colors for the remaining countries)</figcaption></figure><p>This application can be tested <a href="https://edduarte.github.io/living-globe">here</a>. It is built with Javascript ES6, <a href="https://jquery.com/">jQuery</a>, <a href="https://threejs.org/">three.js</a> and <a href="https://gka.github.io/chroma.js/">chroma.js</a>, and the codebase is open-sourced <a href="https://github.com/edduarte/living-globe">on Github</a>.</p><p><em>Originally published at </em><a href="https://edduarte.com/living-globe/"><em>edduarte.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3eeb1845c51" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vokter v0.2: Software architecture & design philosophy]]></title>
            <link>https://medium.com/@EdDuarte/vokter-a-java-library-that-detects-changes-in-web-documents-c4d3d399046d?source=rss-de7fec41027------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4d3d399046d</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[hashing]]></category>
            <category><![CDATA[bloom-filter]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[text-mining]]></category>
            <dc:creator><![CDATA[Ed Duarte]]></dc:creator>
            <pubDate>Thu, 10 Aug 2017 23:26:21 GMT</pubDate>
            <atom:updated>2019-08-12T03:14:03.108Z</atom:updated>
            <content:encoded><![CDATA[<p>This post outlines the architectural choices behind Vokter, an open-source document store in Java that I’ve been developing since October 2014. This does <strong>not</strong> address other projects under the ‘Vokter’ umbrella, such as for example the HTTP server that uses the core library to manage a persistent state of Vokter on the web instead of locally, but I do hope to address them later in a future post.</p><p>What started as a simple project for a University class in Distributed Architectures, which I named Argus (from <a href="https://en.wikipedia.org/wiki/Argus_Panoptes">Argus Panoptes</a>, the all-seeing giant of Greek mythology), it is currently one of my most ambitious and complex libraries, now known as Vokter (Norwegian for watcher).</p><p><a href="https://github.com/vokter/vokter">Vokter</a> is a document store &amp; index that combines <a href="https://github.com/edduarte/near-neighbor-search">Locality-Sensitive Hashing for K-Shingles</a>, <a href="https://github.com/edduarte/indexed-diff-match-patch">a fork of DiffMatchPatch</a>, <a href="https://github.com/google/guava/wiki/HashingExplained#bloomfilter">Bloom filters</a> and<a href="http://www.quartz-scheduler.org/">Quartz jobs</a> to detect changes in web documents, triggering notifications when specified keywords were either added or removed.</p><p>At a basic level, Vokter fetches web documents on a periodic basis and performs <strong>detection</strong> (comparison of occurrences between two snapshots of the same document) and <strong>matching</strong> (finding out if one of the detected differences matches a registered keyword, sending messages to attached consumers if so).</p><p>It optionally supports multi-language stopword filtering, to ignore changes in common words with no important significance, and<a href="http://snowball.tartarus.org/">stemming</a> to detect changes in lexical variants. Appropriate stopword filtering and stemming algorithms are picked based on the inferred language of the document, using a <a href="https://github.com/optimaize/language-detector">N-grams Naïve Bayesian classifier</a>.</p><h3>Job Management</h3><p>There are two types of jobs, concurrently executed and scheduled periodically (using Quartz Scheduler): detection and matching jobs.</p><p>The detection job is responsible for fetching a new document and comparing it with the previous document, detecting textual differences between the two. To do that, the robust DiffMatchPatch algorithm is used. The matching job is responsible for querying the list of detected differences with specific requested keywords.</p><p>Harmonization of keywords-to-differences is performed by using a Bloom filter, removing differences that have a very low chance of containing the specified keywords, before using a exact comparator (character-by-character) on the remaining differences, to ensure that the detected changes contains any of the keywords.</p><p>Since the logic of difference retrieval is spread between two jobs, one that is agnostic of requests and one that is specific to the client and its keywords, Vokter reduces workload by scheduling only one detection job per watched web-page. For this, jobs are grouped into clusters, where its unique identifier is the document URL. This means that each cluster imperatively contains a single scheduled detection job and one or more matching jobs. In other words, When two clients watch the same page, only one detection job for that page is active.</p><h3>Scaling</h3><p>Vokter was conceived to be able to scale and to be future-proof, and to this effect it was implemented to deal with a high number of jobs in terms of batching and persistence.</p><p>The clustering design mentioned above implies that, as the number of clients grows linearly, the detection logic remains independent of the clients and is only executed at a given set of triggers.</p><p>In terms of orchestration, there are two mechanisms created to reduce redundant resource-consumption, both in memory as well as in the database:</p><ol><li>if the difference detection job fails to fetch content from a specific URL after 10 consecutive attempts, the entire cluster for that URL is expired. When expiring a cluster, all of the associated client REST APIs receive a time-out call;</li><li>every time a matching job is canceled by its client, Vokter checks if there are still matching-jobs in its cluster, and if not, the cluster is cleared from the workspace.</li></ol><h3>Persistence</h3><p>Documents, indexing results, found differences are all stored in MongoDB. To avoid multiple bulk operations on the database, every query (document, tokens, occurrences and differences) is covered by memory cache with an expiry duration between 20 seconds and 1 minute.</p><p>Persistence of detection and matching jobs is also covered, using a custom MongoDB Job Store by Michael Klishin and Alex Petrov.</p><h3>Indexing</h3><p>The string of text that represents the document snapshot that was captured during the Reading phase is passed through a parser that tokenizes, filters stop-words and stems text. For every token found, its occurrences (positional index, starting character index and ending character index) in the document are stored. When a detected difference affected a token, the character indexes of its occurrences can be used to retrieve snippets of text. With this, Vokter can instantly show to user, along with the notifications of differences detected, the added text in the new snapshot or the removed text in the previous snapshot.</p><p>Because different documents can have different languages, which require specialized stemmers and stop-word filters to be used, the language must be obtained. Unlike the Content-Type, which is often provided as a HTTP header when fetching the document, the Accept-Language is not for the most part. Instead, Vokter infers the language from the document content using a <a href="https://github.com/optimaize/language-detector">language detector</a> algorithm based on Bayesian probabilistic models and N-Grams, developed by Nakatani Shuyo, Fabian Kessler, Francois Roland and Robert Theis.</p><p>To ensure a concurrent architecture, where multiple parsing calls should be performed in parallel, Vokter will instance multiple parsers when deployed and store them in a blocking queue. The number of parsers corresponds to the number of cores available in the machine where Vokter was deployed to.</p><h3>OSGi-based architecture</h3><p>Vokter support for reading of a given MediaType is provided by Reader modules, where raw content is converted into a clean string filtered of non- informative data (e.g. XML tags). These modules are loaded in a OSGi-based architecture, meaning that compiled Reader classes can be loaded or unloaded without requiring a reboot. When needed, usually when reading a new document or snapshot, Vokter will query for available Readers by Content-Type supported.</p><p>This same plugin-like architecture is implemented for Stemmer modules. Using a language detection prediction model, Vokter determines the most probable language of the document and queries on-demand for available Stemmers by language supported.</p><h3>Caveats / Future Work</h3><p>Despite every part of its architecture having been optimized to accommodate to a massive amount of parallel tasks, Vokter has only been used in a academic environment and has yet to be battle-tested in high-usage consumer software. If you’re using Vokter in your projects, let me know! 😀</p><p>I believe that there are currently two main issues that should be addressed with higher priority: 1) web crawling functionality; and 2) timeout of jobs when clients are missing.</p><h3>i) Web crawling</h3><p>One way to improve user experience is by integrating web crawling in Reader modules, allowing users to set their visit policy (e.g. number of nested documents accessed). Within the current architecture where there is a unique detection job per document, detection jobs must be sorted by link hierarchy.</p><p>Let’s imagine an example where a job 1 watches document A and a job 2 watches document B, where A has a link to B. In this case, job 2 does not need to exist as there would be redundancy of detection jobs and index storage for document B. Instead, job 1 should trigger clients linked to A and B:</p><ul><li>when differences are detected in A, only clients of A are notified;</li><li>when differences are detected in B, both clients of A &amp; B are notified.</li></ul><p>This implies a more optimized architecture that has the potential of significantly reducing the total number of simultaneous jobs.</p><h3>ii) Orchestration for matching jobs</h3><p>After an attempt to load a new snapshot of the document fails too many times, only detection jobs are timed-out. However, the system can fail to send a response to the client as well, and there is currently no way to deprecate matching jobs when the client has “disappeared and lost interest” before canceling their jobs from Vokter. This means that a high number of active detection and matching jobs might be kept alive unnecessarily.</p><p><em>Originally published at edduarte.com</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4d3d399046d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Knowledge-based system for Texas Hold’em outcome prediction]]></title>
            <link>https://medium.com/@EdDuarte/developing-a-knowledge-management-system-for-texas-holdem-outcome-prediction-in-erlang-cf3440ab806b?source=rss-de7fec41027------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf3440ab806b</guid>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[texas-holdem]]></category>
            <category><![CDATA[erlang]]></category>
            <category><![CDATA[knowledge-management]]></category>
            <category><![CDATA[decision-tree]]></category>
            <dc:creator><![CDATA[Ed Duarte]]></dc:creator>
            <pubDate>Thu, 10 Aug 2017 18:45:35 GMT</pubDate>
            <atom:updated>2019-05-20T02:20:20.863Z</atom:updated>
            <content:encoded><![CDATA[<p>For a University class project we were asked to implement a decision-tree classifier and to use a rule engine in order to develop a recommender system for hands and outcomes in Poker Texas Hold’em matches. An additional challenge to this was to make it in a functional language like Erlang, where no variable state is persisted in memory for long periods of time. Instead, the objective was to use a rule engine more-or-less like a disk database. All of the historical data collected over time is sent between functions in a stateless manner and persisted to disk using the rule engine.</p><p>With this, I developed a <a href="https://github.com/edduarte/erlang-poker-ml">Erlang application</a> with a CLI interface that collects game data and sends win- lose percentages on each round. It works by prompting the user to fill the card in his/her hand and table for each round, and whenever the user won or lost each match. The probabilities of occurrence for each card per round, along with the probability of winning or losing the match with the current cards, are recalculated at the end of every match and organized into a Decision tree. Each round the probability of getting a good hand and win the match is queried from the Decision tree and printed to the user, suggesting him to either raise, call or fold.</p><p>The application is fully open-source and only uses a single file (‘poker.erl’). A trained model containing an history of matches and hands is also provided (‘storage’ file), so you can start testing the application immediately.</p><p>This application is composed of three modules:</p><ul><li>a main module, which uses <a href="http://sourceforge.net/projects/eresye/">Eresye</a> to store Texas Hold’em rules and hand rankings;</li><li>a history module, which stores the number of occurrences and the ranking of hands;</li><li>a tree module, that implements the decision tree and the probability calculation methods.</li></ul><h3>Preliminaries</h3><p>A match is considered a result of seven cards that showed up throughout four rounds. The four rounds are numbered from 0 to 3:</p><ul><li>Round 0: when the user is given 2 cards</li><li>Round 1: when the first, second and third cards on the table are shown</li><li>Round 2: when the fourth card on the table is shown</li><li>Round 3: when the fifth card on the table is shown</li></ul><p>We consider that it is only possible to either raise, call or fold between the four rounds. Hence, there are three phases of betting. In this implementation draws are ignored, so as to not influence the collected probabilities of winning or losing by reducing the sample data of both.</p><p>A <strong>rank</strong> is a weight of importance associated with a specific set of cards. These ranks are, in order: 1. Royal Flush; 2. Straight Flush; 3. Four Of A Kind; 4. Full House; 5. Flush; 6. Straight; 7. Three Of A Kind; 8. Two Pair; 9. Pair; 10. High Card.</p><h3>Main module</h3><p>The main module uses the rule-based engine Eresye to store variables per match and Texas Hold’em hand rankings. For each match, the user is prompted to input:</p><ul><li>the 7 cards that are visible to the user;</li><li>the current pot value;</li><li>the final result of the game (‘won’ or ‘lost’).</li></ul><p>Some additional inputs can be used at any time:</p><ul><li>“reset”: discards the current match inputs and starts again from round 0;</li><li>“close”: saves the current history data into a local file ‘storage’ and closes the application.</li></ul><p>The current match data is only committed to history at the end of the match, so a “reset” will discard the current match.</p><p>When prompting for a card, two inputs are required: the suit and the value. Cards are then structured as {card, ID, Suit, Value} and compared with other hands (and their ranks) in Eresye. The ID value is randomly attributed using the method random:uniform(), and is used to ensure that the card will not be compared with itself during Eresye&#39;s operations.</p><p>(In retrospective, using the result of random:uniform() as an ID is a bad idea, as it can lead to collisions (even if they are rare). An unique UUID or a counting integer should have been used instead.)</p><h3>Decision tree module</h3><p>The decision tree module implements a Decision tree where each node corresponds to a round, and each round has 3 branches pointing to 3 child nodes. Each branch and node stores, respectively:</p><ul><li>branch1 — Expected profit on Raise; node1 — Raise value</li><li>branch2 — Expected profit on Fold; node2 — Fold value</li><li>branch3 — Expected profit on Call; node3 — Call value</li></ul><p>Because the probability of winning (PWin) varies according to the user’s hand and the current round, this decision tree is built at the end of each round, and the expected profits are calculated as such:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*-knlln3PpmrV2H7TqUCaJQ.png" /></figure><p>BetsDoneByPlayer is the total value of bets done by the user to that point, or in other words, the number of chips the user placed in the pot.</p><p>PWin can be calculated using the History module and its Bayesian network (see below), where we can obtain the number of wins attained with the current hand, but also the possible hands that can be obtained in future rounds knowing the current hand. So:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*T0fRvolCi4fzIVmQB3V4RQ.png" /></figure><p>Once all of the expected profits are calculated, the action that the user should take corresponds to the one that has the higher expected profit.</p><h3>History module</h3><p>The history module is a data history, implemented using an alternative Eresye engine (different from the one used in the main module). Essentially, using Eresye allows the usage of insertion and query within a single variable that does not need to be passed along functions, something that would otherwise be impossible to do in native Erlang. In addition, the query implementation of Eresye enables the retrieval of tuples without knowing all of its data, using the wildcard ‘_’ (underscore).</p><p>The data in storage is structured as:</p><ul><li>{round_no, current_rank, previous_round_rank, occurrence_count}: the number of times the user had a ranked hand Y knowing that he/she had a ranked hand X on a previous hand (where Rank(Y) &gt;= Rank(X));</li><li>{won/lost, current_rank, occurrence_count}: the number of times the user won or lost with a specific ranked hand;</li><li>{total, total_matches_count}: the total number of matches that were played with the application.</li></ul><p>Note that the above data-types are identified by the first constant, so in practice we will have 7 data-types (4 for each of the four rounds, 2 for won or lost hands, and 1 for total matches count).</p><p>By storing the history on the local file ‘storage’, we have a continually trained model, persistent between different application sessions. The prediction of outcomes is based on conditional probabilities per round. For example, for the following match…</p><ul><li>Round 0 = High Card</li><li>Round 1 = Pair</li><li>Round 2 = Pair</li><li>Round 3 = Two Pair</li></ul><p>… where Total is the total number of matches stored in history and where the asterisk is a wildcard, the conditional probability for each round is calculated as follows:</p><ul><li>Round 0:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*17JdXZI-e1qP5dFzvHI8Ig.png" /></figure><ul><li>Round 1:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*3Fr1EjBjnlAD9n9WKmCrig.png" /></figure><ul><li>Round 2:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*vak0hTRZ_MCrAp2eujCpKw.png" /></figure><p>This lets us know if the chance to get other more valuable ranks is high enough for it to be worth a raise or a call.</p><h3>Final thoughts</h3><p>That’s all! With all these modules, our knowledge management system for Texas Hold’em outcome prediction is complete! In a way, we used Eresye to store state, essentially getting around the functional and immutable nature of Erlang. There might have been better ways to keep the statelessness by passing the complete records around every function, but regardless, the decision-tree classifier is completely stateless and, surprisingly, highly readable and maintainable.</p><p><em>Originally published at </em><a href="https://edduarte.com/erlang-poker-ml/"><em>edduarte.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf3440ab806b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>