Technology

Machine Learning and the Curiosity Engine

The Future

As we progress technologically, there is an increased focus on machine learning.  That is a machine that is not necessarily programmed with the algorithm to solve a problem, but one that has been programmed with the ability to take a given set of input, classify it, and generate an answer.  This is achieved via supervised, unsupervised, or reinforced learning techniques.  My background in this field is creating neural nets and I am more that a bit rusty so for more on topic of machine learning see wikipedia.  I believe machine learning to be only half of the equation to achieve true AI.

Achieving True AI

Machine learning still requires a human to create the learning data set, expected results, and training algorithm.  This is an incomplete view of what is necessary to achieve true artificial intelligence.

  • We must teach machines how to learn a new general task using its current capabilities and apply that to future tasks.
  • We must teach machines how to incorporate new capabilities and algorithms into themselves.
  • We must teach machines a process to learn new tasks with little or no user input.
  • Above all, we must teach machines how to be curious.

The Curiosity Engine

As living, breathing creatures it is our curiosity that drives us to learn new things.  It is how we learn to do anything new from walk to drive to fill-in-the-blank.  I believe that Machine Curiosity is critical to the future of AI.  Once we figure it out, the possibilities are endless.  So this raises a good question, how do we teach machines to be curious?  I don’t think that anyone really knows the answer to that question.  Here, however, are some possibilities.

  • Mimicking –  While mimicking is a learning method, maybe it can help with curiosity too.  The machine could analyze behavior, identify behavior that it doesn’t know, then attempt to mimic the behavior.  This could be considered a crude form of machine curiosity by itself.
  • Chaos (random combinations of known abilities) – Another crude form of curiosity. The machine simply pairs capabilities in the attempt to do something new.  This is brute force, and might take along time to create useful abilities.
  • Observation – The machine selects observed capabilities and applies its current capabilities to it in order to learn about the expected results.  The machine would need a way to create new analytical capabilities.
  • …  Many many more methods …
  • A mix of the above – All of the above can be combined into one curiosity engine.  This method has the potential to be the most efficient since it will make intelligent use of all other methods.
Posted by Chad Dotson in Key Concepts, Technology, 0 comments

Becoming an Entrepreneur as a Software Engineer Vol 1

This is the first post in what I plan to be a series.  In these posts, I will explore ideas in entrepreneurship.  It’s a given that working for yourself, while it brings many risks, can bring many rewards.  I believe that it is one of the only ways to achieve freedom from the daily grind and to meet long term financial goals.

Benefits Of Working For Yourself

  • Achieve – The sky is the limit.
  • Vision – Your the one with the vision (for the company and/or product).
  • Destiny – You make your own destiny.
  • Freedom – You call the shots.
  • Profit – As owner, you reap the rewards.

What I Think Works

My thoughts on what works will probably change a lot over time, but currently I think one of the best ways to become a successful entrepreneur is to develop applications, websites, devices, etc that are an improvement to a larger company’s product in the hopes that they buy out your company.  For example, $10 million is a lot for an individual working the daily grind, but pocket change to large corporations.  Buying other companies is at the heart of how Apple, Google, Microsoft, Facebook, or any other major companies acquire new technology and features so it definitely works for some people.  Think of whatever your company is bought for as excellent seed money into the next.  The big “but” here is don’t undersell either.  If you can see a larger valuation for your company/product, stick with it and don’t take a buyout.

What Doesn’t Work – Writing Books

Apparently, writing books isn’t as profitable as you would think.  If you listen to the Entreprogrammers podcast, you’ll hear just how much they make on their books.  While I don’t remember the exact numbers they say, it wasn’t a lot (only a fraction of a good year’s salary).  It’s enough to make me think that unless you are some big publishing company its simply not worth your time and effort.

Posted by Chad Dotson in Programming, Software Engineering, Work, 0 comments

My Swift App – An Ongoing Experiment

Work is progressing on my first iOS app written in Swift.  I think that I might have a rudimentary alpha product ready to start testing in a few weeks.  Based on my experience with it so far, here are some of my thoughts, observations, and concerns.

  • Developing in Swift is as the name implies, “Swift.”  I didn’t know anything about Objective-C nor Swift before I started my app and I think I’m making decent progress given the amount if time I’ve had to work on it.  Given proper resources, I believe its possible to progress Swift apps from concept to production in a matter of weeks.
  • Language resources (documentation and examples) are still pretty sparse.  Get ready to learn a little Objective-C if you need help with API calls because that is where the majority of the help you will find will be.
  • The iOS 8 Simulator doesn’t save location privacy settings,  That means that every time you run an app that requires location privileges, you have to edit the settings again.  Based on what I’ve read, this issue has existed for some time in the beta code.
    This was due to user error.  You have to use either the location manager’s requestWhenInUseAuthorization or requestAlwaysAuthorization functions paired with the right entries in your projects Info.plist file.  The reason mine wasn’t working was I had erroneously edited the plist file associated with the unit tests.

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Use location when open?</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Use location always?</string>
  • Perhaps the biggest issue is that Xcode cannot refactor Swift code.  To me this seems like a giant shortcoming of the editor.  Hopefully Apple will push an update soon to correct this.
  • While storyboards are powerful, some of the functionality is not so discoverable.  The auto-layout functionality took me awhile to find and not without searching the net.  I think they maybe onto something, but I do tend to like the way Visual Studio makes similar functionality “findable” from the properties panel.
  • As of Xcode 6.0.1 and iOS Simulator 8.0, AVSpeechSynthesizer doesn’t appear to work at all.
    var mySpeechSynthesizer:AVSpeechSynthesizer = AVSpeechSynthesizer()
    var myString:String = "This is a test."
    var mySpeechUtterance:AVSpeechUtterance = AVSpeechUtterance(string:myString)

    When executed in the iOS simulator, the code results in “Speech initialization error: 2147483665”.  I’ve seen a few work arounds on the net, but I don’t believe any of them actually work in Swift.

Posted by Chad Dotson in Programming, Software Engineering, 2 comments

Swift – A Quick First Impression

Swift and Xcode 6

Late last week Apple released Xcode 6 to the general public.  I’ve been waiting for the opportunity to try out Swift, so I started working on an idea I’ve had.

General Thoughts

This is probably a general iOS development comment, but the way you link items on the storyboard to class members seems odd to me (having done a lot of C# development in the past).  However, it does have its advantages.  Counter to the Microsoft environment, it does seem to encourage better design and discourage the worse of some bad habits.

Compared to Android

Its been awhile since I worked with Android, but when I did developing for the platform was disastrous.  Setup of the environment (Eclipse) and the emulator was time-consuming and not so straight-forward.  With Xcode, its all on rails.  You can have a “Hello World” app up in the simulator in 2 minutes.

Problems

The language does seem to be a little wordy at first glance maybe that opinion will get better as I get more experience with it.  While the official Apple documentation is now complete with Swift equivalents to Objective-C,  examples both official and third party are pretty few and far between it seems.

To be continued…

Posted by Chad Dotson in Programming, 0 comments

DSLR Lightning Trigger

June 15, 2011 Lightning CompositeLightning

I use my Nikon D5000 to take a lot of lightning photos.  This one to the right is a composite of several taken during a storm that produced a good amount of of photogenic lightning a few years back.  The photos that make up this one and many of my others were created using timed exposures of up to 30 seconds on length.  This is problematic, at times, due to other light sources, camera movement, etc.  Using simple, arduino-based circuit, we can create a device that will attempt to detect lightning strikes and trigger a camera shutter when one is detected.

Prototyping The Circuit

This circuit consists of 2 major pieces: lightning detection and shutter triggering.  To detect lightning, a phototransistor or photoresistor is required.  For this project, I used a photoresistor.  To trigger the shutter, a 940nm infrared LED is required.  These LEDs can be used to trigger cameras from Nikon, Canon, Pentax, Olympus, Minolta, Sony and possibly others.  Below is the complete parts list I used along with links to them on Amazon.

Components:

  • Arduino UNO R3 (buy)
  • Photoresistor 5mm GM5539 (buy)
  • 940nm Infrared LED (buy)
  • Yellow LED (buy)
  • 1 – 200 Ω Resistor (buy)
  • 1 – 100k Ω Resistor (buy)
  • Miscellaneous jumpers and breadboard (buy)

 

The Code

This circuit’s method of detecting lightning with a photoresistor is pretty simplistic.  It simply loops infinitely recording the analog input from the photoresistor, taking the difference of it to the saved value, and comparing that to the configurable threshold.  In its current configuration, it will take 2 photos per lightning strike.  This is the first iteration of this code, so I may change it to use a moving average instead of just the last recorded value.

To fire the IR LED in the right sequence, I used the Multi-Camera IR Control Library since it supports my Nikon D5000.  In addition to the D5000, this library supports Nikon, Canon, Pentax, Olympus, Minolta, and Sony cameras. If you don’t have a camera that is supported, a custom interface could easily be created with specifics for your camera model.

#include <multiCameraIrControl.h> 

int shutterPin = 13; 
int triggerPin = 0;
int threshold = 5;
int savedLightningValue = 0;
int currentLightningValue = 0;
int delayBetweenShots = 1000;
 
Nikon D5000(shutterPin);

void setup() {
  Serial.begin(9600);
  pinMode(shutterPin, OUTPUT);
  digitalWrite(shutterPin, LOW);
  savedLightningValue = currentLightningValue = analogRead(triggerPin);
}

void loop() {
  currentLightningValue = analogRead(triggerPin);
  Serial.println(savedLightningValue, DEC);
  
  if(abs(currentLightningValue - savedLightningValue) > threshold) {
    Serial.println("Triggering shutter");
    D5000.shutterNow();
    delay(delayBetweenShots);
  }
  savedLightningValue = currentLightningValue;
}

 

To The Field

Since the protoype is fully functional, I plan on fielding it during the next thunderstom.  I will report back once I see how it works along with any refinements.

Resources

As always, I have placed the code and diagrams for this project in a github repository.  It includes code that can be compiled and uploaded via the Arduino IDE and diagrams that can be viewed or edited with Fritzing.

Other Posts in this series:

Posted by Chad Dotson in Arduino, Hobbies, Photography, Programming, Raspberry Pi, Software Engineering, Technology, 8 comments

Comparing Node.js and Python on the Raspberry PI

Picture of my simple led circuit connected to the Pi.

Picture of my simple led circuit connected to the Pi.

Programming on the Raspberry Pi

Python seems to be the more popular language for writing programs on the Raspberry Pi.  However, it is far from the only language: Python, C, C++, Java, and Ruby are some that are automatically supported out of the box.  As it turns out Node.js is also supported.  Perhaps, just based on my preconceptions, I didn’t originally consider JavaScript when interfacing directly with hardware.  The goal of this article is to compare functionally equivalent sample programs written both in Python and JavaScript.

 

The Goal

I decided to make the scope of the problem created for this article as small as possible.  Given that the goal will be to create simple circuit diagram consisting of a LED and then to write a program that makes the LED flash for a specified period of time.

 

Simple LED circuit diagram

Simple LED circuit diagram

Hardware

With the Pi, a circuit that will make a LED flash is relatively simple: Consisting of just a LED and resistor.  I arbitrarily selected pin 7 on the Pi for this build.  I’ve included a diagram of it on this page.

 

Software

As the goal states, the following two implementations do nothing except toggle an LED at half the specified duration (0.5s) and automatically shutoff after 60 seconds.

 

Python

Since Python is the more traditional programming language for the Raspberry Pi, let us start with it.  The Rpi.GPIO module I used can be installed via pip.  Before you read the code sample, let me point out some things about the implementation.  Could it have been done simpler given that the problem was just to make the LED flash for a certain amount of time?  Yes, but I wanted to create something of an asynchronous process that could be controlled from outside its execution context.

import RPi.GPIO as GPIO

from threading import Event, Thread, Timer

class ImprovedThread(Thread):
    def __init__(self, *args, **kwargs):
        super(ImprovedThread, self).__init__(*args, **kwargs)
        self._stopEvent = Event()

    def stop(self):
        self._stopEvent.set()

    def is_stopped(self):
        return self._stopEvent.isSet()

    def wait(self, duration):
        self._stopEvent.wait(duration);


class LEDFlasher(ImprovedThread):
    def __init__(self, pin, duration):
        super(LEDFlasher, self).__init__(target=self._flashLED)
        self.setDaemon(True)

        self._pin = pin
        self._duration = duration
        self._state = False

        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(self._pin, GPIO.OUT)

        self.start()

    def _flashLED(self):
        while not self.is_stopped():
            GPIO.output(self._pin, self._state)
            self._state = not self._state
            self.wait(self._duration/2)

flasher = LEDFlasher(7, 0.5)
Timer(60, flasher.stop).start()

flasher.join()

GPIO.cleanup()

 

JavaScript

I used pi-gpio to interface with the GPIO on the Pi in JavaScript.  It can be installed via npm. It makes use of gpio-admin so that your script doesn’t have to run as sudo.  Follow the installation instructions provided here and it should get you setup.  Note that due to differences int the languages, it was not necessary to thread (web workers) the solution.

var gpio = require("pi-gpio");

function flashLED(pin, duration) {
    return setInterval(function() {
        gpio.open(pin, "output", function(err) {
            gpio.write(pin, 1, function() {
                setTimeout(function() {
                    gpio.write(pin, 0, function(err) {
                        gpio.close(pin);
                    });
                }, duration/2);
            });
        });
    }, duration);
}

var intervalID = flashLED(7, 500);

setTimeout(function() {
    clearInterval(intervalID);
}, 60000);

 

The Findings – I was surprised

When I started writing the JavaScript side of this article, I was mainly doing it to gain experience working with JavaScript on the Pi.  I did not expect to come out of it vastly preferring it over my python implementation.  I find the Python implementation above to be to wordy and overcomplicated.  It just seems that the amount of code needed to achieve the same results is excessive.  Perhaps this is because of the problem scope and implementation.  The problem posed here was a simple one, where a functional solution is superior to an object-oriented one.  Could the Python code above be rewritten into something a bit more functional? Sure!  Are there problems that an object-oriented Python or JavaScript implementation would be the better solution for?  Definitely.  The lesson to take away: be open to working outside your comfort zone and pick solutions to problems based on their fit for the problem not your comfort level with them.

I’ve created a copy of the code as a Gist that is available here: https://gist.github.com/chaddotson/570501a3e3dcfe8928c8

Posted by Chad Dotson in Key Concepts, Programming, Raspberry Pi, Software Engineering, 8 comments

Everyone’s A Coder

Question:

Are we headed to an era where everyone should know how to write at least some rudimentary code?

 

Learn to Code

Today, there are many sites on the internet offering to “teach you to code.” Two of which are KhanAcademy and CodeAcademy.  These sites offer a selection of topics that can be worked through in the span of a few hours.  Can it be done?  Sure.  Matter of fact, I think they are good resources to get you started.

Differentiating Computer Science

Computer science is more than just coding.  Wikipedia defines computer science as the following:

Computer science is the scientific and practical approach to computation and its applications. It is the systematic study of the feasibility, structure, expression, and mechanization of the methodical procedures (or algorithms) that underlie the acquisition, representation, processing, storage, communication of, and access to information, whether such information is encoded as bits in a computer memory or transcribed in genes and protein structures in a biological cell. A computer scientist specializes in the theory of computation and the design of computational systems.

Simply put, Computer Science is more than programming, though most computer scientists do write code.  On the topic of code, colleges don’t so much focus on languages as they do the theory, math, and algorithms.  This allows graduates to quickly assimilate new languages and ideas.

Does a product (or code) have to be perfect?

The answer is a pretty resounding “No,” but bad or inefficient design might harm long term viability.  In terms of a startup, I’d say a Software Engineer should become involved soon after completion of the MVP if not before.

Can everyone be a coder?

Yes!  I believe that in the future everyone should know how to write at least some code.  Right now, JavaScript and Python are the best candidates that could be learned by all.  With it leaning in JavaScript’s favor with Node.js.  Though, if you have serious aspirations to getting a career writing code, I suggest a formal degree.

 

Posted by Chad Dotson in Software Engineering, 0 comments

Project Excelsior – Technology Update

current_stack

Current Project Excelsior Technology

For the past month or so I’ve been working on a little side project that I’ve dubbed “Project Excelsior.”  I’ve not had an abundance of time to spend on it over the past few week, so I’m just now wringing out some of the technology stack.  I’ve almost decided completely on the MEAN stack.  I’m close enough to a final decision that I’ve started prototyping the server side.  I’ve not worked with angular before, but I am familiar with ember and backbone.

 

Posted by Chad Dotson in Diversions, Programming, Software Engineering, Technology, 0 comments