Harry Seldon's blog

Fractals, Chaos, and Control Systems on Rails

Read

How did we get here? Chaos vs God

Posted by Harry Seldon on January 18, 2010

I love the description given by the BBC for their documentary “The Secret Life of Chaos” (which you can watch here).
As I have written a few articles about fractals, chaos and controls lately, I have added links internal to this blog to the text.

“Chaos theory has a bad name, conjuring up images of unpredictable weather, economic crashes and science gone wrong. But there is a fascinating and hidden side to Chaos, one that scientists are only now beginning to understand. It turns out that chaos theory answers a question that mankind has asked for millennia - how did we get here?

In this documentary, Professor Jim Al-Khalili sets out to uncover one of the great mysteries of science -

  • how does a universe that starts off as dust end up with intelligent life?
  • How does order emerge from disorder?

It’s a mindbending, counterintuitive and for many people a deeply troubling idea. But Professor Al-Khalili reveals the science behind much of beauty and structure in the natural world and discovers that far from it being magic or an act of God, it is in fact an intrinsic part of the laws of physics.

Amazingly, it turns out that the mathematics of chaos can explain how and why the universe creates exquisite order and pattern. The natural world is full of awe-inspiring examples of the way nature transforms simplicity into complexity. From trees to clouds to humans - after watching this film you’ll never be able to look at the world in the same way again.”

Notice that this introduction can be sum up by “Chaos vs God” or “Chaotical Design vs Intelligent Design”. However, anyway, one question remains: who created the laws of physics? Or how were created these laws of Physics, if you prefer ;-)

I have often privately said that James Gleick’s Chaos book gives clearer answers than the Bible about our world. Now is the time to say it publicly!

Enjoy the documentary!

Posted in | no comments | Tags , , , , | atom

The Secret Life of Chaos (BBC 2010)

Posted by Harry Seldon on January 18, 2010

The BBC aired on Thursday, January 14th an excellent documentary about Chaos, Fractals and Nature. You can watch it right here thanks to YouTube. If you are in UK you can also watch it on the BBC website at this address.

I am glad the BBC helps making these subjects popular and fashionnable more than 20 years after James Gleick’s Chaos book.

Part 1

All parts follow.

Part 2

Part 3

Part 4

Part 5

Part 6

Enjoy!

Posted in | no comments | Tags , , , , | atom

The fractal Google logo

Posted by Harry Seldon on January 14, 2010

Thx Pixgeeks for reminding me of this nice Google logo involving fractals.

fractal_google_logo

It was in memoriam to Gaston Julia’s Birthday.

In case I need to precise, the fractals you see on the logo are called Julia sets because the French mathematician Gaston Julia described them first. However, most of my readers already know that, right? ;-)

To say something only initiated people can understand: “The Mandelbrot set contains all Julia sets”. (That is why the fractal on the left is actually the Mandelbrot set.)

You can check all google logos here.

Posted in | no comments | Tags , , , , | atom

7 lifechanging books about fractals, chaos, nature, philosophy and even finance for the holidays

Posted by Harry Seldon on December 14, 2009

Mandelbulb
Mandelbulb by Daniel White

As we are still at the beginning of the holiday season, maybe you haven’t bought all your gifts yet. In that case, here are a few lifechanging books you can offer to your loved ones.
By lifechanging, I mean you will never look at the world in the same way after reading one of these books. There is even a good chance you will find the world a lot more simple after your reading because these books give you keys to the behaviour of nature and mankind.

If you don’t like too much specialized books, you will like these ones because each one of them will speak about several topics among geology, economy, biology, social sciences, and climate.

Moreover, you will find some element of answers for several popular questions of our days like:

fractals_nature_model

So, let’s go to the point, here are these absolutely marvellous books. Notice, they are somehow sorted by order of importance.

So, in case it was not clear, now you see why my Twitter name is @Fractalharry ;-)

You can propose other books in the comments.

Enjoy your reading.

PS I have linked to Amazon for your convenience but I don’t touch any commission!

Posted in | 3 comments | Tags , , , , , , , , , | atom

Simplexity: Things are a lot simpler than they seem and vice versa

Posted by Harry Seldon on October 20, 2009

Have you ever heard of simplexity ?

Some systems are a lot simpler than they look like. For instance, let’s consider the shape of a tree. It looks complex, especially if you compare it with a straight line. However, if you have read Mandelbrot or heard of fractals, you know that all you need to draw a tree is a 2 lines pattern, which you repeat a big number of times introducing at each step some light randomness. You can model pretty easily this tree shape. At least you can generate at your will tree shapes. That is typically the way used in computer graphics to generate natural virtual 3D scenes. However, this does not mean you can predict the accurate shape of a tree from its seed.

So, is the tree shape complex or simple? Thanks to Mandelbrot we know now that the shape is a lot simpler than it seems. Associating the notions of predictability and simplicity, the converse is also true: it is more complicated than you could think even if you have heard of fractals. Hence this notion of simplexity, contraction of simplicity and complexity.

Here are a few good books on the subject:

If you know about fractals and chaos, you must be already familiar with that fact that simplicity can bring complexity quickly and easily. But you might not know this term of simplexity.
More generally, each time you think “this thing is a lot simpler than I had imagined at first”, you experience simplexity: in fact, you changed your first impression of overall complexity by discovering the underlying simple principles.

While we are at it. There is a field where simplexity shows all its magnificence: it is in finance. International finance looks complex but there are a limited number of principles behind it. You can even fairly easily model a stock chart. (Even if this model has nothing to do with the actual models used by financial analysts). But even with a good model you cannot predict easily the stock chart of a determined company.
For more info, you can have a look at the Facebook group “Finance & Mandelbrot”.

And at last, because I cannot prevent from saying it again, If you want to keep things simple, then regulate them. Contrary to what you could think, you do not need very accurate models to control a system.

Posted in , | no comments | Tags , , , , | atom

How to draw Mandelbrot's fractal with Rails and Open Flash Chart?

Posted by Harry Seldon on April 18, 2009

Mandelbrot set

Let us draw the Mandelbrot set with OFC. The point is to make a new example of use of OFC and it is also to have some fun with the so interesting fractal theory. To see how fashionable it is, read this post: Good news from the combat against the crisis. This post is highly inspired from this nice French page about the Mandelbrot set. I am using the algorithm given there.

Definition of the Mandelbrot set
For each point of the complex plane we associate the sequence: zn+1=zn2+A with z0=0 and A=a+ib the point affix. Iff the sequence is bounded the point A belongs to the Mandelbrot”s set. Problem is, it is not easy for a computer to say if a sequence remains bounded. It would require an infinite number of calculations. For each point, we are simply going to make a ‘large’ number of calculation on the sequence. It can be shown analytically that if the module of zn is greater than 2 the sequence will diverge. So during nmax iterations, if the sequence goes above 2, the sequence diverges and it has diverged all the quicker as the number of iteration is low. If it is quick to diverge it is far from the set. A color will be associated to each point according to its distance from the set. If the algorithm reaches nmax the probability for the point to belong to the set is maximal with respect to our computation.

To code without complex numbers we will use the real coordinates, the sequence being written equivalently as:
xn+1=xn2-yn2+a
yn+1=2 xn yn+b

Code for Open Flash Chart
The implementation with Rails and OFC is explained hereafter. It is using a scatter chart.

in test_it_controller.rb

  def index_mandelbrot_fractal
    # from http://perso.numericable.fr/~haasjn/haasjn/AlgoMandel.txt 
    @graph = open_flash_chart_object(500,500,"/test_it/graph_code_Mandelbrot_fractal")     
  end

