Showing posts with label math. Show all posts
Showing posts with label math. Show all posts

Sunday, August 9, 2015

Computing at 80,000ft, future tech and the future of tech






Another exciting Winston-Salem Section meeting at CDI !  Wednesday, August 12, 2015 at 11:30am.

Presenter: Francois Dion

Originally from Montreal, Canada, Francois Dion is a Coder, Data Scientist, Entrepreneur, Hacker, Mentor, Musician, Polyglot, Photographer, Polymath and Sound Engineer.  He is the founder of Dion Research LLC, an R&D firm specializing in Fully Integrated Software and Hardware (www.dionresearch.com) and works as a Data Scientist at Inmar, Inc. (www.inmar.com).

He is also the founder of the local Python user group (PYPTUG), a group he founded to “promote and advance computing, electronics and science in general in North Carolina using the Python programming language.”

Detail:

Behind the scene and various aspects of electronics and computing cluster and data science in near space. A glimpse at future technology. and at the future of technology.

When
Date: 12-August-2015
Time: 11:30AM to 01:30PM (2.00 hours)
All times are: America/New_York
Where

Building: CDI
Center For Design Innovation
450 Design Ave.
Winston Salem, North Carolina
United States 27102
Staticmap?size=800x400&sensor=false&zoom=16&markers=36.0906389%2c-80
More

No Admission Charge.


Friday, January 2, 2015

Innovation is not a hotdog

Once upon a time


You would walk in a supermarket, buy hot dogs and hot dog buns. It was a pretty straightforward process. Sausage pack, check. Buns, check.

Then, someone had the idea of making a bun length sausage. Hmm, ok, except that different brand of "bun length" sausages and buns all have different metrics. But hey, that's ok, it was a valiant effort.

More is more


Some time passed, and somebody thought, "hey, let's make a sausage longer than the bun!". Of course, all readers will be quick to point out that there never was a sausage exactly the length of a bun, they were either slightly shorter, or slightly longer. It was just a "more is more" marketing.

What's next


You are probably expecting a sausage to appear on the market "shorter than the bun!". And the circle will be complete. But, which one is the better design? Which one innovates? Same answer to both question: the original design for sausage, which dates back to at least the 9th century BC. Anything beyond that is in the presentation (the marketing).

Tech innovation


Now, back to technology. Let's take the phone, for example. Clearly, going wireless was an innovation. Going pocketable was an innovation. Touchscreen. Haptics. Innovations. But the same tech, just in a different (bigger and bigger, a.k.a. "more is more" marketing) package, is not innovation (*cough* apple *cough* samsung). In fact, one could say there is a clear regression in that field (phones used to have battery life expressed in weeks, could fit in your pocket, even in jogging shorts, could be dropped multiple times on rock hard surfaces without any problem etc)

You can do it


So, why am I talking about all of that? Well, it's my yearly encouragement to truly innovate (see last years post here). But you can't do it in a vacuum. Engage in your local community. If you haven't done so yet, make it a goal this year. Your local programing user groups (Python, Java, Javascript, whatever), maker space or hacker space, robotics, raspberry pi or other creative group, you local coworking, STEM/STEAM school groups etc. Not only will you benefit from attending, by growing your network and your knowledge, but you'll contribute something back to your community, to the society.

Before I sign off for the day, do read my post on innovation in general and personal scale innovation from last year.

@f_dion

Friday, October 11, 2013

IEEE 754/854, when it is needed

Linkedin

There was a post on linkedin IEEE Computer Society group, lamenting the division by zero exception raised by Python, instead of returning infinity (or -infinity). I replied, but it is not that readable. So I'm putting the properly formatted reply on my blog. [edit: no comments followed on linkedin, but many appeared on the original source after that]

IEEE decimal

If you want IEEE 754/854 decimal behaviour, what you want to use is the decimal module:

>>> import decimal
>>> help(decimal)

The above typed in the python interpreter will provide all the help you need. The examples are a little verbose, however.


