2015-11-02 Multiprocessing

Testing some multi-threading libraries

Read more…

Comments

2015-10-27 élasticité expansion

L'installation Elasticité dynamique agit comme un filtre et génère de nouveaux espaces démultipliés, comme un empilement quasi infini d'horizons. Par principe de réflexion, la pièce absorbe l'image de l'environnement et accumule les points de vue ; le mouvement permanent requalifie continuellement ce qui est regardé et entendu.

Ce post étudie commment sampler des points sur la structure.

Read more…

Comments

2015-10-27 élasticité expansion-réaction diffusion

In [ ]:
L'installation [Elasticité dynamique](https://github.com/laurentperrinet/elasticite) agit comme un filtre et génère de nouveaux espaces démultipliés, comme un empilement quasi infini d'horizons. Par principe de réflexion, la pièce absorbe l'image de l'environnement et accumule les points de vue ; le mouvement permanent requalifie continuellement ce qui est regardé et entendu. 

Ce post étudie une reaction de reaction diffusion sur la structure.

<!-- TEASER_END -->
In [11]:
%load_ext autoreload
%autoreload 2
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
In [12]:
import elasticite as el
import numpy as np
np.set_printoptions(precision=2, suppress=True)
import matplotlib.pyplot as plt
In [13]:
class EdgeGrid(el.EdgeGrid):
    def update_particles(self):
        self.particles[2,:] =  np.cos((self.t + np.linspace(0, 1., self.N_particles))*2*np.pi)

    def update(self):
        self.update_particles()

e = EdgeGrid(N_lame=25, grid_type='line')
e.animate()
[MoviePy] >>>> Building video /var/folders/3p/m0g52j9j69z3gj8ktpgg1dm00000gn/T/tmpko8i8esq.webm
[MoviePy] Writing video /var/folders/3p/m0g52j9j69z3gj8ktpgg1dm00000gn/T/tmpko8i8esq.webm
 10%|▉         | 20/201 [00:05<00:47,  3.82it/s]WARNING:py.warnings:/usr/local/lib/python3.5/site-packages/matplotlib/pyplot.py:516: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

                                                 
[MoviePy] Done.
[MoviePy] >>>> Video ready: /var/folders/3p/m0g52j9j69z3gj8ktpgg1dm00000gn/T/tmpko8i8esq.webm 


Out[13]:
In [14]:
CC = e.particles[:, :, np.newaxis]-e.particles[:, np.newaxis, :] # 2xNxN ; en metres
distance = np.sqrt(np.sum(CC**2, axis=0))# NxN ; en metres
print(distance)
print(np.tanh(np.linspace(-2, 2, 15)))
d_min, d_max = .2, 1.
f = lambda d: 900./ e.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
print(f(np.linspace(0, 2, 15)))
[[ 0.    0.43  0.87 ...,  6.72  7.02  7.34]
 [ 0.43  0.    0.43 ...,  6.87  7.15  7.46]
 [ 0.87  0.43  0.   ...,  7.04  7.31  7.59]
 ..., 
 [ 6.72  6.87  7.04 ...,  0.    0.44  0.88]
 [ 7.02  7.15  7.31 ...,  0.44  0.    0.44]
 [ 7.34  7.46  7.59 ...,  0.88  0.44  0.  ]]
[-0.96 -0.94 -0.89 -0.82 -0.69 -0.52 -0.28  0.    0.28  0.52  0.69  0.82
  0.89  0.94  0.96]
[-75.   -29.64  -8.38   1.22   5.2    6.54   6.67   6.27   5.67   5.03
   4.42   3.86   3.36   2.92   2.53]
In [15]:
class EdgeGrid(el.EdgeGrid):
    def update_particles(self):
        CC = self.particles[:, :, np.newaxis]-self.particles[:, np.newaxis, :] # 2xNxN ; en metres
        distance = np.sqrt(np.sum(CC**2, axis=0))# NxN ; en metres
        d_min, d_max = .2, 1.5
        #f = lambda d: -100./ self.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
        #f = lambda d: 100./ self.N_particles* (np.exp(-d/d_max) - np.exp(-d/d_min))
        f = lambda d: -20./ self.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
        #R = lambda w: - 3.5*np.sin(2*np.pi*w)
        #R = lambda w: w*(1 - w**2)
        R = lambda w: .2*np.tanh(w) # (1+w)*(1-w)
        
        w = self.particles[2,:]
        #print('w_t', (np.dot(f(distance), w)).mean(), (np.dot(f(distance), w)).std())
        #w *= (1-self.dt)
        w += np.tanh(np.dot(f(distance), w) + R(w))*self.dt
        #print(w.min(), w.max())
        #w /= np.absolute(w).max()
        self.particles[2,:] = w

    def update(self):
        self.update_particles()

