Skip to content

Instantly share code, notes, and snippets.

@colejhudson
Created April 22, 2018 19:17
Show Gist options
  • Save colejhudson/14ff8d5429e224abae20d5ff0301f6b0 to your computer and use it in GitHub Desktop.
Save colejhudson/14ff8d5429e224abae20d5ff0301f6b0 to your computer and use it in GitHub Desktop.
Anders Sandberg - The morons are marching rather slowly - http://www.aleph.se/andart/archives/2013/10/the_morons_are_marching_rather_slowly.html
Ng=100; % Number of genes
w=randn(1,Ng); % IQ effect of each allele
Np=1000; % Population size
g=rand(Ng,Np)<.5; % Initial population, 50% mixture of all alleles
ff=[]; % Store mean IQ
change=1e6; % Generation to modify fitness.
for generation=1:100
iq = 100+w*g*3; % Calculate individual IQ
ff=[ff mean(iq)];
if (generation<change)
% "Standard" fitness
fitness = interp1([0 50 80 110 150 400],[0 0.1 1 1 0.5 0],iq);
else
% Fitness breeding for intelligence
fitness = interp1([0 50 80 110 150 400],[0 0.1 1 2 2 2],iq);
end
% For Preston-Campbell fitness, run prestoncampbell.m and use
%fitness = interp1(Cclass,Pchild,iq);
%Breed new generation
g2=g*0;
for k=1:Np
k1=selectrand(fitness); % Parent 1
k2=selectrand(fitness); % Parent 2
split=ceil(rand*Ng); % Crossover location
g2(:,k)=g(:,k1);
g2(split:Ng,k)=g(split:Ng,k2);
end
g=g2;
end
plot(ff)
% Number of children with parents in different IQ classes
f=[54 40 19 29 19 5 5
7 19 22 44 27 10 2
11 12 48 107 78 39 11
16 40 94 186 166 100 17
1 22 60 167 143 77 17
10 0 20 62 58 28 11
0 5 2 26 15 16 19];
class=[0 74; 75 84; 85 94; 95 105; 106 115; 116 125; 126 200];
% How many people are statistically in each class?
C=cdf('norm',class(:,2),100,15)
pop=[C(1); diff(C)]
% Fertility rate for mothers (I got the names flipped for the variables)
Pchildmale = sum(f)/sum(f(:));
Pchildmale = Pchildmale./pop'
% fertility ratefor fathers
Pchildfemale = sum(f')/sum(f(:));
Pchildfemale = Pchildfemale./pop'
clf
plot(Pchildmale)
hold on
plot(Pchildfemale,'r')
axis([1 7 0 2.2])
ylabel('Normalized probability of children')
set(gca,'XTickLabel',{'-74', '75-84', '85-94', '95-105', '106-115', '116-125', '126+'});
legend('Mother IQ','Father IQ')
xlabel('IQ')
% Estimated fitness function
Pchild=[0 0 Pchildmale+Pchildfemale 0];
Cclass=[0; 60; 74; (75+84)/2; (85+94)/2; (95+105)/2; (106+115)/2; (116+125)/2; 126; 200]';
function index=selectrand(p)
% select with probability = p
index=1;
cs=0;
r=rand;
p=p/sum(p);
while(cs+p(index)<r)
cs=cs+p(index);
index=index+1;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment