Exemple #1
0
        //Learning Accessory functions
        private static ConsensusResults ConsensusLearning(SimParams par, Population pop,
                                                          List <int>[] tutors, List <int> learners)
        {
            //Create a consensus based on songs from several males
            List <int>[] ConsensusSongs = new List <int> [learners.Count];
            List <int>[] AddSyls        = new List <int> [learners.Count];
            List <int>[] AllSongs;
            List <int>   CollapsedSongs;
            float        Conform;

            for (int i = 0; i < learners.Count; i++)
            {
                ConsensusSongs[i] = new List <int> {
                };
                AddSyls[i]        = new List <int> {
                };
                AllSongs          = ListeningTest(par, pop, tutors[i].ToArray(), par.ListeningThreshold);
                CollapsedSongs    = AllSongs.SelectMany(x => x).ToList();
                ConsensusSongs[i] = CollapsedSongs.Distinct().ToList();
                for (int j = 0; j < ConsensusSongs[i].Count(); j++)
                {
                    Conform = ConsensusCalc(par, ConsensusSongs[i][j], CollapsedSongs);
                    if (par.NextFloat() < Conform)
                    {
                        AddSyls[i].Add(ConsensusSongs[i][j]);
                    }
                }
            }
            ConsensusResults Returnable = new ConsensusResults(AddSyls, ConsensusSongs);

            return(Returnable);
        }
Exemple #2
0
        public static Population ObliqueLearning(SimParams par, Population pop,
                                                 int[] vacant, List <int> notVacant)
        {
            //Get Learners and set up for each learning style
            List <int> Learners = GetLearners(par, pop, notVacant);

            List <int>[] AddSyls;
            List <int>[] LoseSyls;
            if (par.Consensus)
            {
                List <int>[] Tutors = ChooseMultipleTutors(par, pop, Learners,
                                                           notVacant, par.NumTutorConsensusStrategy);
                var Results = ConsensusLearning(par, pop, Tutors, Learners);
                AddSyls  = Results.AddSyls;
                LoseSyls = Results.ConsensusSongs;
            }
            else  //Add&|Forget Learning
            {
                int[] Tutors = ChooseTutors(par, pop, Learners, notVacant);
                AddSyls  = ListeningTest(par, pop, Tutors, par.ListeningThreshold);
                LoseSyls = AddSyls;
            }

            //Add and/or remove syllables as needed and update song-related traits
            if (par.Add)
            {
                AddSyllables(par, pop, Learners, AddSyls);
            }
            if (par.Forget)
            {
                ForgetSyllables(par, pop, Learners, LoseSyls);
            }
            UpdateSongTraits(par, pop, Learners);
            return(pop);
        }
Exemple #3
0
        private static List <int> TestLearningThreshold(SimParams par, Population pop,
                                                        List <int> notVacant)
        {
            /*Get birds with a threshold below the age keepign in mind
             * the vertical learning threshold*/
            float      ModifiedThresh;
            List <int> Learners = new List <int> {
            };

            for (int i = 0; i < notVacant.Count; i++)
            {
                ModifiedThresh = pop.LearningThreshold[notVacant[i]] >= 1?
                                 pop.LearningThreshold[notVacant[i]]:
                                 (pop.LearningThreshold[notVacant[i]] - par.VerticalLearningCutOff) / (1 - par.VerticalLearningCutOff);
                if (pop.Age[notVacant[i]] + 1 <= ModifiedThresh)//full learn to learn
                {
                    Learners.Add(notVacant[i]);
                }
                else if (pop.Age[notVacant[i]] < ModifiedThresh) //Chance to learn during partical year
                {
                    if (par.NextFloat() < ModifiedThresh - pop.Age[notVacant[i]])
                    {
                        Learners.Add(notVacant[i]);
                    }
                }
            }
            return(Learners);
        }
Exemple #4
0
 private static float[] CalculateSocialBonus(SimParams par, Population pop,
                                             List <int> usableMales)
 {
     float[] SocialBonus = new float[usableMales.Count];
     if (par.SocialPreference != 0)
     {
         float[] Soc = new float[usableMales.Count];
         for (int i = 0; i < usableMales.Count; i++)
         {
             Soc[i] = pop.Bred[usableMales[i]];
         }
         float Worst = Soc.Min();
         float Best  = Soc.Max();
         if (Worst == Best)
         {
             SocialBonus = Enumerable.Repeat(par.SocialPreference, usableMales.Count).ToArray();
         }
         else
         {
             float Fraction = 1f / (Best - Worst);
             for (int i = 0; i < usableMales.Count; i++)
             {
                 SocialBonus[i] = ((Soc[i] - Worst) * Fraction) * par.SocialPreference;
             }
         }
     }
     else
     {
         SocialBonus = Enumerable.Repeat(0f, usableMales.Count).ToArray();
     }
     return(SocialBonus);
 }
Exemple #5
0
        //Misc
        public static Population OverLearn(SimParams par, Population pop,
                                           int[] vacant, List <int> notVacant)
        {
            //Get learners and tutors
            List <int> Learners = vacant.ToList();

            List <int>[] Tutors    = ChooseMultipleTutors(par, pop, Learners, notVacant, par.NumTutorOverLearn);
            List <int>[] TutorSyls = new List <int> [Learners.Count];

            //Create combined song with all sylls
            List <int>[] AllSongs;
            List <int>   CollapsedSongs;

            for (int i = 0; i < Learners.Count; i++)
            {
                AllSongs       = ListeningTest(par, pop, Tutors[i].ToArray(), par.ListeningThreshold);
                CollapsedSongs = AllSongs.SelectMany(x => x).ToList();
                TutorSyls[i]   = CollapsedSongs.Distinct().ToList();
            }

            //Add Syls and update song traits
            AddSyllables(par, pop, Learners, TutorSyls);
            UpdateSongTraits(par, pop, Learners);
            return(pop);
        }
Exemple #6
0
        private static int[] RandomDeath(SimParams par, Population pop)
        {
            float[] PickChance   = LearningPenalty(par, pop.LearningThreshold);
            int     numLostBirds = (int)Math.Floor(par.NumBirds * par.PercentDeath);

            int[] LostBirds = par.RandomSampleUnequal(PickChance, numLostBirds, false);
            return(LostBirds);
        }
Exemple #7
0
        //Birth
        private static int[] ChooseMaleFathers(SimParams par, Population pop,
                                               int[] vacant, List <int> notVacant)
        {
            /*Picks fathers to sire chicks into vacancies,
             * Uses only living males.
             * It is likely for high quality males to sire multiple
             * offspring in one sim step for both local and global scopes*/

            //Remove songless birds from notVacant, and mark all not in that list as unavailable
            HashSet <int> PotentialFathersTemp = new HashSet <int>(notVacant.Where(x => pop.SyllableRepertoire[x] > 0));
            HashSet <int> Unavailable          = new HashSet <int>(Enumerable.Range(0, par.NumBirds));

            Unavailable.ExceptWith(PotentialFathersTemp);
            //Get the probabilities
            List <int> PotentialFathers = PotentialFathersTemp.ToList();

            float[] Probs = ReproductiveProbability(par, pop, PotentialFathers);


            //pick fathers
            int[] Fathers = new int[vacant.Length];
            if (par.LocalBreeding)
            {
                float[] Probability = Enumerable.Repeat(0f, par.NumBirds).ToArray();
                for (int i = 0; i < PotentialFathers.Count; i++)
                {
                    Probability[PotentialFathers[i]] = Probs[i];
                }

                for (int i = 0; i < Fathers.Length; i++)
                {
                    Fathers[i] = Locations.GetLocalBirds(par, pop, vacant[i],
                                                         Unavailable, probs: Probability)[0];
                }
            }
            else
            {
                //float[] PotenProbs = new float[PotentialFathers.Count];
                int[] FatherIndex;
                //for(int i=0;i<PotenProbs.Length;i++){
                //    PotenProbs[i] = Probability[PotentialFathers[i]];
                //}
                FatherIndex = par.RandomSampleUnequal(Probs, vacant.Length, true);
                for (int i = 0; i < Fathers.Length; i++)
                {
                    Fathers[i] = PotentialFathers[FatherIndex[i]];
                }
            }


            int[] lol = new int[Fathers.Length];
            for (int i = 0; i < Fathers.Length; i++)
            {
                lol[i] = pop.SyllableRepertoire[Fathers[i]];
            }
            return(Fathers);
        }
Exemple #8
0
        //Constructor
        public Songs(SimParams par)
        {
            Match       = new float[par.NumBirds];
            MaleSongs   = new List <int> [par.NumBirds];
            FemaleSongs = new List <int> [par.NumBirds];

            if (par.MatchPreference == 0 && !par.SaveMatch)
            {
                for (int i = 0; i < par.NumBirds; i++)
                {
                    MaleSongs[i] = GenerateNovelSong(par);
                }
            }
            else  //Matching context
            {
                FemaleSongs = GenerateFemaleSongs(par);
                if (par.MaleDialects == "Same")
                {
                    for (int i = 0; i < MaleSongs.Length; i++)
                    {
                        MaleSongs[i] = FemaleSongs[i].ToList();
                    }
                }
                else
                {
                    for (int i = 0; i < par.NumBirds; i++)
                    {
                        MaleSongs[i] = GenerateNovelSong(par);
                    }
                    if (par.MaleDialects == "Similar" && par.NumDialects > 1)
                    {
                        MaleSongs = EstablishDialects(par, MaleSongs);
                    }
                }
                if (par.ChooseMate && par.MaleDialects != "Same")
                {
                    var          Assign        = AssignFemale(par, MaleSongs, FemaleSongs);
                    List <int>[] NewMaleSong   = new List <int> [par.NumBirds];
                    List <int>[] NewFemaleSong = new List <int> [par.NumBirds];
                    for (int i = 0; i < par.NumBirds; i++)
                    {
                        NewMaleSong[i]   = MaleSongs[Assign.MaleOrder[i]];
                        NewFemaleSong[i] = FemaleSongs[Assign.FemaleOrder[i]];
                    }
                    MaleSongs   = NewMaleSong;
                    FemaleSongs = NewFemaleSong;
                    Match       = Assign.Match;
                }
                else
                {
                    for (int i = 0; i < par.NumBirds; i++)
                    {
                        Match[i] = Songs.GetMatch(par, MaleSongs[i], FemaleSongs[i]);
                    }
                }
            }
        }
Exemple #9
0
        //Getting tutors, the original runs faster, but cannot get more than one tutor
        private static int[] ChooseTutors(SimParams par, Population pop,
                                          List <int> learners, List <int> notVacant)
        {
            //Picks tutos that are alive, not chicks, and not songless,
            //Males can tutor multiple learners

            /*remove chicks and songless birds + any Misc, mark all excluded
             * birds as unavailable*/
            HashSet <int> PotentialTutorsTemp = new HashSet <int>(notVacant.Where(x => pop.Age[x] > 0));

            PotentialTutorsTemp.ExceptWith(PotentialTutorsTemp.Where(x => pop.SyllableRepertoire[x] == 0).ToArray());

            //pick Tutors
            int[] Tutors = new int[learners.Count];
            if (par.LocalTutor)
            {
                //Set up unavailable for local testing
                HashSet <int> Unavailable = new HashSet <int>(Enumerable.Range(0, par.NumBirds));
                Unavailable.ExceptWith(PotentialTutorsTemp);
                for (int i = 0; i < learners.Count; i++)
                {
                    if (par.SocialCues)
                    {
                        Tutors[i] = Locations.GetLocalBirds(par, pop, learners[i], Unavailable, 1, pop.Bred)[0];
                    }
                    else
                    {
                        Tutors[i] = Locations.GetLocalBirds(par, pop, learners[i], Unavailable)[0];
                    }
                }
            }
            else  //drawn individually so no learner is his own tutor
            {
                List <int> PotentialTutors;
                for (int i = 0; i < learners.Count; i++)
                {
                    PotentialTutors = PotentialTutorsTemp.ToList();
                    PotentialTutors.Remove(learners[i]);

                    if (par.SocialCues)
                    {
                        float[] TutorProbs = new float[PotentialTutors.Count];
                        for (int j = 0; j < TutorProbs.Length; j++)
                        {
                            TutorProbs[j] = pop.Bred[PotentialTutors[j]];
                        }
                        Tutors[i] = PotentialTutors[par.RandomSampleUnequal(TutorProbs, 1)[0]];
                    }
                    else
                    {
                        Tutors[i] = PotentialTutors[par.RandomSampleEqualReplace(PotentialTutors, 1)[0]];
                    }
                }
            }
            return(Tutors);
        }
Exemple #10
0
        private static List <int>[] ChooseMultipleTutors(SimParams par, Population pop,
                                                         List <int> learners, List <int> notVacant, int numTutors)
        {
            /*remove chicks and songless birds + any Misc, mark all excluded
             * birds as unavailable*/
            HashSet <int> PotentialTutorsTemp = new HashSet <int>(notVacant.Where(x => pop.Age[x] > 0));

            PotentialTutorsTemp.ExceptWith(PotentialTutorsTemp.Where(x => pop.SyllableRepertoire[x] == 0).ToArray());
            List <int>[] Tutors = new List <int> [learners.Count];

            if (par.LocalTutor)
            {
                HashSet <int> Unavailable = new HashSet <int>(Enumerable.Range(0, par.NumBirds));
                Unavailable.ExceptWith(PotentialTutorsTemp);
                for (int i = 0; i < learners.Count; i++)
                {
                    if (par.SocialCues)
                    {
                        Tutors[i] = Locations.GetLocalBirds(par, pop, learners[i], Unavailable, numTutors, pop.Bred).ToList();
                    }
                    else
                    {
                        Tutors[i] = Locations.GetLocalBirds(par, pop, learners[i], Unavailable, numTutors).ToList();
                    }
                }
            }
            else
            {
                List <int> PotentialTutors;
                for (int i = 0; i < learners.Count; i++)
                {
                    PotentialTutors = PotentialTutorsTemp.ToList();
                    PotentialTutors.Remove(learners[i]);
                    if (par.SocialCues)
                    {
                        float[] TutorProbs = new float[PotentialTutors.Count];
                        for (int j = 0; j < TutorProbs.Length; j++)
                        {
                            TutorProbs[j] = pop.Bred[PotentialTutors[j]];
                        }
                        int[] ChosenIndex = par.RandomSampleUnequal(TutorProbs, numTutors);
                        for (int j = 0; j < numTutors; j++)
                        {
                            ChosenIndex[j] = PotentialTutors[ChosenIndex[j]];
                        }
                        Tutors[i] = ChosenIndex.ToList();
                    }
                    else
                    {
                        Tutors[i] = par.RandomSampleEqualNoReplace(PotentialTutors, numTutors).ToList();
                    }
                }
            }
            return(Tutors);
        }
Exemple #11
0
        private static List <int> GetLearners(SimParams par, Population pop, List <int> notVacant)
        {
            List <int> Capable = TestLearningThreshold(par, pop, notVacant);

            Capable = CheckEncounter(par, Capable);
            if (Capable.Count == 0)
            {
                Console.WriteLine("Warning: There were no learners.");
            }                                                                             //throw new Exception("There were no learners.");}
            return(Capable);
        }
Exemple #12
0
 private static List <int> CheckEncounter(SimParams par, List <int> capable)
 {
     for (int i = capable.Count - 1; i >= 0; i--)
     {
         if (par.NextFloat() > par.EncounterSuccess)
         {
             capable.RemoveAt(i);
         }
     }
     return(capable);
 }
Exemple #13
0
 private static Population UpdateSongTraits(SimParams par, Population pop, List <int> learners)
 {
     for (int i = 0; i < learners.Count; i++)
     {
         pop.SyllableRepertoire[learners[i]] = pop.MaleSong[learners[i]].Count;
         if (par.MatchPreference != 0 || par.SaveMatch)
         {
             pop.Match[learners[i]] = Songs.GetMatch(par, pop.MaleSong[learners[i]], pop.FemaleSong[learners[i]]);
         }
     }
     return(pop);
 }
