Showing posts with label Complex Adaptive Systems. Show all posts
Showing posts with label Complex Adaptive Systems. Show all posts

Tuesday, April 22, 2008

Complex Adaptive Systems - Assignment 3 Finished

Today Ratheesh and I finished the remaining section of our complex adaptive systems homework. We knocked out the programming without too much of a hassle. However, some of the programs took hours to run.

Here are a few of the images we were able to generate based on our simple fractal, with different branching rules and different levels of iteration.


Binary Tree - 4 Levels of Iteration


Binary Tree - 8 Levels of Iteration


6-ary Tree - 4 Levels of Iteration


6-ary Tree - 6 Levels of Iteration


The complete code is available here. Please leave me a comment if you use it to generate any fractals for yourself (or for an assignment).

Also, here is a PDF of our write up. The analysis could probably be a bit stronger, and our simulation is still gathering data, but overall I think it's all right.

Sunday, April 20, 2008

Easier L-System to Analyze

After working for a long, long time with Ratheesh on the L-System:


rule(1).before = 'F';
rule(1).after = 'FF';

rule(2).before = 'G';
rule(2).after = 'F[+G][-G]F[+G][-G]FG';

Which generates this tree.




However, I decided to use this simpler L-system:


rule(1).before = 'F';
rule(1).after = 'F[-F][+F]';


I thought it would be much, MUCH easier to analyze. It would be cool to come up with an expansion that makes the trunk grow more, but keeps the binary relation, but I'm probably not going to be up for that... Here are the different trees that it generates depending on the number of repetitions.


0 reps



1 reps



2 reps




3 reps



4 reps



10 reps

Saturday, April 19, 2008

L-System Fractal Growth Assignment

Today I really started on the L-System assignment Melanie Moses handed out. I am still at a very early stage of development, but I have some interesting images already.





And the following Matlab code:
%
%L-system
%2D

clear all
clf

%Rules-- Cell array {1,x} is the xth string to be replaced
% -- {2,x}

rule(1).before = 'F';
rule(1).after = 'FF';
%rule(1).after = 'F[-F]F[+F]F';

rule(2).before = 'G';
rule(2).after = 'F[+G][-G]F[+G][-G]FG';
%rule(2).after = 'F[+G]F[-G]G';

nRules = length(rule);

%angle: +operator means turn left; -operator means turn right
%delta = 27.5; %degrees
delta = 25.0; % This is 'theta' in the project specifications

%length of the line segments corresponding to the symbols F and G
lenF = 1;
lenG = 1;

%starting seed
axiom = 'G';
%axiom = 'F';

%number of repititions -- This is 'N' in the project specification
nReps = 4;

for i=1:nReps

