Total Pageviews

Tuesday 12 July 2016

HTM Engine example application

HTM Engine example application: live NYC traffic anomaly detection.
This application has two or more parts.

1. HTM Engine Python Server

This server runs NuPIC within the HTM Engine. You must follow those installation instructions before this will work. Then you should start the server with supervisord (see the README).

2. Node.js Client Application

This fetches the data, controls the HTM Engine via HTTP, pipes in mountains of data, displays results in webapp.

3. River View Traffic Data Service

This application is using a data service called River View, which is currently running at http://data.numenta.org. It provides temporal data within a 6-month window, which includes NYC traffic data.
HTM Engine Traffic Demo Architecture

BUILD YOUR OWN

This project started with a fork of the skeleton-htmengine-app. That project is a great place to start if you want to create your own HTM Engine instance. All you really need to change is the MySQL database name and RabbitMQ queue names.

Requires:

Also, if you want to view the map of all the traffic paths (at http://localhost:8083/map) you'll need a Google Maps API key.
export GOOGLE_MAPS_API_KEY=<your key>

Startup

Install and Start HTM Engine (Python)

Read and follow python-engine/README.md, then continue with the directions below.

Start HTM HTTP Server (Python)

This provides a simple GET/POST/PUT HTTP interface on top of the HTM Engine, which is really useful if you don't want to write your HTM application in python. HTM services must be running in supervisor for this HTTP interface to work properly.
cd python-engine
python webapp.py
This will run at http://localhost:8080.

Install HTM Client (JavaScript)

cd node-client
npm install .

Start HTM Client (JavaScript)

npm start
This will run at http://localhost:8083.

Runtime

Immediately after startup, the Node.js client application will start pulling traffic data from River View and pushing it into the HTM Engine. A model is created for every traffic route available. For example, traffic path "1" contains traffic data for "11th ave n ganservoort - 12th ave @ 40th st" in Manhattan. This correlates to an HTM Engine model named "1". You can see the raw data for this model by querying the Python HTM Engine HTTP wrapper athttp://localhost:8080/1. You should see a bunch of text data in the response.
from https://github.com/htm-community/htmengine-traffic-tutorial
-----------
This HTM Engine application was built from the Skeleton HTM Engine App. It is like a scaffolding with an HTM Engine ready to run after a few configuration changes. It is the place to start if you want to create a new HTM Engine application. See its README for more details.

Setup

1. Install and Start Required Services

Install the following services appropriately for your environment:
Go ahead and start the MySQL server and RabbitMQ, but not Supervisor.

2. Install HTM Engine and NTA Utils

You'll need to install nta.utils, which is a dependency of htmengine:
cd numenta-apps/nta.utils
python setup.py develop --user
Then you can install htmengine in development mode:
cd numenta-apps/htmengine
python setup.py develop --user

3. Install Required Python Modules

Now, back in your htmengine-traffic-tutorial directory:
pip install -r python-engine/requirements.txt

4. Set APPLICATION_CONFIG_PATH in your environment

The APPLICATION_CONFIG_PATH environment variable must be set, and point to the htmengine-traffic-tutorial/python-engine/conf/ directory. For example, if you're in the the htmengine-traffic-tutorial directory:
export APPLICATION_CONFIG_PATH=`pwd`/python-engine/conf

5. Create a MySQL database

For this tutorial, we'll be using a database called traffic:
mysql -u root --execute="CREATE DATABASE traffic"

6. Apply database migrations

This will set up the traffic database by creating the appropriate table schema for the application.
Again, from the htmengine-traffic-tutorial directory:
python python-engine/repository/migrate.py

7. Update Two Config Files

In python-engine/conf/supervisord.conf, there are two places where absolute paths need to be updated. Look for the string /Users/mtaylor/nta/ and replace with your local path to your htmeengine-traffic-tutorial checkout.
In python-engine/conf/model-checkpoint.conf, update the storage.root value to point to a directory within your own file system. If this folder does not exist, it will be created.

8. Start services with supervisor

This time, you must be in the htmengine-traffic-tutorial/python-engine directory:
cd python-engine
mkdir logs
supervisord -c conf/supervisord.conf
At this point, the core htmengine services are running. You can see the supervisor status at http://localhost:9001/ or by running supervisorctl status.
To stop supervisord services, run supervisorctl stop all.

Continue

The HTM Engine server is now running. You may now continue setup within the primary README of this repository.

from https://github.com/htm-community/htmengine-traffic-tutorial/tree/master/python-engine