Skip to content

Commit c80ff28

Browse files
author
Simon Charlow
committed
matlab scripts
0 parents  commit c80ff28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+6388
-0
lines changed

Phonology_script.m

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
% JAS: this script simulates consonant cluster data based upon the Simplex
2+
% Onset Hypothesis and identifies the SD of the anchor that best
3+
% fits the data.
4+
% Output is a graph which plots R^2, goodness of fit, statistic by anchor
5+
6+
7+
close all; clear all;
8+
randn('state',0); % Reset the random number generator
9+
10+
simN = 1000; %number of times simulation is repeated
11+
for count=1:simN %loops through iterations of the simulation
12+
13+
14+
N = 30; % number of datapoints; divisible by 3
15+
stdv = 20;
16+
p = 30; % plateau duration
17+
ipi = 40; % inter-plateau interval
18+
19+
% generate timestamps for C3 (the prevocalic consonant)
20+
% preallocate arrays for efficiency
21+
CL3 = zeros(1,N); %left edge of C3
22+
CM3 = zeros(1,N); %right edge of C3
23+
CR3 = zeros(1,N); %right edge of C3
24+
25+
% generate R(ight plateau edge = Release) of prevocalic consonant
26+
CR3 = sqrt(400).*randn(1,N) + 500; % generate N Gaussian distributed numbers with mean 500, variance 400
27+
28+
% generate L(eft plateau edge = Target) of prevocalic consonant
29+
for n=1:N;
30+
e = stdv * randn; % normally distributed random error, 0 mean
31+
CL3(n) = CR3(n) - (p + e); % generate L3 corresponding to R3 by assuming a plateau duration of 10 ms
32+
end;
33+
34+
% calculate midpoint of prevocalic consonant
35+
for n=1:N;
36+
CM3(n) = (CR3(n) + CL3(n))/2; %
37+
end;
38+
39+
%plot timestamps for C3
40+
nbins = 20;
41+
% [CL3h,CL3out] = hist(CL3,nbins); % returns vectors Lh and Lout containing the frequency counts and the bin locations.
42+
% [CR3h,CR3out] = hist(CR3,nbins); % returns vectors Lh and Lout containing the frequency counts and the bin locations.
43+
% subplot(5,2,1);
44+
% bar(CL3out,CL3h); % plot the histogram
45+
% subplot(5,2,2);
46+
% bar(CR3out,CR3h); % plot the histogram
47+
48+
% generate timestamps for C2
49+
% preallocate arrays for efficiency
50+
CL2 = zeros(1,(2*(N/3))); %left edge of C2
51+
CM2 = zeros(1,(2*(N/3))); %right edge of C2
52+
CR2 = zeros(1,(2*(N/3))); %right edge of C2
53+
54+
% generate R(ight plateau edge = Release) of C2 from left edge of C3
55+
% for C tokens
56+
%for n=1:(N/3)
57+
% CR2(n) = CR3(n); % the right edge of the cluster is the same as the right edge of the prevocalic consonant
58+
%end;
59+
60+
% for CC/CCC tokens
61+
for n=1:(2*(N/3)); % alternative, use ceiling function
62+
e = stdv * randn; % normally distributed random error
63+
CR2(n) = CL3(n) - (ipi + e); % generate right edge of C2 from left edge of C2 assuming an ipi of 40 ms
64+
end;
65+
66+
67+
% generate L(eft plateau edge = Target) of C2
68+
% for C tokens
69+
%for n=1:(N/3)
70+
% CL2(n) = CL3(n); % the left edge of the cluster is the same as the left edge of the prevocalic consonant
71+
%end;
72+
73+
% for CC/CCC tokens
74+
for n=1:(2*(N/3));
75+
e = stdv * randn; % normally distributed random error based on relation with CR3
76+
CL2(n) = CR2(n) - (p + e); % generate L2 corresponding to CR3 by assuming a plateau duration
77+
end;
78+
79+
% calculate midpoint of C2
80+
% C tokens have no C2 and therefore no C2 midpoint
81+
for n=1:(2*(N/3));
82+
CM2(n) = (CR2(n) + CL2(n))/2; %
83+
end;
84+
85+
%plot timestamps for C2
86+
% [CL2h,CL2out] = hist(CL2,nbins) % returns vectors Lh and Lout containing the frequency counts and the bin locations.
87+
% [CR2h,CR2out] = hist(CR2,nbins) % returns vectors Lh and Lout containing the frequency counts and the bin locations.
88+
% subplot(5,2,3);
89+
% bar(CL2out,CL2h); % plot the histogram
90+
% subplot(5,2,4);
91+
% bar(CR2out,CR2h); % plot the histogram
92+
93+
% generate timestamps for C1
94+
% preallocate arrays for efficiency
95+
CL1 = zeros(1, N); %left edge of C1
96+
CM1 = zeros(1,(N/3)); %right edge of C1
97+
CR1 = zeros(1,(N/3)); %right edge of C1
98+
99+
% generate R(ight plateau edge = Release) of C1
100+
% for C tokens
101+
% for n=1:(N/3)
102+
% CR1(n) = CR2(n); % the right edge of the cluster is the same as the right edge of the prevocalic consonant
103+
% end;
104+
105+
% % for CC tokens
106+
% for n=(N/3):(2*(N/3))
107+
% CR1(n) = CR3(n); % the right edge of C1 equals the right edge of C3
108+
% end;
109+
110+
% for CCC tokens
111+
for n=1:(N/3);
112+
e = stdv * randn; % normally distributed random error
113+
CR1(n) = CL2(n) - (ipi + e); % generate right edge of C1 from left edge of C2 assuming ipi of 40ms
114+
end;
115+
116+
% generate L(eft plateau edge = Target) of C1
117+
% for CCC tokens
118+
for n=1:(N/3);
119+
e = stdv * randn; % normally distributed random error based on relation with CR3
120+
CL1(n) = CR1(n) - (p + e); % generate L2 corresponding to CR1 by assuming a plateau of 10ms
121+
end;
122+
% for CC tokens
123+
for k=n+1:n+(N/3);
124+
CL1(k) = CL2(k); % left edge of C2 is the left edge of the cluster for CC
125+
end;
126+
% for C tokens
127+
for j=k+1:k+(N/3);
128+
CL1(j) = CL3(j); % the left edge of the cluster is the same as the left edge of the prevocalic consonant
129+
end;
130+
131+
% calculate midpoint of prevocalic consonant
132+
% for CCC only
133+
for n=1:N/3;
134+
CM1(n) = (CR1(n) + CL1(n))/2; %
135+
end;
136+
137+
%plot timestamps for C1
138+
% [CL1h,CL1out] = hist(CL1,nbins) % returns vectors Lh and Lout containing the frequency counts and the bin locations.
139+
% [CR1h,CR1out] = hist(CR1,nbins) % returns vectors Lh and Lout containing the frequency counts and the bin locations.
140+
% subplot(5,2,5);
141+
% bar(CL1out,CL1h); % plot the histogram
142+
% subplot(5,2,6);
143+
% bar(CR1out,CR1h); % plot the histogram
144+
145+
% generate timestamps for CCGlobal
146+
% preallocate array for efficiency
147+
CCglobal = zeros(1, N); %mean of midpoints
148+
149+
%for CCC clusters
150+
for n=1:(N/3);
151+
CCglobal(n) = 1/3 * (CM1(n) + CM2(n) + CM3(n)); % mean of consonant midpoints
152+
end;
153+
154+
%for CC clusters
155+
for k=n+1:n+(N/3);
156+
CCglobal(k) = 1/2 * (CM2(k) + CM3(k)); % mean of consonant midpoints
157+
end;
158+
159+
%for C clusters
160+
for j=k+1:k+(N/3);
161+
CCglobal(j) = CM3(j); % CCglobal synchronous with prevocalic midpoint
162+
end;
163+
164+
% generate series of anchor points increasing in distance from the prevocalic consonant
165+
AN = 20; %number of anchor points
166+
AD = 250; %interval from prevocalic consonant to closest anchor point
167+
DI = 0; % interval added to each subsequent anchor point
168+
VI = 5; % stepwise increase in variability
169+
170+
% preallocate array for efficiency
171+
A = zeros(AN,N); %one column for each anchor (AN) and one row for each token
172+
173+
%cycle loop produces new anchor for each token
174+
for cycle = 1: AN; %creates multiple anchor points for each token
175+
for m=1:N; %creates anchor point for each token from the right edge of the token
176+
Ae = stdv * randn; % normally distributed random error, assuming mean of 0
177+
A(cycle, m) = CR3(m) + AD + Ae; % generate anchor A corresponding to CR3 by assuming a period of 200 ms
178+
end;
179+
AD = AD + DI; %increases distance for each anchor point by interval DI
180+
stdv = stdv + VI; %creates new anchor point
181+
end;
182+
183+
% plot anchor points
184+
% [Ah,Aout] = hist(A(1,:),nbins) % returns vectors Lh and Lout containing the frequency counts and the bin locations.
185+
% subplot(5,2,7);
186+
% bar(Aout,Ah); % plot the histogram
187+
% ylabel('Anchor 1');
188+
189+
% [Ah,Aout] = hist(A(4,:),nbins) % returns vectors Lh and Lout containing the frequency counts and the bin locations.
190+
% subplot(5,2,8);
191+
% bar(Aout,Ah); % plot the histogram
192+
% ylabel('Anchor 4');
193+
194+
195+
%Note about consonantal landmarks: they are replaced with each cycle of the simulation
196+
%in constrast, RSD values for each landmark are stored across simulations.
197+
198+
for cycle = 1: AN; %cycles through for each anchor point
199+
%if CoV==0 % if 1, then coefficient of variance; if 0, standard deviation
200+
201+
%xv = [std(A(cycle)-CL1) std(A(cycle)-CCglobal) std(A(cycle)-CR3)];
202+
%else
203+
%xd(1, cycle) = [(mean(A(cycle,:)))]; %xd = average distance of prevocalic consonant to a given anchor
204+
205+
LE_RSD(count, cycle) = std(A(cycle,:)-CL1)/(mean(A(cycle,:))-mean(CL1));
206+
RE_RSD(count, cycle) = std(A(cycle,:)-CR3)/(mean(A(cycle,:))-mean(CR3));
207+
CC_RSD(count, cycle) = std(A(cycle,:)-CCglobal)/(mean(A(cycle,:))-mean(CCglobal));
208+
209+
LE_SD(count, cycle) = std(A(cycle,:)-CL1);
210+
RE_SD(count, cycle) = std(A(cycle,:)-CR3);
211+
CC_SD(count, cycle) = std(A(cycle,:)-CCglobal);
212+
213+
%end;
214+
215+
end;
216+
217+
end %main simulation loop
218+
219+
%Plot RSD across simulations
220+
% plot mean RSD across simulations as a function of anchor distance
221+
% subplot(5,2,10);
222+
% plot(xd, LE_RSD, 'b-', xd, RE_RSD, 'g-', xd, CC_RSD, 'r:')
223+
224+
% plot mean RSD across simulations for each anchor point as a function of anchor number
225+
226+
x = 1:1:AN; %establishes x-axis as anchor
227+
plot(x, mean(LE_RSD(:,x)), 'b-',x, mean(RE_RSD(:,x)), 'g-',x, mean(CC_RSD(:,x)), 'r:');
228+
229+
230+
231+
232+
233+
234+
235+
236+
237+
238+
239+
240+
241+

calcs.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
a = 30
2+
b = 40
3+
c = 267
4+
d = 400
5+
e = 400
6+
7+
f = (c^2*(a^2/6 + (a*b)/3 + b^2/6 + (83*d)/216 + (29*e)/216))/((a + b/2 + c)^2 - c^2)
8+
9+
10+
a = 20
11+
b = 10
12+
c = 234.8
13+
d = 100
14+
e = 100
15+
16+
f = (c^2*(a^2/6 + (a*b)/3 + b^2/6 + (83*d)/216 + (29*e)/216))/((a + b/2 + c)^2 - c^2)
17+
18+
19+
a = 46.90168176;
20+
b = 46.73126615;
21+
c = 154.9775;
22+
d = 567.9462796;
23+
e = 427.8239681;
24+
25+
f = (c^2*(a^2/6 + (a*b)/3 + b^2/6 + (83*d)/216 + (29*e)/216))/((a + b/2 + c)^2 - c^2);
26+
sd = f^.5

collective_sim.m

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
close all; clear all;
2+
%randn('state',0); %reset the random number generator
3+
4+
param = {'l1' 'l2' 'l3' 'l4' 'l5' 'l6'};
5+
6+
[h w] = size(param);
7+
8+
tokens = 300; %divisible by 3
9+
sims = 100; %number of times to iterate lexical construction
10+
11+
allrems = zeros(sims,w); %preallocate arrays
12+
allccms = zeros(sims,w);
13+
allremstds = zeros(sims,w);
14+
allccmstds = zeros(sims,w);
15+
16+
for sim=1:sims
17+
18+
for i=1:length(param)
19+
cd params;
20+
run(param{i});
21+
cd ..;
22+
datacell{i} = complex_lexicon(tokens,a,b,c,d,e,f);
23+
clear a b c d e f;
24+
end
25+
26+
%number of stimuli types (wordtype-speaker pairs)
27+
types = length(datacell);
28+
29+
%number of simulations
30+
simN = factorial(types);
31+
32+
%preallocate arrays
33+
remstds = zeros(simN,types);
34+
ccmstds = zeros(simN,types);
35+
rems = zeros(simN,types);
36+
ccms = zeros(simN,types);
37+
38+
%errthang
39+
alls = perms(datacell);
40+
41+
%main loop
42+
for count=1:simN
43+
permd=alls(count,1:types);
44+
cumulator=[]; %empty starting cumulator array
45+
for lexicon=1:types
46+
for place=1:lexicon
47+
cumulator=cat(2,cumulator,cell2mat(permd(place)));
48+
end;
49+
summed=sum(cumulator,2);
50+
[h w]=size(cumulator);
51+
avg=summed/w;
52+
avgREM=avg(1,:);
53+
avgCCM=avg(2,:);
54+
stdREM=std(cumulator(1,:));
55+
stdCCM=std(cumulator(2,:));
56+
if w>5
57+
rsdREM=stdREM/avgREM;
58+
rsdCCM=stdCCM/avgCCM;
59+
else
60+
rsdREM=(1+1/(4*w))*(stdREM/avgREM);
61+
rsdCCM=(1+1/(4*w))*(stdCCM/avgCCM);
62+
end
63+
rems(count,lexicon)=rsdREM;
64+
ccms(count,lexicon)=rsdCCM;
65+
remstds(count,lexicon)=stdREM;
66+
ccmstds(count,lexicon)=stdCCM;
67+
cumulator=[]; %resets cumulator
68+
end;
69+
end; %end main loop
70+
71+
%averaging sims
72+
allremstds(sim,:) = sum(remstds,1)/simN;
73+
allccmstds(sim,:) = sum(ccmstds,1)/simN;
74+
allrems(sim,:) = sum(rems,1)/simN;
75+
allccms(sim,:) = sum(ccms,1)/simN;
76+
77+
end
78+
79+
remarray=mean(allrems);
80+
ccmarray=mean(allccms);
81+
remstdarray=mean(allremstds);
82+
83+
x=remstdarray;
84+
85+
plot(x,remarray,'r-',x,ccmarray,'k--');
86+
%lsline;

0 commit comments

Comments
 (0)