Learning something new: WebGL

Recently I set out to learn something new: WebGL.
What is it? WebGL is OpenGL for the Web. It is a subset of standard OpenGL adapted to Javascript and the web browser. Why is it cool? You can build 3D applications that run in the most popular browsers on PCs as well as on Android and the iPhone.

In order to learn to program applications in WebGL look here. Its author adapted the NeHe OpenGL-Tutorials for WebGL. In addition the OpenGL ES 2.0 book is most helpful.

After going through the initial first six lessons of LearningWebGL I went out to adapt one of the examples to my style of writing. I especially wanted to have a more modular and object oriented program without many global variables. You are welcome to download it from here and try the spinning cube for yourself.

The next problem I thought of, was how to implement multiple textures. This led me to adapting lesson 10 of the LearningWebGL tutorials. Please find the result here.

A little webserver is included, since you cannot run the application from the file system. Find information on the very fast WSGI webserver here.

The learning curve was quite steep at the beginning, but it turns out to be quite worthwhile, considering what you can do with WebGL.

Posted in HTML5, WebGL | Leave a comment

Simulation Program for Management Training

Recently we finished an application for the Psychology Department at the University Bamberg: Antarctica, a computer simulation for management training. The program, completely written in Python on Linux is used on Windows XP and Windows 7 operating systems. As user interface toolkit the excellent wxPython library was used to realize perfect cross platform capability. In addition ReportLab was used for printed output. The program relies on data delivered via Excel-Files. Therefore the libraries xlrd and pyExcelerator were employed for reading and writing to and from native Excel-Files.

Posted in Python | Leave a comment

Python Mumble

Python has been my favourite programming language for almost 10 years now. I use it from simple scripts to manage files to several e-commerce applications encompassing dynamic web page creation and delivery, database access, web page scraping, desktop applications, 3D-games, low level protocol manipulation all the way to hardware control.
I have been using the excellent wxPython cross platform toolkit for several applications and it proved invaluable to develop under Linux (my favourite) and deliver under Windows (no comment).
Recently I have run into the following problem using wxPython. For a new application I selected the wxRichTextCntrl in order to be able to enter formatted text. WxPython includes a class to make printing of rich text relatively easy through class wxRichTextPrinting. This works, but it has a major disadvantage which almost turned out to be a show stopper: it calls the printer setup dialog automatically and unconditionally for each new print job. Since my application is about printing a lot of documents to several printers this is unacceptable. The reason for this behaviour can be found in the C++-implementation of class wxRichTextPrinting where wxPrinter::Print () is called with parameter prompt set to true. After some trial and error and reverse engineering of the C++ code I wrote my own method PrintBuffer resembling wxRichTextPrinting’ in behaviour:

class RTP (rt.RichTextPrinting):
     def PrintBuffer (self, buffer):
         rtpout = rt.RichTextPrintout (self.GetTitle ())
         rtpout.SetHeaderFooterData (self.GetHeaderFooterData ())
         rtpout.SetMargins (100, 100, 100, 100)
         rtpout.SetRichTextBuffer (buffer)
         print_data = self.GetPrintData ()
         print_dialog_data = wx.PrintDialogData (print_data)
         print_dialog_data.SetToPage (100)
         printer = wx.Printer (print_dialog_data)
         printer.Print (self.GetParentWindow (), rtpout, prompt = False)

The last line is what made the difference.
Then there was another problem: without printer dialog, no page was printed at all. I checked everything but found no clue. I tried Robin Dunn’s printing example from wxPython in Action – same problem. Then I tried the PrintFramework.py from wxPython-2.9.1.1/demo – with success. The difference was the SetToPage () call. That did it. In the above code I call SetToPage () with parameter 100. That is sufficiant for demonstration but certainly not great style and you should try to set it to the real page count.

Cheerio
Peter

Posted in Python | Leave a comment

What are the Practical Applications of Dörner’s PSI-Theory?

