<?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:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[Tom Carroll]]></title><description><![CDATA[I'm a Machine Learning Engineer located in Boston. My interests include Machine Learning, Computer Vision, and Human Computer Interaction.]]></description><link>https://34.148.43.187:80/</link><generator>Ghost 0.11</generator><lastBuildDate>Wed, 06 May 2026 10:15:01 GMT</lastBuildDate><atom:link href="https://34.148.43.187:80/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Creating Synthia]]></title><description><![CDATA[<p>With the rise of <a href="https://developer.amazon.com/alexa">Amazon Alexa</a> and <a href="https://madeby.google.com/home">Google Home</a> there has been a rapid growth in voice based assistants to help out with everyday life. The use cases are nearly endless: from scheduling reminders, to reciting new recipes, and ordering <a href="https://www.engadget.com/2017/01/05/alexa-offers-voice-controlled-takeout-from-amazon-restaurants">takeout sushi</a>. Even better, Amazon has made Alexa available to</p>]]></description><link>https://34.148.43.187:80/introducing-synthia/</link><guid isPermaLink="false">60d00e50-40bb-4f1c-96fa-c19041356747</guid><category><![CDATA[Python]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[VUI]]></category><category><![CDATA[CV]]></category><dc:creator><![CDATA[Tom Carroll]]></dc:creator><pubDate>Tue, 10 Jan 2017 11:28:14 GMT</pubDate><content:encoded><![CDATA[<p>With the rise of <a href="https://developer.amazon.com/alexa">Amazon Alexa</a> and <a href="https://madeby.google.com/home">Google Home</a> there has been a rapid growth in voice based assistants to help out with everyday life. The use cases are nearly endless: from scheduling reminders, to reciting new recipes, and ordering <a href="https://www.engadget.com/2017/01/05/alexa-offers-voice-controlled-takeout-from-amazon-restaurants">takeout sushi</a>. Even better, Amazon has made Alexa available to developers by introducing <a href="https://developer.amazon.com/alexa-voice-service">Alexa Voice Services</a>. There has never been a better time to build cheap &amp; intelligent agents that can utilize cloud-based AI.</p>

<p>With that idea in mind, I decided to try my hand at creating my own intelligent assistant:  <a href="https://github.com/TomAlanCarroll/synthia"><strong>Synthia</strong></a>, the <strong>Synth</strong>etic <strong>I</strong>ntelligent <strong>A</strong>ssistant for your home.</p>

<p>Synthia is an application that can integrate the best available AI services and be run on cheap and customizable hardware. Using the $35 Raspberry Pi 3, you can setup an agent in your home that can <em>see</em>, <em>hear</em>, and <em>respond</em> to your commands with a wakeword. <br>
<img src="https://raw.githubusercontent.com/TomAlanCarroll/synthia/master/synthia.jpg" alt="Synthia loaded on a Raspberry Pi 3">
<em><div style="text-align: center">Synthia running on a Raspberry Pi 3 in front of a Bluetooth speaker</div></em></p>

<p>What Synthia will do that others cannot is use a camera pointed at your door to let you know when and who enters your home&mdash;and alert you when unrecognized persons are detected. Not only that, but Synthia will greet you and respond to your commands when you get home; from playing music to turning on smart-home lights. Synthia is going to be the digital doorman for your home.</p>

<p>Most importantly, Synthia is and will always remain <em>free</em>. Synthia is open source so that the maker community can extend and contribute to the project. Synthia was kickstarted at a <a href="https://devpost.com/software/synthia-oez751">Hackathon</a> with contributors Geoffrey Khorn &amp; Sarah Carroll.</p>

<p><a href="https://github.com/TomAlanCarroll/synthia">Synthia on GitHub</a></p>]]></content:encoded></item><item><title><![CDATA[Clustered Publish-Subscribe with Play, Akka, and WebSockets]]></title><description><![CDATA[<p>The <a href="https://www.playframework.com" target="_blank">Play Framework</a> has started to gain traction with developers in recent years. The low learning curve of Play makes it a breeze to get started on rapid application development. Let's have some fun by making an example event subscriber using Play.</p>

<p>To get started, download Play with Activator here:</p>]]></description><link>https://34.148.43.187:80/clustered-publish-subscribe-with-play-akka-and-websockets/</link><guid isPermaLink="false">650de286-cf25-48be-b579-e0cc85be4912</guid><category><![CDATA[Java]]></category><category><![CDATA[Scala]]></category><category><![CDATA[Play Framework]]></category><category><![CDATA[Akka]]></category><dc:creator><![CDATA[Tom Carroll]]></dc:creator><pubDate>Sat, 24 Jan 2015 14:43:00 GMT</pubDate><content:encoded><![CDATA[<p>The <a href="https://www.playframework.com" target="_blank">Play Framework</a> has started to gain traction with developers in recent years. The low learning curve of Play makes it a breeze to get started on rapid application development. Let's have some fun by making an example event subscriber using Play.</p>

