Question

In: Computer Science

Creates a function called biochild. The function has as parameters the number m and lists biomotℎer...

Creates a function called biochild. The function has as parameters the number m and lists biomotℎer and biofatℎer. The lists biomotℎer and biofatℎer contain 0’s and 1’s. For example: biomotℎer = [1,0,0,1,0,1] and biofatℎer = [1,1,1,0,0,1] Both lists have the same length n. The 0’s and 1’s represent bits of information (remember that a bit is 0 or 1). The function has to generate a new list (child). The child list has to have the same length n. child is generated by randomly combining some of the information from the biomotℎer and biofatℎer. The first part of the child list will be composed of the first b bits of biomotℎer and the second part by the last n b bits of the biofatℎ

Crea una función llamada biochild. La función tiene como parámetros el número m y las listas ??????ℎ?? y ??????ℎ??. Las listas ??????ℎ?? y ??????ℎ?? contienen 0’s y 1’s. Por ejemplo: ??????ℎ?? = [1,0,0,1,0,1] y ??????ℎ?? = [1,1,1,0,0,1] Ambas listas tienen el mismo largo ?. Los 0’s y 1’s representan bits de información (recuerda que un bit es 0 o 1). La función tiene que generar una nueva lista (child). La lista child tiene que tener el mismo largo ?. child se genera por medio de combinar aleatoriamente parte de la información del ??????ℎ?? y ??????ℎ??. La primera parte de la lista child estará compuesta por los primeros ? bits de ??????ℎ?? y la segunda parte por los últimos ? − ? bits del ??????ℎ??. Por ejemplo, si ? = 3, ??????ℎ?? = [?, ?, ?, 1,0,1] y ??????ℎ?? = [1,1,1, ?, ?, ?], entonces ?ℎ??? = [1,0,0,0,0,1]. El valor ? tiene que ser elegido aleatoriamente por la función.  Luego de haber generado child, cada bit de la lista es considerado para mutación. Para cada bit de child, con probabilidad ? el bit es “mutado” al ser sustituido por su inverso (si el bit es 0 es sustituido por 1, y si es 1 es sustituido por 0). Finalmente, la función devuelve la lista child

Solutions

Expert Solution

import random
def biochild(m,bioMother,bioFather):
b=random.randint(1,len(bioMother))#generate a number b randomly
child=bioMother[:b]+bioFather[b:]#create child list using 1st b elements of mother, and remaining of father
for i in range(len(bioMother)):#loop through the list
if random.random()<=m:#generate a random number in [0,1] and using that to see if but should be inverted
child[i]=int(not child[i])#invert bit using not , then convert boolean to 1 or 0
return child#return the list


Related Solutions

IN PYTHON Create a function called biochild.  The function has as parameters the number m...
IN PYTHON Create a function called biochild.  The function has as parameters the number m and the lists biomother and biofather.  The biomother and biofather lists contain 0’s and 1’s.  For example: biomother = [1,0,0,1,0,1] and biofather = [1,1,1,0,0,1]  Both lists have the same length n.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child).  The child...
Define a Python function named matches that has two parameters. Both parameters will be lists of...
Define a Python function named matches that has two parameters. Both parameters will be lists of ints. Both lists will have the same length. Your function should use the accumulator pattern to return a newly created list. For each index, check if the lists' entries at that index are equivalent. If the entries are equivalent, append the literal True to your accumulator. Otherwise, append the literal False to your accumulator. Hint: Since you must use the same index with each...
in phyton programming: with numpy Create a function called biochild.  The function has as parameters...
in phyton programming: with numpy Create a function called biochild.  The function has as parameters the number m and the lists ??????h?? and ??????h??.  The lists ??????h?? and ??????h?? contain 0’s and 1’s.  For example: ??????h?? = [1,0,0,1,0,1] and ??????h?? = [1,1,1,0,0,1]  Both lists have the same length ?.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child)....
Write a recursive function in C++ that creates a copy of an array of linked lists....
Write a recursive function in C++ that creates a copy of an array of linked lists. Assuming: struct node { int data; node * next; }; class arrayList { public: arrayList(); ~arrayList(); private: node ** head; int size; //(this can equal 10) }
Write a function called price_of_rocks. It has no parameters. In a while loop, get a rock...
Write a function called price_of_rocks. It has no parameters. In a while loop, get a rock type and a weight from the user. Keep a running total of the price for all requested rocks. Repeat until the user wants to quit. Quartz crystals cost $23 per pound. Garnets cost $160 per pound. Meteorite costs $15.50 per gram. Assume the user enters weights in the units as above. Return the total price of all of the material. Using Python For this...
Creates a function called pick. The function receives a "string" representing one year (the variable with...
Creates a function called pick. The function receives a "string" representing one year (the variable with this "string" will be called uve) and a list containing "strings" representing bank accounts (call this bera list). <br> • Each account is represented by 8 characters. The format of each account number is "**-**-**", where asterisks are replaced by numeric characters. o For example, "59-04-23". • The two central characters of the "string" for each account represent the year the account was created....
- Design and implement a function with no input parameters. The function keeps receiving a number...
- Design and implement a function with no input parameters. The function keeps receiving a number from input (user) and adds the numbers together. The application keeps doing it until the user enter 0. Then the application will stop and print the total sum and average of the numbers the user had entered.
Sovle with python 3.8 please. 1, Write a function called same_without_ends that has two string parameters....
Sovle with python 3.8 please. 1, Write a function called same_without_ends that has two string parameters. It should return True if those strings are equal WITHOUT considering the characters on the ends (the beginning character and the last character). It should return False otherwise. For example, "last" and "bask" would be considered equal without considering the characters on the ends. Don't worry about the case where the strings have fewer than three characters. Your function MUST be called same_without_ends. You...
Nested Loops Problem 3 Write a function called makesentence() that has three parameters: nouns, verbs, and...
Nested Loops Problem 3 Write a function called makesentence() that has three parameters: nouns, verbs, and gerunds. Each parameter is a list of strings, where nouns list has noun strings (such as 'homework'), verbs list has veb strings (such as 'enjoy'), and gerunds list has gerund strings (those -ing words, such as 'studying'). The function will go through all these lists in a systematic fashion to create a list of all possible sentences that use all the noun, verb, and...
Write a function in c++, called afterAll that takes two parameters, a vector of string and...
Write a function in c++, called afterAll that takes two parameters, a vector of string and a string. The function returns true if the 2nd parameter comes after all of the strings in the vector, order-wise, false if not. As an example, "zoo" comes after "yuzu".
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT