# Praat script GLAsuccessRate.praat # Paul Boersma, 7 July 2009 # This script is available from http://www.fon.hum.uva.nl/paul/gla/, # where you may find a newer version. form Success rate of learning algorithm comment First define your set of target languages. optionmenu Target_grammar_type 1 option OptimalityTheory option HarmonicGrammar option LinearOT option ExponentialHG option MaximumEntropy option PositiveHG option ExponentialMaximumEntropy natural left_Range_of_number_of_constraints 2 natural right_Range_of_number_of_constraints 20 natural left_Range_of_number_of_inputs 1 natural right_Range_of_number_of_inputs 20 natural left_Range_of_number_of_candidates 2 natural right_Range_of_number_of_candidates 20 natural left_Range_of_maximum_violations 1 natural right_Range_of_maximum_violations 5 boolean Allow_tied_constraints no comment comment Then define your learning settings. optionmenu Decision_strategy 1 option OptimalityTheory option HarmonicGrammar option LinearOT option ExponentialHG option MaximumEntropy option PositiveHG option ExponentialMaximumEntropy real Initial_ranking 10.0 real Evaluation_noise 2.0 optionmenu Reranking_strategy 3 option Demotion only option Symmetric one option Symmetric all option Weighted uncancelled option Weighted all option EDCD option EDCD with vacation option Weighted all up, highest down positive Plasticity 0.1 real Relative_plasticity_spreading 0.0 boolean Check_learning_settings yes comment comment Finally: how sure do you want to be? natural Number_of_languages 1000 natural Number_of_data_per_epoch 10 natural Maximum_number_of_epochs 100000 endform nsuccess = 0 if check_learning_settings if evaluation_noise = 0 and relative_plasticity_spreading = 0 and plasticity <> floor (plasticity) exit By setting evaluation noise and relative plasticity spreading to zero, ... you indicate you want to allow pooling ties in your learners' grammars. In order that Praat handles ... pooling ties correctly, you have to set the plasticity to an integer value, e.g. 1.0. endif endif table = Create Table with column names... table maximum_number_of_epochs time frequency Formula... time number_of_data_per_epoch * row Formula... frequency 0 for itrial to number_of_languages repeat numberOfConstraints = randomInteger (left_Range_of_number_of_constraints, right_Range_of_number_of_constraints) numberOfInputs = randomInteger (left_Range_of_number_of_inputs, right_Range_of_number_of_inputs) maximumViolations = randomInteger (left_Range_of_maximum_violations, right_Range_of_maximum_violations) f$ = "kanweg.OTGrammar" text$ = """ooTextFile""'newline$'""OTGrammar 1""'newline$'<'target_grammar_type$'>'newline$'" text$ = text$ + "'numberOfConstraints''newline$'" for icons to numberOfConstraints text$ = text$ + """Con'icons'"" 0.0 0.0'newline$'" endfor text$ = text$ + "0 'numberOfInputs''newline$'" for iinput to numberOfInputs numberOfCandidates = randomInteger (left_Range_of_number_of_candidates, right_Range_of_number_of_candidates) text$ = text$ + " ""Input'iinput'"" 'numberOfCandidates''newline$'" for icand to numberOfCandidates line$ = """Cand'icand'""" for icons to numberOfConstraints numberOfViolations = randomInteger (0, maximumViolations) line$ = line$ + " 'numberOfViolations'" endfor text$ = text$ + " " + line$ + newline$ endfor endfor text$ > 'f$' targetGrammar = Read from file... 'f$' # Create the target language. # This language is generated by strict ranking, # so that it is representable in OT, HG, and exponential HG alike. for icons to numberOfConstraints ranking = if allow_tied_constraints then randomInteger (2.0, 18.0) else randomUniform (2.0, 18.0) fi Set ranking... icons ranking ranking endfor for iinput to numberOfInputs winner = Get winner... iinput winner'iinput'$ = Get candidate... iinput winner endfor # Create the non-varying environment that corresponds to the target language. d$ = "kanweg.PairDistribution" text$ = """ooTextFile""'newline$'""PairDistribution""'newline$''numberOfInputs''newline$'" for iinput to numberOfInputs winner$ = winner'iinput'$ text$ = text$ + " ""Input'iinput'"" ""'winner$'"" 1'newline$'" endfor text$ > 'd$' distribution = Read from file... 'd$' # Check whether the current grammar does generate the distribution; # this will fail if some optimal candidates have the same violation pattern. plus targetGrammar correct = Get fraction correct... 0 1000 if correct < 1.0 Remove endif until correct = 1.0 # Learn. select targetGrammar learnerGrammar = Copy... learnerGrammar Reset all rankings... initial_ranking Set decision strategy... 'decision_strategy$' plus distribution epoch = 1 repeat noprogress Learn... evaluation_noise "'reranking_strategy$'" ... plasticity number_of_data_per_epoch 0 1 relative_plasticity_spreading no 1 # We define convergence as "having the correct ranking", # not as "producing the correct result in all cases while the noise # is the same as during learning." # So we set the evaluation noise to zero here. # If the decision strategy is MaximumEntropy, # we have to do this by temporarily changing the grammar model to HarmonicGrammar. if decision_strategy$ = "MaximumEntropy" or decision_strategy$ = "ExponentialMaximumEntropy" select learnerGrammar Set decision strategy... HarmonicGrammar plus distribution endif if evaluation_noise = 0.0 fractionCorrect = Get fraction correct... 0.0 1000 else minimumNumberCorrect = Get minimum number correct... evaluation_noise 100 if minimumNumberCorrect >= 75 fractionCorrect = Get fraction correct... evaluation_noise/1000 1000 assert fractionCorrect = 1.0 else fractionCorrect = 0.0 endif endif if decision_strategy$ = "MaximumEntropy" or decision_strategy$ = "ExponentialMaximumEntropy" select learnerGrammar Set decision strategy... 'decision_strategy$' plus distribution endif if fractionCorrect = 1.0 and (index (reranking_strategy$, "EDCD") or reranking_strategy$ = "Demotion only") and evaluation_noise = 0.0 # We are having a stratified hierarchy. # Check that it can be used as a total hierarchy randomly. fractionCorrect = Get fraction correct... plasticity/1000 1000 assert fractionCorrect = 1.0 endif if fractionCorrect = 1.0 nsuccess += 1 plus targetGrammar Remove select table Set numeric value... epoch frequency object [table, epoch, "frequency"] + 1 endif epoch += 1 until epoch > maximum_number_of_epochs or fractionCorrect = 1.0 echo 'nsuccess'/'itrial' endfor