This wikilog article is a draft, it was not published yet.

Julia programming

⇠ Back to Blog:Sandbox
m
m
 
(6 intermediate revisions by one user not shown)
Line 1: Line 1:
We could now study still other methods, such as the Backward Euler method, or Implicit Euler method. But we will instead turn to other numerical problems, namely, interpolation and extrapolation.
+
<center><wz tip="Still frames for an excitable medium with a=11 and g=2">[[File:Screenshot_20210315_164359.png|400px]]</wz></center>
  
Interpolation describes the general problem of providing the value of a function which is known only for a few points, at any point which lies between other known points (if the unknown point is not "surrounded" by known points, then the problem becomes that of "extrapolation").
+
Here is the same but animated:
  
The simplest and also most natural method of interpolation. It has been used since immemorial times throughout history and remains a basic technique in the computer industry, which even formed a special name for it, "lerp" (also used as a verb).
+
<center><wz tip="250 iterations of the a=11 g=2 excitable model.">[[File:excitable-medium-a2-b11.gif|400px]]</wz></center>
  
The method simply consists in finding the equation for a line between two points, those which are known from the data, i.e.,
+
Playing with the parameter space:
  
$$L(x)=f(a)+{f(b)-f(a)\over b-a}(x-a)$$
+
<center><wz tip="Two (out of the many) configurations:">[[File:Screenshot_20210315_181551.png|400px]]</wz></center>
  
Let us assume that in the parametrization of our problem, the range of the function is the number of equally-spaced data points known and we wish to interpolate to real-valued functions. All variations of lerp will do something similar. We can then refer to the known data points $a$ and $b$ from $x$ as:
+
And the bottom case, animated:
  
$$
+
<center><wz tip="250 iterations of the a=10 g=20 excitable model with a lot of initially infected cells in various stages, preventing extinction.">[[File:excitable-medium-a10-b20.gif|400px]]</wz></center>
\begin{align}
+
a&=\lfloor x\rfloor\\
+
b&=\lceil x\rceil
+
\end{align}
+
$$
+
  
where the floor and ceil functions are defined as follows:
+
It is interesting to focus on the surviving spot. We can zoom on this area and see what is going on there. The cells have locked into this stable pattern, involving, apparently, two cells only:
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
plot([floor, ceil], -3:.1:3, legend=false, lw=2)
+
excited = @animate for i ∈ 1:30
 +
          excite()
 +
          plotspace(145, 220, 225, 300)
 +
      end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<center><wz tip="The floor and ceil functions (with linear interpolation causing the tilt).">[[File:Screenshot_26-03-2020_182425.jpg|400px]]</wz></center>
+
<center><wz tip="A stable 2-cells pattern that survives in the g>a configuration by locking two neighbours with a period a+b=30.">[[File:stable-2cells-pattern.gif|400px]]</wz></center>
  
In this case, our linear interpolation is easily implemented. Here is some sample data:
+
It is interesting as well to change parameters during the simulation. This locks the patterns into some dislocated sequences which give rise to apparent cycles of stationary-evolution in space, which, however, are due to structures that formed under previous conditions of evolution. For instance, the following was obtained by iterating 50 iterations with parameters <tt>a=50 and g=25</tt> then changing <tt>g=5</tt> for 50 iterations and coming back to the initial <tt>g=25</tt> and cycling for ever:
  
<syntaxhighlight lang="python">
+
<center><wz tip="Strange oscillations in the wake of changing parameters in mid-flight. This is an interesting optical effect due to dephasing of the wavefronts caused by dislocations in the structure following various types of evolutions.">[[File:strange-oscillations.gif|400px]]</wz></center>
data = [sin(i) for i=0:2pi]
+
</syntaxhighlight>
+
  
