Using Python (or general external scripts) in LIONoso

This page is about using LIONoso to "glue together" different components written in scripting or compiled languages (Python, C or C++, etc.), define complex processes and coordinate them, visualize results.

It was created as support to the LFD Caltech course by Yaser Abu-Mostafa, but is valid inpependently of the course. Yaser's course is not about giving you pre-digested baby food, but about strengthening your teeth. You can use programming languages of your choice (including Python) for the core part of the homework and then connect modules to LIONoso for visualizations, plots, orchestration of complex processes, more advanced and open-ended explorations.
Here we give a skeleton of a Python script for Homework 1 / exercise 7 (due Oct 3) . We provide a stub (a placeholder) for you to insert your Python Perceptron Learning Algorithm code.
What you can do in Python, you can do with other languages, either interpreted or compiled. Here you can find the same skeleton, this time written in C.

If you are a happy Python user remain on this page, if you have an insatiable thirst for the exact specifications about using external scripts in LIONoso (e.g., if you want to use different languages) continue here.

Before proceeding, be sure to have Python installed on your computer, otherwise you will not be able to run the script.

Connecting your Python script to LIONoso

You can download a template script here, containing the basic structure, you need to complete it with your perceptron implementation.

LIONoso works with internal tables (derived from CSV files). We need a tool which can take the parameters of the experiment as input and produce a table containing the results. This is called Parametric table. You can load the script by dragging a Parametric table element into the workbench, and specifying the filename of your script.

In the above figure we just loaded our skeleton (Exercise1-7a.py). Please see the notes for Windows users below if the script doesn't work on Windows.
Depending on the script content, in the left panel you can specify the parameter values, in our case the number of experiments to perform (default 1000) and the dimension of the training set (default 10).

By clicking the "Compute" button, the script is launched and a table containing the results of each experiment is produced. The script outputs the number of iterations and the disagreement reached in each experiments. Beware: data in the skeleton are randomly generated. Your perceptron will produce different data.

To compute the average of the results you can open a Bubblechart from the output table and drag the "Iteration" column on the y axis. Then select the "Advanced properties" tab in the left panel and select "Show polynomial fit" with 0 degree. A red line will appear on the plot showing the average value.

Notes for Windows users

While on most UNIX-based systems (such as Linux and Mac OS X) it is possible to declare the script interpreter in the top line of the script, Windows bases the choice of the interpreter on the filename extension. There can be two types of problems:

  1. The interpreter is installed, but it did not register the file extension (as it happens, e.g., with R)
  2. A specialized application “stole” the file extension and is executed in place of the interpreter (as it happens, e.g., with Canopy, which appropriates the .py extension of Python)
In these cases, it is possible to execute the script from within LIONoso by providing a “wrapper shell script”. In the Python case, use a text editor (e.g., Notepad) to create the file Exercise1-7a.bat containing the following text:
        @echo off
        C:\Python27\python.exe Exercise1-7a.py %*
where C:\Python27\python.exe must be replaced by the path of the python.exe executable in your system. Next, import this file in the Parametric table.