Creating neurons – desynchronized activity

Toying with neural networks can be quite a painstaking process, especially when trying to use these within an artistic context. Usually you end up frying your brains with the overload of mathematics. To counter this, I am trying a totally new approach:

I will look at the brain from a more physical point of view: Neurons, axons, synapses, etc.. What I would like to achieve is the possibility to simulate for instance drug intake into a virtual brain.

What has always bothered me about neural networks, is the way in which electric impulses are synchronized. To counter this, I will aim to simulate each neuron by using physical properties. In this first test, electrical impulses are travelling down the axon, thus arriving at different times at different neurons. Another side-effect is that I can create some nice visualizations.

Firing axons:

And here some dendrites receiving impulses that are travelling towards the nucleus.

Posted in Uncategorized | Tagged , , , | Comments Off

Drawing pixels with javascript: An animated voronoi

For about 20 years I have managed to avoid javascript for interactive and animated content. So far I have used flash, director and java. But now with the coming of HTML5, I am starting to like this (old) option. Desktops are fast enough to render javascripts directly to screen.

The example uses Canvas and the getContext() method. Here we see 350 x 350 = 122500 pixels being calculated on every frame. The pixels are coloured depending on their distance to the moving points. The result is an animated Voronoi.

Feel free to play with the settings below the animation. The source javascript is also available for download.

Your browser does not support the HTML5 canvas tag.

Posted in Research, Uncategorized | Tagged , , | Comments Off

Markov Chain – the implementation

This article builds on the previous article Markov Chain – or how to predict the future. Assuming that one understands the basics of the Markov Chain, I will describe an implementation using the programming language processing.

Generating the Markov Chain

To generate the Markov Chain, we will need some source data to generate the Markov Property. One can use for instance statistic on web browsing, musical notes, events of the day, letters or words. Any chain of events that expose a certain predictability will do. In our example we will use words, since language is something we all understand.

We will implement the following strategy:

  1. Load a text and turn it into a single lowercase string.
  2. Extract sentences using the dot(.), question-mark(?), exclamation-mark(!) as sentence separator.
  3. Remove any special character (those that are not letters or spaces).
  4. WordList: Create a list containing all words. If a word appears several times, this list will contain the word several times.
  5. ComboList: Create another list containing all 1st degree word combinations (i.e. “hello there”).
  6. Generate your first word by picking a random word from the WordList. (i.e. “and”)
  7. Make a sub list of all combinations that start with the previous word. (i.e. “and then”, “and he”, etc..)
  8. Create a new word:
    a. If the sub list contains items, pick the last word of a random combo. (i.e. “and then”)
    b. If the sub list is empty, pick a new random word

  9. Go to 7 using the new word (repeating as much as you want)

If you would want to create proper sentences with a beginning and and ending, we would have to implement three more things:

  • Create a list of words that are only at the beginning of sentences to be used in (6).
  • In (2), add the dot(.) at the ending of each sentence seperated by a space to be identified as a word.
  • In (9) we would have to repeat until the last generated word would be a dot.


1. Load text and turn into a single string:

String[] allLines = loadStrings("bbe_noChap.txt");
StringBuilder sb = new StringBuilder();
for (int i=0;i<allLines.length;i++) {
  sb.append(allLines[i].toLowerCase()+" ");
String fullText = sb.toString();

2. Extract sentences

String[] allSentences = fullText.split("[\\.?!]");

Ok, that looks simple, but What The Fuck? \\.?! The String.split() function splits a String into an array of Strings using a give text pattern. For instance “1-2-3″.split(“-”) will result in an array of Strings containing “1″, “2″ and “3″.

Note that the text pattern is interpreted as a regular expression. The use of regular expressions is a powerful tool for matching text patterns. In our case the String “[\\.?!]” just splits the string using any of the above characters. Since the dot(.) is special character in regular expressions, we need to escape it using to backslashes.

3. Remove any special charaters.

If we don’t want to have words like “man,”, we need remove these special characters from our sentences. Another regular expression is used to replace anything that is not a letter or a whitespace with an empty character. The expression “[a-zA-Z]” stands for any character. “\\s” stands for the white space. The “^” character negates the expression.

NOT ( a to z OR A to Z OR whitespace )
[^ a-z A-Z \\s ]

for (int i=0;i<allSentences.length;i++) {
  allSentences[i] = allSentences[i].replaceAll("[^a-zA-Z\\s]","");

4. Create a list containing all words.

Now we will create the ArrayList containing all words. Because there might be an empty space here and there, we will not add this to our list.

ArrayList allWordList = new ArrayList();
for (int i=0;i<allSentences.length;i++) {
  String[] words = allSentences[i].split(" +");
  for (int j=0;ji<words.length;j++) {
    if (!words[j].equals(" ")) {

5. Create a list containing all 1st degree combinations.

Very similar to 4, but instead we are extracting word pairs. A sentence like “Markov Chains are fun” would result in the array of Strings “Markov Chains”, “Chains are”, “are fun”.

ArrayList allComboList = new ArrayList();
for (int i=0;ii<allSentences.length;i++) {
  String[] words = allSentences[i].split(" ");
  String lastWord = "";
  for (int j=0;ji<words.length;j++) {
    if (!words[j].equals(" ")) {
      if (!lastWord.equals("")) {
        String combo = lastWord+" "+words[j];
      lastWord = words[j];

6. Generate first word.

The word list represents an equal distribution of all words. Choosing random words from this list will result in a list of words exposing the same statistical occurrences as the source texts.

String word = (String)allWordList.get((int)random(allWordList.size()));

List of combinations starting with the word "but"

List of combinations starting with the word “but”

7. Generate a sub list of word pairs to choose from.

We are now looking for a word pair that starts with the previous word. To do so, we simply need to check the word combination list if these start with the previous word plus ” ” and add it to our temporary list.

String toFind = word+" ";
ArrayList subComboList = new ArrayList();
for (int i=0;i<allComboList.size();i++) {
  String combo = (String)allComboList.get(i);
  if (combo.startsWith(toFind)) {

8. Create a new word

If our previous list contains words, we just pick a random combination and extract the last word. If the list is empty, we just pick another random word.

String newWord = "";
if (subComboList.size()>0) {
  String combo = (String)subComboList.get((int)random(subComboList.size()));
  newWord = combo.split(" ")[1];
} else {
  newWord = (String)allWordList.get((int)random(allWordList.size()));

9. Go to (7) using the newWord as word

word = newWord;

Feel free to download the processing implementation and play around with it. Markov Chain Processing

Posted in Optimal artist, Processing, Research, Uncategorized | Tagged , , , , | Comments Off