Exemple #14
0
        /*Functions for decideing how birds learn and
         * allowing them to do so*/

        //Main process
        public static List <int> CoreLearningProcess(SimParams par, Population pop,
                                                     int learner, List <int> learnerSong, List <int> tutorSong)
        {
            //Copy Tutor Syllables
            List <float> Rolls = new List <float> {
            };
            float AccRoll;

            for (int i = 0; i < tutorSong.Count; i++)
            {
                AccRoll = par.NextFloat();
                if (AccRoll < pop.Accuracy[learner])//Correct
                {
                    learnerSong.Add(tutorSong[i]);
                }
                else
                {
                    Rolls.Add(AccRoll);
                }
            }


            //Innovation
            if (Rolls.Count > 0)
            {
                int   Innovation   = 0;
                float InventThresh = 1 - ((1 - pop.Accuracy[learner]) * pop.ChanceInvent[learner]);
                for (int i = 0; i < Rolls.Count; i++)
                {
                    if (Rolls[i] >= InventThresh)
                    {
                        Innovation += 1;
                    }
                }
                if (Innovation > 0)
                {
                    int[]         NewSyls;
                    HashSet <int> AvailableSyllables = new HashSet <int>(par.AllSyls);
                    AvailableSyllables.ExceptWith(Enumerable.Concat(learnerSong, tutorSong));
                    if (Innovation >= AvailableSyllables.Count)//Not enough syls for sampling
                    {
                        NewSyls = AvailableSyllables.ToArray();
                    }
                    else  // Enough syls for sampling
                    {
                        NewSyls = par.RandomSampleEqualNoReplace(AvailableSyllables.ToList(), Innovation);
                    }
                    learnerSong.AddRange(NewSyls);
                } //Otherwise no innovation occured
            }     //Otherwise no mistakes were made
            return(learnerSong);
        }
        //Constructor
        public Population(SimParams par)
        {
            //Get variables dependant on population size (Age, Survival Stats, and Locality)
            Age = Ages.InitialAgeDistribution(par);
            if (par.AgeDeath)
            {
                SurvivalChance = new List <float> {
                    par.ChickSurvival
                };
                SurvivalChance.AddRange(Enumerable.Repeat(par.InitialSurvival, par.MaxAge));
                SurvivalStore = SurvivalChance[1];
            }
            if (par.LocalBreeding || par.LocalTutor)
            {
                Local = Locations.FinalDirections(par);
            }

            //Get Songs and song data
            Songs SongData = new Songs(par);

            MaleSong           = SongData.MaleSongs;
            FemaleSong         = SongData.FemaleSongs;
            Match              = SongData.Match;
            SyllableRepertoire = new int[par.NumBirds];
            for (int i = 0; i < par.NumBirds; i++)
            {
                SyllableRepertoire[i] = MaleSong[i].Count;
            }


            if (par.SaveNames)
            {
                FatherName = Enumerable.Repeat("NA", par.NumBirds).ToArray();
                Name       = new string[par.NumBirds];
                for (int i = 0; i < par.NumBirds; i++)
                {
                    Name[i] = System.Guid.NewGuid().ToString();
                }
            }

            Bred = Enumerable.Repeat(.1f, par.NumBirds).ToArray();

            //Set up distributions for noisy inheritence as needed and fill out arrays
            Accuracy = InitialDistributions(par, par.InheritedAccuracyNoise, par.InitialAccuracy,
                                            par.MaxAccuracy, par.MinAccuracy);
            LearningThreshold = InitialDistributions(par, par.InheritedLearningThresholdNoise, par.InitialLearningThreshold,
                                                     par.MaxLearningThreshold, par.MinLearningThreshold);
            ChanceInvent = InitialDistributions(par, par.InheritedChancetoInventNoise, par.InitialChancetoInvent,
                                                par.MaxChancetoInvent, par.MinChancetoInvent);
            ChanceForget = InitialDistributions(par, par.InheritedChancetoForgetNoise, par.InitialChancetoForget,
                                                par.MaxChancetoForget, par.MinChancetoForget);
        }