<p>To get started, download Play with Activator here: <a href="https://www.playframework.com/download" target="_blank">https://www.playframework.com/download</a></p>

<p>Next, install Play by adding Activator to your PATH by following the instructions here: <a href="https://www.playframework.com/documentation/2.3.x/Installing" target="_blank">https://www.playframework.com/documentation/2.3.x/Installingdownload</a></p>

<p>Play allows you to code with either Java or Scala. For the purposes of this example, use Java by adding "play-java" to the activator command. Go to the parent directory of where you want to create your project directory and run the following commands:  </p>

<pre><code>activator new event-subscriber play-java
cd event-subscriber
activator run</code></pre>

<p>After Activator and Play finish downloading dependencies and starting, navigate your browser to <a href="http://localhost:9000" target="_blank">http://localhost:9000/</a>. The following screen should appear: <br>
<img src="https://raw.githubusercontent.com/TomAlanCarroll/event-subscriber/master/screenshot1.png" alt="Initial Play Website"> <br>
Your project's directory structure should look something like this:</p>

<pre><code>build.sbt
app
  └ controllers
  └ models
  └ views
conf
  └ application.conf
  └ routes
logs
  └ application.log
project
  └ build.properties
  └ plugins.sbt
public
  └ images
  └ javascripts
  └ stylesheets
test
  └ ApplicationTest.java
  └ IntegrationTest.java</code></pre>  

<p>Navigate to app/controllers and make a new controller named Events.java:  </p>

<script src="http://gist-it.appspot.com/github/TomAlanCarroll/event-subscriber/blob/master/app/controllers/Events.java?slice=29:62&footer=minimal"></script>  

<p>For this example, we only need one instance of a Publisher actor. However, we need a new instance of Subscriber for each client connected to the server. Navigate to app/models and define the Publisher and Subscriber actor models as follows:  </p>

<script src="http://gist-it.appspot.com/github/TomAlanCarroll/event-subscriber/blob/master/app/models/Publisher.java?slice=10:&footer=minimal"></script>  

<script src="http://gist-it.appspot.com/github/TomAlanCarroll/event-subscriber/blob/master/app/models/Subscriber.java?slice=13:&footer=minimal"></script>  

<p>In Publisher and Subscriber we are using <a href="http://doc.akka.io/docs/akka/snapshot/contrib/distributed-pub-sub.html" target="_blank">DistributedPubSubExtension</a> to allow for a clustered publish-subscribe system. To setup our cluster, add the following to conf/application.conf:  </p>

<script src="http://gist-it.appspot.com/github/TomAlanCarroll/event-subscriber/blob/master/conf/application.conf?slice=72:&footer=minimal"></script>  

<p>More cluster nodes can be added depending on the scale of your application. We do need to add a few dependencies to our build.sbt in order to compile our project:  </p>

<script src="http://gist-it.appspot.com/github/TomAlanCarroll/event-subscriber/blob/master/build.sbt?slice=8:16&footer=minimal"></script>  

<p>Next, let's add some routes to conf/routes so we can access the Events controller from the web browser:  </p>

<script src="http://gist-it.appspot.com/github/TomAlanCarroll/event-subscriber/blob/master/conf/routes?slice=4:8&footer=minimal"></script>  

<p>We will need some simple views to present our event data through WebSockets. Add jQuery to app/views/main.scala.html:  </p>

<script src="http://gist-it.appspot.com/github/TomAlanCarroll/event-subscriber/blob/master/app/views/main.scala.html?slice=5:10&footer=minimal"></script>  

<p>Create a new JavaScript file in <a href="https://github.com/TomAlanCarroll/event-subscriber/blob/master/app/views/event.scala.js" target="_blank">app/views/event.scala.js</a> and modify app/views/index.scala.html to resemble the following:  </p>

<script src="http://gist-it.appspot.com/github/TomAlanCarroll/event-subscriber/blob/master/app/views/index.scala.html?footer=minimal"></script>  

<p>Restart the server by running "activator run" again in the parent project directory. You can also add <a href="https://github.com/TomAlanCarroll/event-subscriber/blob/master/app/views/send.scala.html" target="_blank">another form view</a> to test out sending events to the publisher and see the following: <br>
<img src="https://raw.githubusercontent.com/TomAlanCarroll/event-subscriber/master/screenshot2.png" alt="Initial Event View"> <br>
<img src="https://raw.githubusercontent.com/TomAlanCarroll/event-subscriber/master/screenshot3.png" alt="Data exchanged between the Publisher and Subscriber"></p>

<p>All of the source code for this example is available here: <a href="https://github.com/TomAlanCarroll/event-subscriber" target="_blank">https://github.com/TomAlanCarroll/event-subscriber</a></p>]]></content:encoded></item><item><title><![CDATA[How to Check if a Huge Number is a Fibonacci Number]]></title><description><![CDATA[<p>A neat Mathematics questions is how to check if a number is part of the Fibonacci sequence. This formula defines the Fibonacci sequence (assuming <em>F</em><sub>0</sub> = 0 and <em>F</em><sub>1</sub> = 1): <br>
<img src="http://upload.wikimedia.org/math/0/c/e/0cebc512d9a3ac497eda6f10203f792e.png"><span style="font-size: 0.7em; font-style: italic; display: block">Source: <a href="http://en.wikipedia.org/wiki/Fibonacci_number">Wikipedia</a></span> <br>
There are a couple of approaches to solve this problem, including the use of <a href="http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html">Binet's formula</a> to</p>]]></description><link>https://34.148.43.187:80/how-to-check-if-a-huge-number-is-a-fibonacci-number/</link><guid isPermaLink="false">807f0711-44b8-4848-85a4-e822ca35263b</guid><category><![CDATA[Coding Problems]]></category><category><![CDATA[Java]]></category><category><![CDATA[TDD]]></category><dc:creator><![CDATA[Tom Carroll]]></dc:creator><pubDate>Sat, 10 Jan 2015 16:16:00 GMT</pubDate><content:encoded><![CDATA[<p>A neat Mathematics questions is how to check if a number is part of the Fibonacci sequence. This formula defines the Fibonacci sequence (assuming <em>F</em><sub>0</sub> = 0 and <em>F</em><sub>1</sub> = 1): <br>
<img src="http://upload.wikimedia.org/math/0/c/e/0cebc512d9a3ac497eda6f10203f792e.png"><span style="font-size: 0.7em; font-style: italic; display: block">Source: <a href="http://en.wikipedia.org/wiki/Fibonacci_number">Wikipedia</a></span> <br>
There are a couple of approaches to solve this problem, including the use of <a href="http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html">Binet's formula</a> to determine if a number is part of the Fibonacci sequence.</p>

<p>For now, let's start out by defining a simple test case to follow <a href="http://en.wikipedia.org/wiki/Test-driven_development">test driven development</a>. Since the Fibonacci sequence is infinite, we'll use Java's <a href="http://docs.oracle.com/javase/8/docs/api/java/math/BigInteger.html">BigInteger</a> class to handle numbers outside of the range of ints and longs.</p>

