public string utterWord(Agent speaker) { Dictionary <string, double> vocabulary = speaker.getVocabulary().getVocabulary(); if (EALoop.RandomInt(0, 100) <= 40) { return(newWord()); } if (vocabulary.Count == 0) { return(newWord()); } double sum = 0; var sortedDict = from entry in vocabulary orderby entry.Value descending select entry; foreach (var i in sortedDict) { sum += i.Value; } double rnd = EALoop.RandomDouble(); double prob = 0; foreach (var i in sortedDict) { prob += i.Value / sum; if (rnd <= prob) { return(i.Key); } } return(vocabulary.ElementAt(EALoop.RandomInt(0, vocabulary.Count)).Key); }
public void mutate(double p) { if (EALoop.RandomDouble() <= p) { //double mutateRate = (EALoop.RandomInt(0,4) - 2) / 10; // Blir et tall mellom -0.2 og 0.2 //if (mutateRate == 0.0) { mutateRate = 1.01; } //int index = EALoop.RandomInt(0,genomeValues.Count); genomeValues[EALoop.RandomInt(0, genomeValues.Count)] = EALoop.RandomInt(0, 100); genomeNormalised = normalise(genomeValues); } }
public Agent selectSpeaker(List <Agent> pop) { double sum = 0; foreach (Agent a in pop) { sum += a.getFitness(); } double rnd = EALoop.RandomDouble(); double n = 0; foreach (Agent a in pop) { n += a.getFitness() / sum; if (rnd <= n) { return(a); } } return(pop[EALoop.RandomInt(0, pop.Count)]); }
public Agent selectListener(Agent agent, SocialNetwork net, List <Agent> population) { var genome = agent.getGenome().getValuesGenome(); double P_extrovert = ((genome[3] + (100 - genome[6]) / 200) * C) / 100; Dictionary <Agent, double> connections = net.getAgentsConnections(agent); //if ((EALoop.RandomDouble() <= P_extrovert && agent.getZ() < maxExtroConv) || net.getAgentsConnections(agent) == null) if (EALoop.RandomDouble() <= P_extrovert) { // Extrovert //System.Console.WriteLine("EXTROVERT"); Agent listener = population[EALoop.RandomInt(0, population.Count)]; while (listener == agent) { listener = population[EALoop.RandomInt(0, population.Count)]; } agent.incrementZ(); return(listener); } // Introvert double sum = 0; foreach (var friend in connections) { sum += friend.Value; } double random = EALoop.RandomDouble(); double to = 0; foreach (var friend in connections) { to += friend.Value / sum; if (random <= to) { return(friend.Key); } } return(null); }