Exemple #16
0
 private static List <int> DropSyllables(SimParams par, List <int> song,
                                         List <int> droppableSyls, float chanceForget)
 {
     //Remove syllables not heard from tutor based on ChanceForget
     for (int i = 0; i < droppableSyls.Count; i++)
     {
         if (par.NextFloat() < chanceForget)
         {
             song.Remove(droppableSyls[i]);
         }
     }
     return(song);
 }
 private static void CheckStatValue(SimParams par, string type, float stat)
 {
     if (type == "Learning")
     {
         if (stat > par.MaxLearningThreshold || stat < par.MinLearningThreshold)
         {
             throw new System.ArgumentException("Chosen invader stat was outside the boundaries for Learning Threshold.");
         }
         if (par.InheritedLearningThresholdNoise != 0)
         {
             Console.WriteLine("Warning: Learning Inheritance noise not set to 0!");
         }
     }
     else if (type == "Accuracy")
     {
         if (stat > par.MaxAccuracy || stat < par.MinAccuracy)
         {
             throw new System.ArgumentException("Chosen invader stat was outside the boundaries for Accuracy.");
         }
         if (par.InheritedAccuracyNoise != 0)
         {
             Console.WriteLine("Warning: Accuracy Inheritance noise not set to 0!");
         }
     }
     else if (type == "Forget")
     {
         if (stat > par.MaxChancetoForget || stat < par.MinChancetoForget)
         {
             throw new System.ArgumentException("Chosen invader stat was outside the boundaries for Chance to Forget.");
         }
         if (par.InheritedChancetoForgetNoise != 0)
         {
             Console.WriteLine("Warning: Forget Inheritance noise not set to 0!");
         }
     }
     else if (type == "Invent")
     {
         if (stat > par.MaxChancetoInvent || stat < par.MinChancetoInvent)
         {
             throw new System.ArgumentException("Chosen invader stat was outside the boundaries for Chance to Invent.");
         }
         if (par.InheritedChancetoInventNoise != 0)
         {
             Console.WriteLine("Warning: Invent Inheritance noise not set to 0!");
         }
     }
     else
     {
         throw new System.ArgumentException("Type can only take the following values:  Learning, Accuracy, Forget, or Invent.");
     }
 }
Exemple #18
0
        private static Population ForgetSyllables(SimParams par, Population pop,
                                                  List <int> learners, List <int>[] tutorSyls)
        {
            //Forget unheard Syllables
            List <int> Lose;

            for (int i = 0; i < learners.Count; i++)
            {
                Lose = pop.MaleSong[learners[i]].Except(tutorSyls[i]).ToList();
                pop.MaleSong[learners[i]] = DropSyllables(par, pop.MaleSong[learners[i]],
                                                          Lose, pop.ChanceForget[i]);
            }
            return(pop);
        }
Exemple #19
0
        //Top Level Organizers
        public static List <int> VerticalLearning(SimParams par, Population pop,
                                                  int fatherInd, int chickInd)
        {
            List <int> NewSong = new List <int> {
            };

            if (pop.LearningThreshold[chickInd] < par.VerticalLearningCutOff)
            {
                return(NewSong);
            }
            List <int> FatherSong = ListeningTest(par, pop, new int[] { fatherInd }, par.FatherListeningThreshold)[0];
            List <int> ChickSong  = CoreLearningProcess(par, pop, chickInd, NewSong, FatherSong);

            return(ChickSong);
        }
Exemple #20
0
 //Reset for next run
 private static Population UpdateDeathProbabilities(SimParams par, Population pop,
                                                    int[] fatherInd)
 {
     //get death probs for next step
     if (pop.SurvivalChance.Count > 2)
     {
         for (int i = par.MaxAge; i > 1; i--)
         {
             pop.SurvivalChance[i] = pop.SurvivalChance[i - 1];
         }
     }
     pop.SurvivalChance[1] = pop.SurvivalStore;
     pop.SurvivalStore     = (float)Math.Pow(1 / (par.ChickSurvival * fatherInd.Length), 1.0 / par.MaxAge);
     return(pop);
 }
Exemple #21
0
        private static Population AddSyllables(SimParams par, Population pop,
                                               List <int> learners, List <int>[] tutorSyls)
        {
            //Learn heard Syllables
            List <int> Gain;

            for (int i = 0; i < learners.Count; i++)
            {
                Gain = tutorSyls[i].Except(pop.MaleSong[learners[i]]).ToList();
                pop.MaleSong[learners[i]] = CoreLearningProcess(par, pop, learners[i],
                                                                pop.MaleSong[learners[i]],
                                                                Gain);
            }
            return(pop);
        }
