<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Singular / plural distinction
Step1:  With these associations, how many of the 15 items will the learner correctly label?
Step2:  How often are they correct (using relative item frequencies)?
Step3:  For a population of 100 learners trying to acquire the number system, what proportion are able to successfully label all 15 items given M trials?
Step4:  Dual / non-dual distinction
Step5:  Singular, dual, plural
Step6:  Singular, dual, trial, plural
Step7:  Singular, dual, trial, quadral, plural
Step8:  A prediction is that the typology of number systems should roughly correspond to how learnable each type of number system is
<ASSISTANT_TASK:>
Python Code:
data['Outcomes'] = 'plural'
data['Outcomes'][1] = 'singular'
data
W = ndl.rw(data,M=10)
A = activation(W)
A
Explanation: Singular / plural distinction
End of explanation
pd.DataFrame([data['Outcomes'], A.idxmax(1), A.idxmax(1) == data['Outcomes']], index = ['Truth', 'Prediction', 'Accurate?']).T
np.mean(A.idxmax(1) == data['Outcomes'])
Explanation: With these associations, how many of the 15 items will the learner correctly label?
End of explanation
float(sum(data['Frequency'] * (A.idxmax(1) == data['Outcomes']))) / float(sum(data['Frequency']))
def accuracy(data, M):
    W = ndl.rw(data, M=M)
    A = activation(W)
    return np.mean(A.idxmax(1) == data['Outcomes'])
accuracy(data, 10)
Explanation: How often are they correct (using relative item frequencies)?
End of explanation
np.mean([accuracy(data, M=10) == 1 for i in xrange(100)])
def population_accuracy(M=10, pop=100):
    return np.mean([accuracy(data, M=M) == 1 for i in xrange(pop)])
MAX_TRIALS = 500
P = {}
P['sg / pl'] = [population_accuracy(M=i) for i in xrange(1,MAX_TRIALS)]
import matplotlib.pyplot as plt
plt.plot(range(1,len(P['sg / pl'])+1), P['sg / pl'], '-', linewidth=2)
plt.title('Singular / plural distinction')
plt.xlabel('Trial Number')
plt.suptitle('Proportion of 100 learners who label all 15 items correctly')
Explanation: For a population of 100 learners trying to acquire the number system, what proportion are able to successfully label all 15 items given M trials?
End of explanation
data['Outcomes'] = 'notdual'
data['Outcomes'][2] = 'dual'
data
P['du / non-du'] = [population_accuracy(M=i) for i in xrange(1,MAX_TRIALS)]
plt.plot(range(1,len(P['du / non-du'])+1), P['du / non-du'], '-', linewidth=2)
plt.title('Dual / non-dual distinction')
plt.xlabel('Trial Number')
plt.suptitle('Proportion of 100 learners who label all 15 items correctly')
Explanation: Dual / non-dual distinction
End of explanation
data['Outcomes'] = 'plural'
data['Outcomes'][1] = 'singular'
data['Outcomes'][2] = 'dual'
P['sg / du / pl'] = [population_accuracy(M=i) for i in xrange(1,MAX_TRIALS)]
plt.plot(range(1,len(P['sg / du / pl'])+1), P['sg / du / pl'], '-', linewidth=2)
plt.title('Singular / dual / plural distinction')
plt.xlabel('Trial Number')
plt.suptitle('Proportion of 100 learners who label all 15 items correctly')
Explanation: Singular, dual, plural
End of explanation
data['Outcomes'] = 'plural'
data['Outcomes'][1] = 'singular'
data['Outcomes'][2] = 'dual'
data['Outcomes'][3] = 'trial'
P['sg / du / tr / pl'] = [population_accuracy(M=i) for i in xrange(1,MAX_TRIALS)]
plt.plot(range(1,len(P['sg / du / tr / pl'])+1), P['sg / du / tr / pl'], '-', linewidth=2)
plt.title('Singular / dual / trial / plural distinction')
plt.xlabel('Trial Number')
plt.suptitle('Proportion of 100 learners who label all 15 items correctly')
Explanation: Singular, dual, trial, plural
End of explanation
data['Outcomes'] = 'plural'
data['Outcomes'][1] = 'singular'
data['Outcomes'][2] = 'dual'
data['Outcomes'][3] = 'trial'
data['Outcomes'][4] = '4ial'
P['sg / du / tr / qu / pl'] = [population_accuracy(M=i) for i in xrange(1,MAX_TRIALS)]
plt.plot(range(1,len(P['sg / du / tr / qu / pl'])+1), P['sg / du / tr / qu / pl'], '-', linewidth=2)
plt.title('Singular / dual / trial / quadral plural distinction')
plt.xlabel('Trial Number')
plt.suptitle('Proportion of 100 learners who label all 15 items correctly')
Explanation: Singular, dual, trial, quadral, plural
End of explanation
for n in ('sg / pl', 'sg / du / pl', 'sg / du / tr / pl', 'du / non-du', 'sg / du / tr / qu / pl'):
    plt.plot(range(1,len(P[n])+1), P[n], '-', linewidth=1.5, label=n)
    
plt.suptitle('Proportion of 100 learners who label all 15 items correctly')
plt.xlabel('Trials')
plt.legend(loc=(-0.55,0.5))
Explanation: A prediction is that the typology of number systems should roughly correspond to how learnable each type of number system is
End of explanation
<END_TASK>