辅导 CE 451/551、讲解 Python 语言程序
CE 451/551 – Computer-Aided Research in the Chemical and Materials Sciences: Homework #11 (Graded #3)
(Due: Tuesday, 11 March Tuesday 2025, 5:00pm)
The goal of this assignment is to practice the use of cookbooks, templates, and code snippets as well as the SciPy and Matplotlib libraries for a given problem setting. Your task is to write a Python program that describes the population development in a simple predator-prey relationship, i.e., one in which there are only two interacting species, one a predator and one its prey. (Predator-prey relationships are typical examples for dynamics in a biological system.) A basic standard model considers (a) the natural birth rate of the prey species; (b) the natural death rate of the prey due to predation; (c) the natural death rate of the predator due to lack of prey; (d) the factor describing how many caught prey animals lead to the birth of a new predator animal. Your task is to expand the basic model by including (e) the natural death rate of the prey independent of predation; (f) the natural death rate of the predator independent of lack of prey (Note: the original model should result as a special case for e = 0.0 and f = 0.0).
Your code should plot the population evolution results for this model for a number of parameter combinations, i.e., a = 1, b = 0.1, c = 1.75, d = (0.25, 0.5, 0.75, 1.0); e = 0.2 and f = 0.1 as well as e = f = 0.0; initial number of prey animals is 50 and the initial number of predator is (1,10,100). In total, your code should thus plot the results of 24 parameter combinations. (If you end up with 48 plots, you missed that two parameters are not independent, which reduces the number of possible combinations.) Your script should write these plots into image files (e.g., pngs) like we did in the modified zombies example, rather than displaying them on screen. The graphs should be meaningful, attractive, and "publication quality", which means that the graph is properly labeled; that there is a legend and potentially a plot title; that fonts, font sizes, line thicknesses are chosen sensibly (e.g., well readable, no overlapping texts); that you make appropriate use of color; that you choose the “right” kind of plot (e.g., if a histogram is the most obvious choice, then do not do a pie-chart); that you consider visual aids if appropriate (e.g., subtle gridlines); that the value ranges make sense (e.g., if the largest y-value is 100, then the y-axis should probably not go to 200); that the files generated are sensibly named (i.e., not just "fig1.png", "fig2.png",...), etc. However, "publication quality" does not mean that they should be overly complicated or full of bells-and-whistles that distract from what you want to show (actually these are all negatives). The recipe may suggest additional field plots which you can add, if you want.
Please submit your zipped source code file to me via email – do not just copy your source into the email. If you want to send multiple files, please add them to the zip folder. You do not have to include the images your code generates as we will run your code for evaluation. Please add a short README text file in which you describe the major changes you made to the original recipe and please also add corresponding comments into the appropriate places of your code (e.g., “# In the following function, I added...”, “# Here I added a loop over all parameters...”). Your submission will be graded based on the quality of your implementation (including efficiency, documentation, readability, clarity), and whether your program actually works or not. As part of the evaluation, I have to be able to execute the file you send me using the current Anaconda version. Do not assume X window access, i.e., write all graphics to file. If your code does not run under those conditions, then you have a problem. Please use the following email subject line “CE 451/551 HW11 submission by ”.
Tip 1: Cookbook recipes, examples, templates, and code snippets for similar problems can be found online, and your primary task is to find and adapt one of them for the task at hand.
1
Tip 2: The Zombie Apocalypse recipe we discussed in class is very similar to the target application at hand and it can in fact be used as the basis to solve this assignment. However, there is an even better recipe for this particular problem.
Tip 3: The most suitable template you will find will only give you results for one parameter combination, so it will require a rewrite to produce results for all 24 parameter combinations using loops (if you do not use loops but just copy the code over and over again, you will loose points on style).
Tip 4: The standard model of the predator-prey relationship in this assignment is rather famous. It was discovered independently by two scientists in 1925/26, and you should have encountered it in high-school biology.
Tip 5: The key to updating the model given in the most suitable template is to understand how the given differential equation works (in the same way we did in class for the zombie example), then adding e and f is straightforward.
Tip 6: If you have trouble getting your code to run, try to google the error message you get. They will likely lead you to a useful stackoverflow page that will help you solve the problem.
Note: Your code should be adequately commented, so that I know what you are doing.
Note: You may interact on technical questions with your classmates, but every student has to submit an individual solution. No two scripts/programs can be alike.
Reminder of the rules:
CE 451/551 has no exams. Grades are primarily determined on the basis of ten graded assignments, each contributing 10% to the final grade. Each graded assignment (and thus the final grade) has a 0-100 points scale. In addition to the graded assignments, there are five pass/fail assignments covering essential content every student has to master to succeed in this class. Failure to complete the latter results in a predetermined number of penalty points that are deducted from the final grade. (Note that you do not literally fail the class if you do not complete a pass/fail assignment, however, the penalty points will have a severely negative impact on your final grade.) In addition to the mandatory assignments, there are seven voluntary bonus assignments. Completion of the latter is rewarded with a predetermined number of bonus points that are added to the final grade. Active in-class participation throughout the semester is rewarded. It is recorded after each class and tallied for each student at the end of the semester. Up to 5 bonus points may be added to the final grade for outstanding and exceptional contributions throughout the course. Note that these bonus points are not required to receive a perfect grade, but that they can compensate for points lost in other places.
The overall letter grades are based on 5-points brackets:
Points 100-96 95-91 90-86 85-81 80-76 75-71 70-66 65-61 60-56 55-51 50-0 Letter A A− B+ B B− C+ C C− D+ D F
In past years, the course average has been around an A−/B+. I reserve the right to curve the grades, should the need arise (however, this has never been necessary so far). I will provide intermediate grades and/or grade projections at regular intervals throughout the semester and you are encouraged to proactively request updates as well. In addition, I am providing the grade_tinker.xlsx spreadsheet on UB Learns with which you can keep track of your standing and assess different grade scenarios.
Good grades are very achievable, and they typically strongly correlate with individual students’ engagement.
The performance expectations that form the basis for the grading of the assignments differ for the graduate vs undergraduate section of the course. In particular for the coding projects, the graduate students are expected to deliver more extensive and technically advanced products that tie into their research work. The grading scale is adjusted correspondingly.
Assignments come in different shapes and forms, including traditional homework, coding tasks, projects, and reports – either for groups or on an individual basis. Assignments and due dates are posted on UB Learns (or given individually), and instructions for electronic submissions via email or UB Learns are provided. Please follow these instructions and the naming conventions for the submissions exactly and submit each assignment individually
2
(rather than in a bundle). Unless stated otherwise, there is a 20-point penalty for late assignments, and additional 20 points are deducted after each additional 24h (given a good reason, I may reduce or wave a late penalty). Late penalties start to apply once the assignment deadline passes. I am open to discussing no-penalty extensions of deadlines, hardship exceptions, and accommodations if warranted.
Late >0h, <24h >24h, <48h >48h, <72h >72h, <96h >96h
Penalty −20 pts −40 pts −60 pts −80 pts −100 pts
Failure to follow all assignment instructions will result in penalty points. Work that is disorganized, unclear, illegible, or otherwise unprofessionally presented may have points deducted or be returned without a grade at my discretion. Subsequent resubmission may be considered late. To receive full credit, you must show all the logical steps of your work. Extra points may be awarded for particularly original solutions, and penalty points may be deducted for outrageously wrong or obviously nonsensical answers (i.e., you may want to leave blanks rather than submit wild guesses). Precision is a virtue, so please avoid fluffed out and waffling answers. Make-up or do-over assignments are generally not offered. These rules may seem strict, but there are many assignments to grade and failure to comply with the rules makes life unnecessarily hard for me and the graders.
Mistakes happen and if you think that you unjustly lost points on an assignment, please write a few sentences explaining your position and making a substantive case for a revision. Send this response to me for review. I will evaluate if you make a good argument, and your claim has merit and correct the corresponding grade if warranted. You can submit claims via email, in class, or leave them in my mailbox in 308 Furnas Hall. I will only accept regrade requests within a week after an assignment is returned, so that issues can be resolved in a timely fashion. Note that we have procedures in place to identify attempts at tempering.
While you are encouraged to collaborate and exchange ideas with your classmates, your work has to be individually and independently written up (unless stated otherwise). No two students' solutions can be identical, nor can they be direct or disguised copies from solution manuals, the internet, or similar sources. Failure to comply constitutes academic dishonesty and carries penalties as discussed below.
Academic integrity
Breaches of academic integrity (e.g., plagiarism, cheating, purchasing or selling of class notes or assignment solutions) are unacceptable and will result in a failing grade for the particular assignment and/or for the entire course. It’s not right and it’s not worth it! Academic integrity is a fundamental university value. Through the honest completion of academic work, students sustain the integrity of the university and of themselves while facilitating the university's imperative for the transmission of knowledge and culture based upon the generation of new and innovative ideas. It is expected that you behave in an honorable and respectful way as you learn and share ideas. To summarize UB’s policy on dishonesty: A student will not present, as his or her own, the work of another, or any work that has not been honestly performed; will not take any examination by improper means and will not aid and abet another in any dishonesty. Please consult UB’s Student Code of Conduct and UB’s Undergraduate Academic Integrity Policy at:
Note: Cheating on an assignment or exam does you no good, and dishonesty reflects poorly on your character. Any incident of academic misconduct, regardless of severity, will be brought to UB’s Office of Academic Integrity. At a very practical level, you should ask yourself how you might expect a reference from faculty members if you have been cheating in their classes. I had to punish offenders before, and it is tough on everyone involved. PLEASE, spare yourself and me this painful situation! You have been warned!
Copyrighted course materials
Course materials (lecture/recitation slides, recordings, files, assignments, master solutions, examples, etc) are for course purposes only, they are copyrighted, and they may not be shared outside this class without my prior written permission. In particular, they may not be shared on Course Hero, Chegg, or similar platforms, or with anyone outside the class. Please note that my course material may contain individualized hidden watermarks and
3
that UB can monitor network access to cheating platforms. Failure to comply constitutes academic dishonesty and carries penalties as discussed above.