Exemple #22
0
 //Functions for getting the ages
 public static int[] InitialAgeDistribution(SimParams par)
 {
     int[] AgeGroup;
     if (par.AgeDeath)
     {
         float[] AgeRates = GetAgeRates(par);
         AgeGroup = GetAgeGroup(par, AgeRates);
     }
     else
     {
         List <int> AgeRange = Enumerable.Range(0, par.MaxAge + 1).ToList();
         AgeGroup = par.RandomSampleEqualReplace(AgeRange, par.NumBirds);
     }
     return(AgeGroup);
 }
        public void Output(SimParams par, string filePath, string tag, bool writePar = true)
        {
            //Make the final .csvs
            File.WriteAllText(filePath + "/" + tag + "SylRep.csv", SylRep.ToString(), Encoding.UTF8);
            if (par.SaveMatch)
            {
                File.WriteAllText(filePath + "/" + tag + "Match.csv", Match.ToString(), Encoding.UTF8);
            }
            if (par.SaveAge)
            {
                File.WriteAllText(filePath + "/" + tag + "Age.csv", Age.ToString(), Encoding.UTF8);
            }
            if (par.SaveNames)
            {
                File.WriteAllText(filePath + "/" + tag + "Name.csv", Name.ToString(), Encoding.UTF8);
                File.WriteAllText(filePath + "/" + tag + "FatherName.csv", FatherName.ToString(), Encoding.UTF8);
            }
            if (par.SaveLearningThreshold)
            {
                File.WriteAllText(filePath + "/" + tag + "LrnThrsh.csv", LearningThreshold.ToString(), Encoding.UTF8);
            }
            if (par.SaveAccuracy)
            {
                File.WriteAllText(filePath + "/" + tag + "Acc.csv", Accuracy.ToString(), Encoding.UTF8);
            }
            if (par.SaveChancetoForget)
            {
                File.WriteAllText(filePath + "/" + tag + "ChanFor.csv", ChanceForget.ToString(), Encoding.UTF8);
            }
            if (par.SaveChancetoInvent)
            {
                File.WriteAllText(filePath + "/" + tag + "ChanInv.csv", ChanceInvent.ToString(), Encoding.UTF8);
            }
            if (par.SaveMSong)
            {
                File.WriteAllText(filePath + "/" + tag + "MSong.csv", MaleSong.ToString(), Encoding.UTF8);
            }
            if (par.SaveFSong)
            {
                File.WriteAllText(filePath + "/" + tag + "FSong.csv", FemaleSong.ToString(), Encoding.UTF8);
            }

            //Save parameters is desired
            if (writePar)
            {
                WriteParams(par, filePath, tag);
            }
        }
Exemple #24
0
 //Adult Learning-Specific Accessory functions
 private static List <int>[] ListeningTest(SimParams par, Population pop, int[] tutors, float lisThresh)
 {
     /*Get syls and test whether Repsize larger than listening threshold,
      * if so, randomly remove extra syllables.*/
     List <int>[] TutorSyls = new List <int> [tutors.Length];
     for (int i = 0; i < tutors.Length; i++)
     {
         TutorSyls[i] = pop.MaleSong[tutors[i]].ToList();
     }
     if (lisThresh >= .999f & lisThresh < 1)
     {
         return(TutorSyls);
     }
     if (lisThresh % 1 == 0)//Absolute number of sylls learned
     {
         int Thresh = (int)lisThresh;
         int Remove;
         for (int i = 0; i < TutorSyls.Length; i++)
         {
             if (TutorSyls[i].Count > Thresh)
             {
                 Remove = TutorSyls[i].Count - Thresh;
                 par.RandomSampleEqualNoReplace(TutorSyls[i], Remove);
             }
         }
     }
     else  //percentage of sylls learned
     {
         float Learnable;
         float Remove;
         for (int i = 0; i < TutorSyls.Length; i++)
         {
             Learnable = (TutorSyls[i].Count - par.MinLearnedSyllables) * lisThresh + par.MinLearnedSyllables;
             if (Learnable < TutorSyls[i].Count)
             {
                 Learnable = par.NextFloat() < Learnable % 1?
                             (float)Math.Ceiling(Learnable):(float)Math.Floor(Learnable);
                 Remove = TutorSyls[i].Count - Learnable;
                 if (Remove > 0)
                 {
                     par.RandomSampleEqualNoReplace(TutorSyls[i], (int)Remove);
                 }
             }
         }
     }
     return(TutorSyls);
 }
