Controlling particle trajectories in rule 146

Can the trajectory of a particle in rule 146 be controlled?

Simplest case: 1 particle in the system, try to make it stay at the same position for all time.

Is there an initial condition that would achieve that?  Perhaps a perfectly symmetric one?

In an evolution where the particle stays at one position for all time, does the particle size distribution change vs an evolution where the particle meanders?  i.e. the run lengths of even runs, does the distribution of even run lengths change?

Is there some trade-off between the size of fluctuations in particle size and the deviation from a random walk?  I mean, if you try to control the particle trajectory, does it require messing with the size of the particle much?  I’m thinking of a Heisenberg uncertainty kind of thing, where localizing the particle in space means the momentum becomes uncertain.  Not sure what the right analogy is between momentum and particle size … or if there’s any anology there at all.  Maybe particle size is literally like the mass?

question-rule146-particle-control_1.gif

question-rule146-particle-control_2.gif

question-rule146-particle-control_3.gif

question-rule146-particle-control_4.gif

question-rule146-particle-control_5.gif

question-rule146-particle-control_6.gif

question-rule146-particle-control_7.gif

question-rule146-particle-control_8.gif

question-rule146-particle-control_9.gif

question-rule146-particle-control_10.gif

question-rule146-particle-control_11.gif

question-rule146-particle-control_12.gif

Hmmm, I thik it’s impossible to have a perfectly symmetric initial condition that has an odd run on the boundary, such that no particle appears there.

question-rule146-particle-control_13.gif

question-rule146-particle-control_14.gif

question-rule146-particle-control_15.gif

question-rule146-particle-control_16.gif

So I have to put the single particle on the boundary intentionally, and then RotateRight …

question-rule146-particle-control_17.gif

question-rule146-particle-control_18.gif

question-rule146-particle-control_19.gif

question-rule146-particle-control_20.gif

question-rule146-particle-control_21.gif

question-rule146-particle-control_22.gif

Right that works, but I happened to choose a width close to 2^n so there was a big annihilation:

question-rule146-particle-control_23.gif

question-rule146-particle-control_24.gif

Choose a different width:

question-rule146-particle-control_25.gif

question-rule146-particle-control_26.gif

question-rule146-particle-control_27.gif

question-rule146-particle-control_28.gif

question-rule146-particle-control_29.gif

question-rule146-particle-control_30.gif

Generalize to any width …
Symmetric random initial with a length of about n:

question-rule146-particle-control_31.gif

question-rule146-particle-control_32.gif

question-rule146-particle-control_33.gif

question-rule146-particle-control_34.gif

question-rule146-particle-control_35.gif

question-rule146-particle-control_36.gif question-rule146-particle-control_37.gif question-rule146-particle-control_38.gif question-rule146-particle-control_39.gif question-rule146-particle-control_40.gif
question-rule146-particle-control_41.gif question-rule146-particle-control_42.gif question-rule146-particle-control_43.gif question-rule146-particle-control_44.gif question-rule146-particle-control_45.gif
question-rule146-particle-control_46.gif question-rule146-particle-control_47.gif question-rule146-particle-control_48.gif question-rule146-particle-control_49.gif question-rule146-particle-control_50.gif
question-rule146-particle-control_51.gif question-rule146-particle-control_52.gif question-rule146-particle-control_53.gif question-rule146-particle-control_54.gif question-rule146-particle-control_55.gif
question-rule146-particle-control_56.gif question-rule146-particle-control_57.gif question-rule146-particle-control_58.gif question-rule146-particle-control_59.gif question-rule146-particle-control_60.gif
question-rule146-particle-control_61.gif question-rule146-particle-control_62.gif question-rule146-particle-control_63.gif question-rule146-particle-control_64.gif question-rule146-particle-control_65.gif
question-rule146-particle-control_66.gif question-rule146-particle-control_67.gif question-rule146-particle-control_68.gif question-rule146-particle-control_69.gif question-rule146-particle-control_70.gif
question-rule146-particle-control_71.gif question-rule146-particle-control_72.gif question-rule146-particle-control_73.gif question-rule146-particle-control_74.gif question-rule146-particle-control_75.gif
question-rule146-particle-control_76.gif question-rule146-particle-control_77.gif question-rule146-particle-control_78.gif question-rule146-particle-control_79.gif question-rule146-particle-control_80.gif
question-rule146-particle-control_81.gif question-rule146-particle-control_82.gif question-rule146-particle-control_83.gif question-rule146-particle-control_84.gif question-rule146-particle-control_85.gif
question-rule146-particle-control_86.gif question-rule146-particle-control_87.gif question-rule146-particle-control_88.gif question-rule146-particle-control_89.gif question-rule146-particle-control_90.gif
question-rule146-particle-control_91.gif question-rule146-particle-control_92.gif question-rule146-particle-control_93.gif question-rule146-particle-control_94.gif question-rule146-particle-control_95.gif
question-rule146-particle-control_96.gif question-rule146-particle-control_97.gif question-rule146-particle-control_98.gif question-rule146-particle-control_99.gif question-rule146-particle-control_100.gif
question-rule146-particle-control_101.gif question-rule146-particle-control_102.gif question-rule146-particle-control_103.gif question-rule146-particle-control_104.gif question-rule146-particle-control_105.gif
question-rule146-particle-control_106.gif question-rule146-particle-control_107.gif question-rule146-particle-control_108.gif question-rule146-particle-control_109.gif question-rule146-particle-control_110.gif
question-rule146-particle-control_111.gif question-rule146-particle-control_112.gif question-rule146-particle-control_113.gif question-rule146-particle-control_114.gif question-rule146-particle-control_115.gif
question-rule146-particle-control_116.gif question-rule146-particle-control_117.gif question-rule146-particle-control_118.gif question-rule146-particle-control_119.gif question-rule146-particle-control_120.gif
question-rule146-particle-control_121.gif question-rule146-particle-control_122.gif question-rule146-particle-control_123.gif question-rule146-particle-control_124.gif question-rule146-particle-control_125.gif
question-rule146-particle-control_126.gif question-rule146-particle-control_127.gif question-rule146-particle-control_128.gif question-rule146-particle-control_129.gif question-rule146-particle-control_130.gif
question-rule146-particle-control_131.gif question-rule146-particle-control_132.gif question-rule146-particle-control_133.gif question-rule146-particle-control_134.gif question-rule146-particle-control_135.gif

ECAM rules: dependence of final density on initial density

ECAM mean field density maps

From my thesis work many moons ago …

I made these really cool map of the number of iterations it took for mean field approximations of the density of ECAM rules to converge …

ECAM-T-density-vs-initial-density-110611_1.gif

ECAMProbs[] returns the probability vector for an ECAM, which is a modification of that for an ECA, where the centre cell in each 3-cell neighborhood has probability p[t-δ].

ECAM-T-density-vs-initial-density-110611_2.gif

ECAM-T-density-vs-initial-density-110611_3.gif

ECAM-T-density-vs-initial-density-110611_4.gif

ECAM-T-density-vs-initial-density-110611_5.gif

ECAM-T-density-vs-initial-density-110611_6.gif

ECAM-T-density-vs-initial-density-110611_7.gif

ECAM-T-density-vs-initial-density-110611_8.gif

ECAM-T-density-vs-initial-density-110611_9.gif

ECAM-T-density-vs-initial-density-110611_10.gif

ECAM-T-density-vs-initial-density-110611_11.gif

ECAM-T-density-vs-initial-density-110611_12.gif

ECAM-T-density-vs-initial-density-110611_13.gif

ECAM-T-density-vs-initial-density-110611_14.gif

ECAM-T-density-vs-initial-density-110611_15.gif

ECAM-T-density-vs-initial-density-110611_16.gif

ECAM-T-density-vs-initial-density-110611_17.gif

ECAM-T-density-vs-initial-density-110611_18.gif

Number of iterations required for density convergence of rule 30 as a function of the initial densities p1 and p2 on the x and y axis, respectively.  p1 and p2 are the densities of the two rows comprising the initial condition for the ECAM-1 rule.

ECAM-T-density-vs-initial-density-110611_19.gif

ECAM-T-density-vs-initial-density-110611_20.gif

ECAM-T-density-vs-initial-density-110611_21.gif

ECAM-T-density-vs-initial-density-110611_22.gif

ECAM-T-density-vs-initial-density-110611_23.gif

ECAM-T-density-vs-initial-density-110611_24.gif

It’s a pretty interesting map!

now do something similar without the mean-field approximation …
actually run the rule
plot the final density after T time steps as a function of the inital density

original notebook from April 2006:

ECAM-T-density-vs-initial-density-110611_25.gif

ECAM-T-density-vs-initial-density-110611_26.gif

ECAM-T-density-vs-initial-density-110611_27.gif

ECAM-T-density-vs-initial-density-110611_28.gif

ECAM-T-density-vs-initial-density-110611_29.gif

ECAM-T-density-vs-initial-density-110611_30.gif

ECAM-T-density-vs-initial-density-110611_31.gif

ECAM-T-density-vs-initial-density-110611_32.gif

ECAM-T-density-vs-initial-density-110611_33.gif

ECAM-T-density-vs-initial-density-110611_34.gif

MapECAMDensity[rl_,T_,n_,initdensity_] returns the density of T steps of evolution of rule rl ECAM-T, with n spatial sites and memory T.

ECAM-T-density-vs-initial-density-110611_35.gif

ECAM-T-density-vs-initial-density-110611_36.gif

ECAM-T-density-vs-initial-density-110611_37.gif

Evolution of rule 18 ECAM-20 (i.e. memory T=20) for 20 time steps:

ECAM-T-density-vs-initial-density-110611_38.gif

ECAM-T-density-vs-initial-density-110611_39.gif

Varying the initial density:

ECAM-T-density-vs-initial-density-110611_40.gif

ECAM-T-density-vs-initial-density-110611_41.gif

Density after T time steps as a function of the density of the initial condition:

ECAM-T-density-vs-initial-density-110611_42.gif

Graphics:rule 18 ECAM, T=20

Same for rule 232 ECAM-20:

ECAM-T-density-vs-initial-density-110611_44.gif

ECAM-T-density-vs-initial-density-110611_45.gif

ECAM-T-density-vs-initial-density-110611_46.gif

Graphics:rule 232 ECAM, T=20

… and for rule 146 ECAM-20:

ECAM-T-density-vs-initial-density-110611_48.gif

ECAM-T-density-vs-initial-density-110611_49.gif

ECAM-T-density-vs-initial-density-110611_50.gif

Graphics:rule 146 ECAM, T=20

Take an average of 10 runs for each point (and show the point plus and minus one standard deviation from the mean above and below the average curve):

ECAM-T-density-vs-initial-density-110611_52.gif