The PSI-Theory is a comprehensive theory of the human soul. It offers a model to build systems with capabilities approaching that of humans in numerous fields. Systems built based on the PSI-Theory will have a vast number of applications including:

  • autonomous robots
  • unmanned aerial vehicles (UAVs)
  • non player characters in computer games
  • simulation of human behaviour for training purposes (human factors training, serious games)
  • more intelligent software agents than currently available

The PSI-Theory’s provides a different path to building autonomous agents compared with the state of the art as described in Russell & Norvig’s Artificial Intelligence: A Modern Approach.

Posted in AMPSI, PSI3 | Leave a comment

Version 0.6 of AMPsi Adds Generalization and Abstraction

The new version 0.6 of AMPsi is online here. The agent is now able to learn from experience, generalize observations, abstract this knowledge and apply it to new situations. Whatever the agent sees, becomes part of the current situation. The agent’s vision system consists of a window of 5 by 5 elements of the world it lives in. Whenever a positive need (i. e. hunger or thirst) is satisfied or a negative experience (i. e. pain) arises, the agent stores this situation with the appropriate motive. This means that all situations in which hunger has just been satisfied are stored with the motive hunger. The same hold for motive thirst. Whenever the agent experiences pain (i. e. a negative motive), the situation is saved with this motive as well.

Later, when the agent feels hunger or thirst, it looks up all situations, where this motive was satisfied before and tries to go the same path to where that motive had been satisfied before. (Abstraction is not built in here yet.)

In each step, the agents looks at the current situation (function percept) and compares it to general patterns of situations that have caused pain before. This is impossible in the beginning because the agent doesn’t know, what to look for. Even after very few occurrences of pain it is not able to generalize the situations. This is especially more difficult (than finding situations satisfying hunger or thirst) because pain is induced by more than one feature: whenever the agent tries to eat or drink one of the characters ‘P’, ‘Q’, ‘R’, ‘S’ or ‘T’, it leads to pain. However, after several (painful) experiences, the agents has learned the pattern, abstract from it and avoid painful food in unknown situations reliably later on. This can be observed very nicely in the pain section of the graph.

Posted in AMPSI, PSI3 | Leave a comment

Version 0.5 of AMPsi

The latest version of the AMPsi human behaviour simulator can be found on the new project page.
An initial version of an AMPsi book is released and available for separate download.

The system is now more generalized. Situations are compared through special similarity function. As in previous releases AMPsi does not remember coordinates but stores situations “visually”, that is based on its contents.

Posted in AMPSI, PSI3 | Leave a comment

Version 0.4 of “AMPSI” the Human Behaviour Simulation System

Version 0.4 of the, now renamed AMPSI, has been uploaded. You can find it here. Rename became necessary after I found out that there is another program (for a completely different purpose) called ‘psi3′.
Both the world server “welt” as well as the client “ampsi” received an improved user interface.
Welt can display an arbitrary number of ampsi instances. Each instance has a different color to distinguish them. With the menu “Psis” you can hide instances which are not active.

The client’s interface received a marker bar. Klick anywhere in the graph, but within the lifetime of the current instance of psi to turn on the red marker bar an open the detail window. Move the marker bar with your mouse.

The detail window shows information on the particular psi cycle.

Have fun with the new release.

Peter

Posted in AMPSI, PSI3 | Leave a comment

PSI3 feels pain

Release 0.3 (20101001) is available here.
The new motive “pain” was introduced. As opposed to “hunger” and “thirst”, “pain” is a “negative” motive. PSI3 tries to avoid pain. PSI3 remembers situations where it felt pain an avoids these situations later. Pain is experienced, when PSI3 eats or drinks something “bitter” or “poisonous”. Look at the graph to see what it means.
As always: have fun with this version of PSI3.

Posted in PSI3 | Leave a comment

Release 0.2 of PSI3

The second release of PSI3 is available in the download area.
Now the program is split up: there is a world server called “welt.py” and a PSI3 server called “psi3.py”. Run “welt.py n 1″ in order to create a new world for one PSI3. Run “welt.py n 3″ to create a new world for three PSI3s. A new world file “welt” is created, that keeps the status of the world and the PSI3s. After initialization just call “welt.py” to start the world server with the current “welt”. World server and client communicate via the shared file “welt”.
Start as many PSI3s as you have initialized the world for. You can start, stop and restart the PSI3s at anytime without touching the running world server. The world server shows your PSI3s living in its world.
The PSI3s have been modified as well. After birth, they don’t know anything about their operators or how to satisfy their needs. The PSI3s have the four operators “move_left”, “move_right”, “move_up” and “move_down” just like in the previous version. Besides they have the two operators “eat” and “drink”. However these two have no connection to the two motives “Hunger” and “Thirst” – the PSI3s will have to learn that – and they do.
Fire up the world and give birth to a PSI3 and follow the graphs. Very soon you will see that PSI3 mostly follows its automatisms (called “auto”), rather than blindly exploring the world to find something to eat or to drink.
Give it a try and have fun.

Posted in PSI3 | Leave a comment

A new PSI Implementation: PSI3

Today I would like to introduce a new PSI implementation called PSI3.
I have begun to write a new version of PSI from scratch. It is written in a modern language, Python and will have a lot of new features compared to Dörner’s original PSI implementation.
I have only just begun, so there is not much to see, yet.
PSI3′s world consists of a rectangular area of uppercase letters and blanks.

In this world, PSI3 is at the position depicted by the position of the black square encompassing the 5 by 5 character area in the screenshot. At the same time, this is exactly what PSI3 sees. PSI3 can move around in this world of letters on character position or on line by one. PSI3 always sees a 5 by 5 character area of the world.
PSI3 has two motives: hunger and thirst. PSI3 needs water and food (energy) to survive. PSI3 finds new energy in its world in the letters ‘W’ for water and ‘E’ for energy. PSI3 cat ‘eat’ letters ‘E’ or drink letters ‘W’ thereby satisfying hunger and thirst respectively.
Immediately after PSI3 is born, it knows that in order to satisfy hunger or thirst, it needs to eat ‘E’ or drink ‘W’. However it doesn’t know where to find them.
When PSI3 enters its world it immediately starts to explore it. It uses its four operators move_left, move_right, move_up and move_down to move about. All actions are recorded in memory as a protocol. Situations, that is PSI3′s views, the 5 by 5 matrices, are stored as well, with pointers from the protocol node to the situation.
When PSI3′s levels of hunger or thirst have risen above a certain threshold, PSI3 tries to eat ‘E’ or drink ‘W’. If nothing can be found at the current position, PSI3 tries to remember previous occurences of need satisfaction. If PSI3 doesn’t know of previous places of satisfaction, it just continues to explore the world, trying to find something edible or drinkable in the next cycle. If PSI3 remembers one or more places of satisfaction, it tries to find a path to these places using breadth first search: it starts to execute an ‘automatism’ as Dörner
calls it. (This is erroneously called a plan in the initial program version 20100923.) This automatism is followed until the current motive is satisfied or another motives overrides and becomes the determining motive.
PSI3′s world regenerates itself after a while: that is, if PSI3 came by and ate or drank something (‘E’ for energy’ or ‘W’ for water), after a while the ‘E’ grows again and water ‘W’ is fills up by itself.
In order to see what’s happening inside of PSI3, an information screen is provided:

This information screen consists of three vertical sections, from top to bottom: the hunger section, the thirst section for the two motives respectively an a general section showing exploration behaviour.
Each motive section consists of a curve show the level of the motive. The yellow vertical line is a threshold value above which PSI3 notices the need. After a need is satisfied it falls back to zero. The lines called “Hunger: follow plan” shows red markings, when PSI3 follows an automatism. The same goes for “Thirst: follow plan”. The last line “no new operators left”, means, PSI3 has no new, untried operators left in the current situation (while exploring, PSI3 usually tries to use an operator it has not tried before – until it runs out of new operators).

So, go ahead and try it out! Look at the source code and improve it. To run PSI3, you need a version of Python (I use Version 2.6.5) as well as wxPython. Download the source code from here, unzip it and run psi3.py. Have fun.

Posted in PSI3 | Leave a comment