e = EdgeGrid(N_lame=25, grid_type='line')
#e.particles[2, :] = 0
#e.particles[2, 0] = -1.
#e.particles[2, -1] = 1.
#e.particles[2, :] = 2*np.random.rand(e.N_particles)-1
e.animate(duration=40, fps=10, fname='../files/elasticite/reaction-diffusion.mp4')
WARNING:py.warnings:/usr/local/lib/python3.5/site-packages/matplotlib/pyplot.py:516: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

[MoviePy] >>>> Building video ../files/elasticite/reaction-diffusion.mp4
[MoviePy] Writing video ../files/elasticite/reaction-diffusion.mp4
                                                 
[MoviePy] Done.
[MoviePy] >>>> Video ready: ../files/elasticite/reaction-diffusion.mp4 


Out[15]:
In [16]:
class EdgeGrid(el.EdgeGrid):
    def update_particles(self):
        CC = self.particles[:, :, np.newaxis]-self.particles[:, np.newaxis, :] # 2xNxN ; en metres
        distance = np.sqrt(np.sum(CC**2, axis=0))# NxN ; en metres
        d_min, d_max = .2, 1.5
        #f = lambda d: -100./ self.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
        #f = lambda d: 100./ self.N_particles* (np.exp(-d/d_max) - np.exp(-d/d_min))
        f = lambda d: 20./ self.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
        #R = lambda w: - 3.5*np.sin(2*np.pi*w)
        #R = lambda w: w*(1 - w**2)
        R = lambda w: -10.*np.tanh(w) # (1+w)*(1-w)
        
        w = self.particles[2,:]
        #print('w_t', (np.dot(f(distance), w)).mean(), (np.dot(f(distance), w)).std())
        #w *= (1-self.dt)
        w += np.tanh(np.dot(f(distance), w) + R(w))*self.dt
        #print(w.min(), w.max())
        #w /= np.absolute(w).max()
        self.particles[2,:] = w

    def update(self):
        self.update_particles()

e = EdgeGrid(N_lame=25, grid_type='line')
#e.particles[2, :] = 0
#e.particles[2, 0] = -1.
#e.particles[2, -1] = 1.
#e.particles[2, :] = 2*np.random.rand(e.N_particles)-1
e.animate(duration=40, fps=10, fname='../files/elasticite/reaction-diffusion-up.mp4')
WARNING:py.warnings:/usr/local/lib/python3.5/site-packages/matplotlib/pyplot.py:516: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

[MoviePy] >>>> Building video ../files/elasticite/reaction-diffusion-up.mp4
[MoviePy] Writing video ../files/elasticite/reaction-diffusion-up.mp4
                                                 
[MoviePy] Done.
[MoviePy] >>>> Video ready: ../files/elasticite/reaction-diffusion-up.mp4 


Out[16]:
In [17]:
class EdgeGrid(el.EdgeGrid):
    def update_particles(self):
        CC = self.particles[:, :, np.newaxis]-self.particles[:, np.newaxis, :] # 2xNxN ; en metres
        distance = np.sqrt(np.sum(CC**2, axis=0))# NxN ; en metres
        d_min, d_max = .2, 1.5
        #f = lambda d: -100./ self.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
        #f = lambda d: 100./ self.N_particles* (np.exp(-d/d_max) - np.exp(-d/d_min))
        f = lambda d: 20./ self.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
        #R = lambda w: - 3.5*np.sin(2*np.pi*w)
        #R = lambda w: w*(1 - w**2)
        R = lambda w: -10.*np.tanh(w) # (1+w)*(1-w)
        
        w = self.particles[2,:]
        #print('w_t', (np.dot(f(distance), w)).mean(), (np.dot(f(distance), w)).std())
        #w *= (1-self.dt)
        w += np.tanh(np.dot(f(distance), w) + R(w))*self.dt
        #print(w.min(), w.max())
        #w /= np.absolute(w).max()
        self.particles[2,:] = w

    def update(self):
        self.update_particles()

e = EdgeGrid(N_lame=25, grid_type='line')
#e.particles[2, :] = 0
#e.particles[2, 0] = -1.
#e.particles[2, -1] = 1.
#e.particles[2, :] = 2*np.random.rand(e.N_particles)-1
e.animate(duration=40, fps=10, fname='../files/elasticite/reaction-diffusion-up.mp4')
WARNING:py.warnings:/usr/local/lib/python3.5/site-packages/matplotlib/pyplot.py:516: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

[MoviePy] >>>> Building video ../files/elasticite/reaction-diffusion-up.mp4
[MoviePy] Writing video ../files/elasticite/reaction-diffusion-up.mp4
                                                 
[MoviePy] Done.
[MoviePy] >>>> Video ready: ../files/elasticite/reaction-diffusion-up.mp4 


Out[17]:

git