Graphics:rule 146 ECAM, T=20

Rule 18 particle: correlation statistics (jellyfish plots)

single-particle correlation data

rule-18-correlations-032711_1.gif

rule-18-correlations-032711_2.gif

rule-18-correlations-032711_3.gif

rule-18-correlations-032711_4.gif

rule-18-correlations-032711_5.gif

rule-18-correlations-032711_6.gif

rule-18-correlations-032711_7.gif

rule-18-correlations-032711_8.gif

rule-18-correlations-032711_9.gif

Single-particle correlations from just one evolution, for width 251:

rule-18-correlations-032711_10.gif

rule-18-correlations-032711_11.gif

statistical sampling of correlations at each correlation distance

system width: 251

rule-18-correlations-032711_12.gif

rule-18-correlations-032711_13.gif

rule-18-correlations-032711_14.gif

rule-18-correlations-032711_15.gif

rule-18-correlations-032711_16.gif

rule-18-correlations-032711_17.gif

rule-18-correlations-032711_18.gif

rule-18-correlations-032711_19.gif

Find a histogram of the correlations at a given correlation distance

rule-18-correlations-032711_20.gif

rule-18-correlations-032711_21.gif

rule-18-correlations-032711_22.gif

rule-18-correlations-032711_23.gif

rule-18-correlations-032711_24.gif

rule-18-correlations-032711_25.gif

rule-18-correlations-032711_26.gif

rule-18-correlations-032711_27.gif

rule-18-correlations-032711_28.gif

rule-18-correlations-032711_29.gif

rule-18-correlations-032711_30.gif

rule-18-correlations-032711_31.gif

rule-18-correlations-032711_32.gif

rule-18-correlations-032711_33.gif

rule-18-correlations-032711_34.gif

rule-18-correlations-032711_35.gif

rule-18-correlations-032711_36.gif

correlation histograms for various correlation distances

rule-18-correlations-032711_37.gif

rule-18-correlations-032711_38.gif

correlation envelopes

Now show the histogram as a function of correlation distance:

rule-18-correlations-032711_39.gif

rule-18-correlations-032711_40.gif

rule-18-correlations-032711_41.gif

rule-18-correlations-032711_42.gif

rule-18-correlations-032711_43.gif

rule-18-correlations-032711_44.gif

rule-18-correlations-032711_45.gif

The boundaries above and below in the plot define an envelope for the correlations at this system width:

rule-18-correlations-032711_46.gif

rule-18-correlations-032711_47.gif

How does the shape of the envelope change as the system width is increased?

width 398

rule-18-correlations-032711_48.gif

rule-18-correlations-032711_49.gif

rule-18-correlations-032711_50.gif

rule-18-correlations-032711_51.gif

rule-18-correlations-032711_52.gif

rule-18-correlations-032711_53.gif

rule-18-correlations-032711_54.gif

width 630

rule-18-correlations-032711_55.gif

rule-18-correlations-032711_56.gif

rule-18-correlations-032711_57.gif

rule-18-correlations-032711_58.gif

rule-18-correlations-032711_59.gif

rule-18-correlations-032711_60.gif

rule-18-correlations-032711_61.gif

width 1000

rule-18-correlations-032711_62.gif

rule-18-correlations-032711_63.gif

rule-18-correlations-032711_64.gif

rule-18-correlations-032711_65.gif

rule-18-correlations-032711_66.gif

rule-18-correlations-032711_67.gif

rule-18-correlations-032711_68.gif

rule-18-correlations-032711_69.gif

rule-18-correlations-032711_70.gif

width 1584

rule-18-correlations-032711_71.gif

rule-18-correlations-032711_72.gif

rule-18-correlations-032711_73.gif

rule-18-correlations-032711_74.gif

rule-18-correlations-032711_75.gif

rule-18-correlations-032711_76.gif

rule-18-correlations-032711_77.gif

rule-18-correlations-032711_78.gif

rule-18-correlations-032711_79.gif

width 2511

rule-18-correlations-032711_80.gif

rule-18-correlations-032711_81.gif

rule-18-correlations-032711_82.gif

rule-18-correlations-032711_83.gif

rule-18-correlations-032711_84.gif

rule-18-correlations-032711_85.gif

rule-18-correlations-032711_86.gif

rule-18-correlations-032711_87.gif

rule-18-correlations-032711_88.gif

width 3981

rule-18-correlations-032711_89.gif

rule-18-correlations-032711_90.gif

rule-18-correlations-032711_91.gif

rule-18-correlations-032711_92.gif

rule-18-correlations-032711_93.gif

rule-18-correlations-032711_94.gif

rule-18-correlations-032711_95.gif

rule-18-correlations-032711_96.gif

rule-18-correlations-032711_97.gif

width 6309

rule-18-correlations-032711_98.gif

rule-18-correlations-032711_99.gif

rule-18-correlations-032711_100.gif

rule-18-correlations-032711_101.gif

rule-18-correlations-032711_102.gif

rule-18-correlations-032711_103.gif

rule-18-correlations-032711_104.gif

rule-18-correlations-032711_105.gif

rule-18-correlations-032711_106.gif

width 10000

rule-18-correlations-032711_107.gif

rule-18-correlations-032711_108.gif

rule-18-correlations-032711_109.gif

rule-18-correlations-032711_110.gif

rule-18-correlations-032711_111.gif

rule-18-correlations-032711_112.gif

rule-18-correlations-032711_113.gif

These plots totally look like jellyfish.

rule-18-correlations-032711_114.gif

rule-18-correlations-032711_115.gif

next: plot the raw particle trajectories in an interesting way …

rule-18-correlations-032711_116.gif

rule-18-correlations-032711_117.gif

rule-18-correlations-032711_118.gif

rule-18-correlations-032711_119.gif

rule-18-correlations-032711_120.gif

rule-18-correlations-032711_121.gif

rule-18-correlations-032711_122.gif

rule-18-correlations-032711_123.gif

Rule 18: correlations vs system size

autocorrelations in rule 18 particle position as a function of system size

It’s time to look at the autocorrelations in the rule 18 single-particle movement as a function of system size, for a larger range of system sizes (several orders of magnitude), with some statistics for each width.

Here’s the simulation code …

functions

rule-18-corr-vs-system-size-031211_1.gif

rule-18-corr-vs-system-size-031211_2.gif

rule-18-corr-vs-system-size-031211_3.gif

rule-18-corr-vs-system-size-031211_4.gif

rule-18-corr-vs-system-size-031211_5.gif

rule-18-corr-vs-system-size-031211_6.gif

rule-18-corr-vs-system-size-031211_7.gif

rule-18-corr-vs-system-size-031211_8.gif

simulation code:
correlation vs distance as a function of system size

rule-18-corr-vs-system-size-031211_9.gif

rule-18-corr-vs-system-size-031211_10.gif

rule-18-corr-vs-system-size-031211_11.gif

rule-18-corr-vs-system-size-031211_12.gif

data analysis

Now grab the resulting data files:

rule-18-corr-vs-system-size-031211_13.gif

rule-18-corr-vs-system-size-031211_14.gif

rule-18-corr-vs-system-size-031211_15.gif

Each index here is a different width:

rule-18-corr-vs-system-size-031211_16.gif

rule-18-corr-vs-system-size-031211_17.gif

rule-18-corr-vs-system-size-031211_18.gif

rule-18-corr-vs-system-size-031211_19.gif

I chose widths logarithmically spaced spanning 3 orders of magnitude, in the range 100 to 10,000:

rule-18-corr-vs-system-size-031211_20.gif

rule-18-corr-vs-system-size-031211_21.gif

These widths will be evenly spaced on a log plot.

Take a look at a single run at width 100:

rule-18-corr-vs-system-size-031211_22.gif

rule-18-corr-vs-system-size-031211_23.gif

rule-18-corr-vs-system-size-031211_24.gif

rule-18-corr-vs-system-size-031211_25.gif

rule-18-corr-vs-system-size-031211_26.gif

rule-18-corr-vs-system-size-031211_27.gif

Here’s the particle position vs. time, run for 50k steps:

rule-18-corr-vs-system-size-031211_28.gif

rule-18-corr-vs-system-size-031211_29.gif

The particle position went periodic.  Not surprising for such a small system width.  Here’s the correlation function, which also has a strong periodicity:

rule-18-corr-vs-system-size-031211_30.gif

rule-18-corr-vs-system-size-031211_31.gif

Let’s look at all of the runs for width 100:

rule-18-corr-vs-system-size-031211_32.gif

rule-18-corr-vs-system-size-031211_33.gif

rule-18-corr-vs-system-size-031211_34.gif

(Note that my particleposition code treats periodic boundary crossings as reflections.)

And all the correlations at this width:

rule-18-corr-vs-system-size-031211_35.gif

rule-18-corr-vs-system-size-031211_36.gif

rule-18-corr-vs-system-size-031211_37.gif

The correlations have a pretty regular structure, since all the evolutions seemed to have gone periodic within about 10k steps.  Given this reglar structure, it seems worthwhile to take the average autocorrelation at each distance:

rule-18-corr-vs-system-size-031211_38.gif

rule-18-corr-vs-system-size-031211_39.gif

rule-18-corr-vs-system-size-031211_40.gif

rule-18-corr-vs-system-size-031211_41.gif

rule-18-corr-vs-system-size-031211_42.gif

rule-18-corr-vs-system-size-031211_43.gif

rule-18-corr-vs-system-size-031211_44.gif

Do this for all the other system widths:

rule-18-corr-vs-system-size-031211_45.gif

rule-18-corr-vs-system-size-031211_46.gif

rule-18-corr-vs-system-size-031211_47.gif

rule-18-corr-vs-system-size-031211_48.gif

rule-18-corr-vs-system-size-031211_49.gif

rule-18-corr-vs-system-size-031211_50.gif

rule-18-corr-vs-system-size-031211_51.gif

rule-18-corr-vs-system-size-031211_52.gif

Graphics:width 100
Graphics:width 158
Graphics:width 251
Graphics:width 398
Graphics:width 630
Graphics:width 1000
Graphics:width 1584
Graphics:width 2511
Graphics:width 3981
Graphics:width 6309
Graphics:width 10000

The correlation functions at each width have a prett similar structure.  It isn’t clear if I’m resolving any real differences it the correlations here at all actually.  It could be that the particle really isn’t much effected by the system size.

Vitaliy recommended that I look at the power spectrum, which is related to these correlation functions via the Weiner-Kinchin theorem.  That’s the next thing to do I think.

Rule 18: long-range particle correlations

I ran a few batch jobs with longer evolutions of rule 18 (100k steps, used to be 10k steps), and measuring much longer-range correlations than before (out to distances of 50k and 100k correlation distances).

