Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in the below code what woud you use to generate the plot, there is a spot in the code where it should be located at?

in the below code what woud you use to generate the plot, there is a spot in the code where it should be located at? the paramaization should be turned off

#!/usr/bin/env python

#import necessary python packages import numpy as np import sys from matplotlib import pyplot as plt

#Use raw input to determine whether the run will be used to parameterize hunting mortality rate or just describe population dynamics if raw_input('Parameterizing run?')=='N': Parameterize = True else: Parameterize = False

"""" Created class representing prey organisms. Each organism has an age and number of offspring if can contribute to annual reproduction. It also has two methods. One that allows it to participate in reproduction if selected (can only contribute 2 offspring to the next generation) and another that allows the organism to age 1 year at a time. """ class Prey: def __init__(self): self.age = 0 self.offspring = 0 def reproduce(self): self.offspring = 4 def changeAge(self): self.age += 1

#CREATE YOUR PREDATOR CLASS HERE class Predator: def __init__(self): self.age = 0 self.offspring =0 def reproduce(self): self.offspring = 2 def changeAge(self): self.age += 1

#Initialize variable you need after the loop RateParameters=[] # iterations = int(raw_input('How many iterations to run: ')) # for j in range(iterations): # if Parameterize: HuntMortRate = np.random.random()*0.5 print j+1, HuntMortRate #Initialize population parameters for each run of the model Q = 5000 ProbSurvival = 0.5 InitPreyPopSize = 1000 InitPredPopSize = 500 PreyAgeReprod = 2 PredAgeReprod = 5 PreyEaten = 0 PreyPop = [] PredatorPop = [] NewPrey=0 NewPredators = 0 PredMortRate = 0.25 HuntMortRate = np.random.random()*0.75 StDev = 50 PredRate = 5 NumPrey=[] NumPred=[]

#Create a population of Organism objects of a pre-determined initial population size for i in range(InitPreyPopSize): PreyPop.append(Prey()) # for i in range(InitPredPopSize): PredatorPop.append(Predator()) #Let population cycle for 50 "years" using a for loop. Populations will grow and diminish based on population parameters that are affecting survival and reproduction for i in range(50): if Parameterize==False: print 1+i, len(PreyPop), len(PredatorPop) NumPrey.append(len(PreyPop)) NumPred.append(len(PredatorPop)) # PreyEaten = 0 NewPrey = 0 NewPredators = 0 PossibleNewPredators=0 # for i in range(len(PreyPop)): PreyPop[i].offspring = 0 # for i in range(len(PredatorPop)): PredatorPop[i].offspring = 0 # for i in range(len(PreyPop)): # if(np.random.random()>(float(len(PredatorPop))/float(len(PreyPop)))): PreyPop.pop() PreyEaten+=1 for i in range(len(PredatorPop)): if Parameterize: # if(np.random.random()<(PredMortRate+HuntMortRate)): PredatorPop.pop() else: # if(np.random.random()0): PossibleNewPredators=int(round(PreyEaten*0.33)) else: break for i in range(len(PreyPop)): # if(PreyPop[i].age>=PreyAgeReprod and len(PreyPop) < Q): #LOOK HERE FOR PART 4 PreyPop[i].reproduce() # NewPrey+=PreyPop[i].offspring #Have each surviving member of the population age 1 year PreyPop[i].changeAge() for i in range(len(PredatorPop)): # if(PredatorPop[i].age>=PredAgeReprod and PossibleNewPredators>0): PredatorPop[i].reproduce() # if(NewPredators<=PossibleNewPredators): # NewPredators+=PredatorPop[i].offspring #Have each surviving member of the population age 1 year PredatorPop[i].changeAge() #Add new offspring/recruit Organisms to population for i in range(NewPrey): PreyPop.append(Prey()) # for i in range(NewPredators): PredatorPop.append(Predator()) # if Parameterize: if len(PredatorPop)>20: RateParameters.append(HuntMortRate) print "Number of Accepted Values: ", len(RateParameters)

if Parameterize==False: #PUT CODE TO GENERATE LINE PLOTS HERE plt.plot() plt.savefig('population_dynamics.png') #If parameterization is turned on, output a histogram with 20 bins to a png file if Parameterize: plt.hist(RateParameters,20, facecolor='blue',alpha=0.5) plt.savefig('parameter_histogram.png')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

Identify and control your anxieties

Answered: 1 week ago

Question

Understanding and Addressing Anxiety

Answered: 1 week ago