<pre><code class="language-java">@Test
    public void testIsFibonacciWithBigIntegers() {
        long startTime = System.currentTimeMillis();
        for (int i = 0; i &lt; TestData.fibonacciNumbers.length; i++) {
            assertTrue(Fibonacci.iterativeIsFibonacci(TestData.fibonacciNumbers[i]));
        }

        for (int i = 0; i &lt; TestData.nonFibonacciLargeNumbers.length; i++) {
            assertFalse(Fibonacci.iterativeIsFibonacci(TestData.nonFibonacciLargeNumbers[i]));
        }
        long endTime = System.currentTimeMillis();
        System.out.println("Completed iterative Fibonacci test in " + (endTime - startTime) + "ms");
    }</code></pre>

<pre><code class="language-java">public class TestData {
    public static final BigInteger[] fibonacciNumbers = {
            new BigInteger("0"),
            new BigInteger("1"),
            new BigInteger("1"),
            new BigInteger("2"),
            new BigInteger("3"),
            ...
    public static final BigInteger[] nonFibonacciLargeNumbers = {
            new BigInteger("9539593446744073709551615"),
            new BigInteger("7492050343423470955161623"),
            new BigInteger("7382950684327734869302126"),
            new BigInteger("2382132136549430123910054"),
            ...</code></pre>

<p>So now let's try the most obvious solution: iterate over the fibonacci sequence until we either exceed the number being tested or match it:  </p>

<pre><code class="language-java">public static boolean isFibonacci(BigInteger number) {
        BigInteger Fprevious = BigInteger.ZERO, Fn = BigInteger.ONE;

        if (number.compareTo(BigInteger.ZERO) &lt; 0) { return false; }
        if (number.equals(Fprevious) || number.equals(Fn)) { return true; }

        while (Fn.compareTo(number) &lt; 0) {
            BigInteger temp = Fn;
            Fn = Fn.add(Fprevious);
            Fprevious = temp;

            if (Fn.compareTo(number) == 0) {
                return true;
            }
        }
        return false;
    }</code></pre>

<p>This approach is far from ideal because every previous Fibonacci number must be iterated through. Another approach, proved by <a href="http://www.cs.swan.ac.uk/~csulrich/ftp/PhilJames1008.pdf">Phillip James</a>, is to verify at least one of these calculations is a perfect square: <br>
<img src="http://upload.wikimedia.org/math/b/d/2/bd245a80e5af65bfc4a6425b78f1a81b.png"> or <img src="http://upload.wikimedia.org/math/1/7/b/17b1ef01647990356d7c482933699f3c.png"> <br>
Let's try this out using Java's BigInteger class:  </p>

<pre><code class="language-java">public static boolean binetIsFibonacci(BigInteger number) {
        if (number.compareTo(BigInteger.ZERO) &lt; 0) { return false; }

        BigInteger product = number.pow(2), four = new BigInteger("4");
        product = product.multiply(new BigInteger("5"));

        if (BigIntegerMath.isSquare(product.add(four)) ||
            BigIntegerMath.isSquare(product.subtract(four))) { return true; }
        return false;
    }</code></pre>

<p><code>BigIntegerMath.isSquare</code> determines whether a given number is a perfect square using Newton's method. The source can be found <a href="http://mapreduce-integer-factorization.googlecode.com/hg-history/7bdcbb5870a57bf4e7701dd973d5db4069a31c19/java/com/javiertordable/mrif/FindSquaresReducer.java">here</a>.</p>

<p>Unfortunately, the need to calculate the square root slows down the Fibonacci check so severely that the Binet approach takes <strong>4 to 5 times longer</strong> than the above iterative approach as seen here:  </p>

<pre><code class="language-bash">Completed Binet Fibonacci test in     689ms
Completed iterative Fibonacci test in 150ms</code></pre>

<p>All source code is available here: <a href="https://github.com/TomAlanCarroll/coding-practice/tree/master/src/main/java" target="_blank">https://github.com/TomAlanCarroll/coding-practice/tree/master/src/main/java</a></p>]]></content:encoded></item></channel></rss>