%one character/cell, with indexes the same as orilsys.mginal axiom string
axiomINcells = cellstr(axiom');
%axiom

for j=1:nRules
%the indexes of each 'before' string
hit = strfind(axiom, rule(j).before);
if (length(hit)>=1)
for k=hit
axiomINcells{k} = rule(j).after;
end
end
end
%now convert individual cells back to a string
axiom=[];0
for j=1:length(axiomINcells)
axiom = [axiom, axiomINcells{j}];
end
end

leaf_count = (axiom == 'G');
leaf_count = leaf_count(axiom == 'G');
sprintf('leaf_count = %d',length(leaf_count))

branch_count = (axiom == 'F');
branch_count = branch_count(axiom == 'F');
sprintf('branch_count = %d', length(branch_count))

sprintf('length(axiom) = %d', length(axiom))

axiom

% Now draw the string as turtle graphics
%Upper case (e.g. F or G) causes a line to be drawn in the current direction of the turtle
%Lower case causes a move with no draw
%angle +operator means turn left; -operator means turn right

%Init the turtle
xT = 0;
yT = 0;
aT = 0;
da = deg2rad(delta) ; %convert to radians

%init the turtle stack
stkPtr = 1;

%set(gca,'xlim', [-5 5], 'ylim', [-5 5]);
hold on

% Leaf counter
leafs = 0;

for i=1:length(axiom)
cmdT = axiom(i);
switch cmdT
case 'F' % Branches
newxT = xT + lenF*cos(aT);
newyT = yT + lenF*sin(aT);
%line([xT newxT], [yT newyT]);
line([yT newyT], [xT newxT],'color',[.3 .3 0], 'linewidth',2);
xT = newxT;
yT = newyT;
case 'G' % Leaves
leafs = leafs + 1;
newxT = xT + lenG*cos(aT);
newyT = yT + lenG*sin(aT);
%line([xT newxT], [yT newyT]);
line([yT newyT], [xT newxT],'color','g', 'linewidth',2);
xT = newxT;
yT = newyT;
case '+'
aT = aT + da;
case '-'
aT = aT - da;
case '[' %push the stack
stack(stkPtr).xT = xT ;
stack(stkPtr).yT = yT ;
stack(stkPtr).aT = aT ;
stkPtr = stkPtr +1 ;
case ']' %pop the stack
stkPtr = stkPtr -1 ;
xT = stack(stkPtr).xT ;
yT = stack(stkPtr).yT ;
aT = stack(stkPtr).aT ;
otherwise
disp('error')
return
end
%drawnow
end

sprintf('leafs = %d', leafs);

daspect([1,1,1])






Saturday, April 12, 2008

New Complex Adaptive Systems Assignment

Dr. Moses posted a new assignment for the Complex Adaptive Systems class I am taking. Unfortunately, she didn't actually post the assignment. She handed it out on a piece of paper, which due to some absent minded mistake of mine, I didn't get a copy of. Luckily, my friend Rosh gave me a copy that I scanned.



Click it for a bigger image


Or check out the text I OCR'd from this website (and formatted a tiny bit):

Complex Adaptive Systems, CS 591
Assignment 3: Fractals
Due midnight April 21,2008

For this assignment (worth 50 rather than 100 points) you do not need to prepare a report.

You only need to do the following.

Write a program that draws trees following the West et al 1997 algorithm. To make things
easier, draw your trees in 2 dimensions so that each branch has a width and a length (not a
radius). The length ratio (y) is set so that the branches are area filling (as opposed to volume
filling in West et al). Thus, given a branching ratio (n), y= n1/2 rather than y= n1/3. Similarly,
rather than being area-preserving, the widths of branches should be width-preserving, that
so that ft = n1. In the 2-D version, of West et al predict Nt ~A„et?ft, where JVt = the number of
terminal units andA,et = the area (or footprint) of the network.

Allow the user to specify a depth (N) of the tree, the number of daughter branches (n) per
parent and the branching angle (0). Specify the size of the 'invariant terminal unit1 (the leaf
or capillary) to be length ln= 2 and width wn= 1/2, so that the area of a terminal unit An = 1.

Build your tree from the leaves back to the trunk.

For each tree your program should output:
a) A 2D drawing of your tree.
b) Report the number of leaves (Nt), the Area of the whole tree (Ami), and the ratio of
leaf area to whole network area ((Wt* A)/A„et) given N.
c) Calculate and report the fractal dimension of each tree you generate.

Turn ln
i) Your code
11) Drawings of 2 trees generated by your code (specify JV, n and ff).
iii) A table reporting the items in b) and c) for trees with the following inputs
(12 lines in your table): N = 2,4,8,10; n = 2,4,8
iv) A mathematical description of
a. the relationship between Nt and A„ec
b. how fractal dimension depends on n and N?
Extra credit (10 points if you solve how fractal networks fit ln Euclidean organisms, partial
credit for a good effort). Consider that the networks you generated above are circulatory
networks for 2D circular animals (small networks for circular mice, big networks for
circular cows). If the maximum distance between leaves of the tree equals the diameter of
the animal, how big is the animal, i.e. what is its area? (This makes the most sense visually if
you use n=4 in 2d). Calculate the area of the animal (given the diameter above) as a function
of the area of the network.
You should see that the area of the circle does not equal the area of the network. West et al
propose the following (translated to 2D):
a. The number of capillaries is n" and n" oc AnM2/3
b. To achieve A„eta Adrcie, set Nt °cAcircie2/3. then AMt« Nt3/2 \< x Acireie2''3)2/3o<:Acirde.
Can you draw a tree, and an organism surrounding that tree that shows whether these
conditions cause A„et ~ ACMe? Can you relax the assumption that the animal is circular to
show that this is true under other assumptions? Can you relax the assumption that the
terminal units are invariant to solve this problem? Can you systematically change 8 or n as
you change N to cause Anet ~ AcWe? Show your results with fractal branches that fill the area
of the circular organisms, and explain them mathematically.