Also in test_it_controller.rb

  def graph_code_Mandelbrot_fractal
    #    Algorithm to draw Mandelbrot's fractal 
    #    
    #    variables a,b,x,y,xmin,ymax,cx,cy,width,step:real
    #              i,j,nx,ny,n:int
    #              r: table
    #        
    #    cx,cy    coordinates of the image center in the complex plane
    #    xmin     image left limit 
    #    ymax     image upper limit
    #    width    image width in the complex plane
    #    nx       image horizontal resolution 
    #    ny       image vertical resolution
    #    nmax     maximum number of loops to compute the convergence of the complex sequence
    #    step     step between 2 points 
    #    r        table containing the result for each point
    #
    #    in the loop 
    #    i,j  indices of the point 
    #    a,b  point coordinates
    #    x,y  values of the complex sequence
    #    x1   next value of x 
    #    n    indice of the complex sequence
    # 
    #    Algorithm beginning 
    #    cx,cy,width,nx,ny,nmax are given at start 
    cx = 0
    cy = 0
    width = 4.to_f
    nx = 100.to_f
    ny = 100.to_f
    nmax = 250.to_f

    xmin = cx-width/2
    ymax = cy+width/2*ny/nx
    step  = width/nx

    # Preparation of the chart
    chart = OpenFlashChart.new
    title = Title.new("Mandelbrot set")
    chart.set_title(title)
    r = Array.new # results 

    # The loop asks : does the point (a,b) belong to the Mandelbrot set ? 
    # The bigger n, the more probable the point belongs to  the set 
    for j in 0..ny-1
      b=ymax-j*step       
      for i in 0..nx-1
        a=i*step+xmin
        x=0
        y=0 
        n=0
        #  while x*x+y*y<4 and n<=nmax
        while x*x+y*y<4 && n<=nmax
          x1=x*x-y*y+a
          y=2*x*y+b
          x=x1
          n=n+1
        end

        # Adding the point to the chart
        # Needs to associate a color according to n 
        # that is according to the time needed to converge
        amplif = 1
        c = (16.0.+n/nmax*(255.0-16.0)*amplif).to_int
        c = [255,c].min
        col_gray = (255-c).to_int.to_s(16).to_s
        col =  "#"+col_gray+col_gray+col_gray
        scatter = Scatter.new(col, 2);
        scatter.set_values([ScatterValue.new(a,b)])
        chart.add_element( scatter )

        # if you want to store the result 
        r.push([a,b,n,c])
      end #i
    end #j

    x_axis = XAxis.new
    x_axis.set_range(xmin,-xmin)
    chart.x_axis = x_axis

    y_axis = YAxis.new
    y_axis.set_range( -ymax, ymax )
    chart.y_axis = y_axis
    render :text => chart.to_s      
  end

in index_mandelbrot_fractal.html.erb

<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<%= @graph %>

Notice the code for the computation and the graph are made together in the controller code. This is just for simplicity to write this post. Technically, the computation is more a work for your model. Preparing the graph is also a work for the model. With a DRY code you would have one model method to prepare the data, one to prepare the chart. Then in the controller you call the method that prepares the chart and you sends the data to the view.

Result
Here is the Mandelbrot set chart. Beware it takes about 10 seconds to load. Indeed the algorithm is computationally intensive. The code is available in the OFC test app on github. Here is the controller code.

Thanks for having read this world first: drawing the Mandelbrot set with Ruby on Rails and OFC.

Posted in , | 2 comments | Tags , , , , , | atom

Yes, he can save the world !

Posted by Harry Seldon on February 23, 2009

He is from a minority. He is American, lives in the US but has a dual culture. He studied in the best universities. He is one of the smartest guys on Earth. He had many awards for his outstanding work along his long and brilliant career. He has always fought received ideas. He is not afraid of complexity but knows to recognize simplicity in the middle of intricated systems that most people consider as infinitely complex. He is not afraid of telling people when they are wrong. He is not afraid of telling them what to do. He does not hesitate to fight alone against the majority but definitely prefers to be with the majority. If listened to earlier, many casualties would have been avoided. He wants to change the world and he has a plan.
No, I am not speaking about Barack Obama. Let me continue. He is Franco-American. He studied aeronautics. He deserves a Nobel prize in all categories: economy, physics, medecine (biology), chemistry, and even litterature and peace, because his work helped describing and understanding the geometry of nature. His work can indeed be applied to stock market, natural borders, lungs description, fluid mechanics, animal population evolution, clouds. He wrote many inspiring books. If more listened to the world would be way more peaceful because better understood and less submitted to crisis.
Yes, I am speaking about Benoit Mandelbrot and the good news is: his work on finance is slowly being recognized by the media and by economists.

Listen to Mandelbrot and global warming, crisis and wars will just be bad memories. OK I am exaggerating, but I am not sure how much ;-).

PS If you know which conferences Mandelbrot is going to attend this year, please let me know in the comments because he is definitely the celebrity I would love most to meet.
mandelbrot antenna

Posted in , | no comments | Tags , , , , , , | atom

Good news from the combat against the crisis

Posted by Harry Seldon on February 22, 2009