ExtendedContext


If you want to be shorthand, you can copy/paste the following at the top of your program:

from decimal import setcontext,ExtendedContext, Decimal as ieee
setcontext(ExtendedContext)


Then whenever you want to use ieee behaviour use ieee(value):

>>> 1/ieee(0)
Infinity
>>> -1/ieee(0)
-Infinity

Python does it right



It is good that it has to be explicitly stated that you want this. A division by zero should raise an exception when dealing with financial data[*]. I would recommend numpy if dealing with scientific data.


François
@f_dion

* Unless you are calculating my bonus...

Monday, September 9, 2013

@surgeterrix to XOR or not to XOR

By way of twitter


Taking 2 strings of hexadecimal characters, converting hex to binary values, then xorsum the 2 values, and convert sum back to hex.

The other XOR


So the normal xor will not work on strings, so what do you do?

from binascii import hexlify, unhexlify  
from Crypto.Cipher import XOR  
  
# you can encounter hex strings with no spaces  
encrypted = '556e6e216c606f78217264627364757216'  
# or hex strings with spaces  
key = '01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01'  
  
#let's get binary representations  
b_encrypted = unhexlify(encrypted)  
b_key = unhexlify(key.replace(' ','')) # we remove the spaces  
 
#to see a binary string output, use repr: print(repr(b_key))  
  
cosmo = XOR.new(b_key)  
bishop = cosmo.encrypt(b_encrypted) # yeah, encrypt to decrypt  
  
print hexlify(bishop)  
# the above is what was asked  
# the plain ascii decrypted message is print(bishop)  

I think the (not really) hidden references are pretty obvious...However, even in the decrypted message, there is still a question left... :)

François
@f_dion

Tuesday, December 4, 2012

On fractals

I did say I'd talk about fractals, didn't I? I've been fascinated by them for a good 25 years now... A few weeks ago I attended a presentation at the local IEEE chapter. It didn't feature a lot of graphics, but instead it focused on practical applications of fractals to analyze lots of data. So I figured I'd bring them up at some point on this blog.

Today I'll mention some stuff just to whet your appetite.

Definition...


Or perhaps not. According to wikipedia:
"There is some disagreement amongst authorities about how the concept of a fractal should be formally defined. The general consensus is that theoretical fractals are infinitely self-similar, iterated and detailed mathematical constructs having fractal dimensions, of which many examples have been formulated and studied in great depth..."
Clear as mud, I'm sure. But still, fractals are quite interesting. Not just from a mathematical standpoint, but from a wide variety of angles.

Back when I was in school, one of my math teachers talked a good bit about fractals. The term had been around less than 10 years, but already it was quite popular in academic circles. I don't really remember anything he told us, but I will never forget the picture of the Mandelbrot set he showed us.

To him, fractals were fascinating equations. To us, they were fascinating graphics:

Actually... no, that is the Python code!
Yep, that's it! The Mandelbrot set
Regarding the source code, that's not how Python code looks usually. This is what is called obfuscated code. It is an art form in itself. The source was taken from the Preshing blog.

For a non obfuscated version of the code, and lots of explanations, check out: Python Patterns.

Sierpinski