My first task was to speed up the correlation distance function as much as possible.

speeding up the correlation function

Generate a random walk:

long-range-correlations-rule-18-walk_1.gif

long-range-correlations-rule-18-walk_2.gif

long-range-correlations-rule-18-walk_3.gif

My original version of the correlation function, which I want to speed up:

long-range-correlations-rule-18-walk_4.gif

Timing for a single correlation data point (lag 1):

long-range-correlations-rule-18-walk_5.gif

long-range-correlations-rule-18-walk_6.gif

I want to do this without using Partition, since I think it’s taking a lot of memory.

Try using RotateRight instead … already an order of magnitude faster:

long-range-correlations-rule-18-walk_7.gif

long-range-correlations-rule-18-walk_8.gif

long-range-correlations-rule-18-walk_9.gif

long-range-correlations-rule-18-walk_10.gif

long-range-correlations-rule-18-walk_11.gif

long-range-correlations-rule-18-walk_12.gif

A similar version which doesn’t wrap at the boundaries.  I don’t want to wrap around the boundaries in *time*, because there’s no reason to correlate the beginning of the timeseries with the end of the timeseries.  Normalization uses a few less points of the list, so the correlation comes out numerically slightly different:

long-range-correlations-rule-18-walk_13.gif

long-range-correlations-rule-18-walk_14.gif

… but it’s just as fast as the RotateRight method, and I think it’s more accurate for my purposes since it doesn’t do temporal wrapping.

So here’s my new correlation function:

long-range-correlations-rule-18-walk_15.gif

long-range-correlations-rule-18-walk_16.gif

long-range-correlations-rule-18-walk_17.gif

measuring long-range correlations in the rule 18 particle movement

Grab the particle correlation data for a rule 18 evolution of 100k timesteps (still using a width of 199 cells):

long-range-correlations-rule-18-walk_18.gif

And grab the actual position vs. time for the particle:

long-range-correlations-rule-18-walk_19.gif

long-range-correlations-rule-18-walk_20.gif

long-range-correlations-rule-18-walk_21.gif

long-range-correlations-rule-18-walk_22.gif

long-range-correlations-rule-18-walk_23.gif

Got about 50k correlation data points:

long-range-correlations-rule-18-walk_24.gif

long-range-correlations-rule-18-walk_25.gif

long-range-correlations-rule-18-walk_26.gif

long-range-correlations-rule-18-walk_27.gif

Here’s the beginning of the walk:

long-range-correlations-rule-18-walk_28.gif

long-range-correlations-rule-18-walk_29.gif

But it clearly went periodic:

long-range-correlations-rule-18-walk_30.gif

long-range-correlations-rule-18-walk_31.gif

And the correlations also went periodic:

long-range-correlations-rule-18-walk_32.gif

long-range-correlations-rule-18-walk_33.gif

So I did another evolution, this time using width of 999 cells:

long-range-correlations-rule-18-walk_34.gif

long-range-correlations-rule-18-walk_35.gif

long-range-correlations-rule-18-walk_36.gif

long-range-correlations-rule-18-walk_37.gif

long-range-correlations-rule-18-walk_38.gif

long-range-correlations-rule-18-walk_39.gif

long-range-correlations-rule-18-walk_40.gif

long-range-correlations-rule-18-walk_41.gif

Now the walk doesn’t go periodic, because the underlying evolution didn’t go periodic:

long-range-correlations-rule-18-walk_42.gif

long-range-correlations-rule-18-walk_43.gif

And behold the long-range correlations!

long-range-correlations-rule-18-walk_44.gif

long-range-correlations-rule-18-walk_45.gif

This is an interesting plot.  Correlations fall gradually here over about 50k lag, then hover around a negative correlation of around -0.4 from 50k to 100k lag.

Next steps:

1. Get a statistical distribution of correlations at each lag, from multiple runs of the rule 18 particle

Rule 18 single-particle correlations: larger correlation distances

Rule 18: Eating its own light cone (Part 5)

At the last ruleshack meetup, we discussed why the autocorrelation curve for the position of the rule 18 particle appears to be linear.  And we realized that I’m probably just not looking at large enough correlation distances (lags).

The particle position vs time looks like this:

rule-18-random-walk-022611_1.gif

rule-18-random-walk-022611_2.gif

rule-18-random-walk-022611_3.gif

rule-18-random-walk-022611_4.gif

rule-18-random-walk-022611_5.gif

rule-18-random-walk-022611_6.gif

And the autocorrelations out to lag 100 look like this:

rule-18-random-walk-022611_7.gif

rule-18-random-walk-022611_8.gif

rule-18-random-walk-022611_9.gif

rule-18-random-walk-022611_10.gif

During the meetup, we looked at the particle position with the mean subtracted (since that’s what the autocorrelation function is based on):

rule-18-random-walk-022611_11.gif

rule-18-random-walk-022611_12.gif

We noticed that the typical time between zero crossings (when the curve crosses the x-axis in this plot, or equivalently the instants in time when the particle passes through its average position), is greater than the maximum lag I was using of 100 time steps.  In fact, looking at the mean-subtracted position plot above, sometimes it’s more like 1000 time steps between crossings.  That means I need to sample much larger lags in order to capture more features of the random walk.

To be more precise, I can compute the crossing intervals, and the distribution of interval sizes:

rule-18-random-walk-022611_13.gif

rule-18-random-walk-022611_14.gif

rule-18-random-walk-022611_15.gif

rule-18-random-walk-022611_16.gif

rule-18-random-walk-022611_17.gif

rule-18-random-walk-022611_18.gif

rule-18-random-walk-022611_19.gif

The average interval size:

rule-18-random-walk-022611_20.gif

rule-18-random-walk-022611_21.gif

rule-18-random-walk-022611_22.gif

rule-18-random-walk-022611_23.gif

The interval distribution:

rule-18-random-walk-022611_24.gif

rule-18-random-walk-022611_25.gif

rule-18-random-walk-022611_26.gif

rule-18-random-walk-022611_27.gif

It looks like the average crossing interval size is of the order of a few hundred time steps, with a intervals of order 10 being most common, but with some rare intervals being on the order of 1000 time steps.  

Call the average crossing interval rule-18-random-walk-022611_28.gif.  Then the products p(t)*p(t+r) will tend to be positive for rule-18-random-walk-022611_29.gif.  But for lags rule-18-random-walk-022611_30.gif, there will be more products where p(t) and p(t+r) have different sign, and thus contributing negative terms to the sum over t.  So I’d expect the autocorrelations to start becoming negative somewhere around rule-18-random-walk-022611_31.gif.

Here’s what the correlations look like out to lag 2000 (which I ran on a server).  The curve is looking more interesting now, with the linearity going away at around lag 1000.

rule-18-random-walk-022611_32.gif

rule-18-random-walk-022611_33.gif

rule-18-random-walk-022611_34.gif

rule-18-random-walk-022611_35.gif

Blog this notebook! A WordPress client for Mathematica.

weblog-client-021211_1.gif

weblog-client-021211_2.gif

An XML-RPC WordPress Weblog Client for Mathematica
Sat Feb 12, 2011

I’m getting tired of having to manually copy the HTML code generated by Mathematica’s Export[file, “HTML”] command into the WordPress editor in order to post a notebook to my blog.  So I decided to write a WordPress weblog client for Mathematica.  The client uses the WordPress XML-RPC (XML remote procedure call) API to send blog post data directly from my home computer to my web server.

The first step was to find some documentation on the WordPress XML-RPC API, which I found on a few different sites:  the main WP API codex, a helpful blog detailing more of the API functions than are listed in the codex, and the actual XML-RPC spec.

I also discovered that I needed to enable the XML-RPC server in my WordPress installation
before attempting to post to the blog remotely.

The basic steps in posting a Mathematica notebook to my WordPress blog are:

1. Export the Mathematica notebook as HTML
2. Encode the resulting HTML in an XML message using the XML-RPC format expected by WordPress
3. Send the XML to the WordPress server as an HTTP POST request
4. Decode the XML response sent back from the server
5. Repeat steps 2-4 to upload all image files generated by the HTML export to the server

In order to easily test that all this was working, I decided to install a local web server on my MacBook Pro.  Rather than mess with trying to install Apache Tomcat from scratch, I opted to install MAMP, which is a self-contained web server for Macs that includes Apache, MySQL, and PHP all in one.

After using MAMP to create a web server on http://localhost:8888, I installed WordPress at http://localhost:8888/wordpress.  So now I was up and running with a local WordPress installation that I could test my blog client code against.

Here’s the simple example notebook I want to post to my blog:

weblog-client-021211_3.gif

1. Export the Mathematica notebook as HTML

The first step is to export the notebook in HTML format.  I took some pointers from another Mathematica-based blog in getting a first version of the following function to work.  It’s working at a basic level now, but it needs improvement.  Mainly, I need to add a “ConversionRules” option to Export in order to wrap the various Mathematica styes (from Mathematica’s own stylesheet) in custom tags, which will allow me to match the CSS classes referenced in the generated HTML with the CSS file used in my WordPress theme.

weblog-client-021211_4.gif

weblog-client-021211_5.gif

I feed this function a notebook file name, an HTML file name, and a date.  It does the HTML export (which creates a .html file and bunch of .gif files for every cell in the notebook containing code) and then reads the HTML file back in and does some hacky string processing on it in order to convert local image file paths into file paths valid for my web server (which is what the date is used for).

weblog-client-021211_6.gif

weblog-client-021211_7.gif

weblog-client-021211_8.gif

weblog-client-021211_9.gif

I use the HTML export option “FullDocument”→False so the HTML is generated without headers (because WordPress will wrap the blog post content I send it with its own header material):

weblog-client-021211_10.gif

weblog-client-021211_11.gif

weblog-client-021211_12.gif

The Export command generates an HTML file:

weblog-client-021211_13.gif

weblog-client-021211_14.gif

… and an image file for every Input/Output cell:

weblog-client-021211_15.gif

weblog-client-021211_16.gif

Here are the thumbnails of the generated image files:

weblog-client-021211_17.gif

weblog-client-021211_18.gif

2. Encode the HTML in an XML-RPC formatted message

In order to use the WordPress weblog client API, I had to be able to create XML blobs using the XML-RPC encoding conventions.  I decided to handle this in top level Mathematica by creating an XMLObject expression for each request, and using ExportString[_XMLObject, “XML”] to create the XML blob as a String.  This XML string then serves as the HTTP POST request body sent to the XML-RPC server.

The XML-RPC encoding functions for the atomic datatypes are below.  I use a common head (xmlrpcencode) with a different DownValue for each XML-RPC datatype (“int”, “double”, “base64”, etc.).  Each XML-RPC datatype corresponds to a different Mathematica Head: Integer -> int, String -> string, Real -> double, “Base64” -> base64, and Boolean -> boolean:

weblog-client-021211_19.gif

weblog-client-021211_20.gif

weblog-client-021211_21.gif

weblog-client-021211_22.gif

weblog-client-021211_23.gif

weblog-client-021211_24.gif

Then there are two types of XML-RPC data structures: struct and array.  A struct gets encoded from a list of rules, for which the Mathematica pattern is {__Rule} (see my NKS Summer School lecture on patterns in Mathematica). An array gets encoded from any List: {___}.  The following DownValues take care of the data structure encodings.  Note that they’re set up recursively, so that the elements inside the lists get properly encoded.  The XML-RPC spec allows for nesting of these data structures, so an element inside a struct can be another struct or array, and similarly for arrays.

weblog-client-021211_25.gif

weblog-client-021211_26.gif

This final DownValue creates the overall XMLObject, and serves as the entry point for creating the request:

weblog-client-021211_27.gif

Using this encoder I can generate arbitrary XML-RPC requests.  So for example, here’s the request given as an example in the XML-RPC spec:

weblog-client-021211_28.gif

weblog-client-021211_29.gif

And here’s what an actual WordPress API request looks like (in this case, a request to create a new blog post):

weblog-client-021211_30.gif

weblog-client-021211_31.gif

Then I also need top level code for decoding the XML responses sent back by the server:

weblog-client-021211_32.gif

weblog-client-021211_33.gif

weblog-client-021211_34.gif

weblog-client-021211_35.gif

weblog-client-021211_36.gif

weblog-client-021211_37.gif

Here’s an example of a decoding, using the example response given in the XML-RPC spec:

weblog-client-021211_38.gif

weblog-client-021211_39.gif

weblog-client-021211_40.gif

3. Send the XML to the WordPress server as an HTTP POST request

Now that I have the ability to encode and decode these XML-RPC blobs, I need to be able to send HTTP POST requests from Mathematica to the web server running WordPress.

The key to all this is the ability to send an HTTP POST request from Mathematica.  While this isn’t directly supported by any top-level function in Mathematica, you can accomplish it using the built-in J/Link framework, which allows you to instantiate and access methods in Java objects directly from Mathematica.  A recent Wolfram Research blog post by Rob Raguet-Schofield explains very nicely how to send HTTP POST requests using J/Link.

I’ll use my WordPress install running on localhost to illustrate the steps in creating and sending the POST request.

The basic idea is to instantiate an org.apache.commons.httpclient.HttpClient object, and set up its authentication credentials:

weblog-client-021211_41.gif

weblog-client-021211_42.gif

weblog-client-021211_43.gif

weblog-client-021211_44.gif

weblog-client-021211_45.gif

weblog-client-021211_46.gif

weblog-client-021211_47.gif

weblog-client-021211_48.gif

weblog-client-021211_49.gif

Then the real work happens by instantiating an org.apache.commons.httpclient.methods.PostMethod, and filling it out with the XML-RPC blob to serve as the request body.

Instantiate the PostMethod:

weblog-client-021211_50.gif

weblog-client-021211_51.gif

Here’s explicitly what the XML-RPC request will look like:

weblog-client-021211_52.gif

weblog-client-021211_53.gif

(Note the XML preamble, e.g.
“POST /RPC2 HTTP/1.0
User-Agent: Frontier/5.1.2 (WinNT)
Host: betty.userland.com
Content-Type: text/xml
Content-length: 181”
isn’t included in the XML blob.  That’s because the preamble is added for you by the HttpClient when the POST request is sent.  I learned this the hard way.  I was manually adding the preamble, but all the POST requests were generating fault responses (malformed request).  I had to packet-sniff a bunch of failed requests to realize they had
two copies of the preamble in them: one generated by the HttpClient, and a superfluous one I was tacking on.)

The request is often referred to as the “payload”:

weblog-client-021211_54.gif

Instantiate an org.apache.commons.httpclient.methods.StringRequestEntity:

weblog-client-021211_55.gif

weblog-client-021211_56.gif

… and add it to the PostMethod object:

weblog-client-021211_57.gif

Now execute the POST request:

weblog-client-021211_58.gif

weblog-client-021211_59.gif

If the request is well-formed, we get the response we’re looking for from the server:

weblog-client-021211_60.gif

weblog-client-021211_61.gif

weblog-client-021211_62.gif

4. Decode the XML response sent back from the server

Now I just have to decode the XML response from the server into a Mathematica expression that I can digest easily.  The code for that was described in step 2.

weblog-client-021211_63.gif

Since the API method I used was “metaWeblog.newPost”, the server sent back the post ID of the newly created post:

weblog-client-021211_64.gif

weblog-client-021211_65.gif