Julia island
In my 2009 wishes, I wished that people better understand the world. For this purpose, I suggested they read The (Mis)behaviour of Markets: A Fractal View of Risk, Ruin and Reward by Benoit Mandelbrot.
Actually, for one year and a half we have been inside this growing up crisis I have been appalled by the small number of articles in the media about Mandelbrot’s work on Finance and more generally by the small number of articles about chaos theory and economy. Indeed more than ten years ago, Mandelbrot explained why the finance world was walking on its head. To make it short, it is because financial theory fundamental principles are wrong and over-optimistic. These principles state that the hazard involved in the market theory is regular enough to be smoothed by the big numbers law. This hazard is “benign”. Basically, with the standard theory, crisis can’t happen. So yes, you must be dreaming, there is no crisis, unless you listen to Mandelbrot that tells you that the hazard is actually “savage” and potentially leading to a collapse of the market: a crash.

So where is the good news ?

It looks like main stream media are slowly understanding Mandelbrot’s work and they are speaking about it. I found yesterday an excellent article in one of the main French financial newspapers about Mandelbrot’s work on finance. The second good news, contained in that article, is that Mandelbrot’s book are being republished. A third good news, is that the author of the previous article, Philippe Herlin is very proactive and has just created a Facebook group called “Finance & Mandelbrot”. I joined immediately ! An instant interest of this group is that Philippe Herlin gives a list of news articles about the subject (given below). Please notice the link called How Fractals Can Explain What’s Wrong with Wall Street which is dated on February 1999. Yep, it is not a typo for 2009 !
Last but not least, there is a significant political news. Mandelbrot showed that the financial system was fractal, exhibiting the same behaviour at all scales. Actually that was the start of his long and brilliant career. Later on he showed the same behaviour for climate, geology, ecology, or biology. Actually about any natural system is fractal and even chaotical. However, there is a good way to smooth the behaviour of a system, it is called control. Our world needs more control (distributed control whenever possible). That is to say, more rules, more ways to enforce them and more ways to measure their efficiency. So the good news is today European leaders backed sweeping new regulations for financial markets. Questions remain, will the rules be good and will they be enforced?

By the way, if you want to understand a little better the whole world, if you want to hear about economy, climate, geology, ecology, or biology in less than 200 pages, just read these two amazing books. Your vision of the world will change and for almost free because these books are quite old (but have never been so fashionnable).

Nostalgia: I was offered these books 13 years ago. I read them then. They are definitely among the best gifts I have ever received. They stand in my bookshelf, one arm away from where I am writing these lines. Believe me these books are far easier to read than the Bible so you can give them to your children. I read them again 2 years ago after completing my studies in Dynamical Systems and Controls. I understood plenty of things I had missed in the first reading. So you can also offer these books to adults. They will learn quite a few things about the nature of our world.

Resources

In English

In French

If you know other good links about fractal, chaos theory and economy, please leave them in the comments.
Mandelbrot set

Posted in | no comments | Tags , , , , , , , , | atom

Happy new year 2009! May we better understand the world!

Posted by Harry Seldon on January 02, 2009

I wish you all an excellent year 2009 filled with happiness in your private life as well as in your professional life.
Besides that, I wish you to better understand the world we all live in. For this purpose, here are some subjects that deserve all your attention and about which I will blog soon.

This beginning of the new year will be very busy around here. Indeed, I am going to make a major update for ThinkoSphere.com with the new design and I will start a blogging series about Control Systems. Later on I will blog about the fractal theory applied to finance because it is today the best theory explaining the crisis that I have found so far. I am currently reading the book “fractals, hazard and finance” from Benoit Mandelbrot*, father of the fractal theory. This book is amazing, it is ten years old but it looks like it was written 2 days ago, after the crisis.

Moreover, I also wish you to be better understood by your company, by your mayor, by your government. I wish you more democracy in your environment. This starts by giving more your opinion when you are polled. So I wish you more polls and finally I wish you to find your interest in ThinkoSphere.com.

* I am actually speaking about “fractale, hasard et finance” a book in French. Its equivalent in English is The (Mis)behaviour of Markets: A Fractal View of Risk, Ruin and Reward. This is probably the best quality and best quality/price ratio book about finance you can buy nowadays!

Posted in | no comments | Tags , , , , , , , | atom

Search

Sponsor