Exemple #25
0
        private static float[] LearningPenalty(SimParams par, float[] learnThreshold)
        {
            float Base = par.LearningPenalty / (par.MaxAge - 1);

            float[] PickChance = new float[par.NumBirds];
            for (int i = 0; i < par.NumBirds; i++)
            {
                PickChance[i] = Base * (learnThreshold[i] - 1) + 1;
            }
            List <int> Cheaters = Enumerable.Range(0, PickChance.Length).Where(x => PickChance[x] < 1).ToList();

            for (int i = 0; i < Cheaters.Count; i++)
            {
                PickChance[Cheaters[i]] = 1;
            }
            return(PickChance);
        }
Exemple #26
0
 private static float[] CalculateMatchBonus(SimParams par, Population pop,
                                            List <int> usableMales)
 {
     float[] MatBonus = new float[usableMales.Count];
     if (par.MatchPreference != 0)
     {
         for (int i = 0; i < usableMales.Count; i++)
         {
             MatBonus[i] = par.MatchPreference * pop.Match[usableMales[i]];
         }
     }
     else
     {
         MatBonus = Enumerable.Repeat(0f, usableMales.Count).ToArray();
     }
     return(MatBonus);
 }
Exemple #27
0
        public static Population ChooseMates(SimParams par, Population pop)
        {
            //All females can pick a new mate
            var Assign = AssignFemale(par, pop.MaleSong, pop.FemaleSong);

            List <int>[] NewMaleSong   = new List <int> [par.NumBirds];
            List <int>[] NewFemaleSong = new List <int> [par.NumBirds];
            for (int i = 0; i < par.NumBirds; i++)
            {
                NewMaleSong[i]   = pop.MaleSong[Assign.MaleOrder[i]];
                NewFemaleSong[i] = pop.FemaleSong[Assign.FemaleOrder[i]];
            }
            pop.MaleSong   = NewMaleSong;
            pop.FemaleSong = NewFemaleSong;
            pop.Match      = Assign.Match;
            return(pop);
        }
Exemple #28
0
        private static List <int> GenerateNovelSong(SimParams par)
        {
            //Test whether each syllable is learned
            List <int> Song = new List <int>();

            while (Song.Count == 0)
            {
                for (int i = 0; i < par.SongCore.Count; i++)
                {
                    if (par.NextFloat() < par.SongCore[i])
                    {
                        Song.Add(i);
                    }
                }
            }
            return(Song);
        }
Exemple #29
0
        static float[] GetAgeRates(SimParams par)
        {
            /*Get the fraction of the population in each age group
             * The last element in the Survival Rates is omitted,
             * because that is the "dead" slot; no birds in the
             * population of live birds can be dead.
             */
            List <float> SurvivalRates = CalculateAllGenerations(par);

            float[] AgeRates = new float[SurvivalRates.Count - 1];
            for (int i = 0; i < AgeRates.Length; i++)
            {
                AgeRates[i] = SurvivalRates[i] / par.NumBirds;
                AgeRates[i] = AgeRates[i] * (1 / (1 - (par.DeathThreshold / par.NumBirds)));
            }
            return(AgeRates);
        }
        public static int[] GetGlobalBirds(SimParams par, Population pop,
                                           int learner, List <int> potentialBirds, int numBirds = 1)
        {
            int[]      Birds;
            List <int> PotentialBirds = potentialBirds.ToList();

            PotentialBirds.Remove(learner);
            if (numBirds == 1)
            {
                Birds = par.RandomSampleEqualReplace(PotentialBirds, numBirds);
            }
            else
            {
                Birds = par.RandomSampleEqualNoReplace(PotentialBirds, numBirds);
            }
            return(Birds);
        }