And here is the function to "lerp" it:
+
There clearly appears to have two types of oscillations, one seemingly stationary in space whereas the over travels as wavefronts, that get periodically frozen. This is, however, merely an optical artifact, that can be well understood by looking at the state of the cell's evolution in time. Here is such a cut obtained in a similar configuration as the one displayed as a full density plot:
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
function lerpdata(x)
+
for i=1:75
    a=floor(Int,x);
+
  println(global iteration+=1); excite();
    b=ceil(Int,x);
+
  Plots.display(plot(space[[100],:]', ylims=(0,a+g), lw=2, legend=false))
    data[a]+((data[b]-data[a])/(b-a))*(x-a)
+
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<syntaxhighlight lang="python">
+
<center><wz tip="Slice through the cellular automaton showing two types of oscillations, as a result of dislocations: drifting and collapsing.">[[File:wavefronts-excitable-medium-cut.gif|400px]]</wz></center>
scatter(data)
+
plot!(lerpdata,1:.01:7, lw=3, ls=:dash, legend=false)
+
</syntaxhighlight>
+
 
+
<center><wz tip="Linear interpolation of a sine.">[[File:Screenshot_26-03-2020_202110.jpg|400px]]</wz></center>
+
 
+
While it works well with enough points if the data has no noise, if it has, it gives disagreeable results:
+
 
+
<syntaxhighlight lang="python">
+
data = [sin(i)+rand()/5 for i=0:.1:2pi]
+
scatter(data)
+
plot!(lerpdata,1:.0001:63, lw=3, legend=false)
+
</syntaxhighlight>
+
 
+
<center><wz tip="Linear interpolation of a highly-sampled noisy sine: not a very good result.">[[File:Screenshot_26-03-2020_202640.jpg|400px]]</wz></center>
+
 
+
 
+
 
+
In two dimensions, linear interpolation becomes bilinear interpolations (in 3D, trilinear, etc.)
+
  
Polynomial interpolation.
+
One can see how the dislocations cause this alternances of drifting or collapsing evolution of the cell states.
  
Spline interpolation.
+
Clearly there are many variations and configurations to explore, this is barely scratching the surface. Instead of delving further into this model, we turn to the most famous and also more impressive Hodgepodge machine.
  
Runge's phenomenon.
+
{{WLP6}}

Latest revision as of 21:51, 15 March 2021

Screenshot 20210315 164359.png

Here is the same but animated:

Excitable-medium-a2-b11.gif

Playing with the parameter space:

Screenshot 20210315 181551.png

And the bottom case, animated:

Excitable-medium-a10-b20.gif

It is interesting to focus on the surviving spot. We can zoom on this area and see what is going on there. The cells have locked into this stable pattern, involving, apparently, two cells only:

excited = @animate for i ∈ 1:30
           excite()
           plotspace(145, 220, 225, 300)
       end
a configuration by locking two neighbours with a period a+b=30.">Stable-2cells-pattern.gif

It is interesting as well to change parameters during the simulation. This locks the patterns into some dislocated sequences which give rise to apparent cycles of stationary-evolution in space, which, however, are due to structures that formed under previous conditions of evolution. For instance, the following was obtained by iterating 50 iterations with parameters a=50 and g=25 then changing g=5 for 50 iterations and coming back to the initial g=25 and cycling for ever:

Strange-oscillations.gif

There clearly appears to have two types of oscillations, one seemingly stationary in space whereas the over travels as wavefronts, that get periodically frozen. This is, however, merely an optical artifact, that can be well understood by looking at the state of the cell's evolution in time. Here is such a cut obtained in a similar configuration as the one displayed as a full density plot:

for i=1:75
   println(global iteration+=1); excite();
   Plots.display(plot(space[[100],:]', ylims=(0,a+g), lw=2, legend=false))
end
Wavefronts-excitable-medium-cut.gif

One can see how the dislocations cause this alternances of drifting or collapsing evolution of the cell states.

Clearly there are many variations and configurations to explore, this is barely scratching the surface. Instead of delving further into this model, we turn to the most famous and also more impressive Hodgepodge machine.