<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/splitting-a-field-by-annealing/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://xianblog.wordpress.com/2017/10/18/splitting-a-field-by-annealing/"> R – Xi'an's Og</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><strong><a rel="nofollow" href="https://xianblog.files.wordpress.com/2017/10/dukal.jpg" target="_blank"><img data-orig-file="https://xianblog.files.wordpress.com/2017/10/dukal.jpg?w=334&amp;h=448&amp;fit=334%2C448&amp;resize=334%2C448" data-orig-size="1432,1918" data-medium-file="https://xianblog.files.wordpress.com/2017/10/dukal.jpg?w=334&amp;h=448&amp;fit=334%2C448&amp;resize=334%2C448?w=224" data-attachment-id="34531" data-image-meta="{" data-image-description="" src="https://xianblog.files.wordpress.com/2017/10/dukal.jpg?w=334&h=448&fit=334%2C448&resize=334%2C448" data-permalink="https://xianblog.wordpress.com/2017/10/18/splitting-a-field-by-annealing/olympus-digital-camera-359/" data-large-file="https://xianblog.files.wordpress.com/2017/10/dukal.jpg?w=334&amp;h=448&amp;fit=334%2C448&amp;resize=334%2C448?w=450" alt="" data-image-title="" sizes="(max-width: 334px) 100vw, 334px" data-comments-opened="1" class="wp-image-34531" data-recalc-dims="1"></a>A</strong> recent riddle [from The Riddle] that I pondered about during a [long!] drive to Luxembourg last weekend was about splitting a square field into three lots of identical surface for a minimal length of separating wire… While this led me to conclude that the best solution was a T like separation, I ran a simulated annealing R code on my train trip to <a rel="nofollow" href="https://xianblog.wordpress.com/2017/09/08/school-of-statistics-for-astrophysics-autrans-france-october-9-13/" target="_blank"><del datetime="2017-10-10T04:50:58+00:00">Autrans</del></a>Valence, seemingly in agreement with this conclusion.<a rel="nofollow" href="https://xianblog.files.wordpress.com/2017/10/riddler10071.jpg" target="_blank"><img data-orig-file="https://xianblog.files.wordpress.com/2017/10/riddler10071.jpg" data-orig-size="480,480" data-medium-file="https://xianblog.files.wordpress.com/2017/10/riddler10071.jpg?w=300&amp;h=300&amp;fit=300%2C300&amp;resize=300%2C300" data-attachment-id="34532" data-image-meta="{" data-image-description="" src="https://xianblog.files.wordpress.com/2017/10/riddler10071.jpg?w=300&h=300&fit=300%2C300&resize=300%2C300" data-permalink="https://xianblog.wordpress.com/2017/10/18/splitting-a-field-by-annealing/riddler10071/" data-large-file="https://xianblog.files.wordpress.com/2017/10/riddler10071.jpg?w=450" alt="" data-image-title="riddler10071" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-34532" data-recalc-dims="1"></a>I discretised the square into n² units and explored configurations by switching two units with different colours, according to a simulated annealing pattern (although unable to impose connectivity on the three regions!):</p>
<pre>partz=matrix(1,n,n)
partz[,1:(n/3)]=2;partz[((n/2)+1):n,((n/3)+1):n]=3
#counting adjacent units of same colour 
nood=hood=matrix(4,n,n)
for (v in 1:n2) hood[v]=bourz(v,partz)
minz=el=sum(4-hood)
for (t in 1:T){
  colz=sample(1:3,2) #picks colours
  a=sample((1:n2)[(partz==colz[1])&amp;(hood&lt;4)],1)
  b=sample((1:n2)[(partz==colz[2])&amp;(hood&lt;4)],1) 
  partt=partz;partt[b]=colz[1];partt[a]=colz[2] 
#collection of squares impacted by switch 
  nood=hood 
  voiz=unique(c(a,a-1,a+1,a+n,a-n,b-1,b,b+1,b+n,b-n)) 
  voiz=voiz[(voiz>0)&amp;(voiz&lt;n2)] 
  for (v in voiz) nood[v]=bourz(v,partt) 
  if (nood[a]*nood[b]>0){
    difz=sum(nood)-sum(hood)
    if (log(runif(1))&lt;difz^3/(n^3)*(1+log(10*rep*t)^3)){
      el=el-difz;partz=partt;hood=nood     
      if (el&lt;minz){ minz=el;cool=partz}
  }}}
</pre>
<p>(where bourz computes the number of neighbours), which produces completely random patterns at high temperatures (low t) and which returns to the T configuration (more or less):<a rel="nofollow" href="https://xianblog.files.wordpress.com/2017/10/riddler10072.jpg" target="_blank"><img data-orig-file="https://xianblog.files.wordpress.com/2017/10/riddler10072.jpg" data-orig-size="480,480" data-medium-file="https://xianblog.files.wordpress.com/2017/10/riddler10072.jpg?w=303&amp;h=303&amp;fit=303%2C303&amp;resize=303%2C303" data-attachment-id="34534" data-image-meta="{" data-image-description="" src="https://xianblog.files.wordpress.com/2017/10/riddler10072.jpg?w=303&h=303&fit=303%2C303&resize=303%2C303" data-permalink="https://xianblog.wordpress.com/2017/10/18/splitting-a-field-by-annealing/riddler10072/" data-large-file="https://xianblog.files.wordpress.com/2017/10/riddler10072.jpg?w=450" alt="" data-image-title="riddler10072" sizes="(max-width: 303px) 100vw, 303px" data-comments-opened="1" class="wp-image-34534" data-recalc-dims="1"></a>if not always, as shown below:<a rel="nofollow" href="https://xianblog.files.wordpress.com/2017/10/riddler10073.jpg" target="_blank"><img data-orig-file="https://xianblog.files.wordpress.com/2017/10/riddler10073.jpg?w=301&amp;h=301&amp;fit=301%2C301&amp;resize=301%2C301" data-orig-size="480,480" data-medium-file="https://xianblog.files.wordpress.com/2017/10/riddler10073.jpg?w=301&amp;h=301&amp;fit=301%2C301&amp;resize=301%2C301?w=300" data-attachment-id="34546" data-image-meta="{" data-image-description="" src="https://xianblog.files.wordpress.com/2017/10/riddler10073.jpg?w=301&h=301&fit=301%2C301&resize=301%2C301" data-permalink="https://xianblog.wordpress.com/2017/10/18/splitting-a-field-by-annealing/riddler10073/" data-large-file="https://xianblog.files.wordpress.com/2017/10/riddler10073.jpg?w=301&amp;h=301&amp;fit=301%2C301&amp;resize=301%2C301?w=450" alt="" data-image-title="riddler10073" sizes="(max-width: 301px) 100vw, 301px" data-comments-opened="1" class="wp-image-34546" data-recalc-dims="1"></a>Once <a rel="nofollow" href="https://fivethirtyeight.com/features/how-much-is-a-perfect-game-of-jeopardy-worth/" target="_blank">the (a?) solution</a> was posted on <a rel="nofollow" href="https://fivethirtyeight.com/features/how-much-is-a-perfect-game-of-jeopardy-worth/" target="_blank">The Riddler</a>, it appeared that one triangular (Y) version proved better than the T one [if not started from corners], with a gain of 3% and that a curved separation was even better with an extra gain less than 1% [<a rel="nofollow" href="https://fivethirtyeight.com/features/how-much-is-a-perfect-game-of-jeopardy-worth/" target="_blank">solution</a> that I find quite surprising as straight lines should improve upon curved ones…]</p>
<p>Filed under: <a rel="nofollow" href="https://xianblog.wordpress.com/category/kids/" target="_blank">Kids</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/category/pictures/" target="_blank">pictures</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/category/statistics/r-statistics/" target="_blank">R</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/category/statistics/" target="_blank">Statistics</a> Tagged: <a rel="nofollow" href="https://xianblog.wordpress.com/tag/autrans/" target="_blank">Autrans</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/luxembourg/" target="_blank">Luxembourg</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/mathematical-puzzle/" target="_blank">mathematical puzzle</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/palais-ducal/" target="_blank">Palais Ducal</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/r/" target="_blank">R</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/random-walk/" target="_blank">random walk</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/simulated-annealing/" target="_blank">simulated annealing</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/the-riddler/" target="_blank">The Riddler</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/vercors/" target="_blank">Vercors</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xianblog.wordpress.com/34530/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/xianblog.wordpress.com/34530/"></a> <img border="0" alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" data-recalc-dims="1"></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://xianblog.wordpress.com/2017/10/18/splitting-a-field-by-annealing/"> R – Xi'an's Og</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/tDI4NqD_Uog" height="1"></a></div>