EE 194/BIO 196: Modeling,simulating and optimizing biological systems

Slides:



Advertisements
Similar presentations
The Order of Operations
Advertisements

Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 04 / 21 / 2010 Instructor: Michael Eckmann.
Lecture 05 – Classes.  A class provides the definition for the type of an object  Classes can store information in variables  Classes can provide methods.
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
Classes 2 COMPSCI 105 S Principles of Computer Science.
Classes and Objects, Part 1 Victor Norman CS104. Reading Quiz, Q1 A class definition define these two elements. A. attributes and functions B. attributes.
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
Classes COMPSCI 105 SS 2015 Principles of Computer Science.
Testing CSE 160 University of Washington 1. Testing Programming to analyze data is powerful It’s useless (or worse!) if the results are not correct Correctness.
Process Mapping Dr. Nishan Sharma University of Calgary, Canada October
Classes and Objects, Part 1 Victor Norman CS104. “Records” In Excel, you can create rows that represent individual things, with each column representing.
Chapter More on Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Spring 2008Programming Development Techniques 1 Topic 5.5 Higher Order Procedures (This goes back and picks up section 1.3 and then sections in Chapter.
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 13 October 4, 2001 Fall Semester.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
CMSC201 Computer Science I for Majors Lecture 25 – Classes
Andrew(amwallis) Classes!
Python programming - Defining Classes
COMPSCI 107 Computer Science Fundamentals
EN 001-4: Introduction to Computational Design
CMSC201 Computer Science I for Majors Lecture 18 – Recursion
What does “assertiveness” mean?
Testing UW CSE 160 Winter 2017.
Lecture VI Objects The OOP Concept Defining Classes Methods
Lesson 2: Building Blocks of Programming
Functions BIS1523 – Lecture 17.
Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro.
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
Testing UW CSE 160 Winter 2016.
CMSC201 Computer Science I for Majors Lecture 16 – Classes and Modules
Review and Q/A.
Fall 2018 CISC124 12/3/2018 CISC124 or talk to your grader with questions about assignment grading. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
Transforming Data (Python®)
Passing Parameters by value
Story time Task 5 Computer Programming Gray , Calibri 24
Topic 1: Problem Solving
Coding Concepts (Basics)
Go to =>
An Introduction to Object Orientated Programming
Heaps Chapter 11 has several programming projects, including a project that uses heaps. This presentation shows you what a heap is, and demonstrates.
Body Image. Body Image Body Image Do you ever wish you could change something about your body? If so, you're not alone. Lots of people feel unhappy.
EE 193: Parallel Computing
Applied Software Project Management
Object-Oriented Programming
A Gentle introduction Richard P. Simpson
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
EE 194/Bio 196: Modeling,simulating and optimizing biological systems
A Level Computer Science Topic 6: Introducing OOP
EE 194/Bio 196 Modeling,simulating and optimizing biological systems
EE 194/BIO 196: Modeling,simulating and optimizing biological systems
EE 155 / COMP 122: Parallel Computing
EE 194 / Bio 196: Modeling biological systems
Spring 2018 Tufts University Instructor: Joel Grodstein
EE 194/BIO 196: Modeling,simulating and optimizing biological systems
EE 194/Bio 196: Modeling biological systems
EE 194/BIO 196: Modeling biological systems
Introduction to Object-Oriented Programming (OOP) II
EE 194/BIO 196: Modeling,simulating and optimizing biological systems
Object-Oriented Programming and class Design
Introduction to Computer Science
Object-Oriented Programming and class Design
Lecture 6 - Recursion.
Presentation transcript:

EE 194/BIO 196: Modeling,simulating and optimizing biological systems Spring 2018 Tufts University Instructor: Joel Grodstein joel.grodstein@tufts.edu Objects

Why do we care about objects We’ve learned about variables Variables are great, but there’s only one of each We’ve learned about arrays Arrays are great, but … each member of an array has the same data type and is, conceptually, an instance of the same “thing.” Often we want to treat a group of dissimilar things as one big group. Example: A student has name, UTLN, year, grades, but it's still one student – and there are many students. We have no good way to do that so far EE 194/Bio 196 Joel Grodstein

More examples? What other examples can you think of? An item in a store has price, bar code, shelf location, weight A Manduca sexta might have one 2D array for its leg-locked pattern and another for its muscle-activation pattern and a variable for its name, perhaps  EE 194/Bio 196 Joel Grodstein

Demo Demo using Lunchables to introduce objects. EE 194/Bio 196 Joel Grodstein

Impressive terminology Other courses will take this idea much further: A student, or a lunch, or a hornworm will be an object. Nobody has to know what’s inside of it. You just know what you can do to it; you can make() your lunch, eat() it, or trade() it. We’re taking the first steps in object-oriented programming. EE 194/Bio 196 Joel Grodstein

Objects Computer programs can get big. Really big. Mac OS/X is about 85 million of lines of code Nobody can do that alone; big projects have big teams Big teams of people don’t really help if everyone has to understand all 85M lines of code. We’ve talked about using functions and packages to divide up the work Objects are the next big tool divide up the work. One team of people implements a Manduca object like what you’ll see in the HW. It can be created, mate and mutate. It can be printed and simulated. Another team of people uses Manduca. E.g., put together a genetic algorithm that uses the abilities just described. They don’t have to know how Manduca is implemented They need only know what its capabilities are Object-oriented programming is a Big Deal in Computer Science. EE 194/Bio 196 Joel Grodstein

Objects Let’s start writing code for a Manduca object class Manduca: def __init__(self, legs, muscles): self.legs=np.copy(legs) self.muscles=np.copy(muscles) self.name = "Bob" says that the rest of this code will define a class of object called a “Manduca” says what leg and muscle patterns go into the new Manduca this function tells how to make a new Manduca copy/save the parameters into this Manduca says which of the many Manducas to work with Fine, all worms have the same name! EE 194/Bio 196 Joel Grodstein

The basics my_legs = np.array ([[1,1,0,0,0],…]) my_musc = np.array ([[100,0,0,100],…]) m1 = Manduca (my_legs, my_musc) def __init__(self, legs, muscles): self.legs=np.copy(legs) self.muscles=np.copy(muscles) self.name= "Bob" legs my_musc my_legs m1 muscles name [100,0,…] [1,1,0,…] [1,1,0,…] [100,0,…] "Bob" self EE 194/Bio 196 Joel Grodstein

Next steps Great, we can make a Manduca. In fact, we can make as many of them as we want: my_legs = np.array ([[1,1,0,0,0],…]) my_musc = np.array ([[100,0,0,100],…] m1 = Manduca (my_legs, my_musc) my_legs[3,:]=[1,0,0,0,1]; m2 = manduca (my_legs, my_musc) But what else can we do with them? Print them out EE 194/Bio 196 Joel Grodstein

Printing an object class Manduca: def __init__(self, legs, muscles, name): … def __repr__(self): str = self.name + " legs | muscles\n" for r in range(10): # for each row str+= np.array2string (self.legs[r,:]) + " | " + \ np.array2string (self.muscles[r,:]) + "\n" return(str) __repr__() is a special function that Python calls whenever you print an object. It lets you control how an object gets printed. EE 194/Bio 196 Joel Grodstein

Printing example m1 = Manduca (my_legs, my_musc) my_legs[0,:]=[1,0,0,0,1] m2 = manduca (my_legs, my_musc) print (m1) print (m2) legs muscles [1 1 0 0 0] | [100 0 0 100] … the other 9 rows … [1 0 0 0 1] | [100 0 0 100] EE 194/Bio 196 Joel Grodstein

What else can you do with a worm? Mutate it class Manduca: def __init__(self, legs, muscles): … def __repr__(self): … def mutate (self): self.legs[3,3] = 1 – self.legs[3,3] How do we use this? child = parent child.mutate() Now we have a mutated child What about the parent. Is it mutated too? Real mutations might be more random and perhaps more widespread Unfortunately, yes  Objects are also too big to fit into a cup. EE 194/Bio 196 Joel Grodstein

The issue start with the parent child = parent child.mutate() Now the child points at the same worm as the parent. There's only one worm here When we mutate the child, the parent changes too – they are just different names for the same worm. parent child legs [0,1,0,…] [1,1,0,…] musc [100,0,…] EE 194/Bio 196 Joel Grodstein

More fun with a worm child = parent.copy() child.mutate() Add a copy function: class Manduca: def __init__(self, legs, muscles, name): … def __repr__(self): … def mutate (self): … def copy (self): return (Manduca (self.legs.copy(), self.muscles.copy()) child = parent.copy() child.mutate() parent child EE 194/Bio 196 Joel Grodstein

The fix start with the parent child = parent.copy() child.mutate() parent.copy() creates a new worm with identical “genes” as the parent. When we mutate the child, the parent is not affected. parent child legs legs musc musc [1,1,0,…] [100,0,…] [0,1,0,…] [1,1,0,…] [100,0,…] EE 194/Bio 196 Joel Grodstein

More exercises https://www.w3resource.com/python-exercises/class-exercises/ problems #10 and #11. Play with the homework: Look at the Manduca homework program manducaEv.py. Make sure you understand the class it uses. Write your own mutate() or mate() function, and print the resulting object to see if your function worked. The __repr__ function is a bit complicated. Write your own, and see if you can get it to print differently. EE 194/Bio 196 Joel Grodstein