And the post shows up on WordPress under post ID 392 (at “http://localhost:8888/wordpress/?p=392”) as expected:

weblog-client-021211_66.gif

But notice that none of the images are showing up.  That’s because we haven’t uploaded the images to the server yet …

5. Upload all image files to the server

In step 1 I mentioned that the HTML export generates a bunch of image files on the client.  Here are the thumbnails again:

weblog-client-021211_67.gif

weblog-client-021211_68.gif

These all have to be uploaded to the server, since the generated HTML is expecting them to be there.  

We can use the API method “wp.uploadFile” to upload the image files.

Take the first of these image files:

weblog-client-021211_69.gif

… and encode it (as XML-RPC “base64” data) within a wp.uploadFile request:

weblog-client-021211_70.gif

(Note the idiom ExportString[Import[image, ”String”], ”Base64”] for encoding the image in base-64 as required by the XML-RPC spec.)

Now instantiate and execute a PostMethod as before, this time with the new image payload:

weblog-client-021211_71.gif

weblog-client-021211_72.gif

weblog-client-021211_73.gif

weblog-client-021211_74.gif

weblog-client-021211_75.gif

weblog-client-021211_76.gif

weblog-client-021211_77.gif

weblog-client-021211_78.gif

weblog-client-021211_79.gif

Success!  The server responds with the URL of the uploaded image:

weblog-client-021211_80.gif

weblog-client-021211_81.gif

weblog-client-021211_82.gif

Do it again for the second image:

weblog-client-021211_83.gif

weblog-client-021211_84.gif

weblog-client-021211_85.gif

weblog-client-021211_86.gif

weblog-client-021211_87.gif

weblog-client-021211_88.gif

weblog-client-021211_89.gif

weblog-client-021211_90.gif

weblog-client-021211_91.gif

weblog-client-021211_92.gif

And now the images show up in the post:

weblog-client-021211_93.gif

Blog this notebook

Putting this all together, here’s all the code thus far packaged up into a few functions:

weblog-client-021211_94.gif

weblog-client-021211_95.gif

weblog-client-021211_96.gif

weblog-client-021211_97.gif

weblog-client-021211_98.gif

weblog-client-021211_99.gif

weblog-client-021211_100.gif

weblog-client-021211_101.gif

weblog-client-021211_102.gif

weblog-client-021211_103.gif

weblog-client-021211_104.gif

weblog-client-021211_105.gif

weblog-client-021211_106.gif

weblog-client-021211_107.gif

weblog-client-021211_108.gif

weblog-client-021211_109.gif

weblog-client-021211_110.gif

weblog-client-021211_111.gif

weblog-client-021211_112.gif

weblog-client-021211_113.gif

weblog-client-021211_114.gif

weblog-client-021211_115.gif

weblog-client-021211_116.gif

Now let’s blog this very notebook!

weblog-client-021211_117.gif

weblog-client-021211_118.gif

weblog-client-021211_119.gif

weblog-client-021211_120.gif

And here’s what it looks like:

weblog-client-021211_121.gif

Rule 18 particle: correlations versus system size

part 4

I need to measure the correlations in the particle position as a function of system size.  This will give me a sense if the results from part 3 are at all accurate.  Specifically, I want to know if perturbing the sides of the rule 18 evolution really does simulate an infinite system, or if that’s just perturbing the system and has nothing to do with the behavior for large system sizes.

rule-18-random-walk-p4-020811_1.gif

So I’ve got my code for measuring the particle position versus time:

rule-18-random-walk-p4-020811_2.gif

rule-18-random-walk-p4-020811_3.gif

… and I run it on a rule 18 evolution with system width 199 for 10,000 steps:

rule-18-random-walk-p4-020811_4.gif

rule-18-random-walk-p4-020811_5.gif

rule-18-random-walk-p4-020811_6.gif

rule-18-random-walk-p4-020811_7.gif

rule-18-random-walk-p4-020811_8.gif

rule-18-random-walk-p4-020811_9.gif

And I get a list of the particle position versus time:

rule-18-random-walk-p4-020811_10.gif

rule-18-random-walk-p4-020811_11.gif

Now I take my code to measure the autocorrelations of the walk:

rule-18-random-walk-p4-020811_12.gif

… and measure the autocorrelation rule-18-random-walk-p4-020811_13.gif as a function of the lag time r:

rule-18-random-walk-p4-020811_14.gif

rule-18-random-walk-p4-020811_15.gif

rule-18-random-walk-p4-020811_16.gif

Now I want to see how this autocorrelation curve changes as a function of the system width:

rule-18-random-walk-p4-020811_17.gif

rule-18-random-walk-p4-020811_18.gif

rule-18-random-walk-p4-020811_19.gif

rule-18-random-walk-p4-020811_20.gif

rule-18-random-walk-p4-020811_21.gif

Now I’ll plot each of the correlation vs. lag curves on one graph.  There’s might be a pattern emerging here, with larger system widths resulting in higher correlations:

rule-18-random-walk-p4-020811_22.gif

rule-18-random-walk-p4-020811_23.gif

Since the correlation seems to be pretty firmly linear with lag, let’s find the simple slope of these curves and plot slope vs. system width:

rule-18-random-walk-p4-020811_24.gif

rule-18-random-walk-p4-020811_25.gif

rule-18-random-walk-p4-020811_26.gif

rule-18-random-walk-p4-020811_27.gif

There’s a downward trend with N for small N < 400, but then a pretty consistent upward trend for 400 < N 1000.  But in order to confirm the trend, I need to look at a broader range of system widths.

But these preliminary results do agree with the results in part 3: correlations are going up for larger system sizes N (i.e. more random input, more perturbations to the system through time).

And this suggests that somehow the randomness in the particle movement is actually higher when there’s less external randomness being injected into the system.  It’s as though the particle is saying, “I can generate all the randomness I need thank you very much”.  So intuitively this seems to me like an example of intrinsic randomness generation at work.

To Do:
1. Look at the convergence of the autocorrelation values as a function of the number of time steps measured.
2. Measure autocorrelation slope vs.
N for a wider range of values for N.