Before you can run, you have to learn how to walk. Mandelbrot demanded a lot of horsepower back in the mid 80s. My Apple ][ was only 1MHz and my Mac, 8MHz. It would have taken days. So I played around with assembler and Pascal, doing this:



                               @                               
                              @ @                              
                             @   @                             
                            @ @ @ @                            
                           @       @                           
                          @ @     @ @                          
                         @   @   @   @                         
                        @ @ @ @ @ @ @ @                        
                       @               @                       
                      @ @             @ @                      
                     @   @           @   @                     
                    @ @ @ @         @ @ @ @                    
                   @       @       @       @                   
                  @ @     @ @     @ @     @ @                  
                 @   @   @   @   @   @   @   @                 
                @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @                
               @                               @               
              @ @                             @ @              
             @   @                           @   @             
            @ @ @ @                         @ @ @ @            
           @       @                       @       @           
          @ @     @ @                     @ @     @ @          
         @   @   @   @                   @   @   @   @         
        @ @ @ @ @ @ @ @                 @ @ @ @ @ @ @ @        
       @               @               @               @       
      @ @             @ @             @ @             @ @      
     @   @           @   @           @   @           @   @     
    @ @ @ @         @ @ @ @         @ @ @ @         @ @ @ @    
   @       @       @       @       @       @       @       @   
  @ @     @ @     @ @     @ @     @ @     @ @     @ @     @ @  
 @   @   @   @   @   @   @   @   @   @   @   @   @   @   @   @ 
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @



It is a text representation of a Sierpinski triangle or gasket. It is a Fractal that was discovered by the Polish mathematician Waclaw Sierpinski in 1915, before we even had a name for fractals (that was coined by Benoit Mandelbrot in 1975).

Perhaps not that impressive nowadays, but it was a lot of assembler code to do this. In Pascal too, I seem to remember it was at least 60 lines.

On Rosettacode, you can find the following Python program that does the equivalent:

def sierpinski(n):
    d = ["*"]
    for i in xrange(n):
        sp = " " * (2 ** i)
        d = [sp+x+sp for x in d] + [x+" "+x for x in d]
    return d
 
print "\n".join(sierpinski(4))

But dont be fooled by that short piece of code, it is a complex subject.

Other fractals that have been around for a long long time and dont require a lot of computing power, are the cantor set, the Heighway Dragon and the Koch snowflake. All of them are examples of iterated function systems (IFS). The Mandelbrot and Julia sets are of a different type of fractals: escape time fractals. Also, there have been some interesting links made between the Cantor set and Fibonacci's series, so it is a normal continuation from that theme, since I've had a few blog entries on Fibonacci: here, here and here.

Fractint


In 1988 appeared on BBSes and usenet the program Fract386, and renamed Fractint the following year. That was pretty exciting, we could render Mandelbrot without hardware floating point math. It was fast! Well... compared to what it was up to that point...

Mandelbrot set


Fractint is a DOS program. It is also available for Windows (old windows 3.1...) and Linux now, but let's stay with this concept for a minute. How can we run DOS programs on the Raspberry Pi?

Video mode selection

Dosbox

Dosbox is a dos on x86 emulator. It runs on non x86 platform, such as the Raspberry Pi (ARM processor) without problems. By comparison, WINE does not work on the Pi.

$ sudo apt-get install dosbox

Once installed, run it once so the configuration file gets written, then exit. If you get issues with the keyboard mapping:

$ cd .dosbox
$ vi dosbox.conf

usescancodes=false


That should take care of it. Now create a dos directory and download fractint there:
$ cd
$ cd dos
$ wget http://www.nahee.com/spanky/pub/fractals/programs/ibmpc/frain204.zip
$ unzip fain204.zip

Now, run dosbox and mount the dos folder:

mount c dos
 You can now type c:, change (cd) to the fracti~1.04p folder and run Fractint!

We'll continue on fractals at a later date.

Friday, November 23, 2012

Python: de débutant a expert

Série de tutoriels 

 Je vais commencer une série de tutoriels pour Python, en français. On va couvrir l'ABC du langage. Python est parfait comme premier langage de programmation, car il est relativement facile a apprendre pour faire ce que l'on veut. De plus, c'est un langage sérieux qui est partout en industrie.

Donc, non seulement on peut s'amuser, mais on peut être payés pour cela!

Débutants

On va commencer bien sur par la sélection d'un éditeur. Comme la majorité des lecteurs vont faire les tutoriels sur leur Raspberry Pi, on va surtout parler de geany. Mais je vais aussi mentionner d'autres en mode graphique, et aussi quelques configurations pour vim, pour ceux qui veulent rester en mode texte, ou qui préfèrent la console.

Intermédiaireset experts

Pour le moment, je vous conseille les articles du blog sur Python qui sont en anglais, et de suivre en simultané avec google translate.

Je vais introduire de temps a autres, un thème pour intermédiaires et experts. Par exemple, aujourd'hui, je vous laisse sur un sujet intéressant, mais pas pour débutants. René Bastien, a écrit un module pour faire de la composition de musique électronique. Un lien, une présentation de PyConFR et un module:

site officiel de Pythoneon

Présentation PyConFR 2012: PDF

L'installation de pythoneon (il faut avoir easy_install au minimum):
$ sudo easy_install pythoneon
 ou
$ sudo pip install pythoneon
Je vous conseille de voir les diapos de PyConFR (le PDF).

Je vous laisse vous amuser avec cela, et on y revient plus tard. La musique, c'est un autre de mes domaines d'expertise.


Monday, November 19, 2012

Fibospeak

espeak

Speaking (of) the Fibonacci numbers, did you figure it out?

It is actually quite simple to use espeak. On the Raspberry Pi, we cant use directly the espeak module in Python. We thus have to call the espeak application through the os module.

 import os  

 def say(something):  
   os.system('espeak -ven+f2 "{0}"'.format(something))

 a, b = 0, 1  
 say(a)  
 while b < 50:  
     say(b)  
     a, b = b, a+b  

And that is basically it!

Variations

If we wanted the numbers read in spanish:
   os.system('espeak -ves+f2 "{0}"'.format(something))  

Or in French, male, female and Portuguese, male female:
   os.system('espeak -vfr+m2 "{0}"'.format(something)) 
   os.system('espeak -vfr+f2 "{0}"'.format(something)) 
   os.system('espeak -vpt+m2 "{0}"'.format(something)) 
   os.system('espeak -vpt+f2 "{0}"'.format(something)) 

Under Linux, on a PC with a properly functioning espeak-python module, it would bea little different. After importing espeak, instead of using my function say(), we would use:

   espeak.synth(str(s))

Other options

On the raspberry pi forum, someone pointed to a different approach, which is to use the google translate web service.

Under Linux, but not on the Raspberry Pi (it just clicks instead of speaking), you could also use the Speech Dispatcher server (speechd, python-dispatcher).

Still unresolved

I'll follow up with the visual version tomorrow. There is still time to leave a solution in a comment.

See the next part: Fibovisual

Saturday, November 17, 2012

Python Speak Hint

A hint for our current python challenge:

$ sudo apt-get install espeak

or

import pycairo

Depending which challenge you picked... The answer will probably vary if you try it under Raspbian versus Debian, it is all in the library.

Thursday, November 15, 2012

Fibonacci

When we say Fibonacci, some might think of the man, the mathematician, the Fibonacci numbers or even specifically of the following relation:



Or, if you watched (or read) David Mitchell's presentation on iPython at PyHack Workshop #01, you'll recall that it was part of it.

The code was:

 a, b = 0, 1  
 print a,  
 while b < 50:  
   print b,  
   a, b = b, a + b  

Incredibly simple, isn't it? The result of which is:

0 1 1 2 3 5 8 13 21 34


I added the print a, since mathematically speaking, the Fibonacci sequence starts at 0, but most of the time it is displayed starting at 1 (1, 1, 2, 3 etc). I also increased the upper boundary to 50 (it was 10 in the demo).

If you can't read the math, you can at least clearly see that any given member of the Fibonacci series is equal to the sum of the two preceding elements.

So, why am I talking about this?


I have two challenges for my readers. The first, is a Python programming challenge, while the other just requires some power of observation:

  1. modify the above code to have the numbers read (audio) instead of printed, or visualize them graphically, but not as numbers.
  2. look around. Where can you find occurrences of Fibonacci numbers

Bucolic Mix


You'll see where we are going with this on our next mathematical intrigue, perhaps this weekend... In the meantime, do post your answers to the challenge in our comments section below.


See the next step: Fibospeak