This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// The Typing monkey generates random strings - can't be static 'cause it's a monkey. | |
/// </summary> | |
/// <remarks> | |
/// If you wait long enough it will eventually produce Shakespeare. | |
/// </remarks> | |
class TypingMonkey | |
{ | |
private const string legalCharacters = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890."; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% the size of our array of cells | |
latticeSize=149; | |
% number of time steps | |
max=320; | |
a=zeros(1,149); | |
newa=zeros(1,149); | |
% the ruleset data object | |
ruleSet = CARuleset; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% the size of our array of cells | |
latticeSize=149; | |
% neighborhood radius | |
radius = 1; | |
% rule size | |
ruleSize=3; | |
% number of time steps | |
max=320; | |
a=zeros(1,latticeSize); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [a] = circularSubarray(A, m, n) | |
if isempty(A), | |
error('circularSubarray: isempty(A)','A is empty') ; | |
elseif m==n, | |
error('circularSubarray: m==n','first and second index are the same') ; | |
end | |
N = size(A); | |
N = N(2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% the size of our array of cells | |
latticeSize=149; | |
% neighborhood radius | |
radius = 3; | |
% rule size | |
ruleSize= radius*2 +1; | |
% number of time steps | |
max=200; | |
a=zeros(1,latticeSize); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% patterns | |
ruleSet.patterns = flipud(combn([0 1],ruleSize)); | |
% declare transformation rules array - 148 bits (2^7) initialized to zero | |
gkl = zeros(1,2^ruleSize); | |
% GKL rule: | |
% If ci(t) = 0, then ci(t + 1) = majority [ci(t), ci-1(t) ci-3(t)]; | |
% If ci(t) = 1, then ci(t + 1) = majority [ci(t), ci+1(t) ci+3(t)]; | |
for j=1:2^ruleSize, | |
pattern = ruleSet.patterns(j,:); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% clear memory so that we can compare timespans | |
clear | |
tic | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
%CONSTANTS DECLARATION | |
% the size of our array of cells | |
latticeSize=149; | |
% neighborhood radius | |
radius = 3; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [C] = generateBinaryInitialConfigurations(total, sizeOfEach) | |
% will generate [total] initial configuration each of size [sizeOfEach] | |
howManyOfEach = total/2; | |
blackCounter = 0; | |
whiteCounter = 0; | |
tot = 0; | |
while((blackCounter < howManyOfEach || whiteCounter < howManyOfEach) && tot<total) | |
a = randint(1, sizeOfEach, [0 1]); | |
if(sum(a)>sizeOfEach/2 && blackCounter < howManyOfEach) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [ fitness ] = majorityClassificationFitness( rule , varargin ) | |
%CALCULATEFITNESS | |
% this function calculates performance fitness of given rule - returns a | |
% scalar calculated as successfulRuns/TotalRuns. Takes a 128 bits vector | |
% representing a CA rule for a neighborhood of radius 3. | |
% Note: A lot of (if not all) the costants declared here could be passed down as | |
% parameters - but since this is going to be used as the fitness function | |
% in a Genetic Algorithm very specific to the problem at hand to be called | |
% from the matlab Genetic Algorithm toolkit, it is more practical to pass | |
% down as input param only the transformation rule. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [ fitness ] = majorityClassificationFitness( rule , varargin ) | |
%CALCULATEFITNESS | |
% this function calculates performance fitness of given rule - returns a | |
% scalar calculated as successfulRuns/TotalRuns. Takes a 128 bits vector | |
% representing a CA rule for a neighborhood of radius 3. | |
% Note: A lot of (if not all) the costants declared here could be passed down as | |
% parameters - but since this is going to be used as the fitness function | |
% in a Genetic Algorithm very specific to the problem at hand to be called | |
% from the matlab Genetic Algorithm toolkit, it is more practical to pass | |
% down as input param only the transformation rule. |
OlderNewer