In [18]:
!git s
 M ../files/elasticite/reaction-diffusion-up.mp4
 M ../files/elasticite/reaction-diffusion.mp4
 M "2015-10-14 \303\251lasticit\303\251, Fresnel.ipynb"
 M "2015-10-27 \303\251lasticit\303\251 expansion-r\303\251action diffusion.ipynb"
?? __temp_ipython__.png
?? anim.gif
In [19]:
!git commit -am' expansion - équation de reaction diffusion'
[master c4c5757]  expansion - équation de reaction diffusion
 4 files changed, 823 insertions(+), 43 deletions(-)
 rewrite files/elasticite/reaction-diffusion-up.mp4 (98%)
 rewrite files/elasticite/reaction-diffusion.mp4 (75%)
In [20]:
! git push
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (9/9), 13.05 MiB | 10.68 MiB/s, done.
Total 9 (delta 6), reused 0 (delta 0)
To git@git.framasoft.org:laurentperrinet/elasticte.git
   6f0f09b..c4c5757  master -> master
In [21]:
!git pull
Already up-to-date.

Comments

2015-10-27 élasticité rapsberry pyserial

L'installation Elasticité dynamique agit comme un filtre et génère de nouveaux espaces démultipliés, comme un empilement quasi infini d'horizons. Par principe de réflexion, la pièce absorbe l'image de l'environnement et accumule les points de vue ; le mouvement permanent requalifie continuellement ce qui est regardé et entendu.

Ce post étudie la connection entre le raspberry π (qui fait tourner les simulations) et les arduino (qui commandent les moteurs).

Read more…

Comments

2015-10-14 élasticité, control scenario

L'installation Elasticité dynamique agit comme un filtre et génère de nouveaux espaces démultipliés, comme un empilement quasi infini d'horizons. Par principe de réflexion, la pièce absorbe l'image de l'environnement et accumule les points de vue ; le mouvement permanent requalifie continuellement ce qui est regardé et entendu.

Ce post simule une configuration de contrôle sur l'ensemble de la structure.

Read more…

Comments

2015-10-14 élasticité, Fresnel

L'installation Elasticité dynamique agit comme un filtre et génère de nouveaux espaces démultipliés, comme un empilement quasi infini d'horizons. Par principe de réflexion, la pièce absorbe l'image de l'environnement et accumule les points de vue ; le mouvement permanent requalifie continuellement ce qui est regardé et entendu.

Ce post simule une configuration de type Fresnel sur l'ensemble de la structure.

Read more…

Comments

2015-09-30 élasticité, vapory and reflections

L'installation Elasticité dynamique agit comme un filtre et génère de nouveaux espaces démultipliés, comme un empilement quasi infini d'horizons. Par principe de réflexion, la pièce absorbe l'image de l'environnement et accumule les points de vue ; le mouvement permanent requalifie continuellement ce qui est regardé et entendu.

Ce post simule un rendu de reflection utilisant povray.

A scene with mirrors rendered with vapory (see http://blog.invibe.net/posts/2015-01-16-rendering-3d-scenes-in-python.html )

Read more…

Comments

2015-06-12 homebrew cask : updating mactex

Read more…

Comments

2015-05-22 A hitchhiker guide to Matching Pursuit

The Matching Pursuit algorithm is popular in signal processing and applies well to digital images.

I have contributed a python implementation and we will show here how we may use that for extracting a sparse set of edges from an image.



@inbook{Perrinet15bicv,
    title = {Sparse models},
    author = {Perrinet, Laurent U.},
    booktitle = {Biologically-inspired Computer Vision},
    chapter = {13},
    citeulike-article-id = {13566753},
    editor = {Keil, Matthias and Crist\'{o}bal, Gabriel and Perrinet, Laurent U.},
    publisher = {Wiley, New-York},
    year = {2015}
}

Read more…

Comments

2015-05-21 A simple pre-processing filter for image processing

When processing images, it is useful to avoid artifacts, in particular when you try to understand biological processes. In the past, I have used natural images (found on internet, grabbed from holiday pictures, ...) without controlling for possible problems.

In particular, digital pictures are taken on pixels which are most often placed on a rectangular grid. It means that if you rotate that image, you may lose information and distort it and thus get wrong results (even for the right algorithm!). Moreover, pictures have a border while natural scenes do not, unless you are looking at it through an aperture. Intuitively, this means that large objects would not fit on the screen and are less informative.

In computer vision, it is easier to handle these problems in Fourier space. There, an image (that we suppose square for simplicity) is transformed in a matrix of coefficients of the same size as the image. If you rotate the image, the Fourier spectrum is also rotated. But as you rotate the image, the information that was in the corners of the original spectrum may span outside the spectrum of the rotated image. Also, the information in the center of the spectrum (around low frequencies) is less relevant than the rest.

Here, we will try to keep as much information about the image as possible, while removing the artifacts related to the process of digitalizing the picture.

Read more…

Comments