Question

In: Computer Science

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).  The child list must have the same length ?.
 child is generated by randomly combining part of the child's information ??????h?? and ??????h??.
 The first part of the child list will be made up of the first ? bits of ??????h?? and the second part by the last ? - ? bits of the ??????h??.
 For example, if ? = 3, ??????h?? = [?, ?, ?, 1,0,1] and ??????h?? = [1,1,1, ?, ?, ?], then ?h??? = [1,0,0,0,0,1].
 The value ? has to be chosen randomly by the function.

 After generating child, each bit in the list is considered for mutation.
 For each bit of child, with probability ? the bit is “mutated” by being replaced by its inverse (If the bit is 0 it is replaced by 1, and if it is 1 it is replaced by 0).
 Finally, the function returns the list child.

Solutions

Expert Solution

import numpy as np


def biochild(m, biomother, biofather):

    # child is generated by randomly combining part of the child's information ??????h?? and ??????h??.

    n = len(biomother)

    # randomly choose b from 1 to n

    b = np.random.randint(1, n)

    # The first part of the child list will be made up of the first ? bits of ??????h?? and the second part by the last ? - ? bits of the ??????h??.

    child = []

    for i in range(b):

        child.append(biomother[i])

    for i in range(b, n):

        child.append(biofather[i])

    # After generating child, each bit in the list is considered for mutation.

    # For each bit of child, with probability ? the bit is “mutated” by

    for i in range(n):

        # being replaced by its inverse (If the bit is 0 it is replaced by 1, and if it is 1 it is replaced by 0).

        p = np.random.uniform(0, 1)

        if p <= m:

            if child[i] == 0:

                child[i] = 1

            if child[i] == 1:

                child[i] = 0

    # Finally, the function returns the list child.

    return child


# For example: ??????h?? = [1,0,0,1,0,1] and ??????h?? = [1,1,1,0,0,1]

print(biochild(0.5, [1, 0, 0, 1, 0, 1], [1, 1, 1, 0, 0, 1]))

.

Screenshot:

Output:

.


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...
In Python Create a function called ℎ?????. The function has as arguments a list called ??????...
In Python Create a function called ℎ?????. The function has as arguments a list called ?????? and a list call center. • List ?????? contains lists that represent points. o For example, if ?????? = [[4,2], [3,2], [6,1]], the list [4,2] represents the point with coordinate ? at 4 and y coordinate at 2, and so on for the other lists. Assume that all lists within points contain two numbers (that is, they have x, y coordinates). • List ??????...
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...
C# Programming create a Hash Function
C# Programming create a Hash Function
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...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes one doyble argument called "num". The function will declare, ask, and get another double from the user. Compare the double entered by the user to "num" and return a 0 if they are the same, a -1 num is less than the double entered by the user and 1 if it is greater.
Create a function named getCreds with no parameters that will prompt the user for their username...
Create a function named getCreds with no parameters that will prompt the user for their username and password. This function should return a dictionary called userInfo that looks like the dictionaries below: # Administrator accounts list adminList = [ { "username": "DaBigBoss", "password": "DaBest" }, { "username": "root", "password": "toor" } ] Create a function named checkLogin with two parameters: the userInfo and the adminList. The function should check the credentials to see if they are contained within the admin...
Android Programming Create an app called GuessWho. The point of the app will to have the...
Android Programming Create an app called GuessWho. The point of the app will to have the user play a guessing game based on a displayed image. The user will be greeted with a screen that has an image of a person, four buttons and a next button. The four buttons should each have a different name on it. One of the names will be the actual name of the person in the image. Your guess who quiz should consist of...
Which ways can you change the values of parameters inside the function in C programming?
Which ways can you change the values of parameters inside the function in C programming?
Programming Problem 2 - Cycle [A] Create a class called “Cycle” which has two instance integer...
Programming Problem 2 - Cycle [A] Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.” Create a constructor with two parameters, using the same variable names in the parameter list. Assign each variable to numberOfWheels” and “weight” respectively. Write a separate application to test the class and display its properties. Note: Do not change the names of the instance variables or the variables listed in the constructor’s parameter list. [B] Edit your class...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT