<?xml version='1.0' encoding='UTF-8'?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>
<chapter name="Tutorial 17: Feedback Using Named Matrices">
<setdocpatch name="17jMatrixFeedback" patch="17jMatrixFeedback.maxpat"/>

<previous name="jitterchapter16">Using Named Jitter Matrices</previous>
<next name="jitterchapter18">Iterative Processes and Matrix Re-Sampling</next>
<parent name="jitindex">Jitter Tutorials</parent>



<h1>Tutorial 17: Feedback Using Named Matrices</h1>
<p>This tutorial shows a simple example of using named <o>jit.matrix</o> objects in a feedback loop. We'll use a matrix of random values to seed an iterative process (in this case, Conway's Game of Life).</p>


<p>The tutorial patch generates an initial matrix of randomized values with the <o>jit.noise</o> object:</p>

<illustration><img src="images/jitterchapter17a.png"/>The <o>jit.noise</o> object</illustration>

<p>The <o>jit.noise</o> object generates a Jitter matrix full of random values. The <m>dim</m>, <m>planecount</m>, and <m>type</m> attributes of the object determine its output matrix (in this instance, we want an <m>80</m> x <m>60</m> cell matrix of one-plane char data). Our random cell values (which are initially in the range <m>0</m> -<m>255</m>) are then set to false (<m>0</m>) or true (<m>255</m>) by the <o>jit.op</o> object. The <m>&gt;</m> operator to <o>jit.op</o> takes the value from the <o>number</o> box (arriving at the right inlet of the object) and uses it as a comparison operator. If a cell value is below that value the cell's value is set to <m>0</m>. Otherwise the cell is set to <m>255</m>. Sending a <m>bang</m> to <o>jit.noise</o> will generate a new random matrix.</p>

<bullet>Try changing the number box attached to the <o>jit.op</o> object. Click the <o>button</o> attached to the <o>jit.noise</o> object to generate a new matrix each time. Notice how higher comparison values yield fewer white (<m>255</m>) cells. The small <o>jit.pwindow</o> below the <o>jit.op</o> object shows you the random matrix. The one-plane matrix data is correctly interpreted by the <o>jit.pwindow</o> object as grayscale video.</bullet>
<h2>Jitter Matrix Feedback</h2>
<p>The quantized noise we've generated at the top of our patch goes from the <o>jit.op</o> object into a <o>jit.matrix</o> object with the <m>name</m> of <m>cellular</m>:</p>

<illustration><img src="images/jitterchapter17b.png"/>Two named <o>jit.matrix</o> objects in a feedback loop</illustration>

<p>This <o>jit.matrix</o> object, which receives <m>bang</m> messages from a <o>metro</o> object at the top of the patch, is connected to an object called <o>jit.conway</o>, the output of which is hooked up to another <o>jit.matrix</o> with the same <m>name</m> (<m>cellular</m>) as the first. The result of this is that the output of the <o>jit.conway</o> object (whatever it does) is written into the <i>same</i> matrix that its input came from, creating a feedback loop.</p>

<bullet>Start the <o>metro</o> object by clicking the <o>toggle</o> box. The <o>jit.pwindow</o> at the bottom of the patch will show you the output of the <o>jit.conway</o> object.</bullet>
<p>If you want to start with a fresh random matrix, you can always copy a new matrix into the feedback loop by clicking the <o>button</o> attached to the<o> jit.noise</o> object. The matrix from the <o>jit.op</o> object will go into our shared <m>cellular</m> matrix and will be used in the feedback loop.</p>

<h2>The Game of Life</h2>
<p>The <o>jit.conway</o> object performs a very simple cellular automata algorithm called the 'Game of Life' on an input matrix. Developed by John Conway at Princeton University, the algorithm simulates cycles of organic survival in an environment with a finite food supply. The cells in the matrix are considered either alive (non-<m>0</m>) or dead (<m>0</m>). Each cell is compared with the cells surrounding it in space. If a live cell has two or three live neightbors, it stays alive. If it has more or less than that number, it dies (i.e. is set to <m>0</m>). If a dead cell has exactly three live neighbors it becomes alive (i.e. is set to <m>255</m>). It's that simple.</p>

<p>Every time the <o>jit.conway</o> object receives an input matrix it performs one generation of the Game of Life on that matrix. Therefore, it makes sense to use the object inside of a feedback loop, so we can see multiple generations of the algorithm performed on the same initial set of data.</p>

<p>For example, the initial random matrix:</p>

<illustration><img src="images/jitterchapter17c.png"/>Some random matrix values</illustration>

<p>Generates the following matrices in the first four iterations through the <o>jit.conway</o> object:</p>

<illustration><img src="images/jitterchapter17d.png"/>The first four generations of the Game of Life performed on the dataset above</illustration>

<p>After seeding the feedback loop with a random matrix, you can turn on the <o>metro</o> object and watch the algorithm run! The Game of Life is designed in such a way that the matrix will eventually stabilize to either a group of self-oscillating cell units or an empty matrix (a dead world). In either case you can just <m>bang</m> in a new set of numbers and start all over again.</p>

<h2>Summary</h2>
<p>You can use the <m>name</m> attribute of the <o>jit.matrix</o> object to create feedback loops in your Jitter processing. By using two <o>jit.matrix</o> objects with the same <m>name</m> at either end of an object chain, you create a patch where the output of the chain gets written to the same Jitter matrix as the input comes from. The <o>jit.noise</o> object generates matrices of random numbers of any <m>type</m>, <m>dim</m>, or <m>planecount</m>. The <o>jit.conway</o> object, which works best within such a feedback loop, performs simple cellular automatation on an input matrix.</p>

	<seealsolist>
		<seealso name="jit.conway">Conway's game of life (cellular automata)</seealso>
		<seealso name="jit.matrix">The Jitter Matrix!</seealso>
		<seealso name="jit.noise">Generate white noise</seealso>
		<seealso name="jit.op">Apply binary or unary operators</seealso>
		<seealso name="jit.pwindow">In-Patcher Window</seealso>
	</seealsolist>
</chapter>
