COS 126 – Atomic Theory of Matter

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

The Singleton Pattern II Recursive Linked Structures.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Observe Brownian motion of particles.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
CSCI 103 – Atomic Theory of Matter. Goal of the Assignment Calculate Avogadro’s number Using Einstein’s equations Using fluorescent imaging Input data.
COS 126 – Atomic Theory of Matter. Goal of the Assignment Calculate Avogadro’s number Using Einstein’s equations Using fluorescent imaging Input data.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
CS 206 Introduction to Computer Science II 01 / 21 / 2009 Instructor: Michael Eckmann.
COS 126 – Atomic Theory of Matter. Atomic Theory Overview Brownian Motion Random collision of molecules Displacement over time fits a Gaussian distribution.
COS 126 – Atomic Theory of Matter. Announcements Project – due Friday (1/12) midnight TA Office Hours this week (check website) Lab Help (Mon-Fri 7pm-9pm)
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Introduction to Computer Science Exam Information Unit 20.
CS 106 Introduction to Computer Science I 03 / 30 / 2007 Instructor: Michael Eckmann.
Scanner class for input Instantiate a new scanner object Scanner in = new Scanner(System.in); Getting input using scanner – int i = scanner.nextInt() –
Chapter 6—Objects and Classes The Art and Science of An Introduction to Computer Science ERIC S. ROBERTS Java Objects and Classes C H A P T E R 6 To beautify.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
ImageJ EE4H, M.Sc Computer Vision Dr. Mike Spann
Checking Equality of Reference Variables. Arrays and objects are both “reference” types n They are allocated a chunk of memory in the address space n.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
Pointers OVERVIEW.
Dynamic Programming. Algorithm Design Techniques We will cover in this class: ◦ Greedy Algorithms ◦ Divide and Conquer Algorithms ◦ Dynamic Programming.
COS 126 – Atomic Theory of Matter. Goal of the Assignment Calculate Avogadro’s number Using Einstein’s equations Using fluorescent imaging Input data.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
COS 126 – Atomic Theory of Matter. Goal of the Assignment Calculate Avogadro’s number Using Einstein’s equations Using fluorescent imaging Input data.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Java Variables, Types, and Math Getting Started Complete and Turn in Address/Poem.
1 Recursion Recursion is a powerful programming technique that provides elegant solutions to certain problems. Chapter 11 focuses on explaining the underlying.
Where’s the title? You gotta search for it!. PotW Solution String s = new Scanner(System.in).next(); int[] prev = new int[s.length() * 2 + 2]; Arrays.fill(prev,
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 A Case Study: Percolation Percolation. Pour liquid on top of some porous material. Will liquid reach the bottom? Applications. [ chemistry, materials.
2.4 A Case Study: Percolation Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008.
Arrays Chap. 9 Storing Collections of Values 1. Introductory Example Problem: Teachers need to be able to compute a variety of grading statistics for.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Building Java Programs Generics, hashing reading: 18.1.
3.1 Objects. Data type. Set of values and operations on those values. Primitive/Built-In types. n Usually single values n Can build arrays but they can.
Arrays Chapter 7.
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Chapter 7 User-Defined Methods.
Real-Time Soft Shadows with Adaptive Light Source Sampling
Java Course Review.
Chapter 5 Ordered List.
Chapter 7 Part 1 Edited by JJ Shepherd
COSC160: Data Structures Linked Lists
COS 126 – Atomic Theory of Matter
Java Software Structures: John Lewis & Joseph Chase
Class Variables We’ve seen how to add extra subroutines into our programs Can be accessed from within one another We can also add variables that are “global”
Chapter 2.
Chapter 5 Ordered List.
Building Java Programs
Lesson Objectives Aims
Phil Tayco Slide version 1.0 Created Oct 9, 2017
Java Variables, Types, and Math Getting Started
COS 126 – Atomic Theory of Matter
CSE 143 Lecture 2 Collections and ArrayIntList
Barb Ericson Georgia Institute of Technology April 2006
Observe Brownian motion of particles.
COS 126 – Atomic Theory of Matter
Namespaces, Scopes, Access privileges
slides created by Ethan Apter
COS 126 – Atomic Theory of Matter
slides created by Alyssa Harding
Data Structures & Algorithms
CSE 143 Lecture 2 ArrayIntList, binary search
State Machines 8-May-19.
State Machines 16-May-19.
slides created by Alyssa Harding
2.4 A Case Study: Percolation
Presentation transcript:

COS 126 – Atomic Theory of Matter

Goal of the Assignment Calculate Avogadro’s number Input data Output Using Einstein’s equations Using fluorescent imaging Input data Output Estimate of Avogadro’s number 7.1833 4.7932 2.1693 5.5287 5.4292 ... Video Frames Blobs/Beads Displacements

Overview – Four Classes BeadFinder Find all blobs in a JPEG image List all the big blobs (aka beads) Blob Maximal set of connected light pixels client of video data client of Avogadro Data analysis to estimate Avogadro’s number from the motion of beads BeadTracker Track beads from one image to the next Pictures (frames) displacement data Boltzmann Avogadro Command line args

Atomic Theory Overview Brownian Motion Random collision of molecules Displacement over time fits a Gaussian distribution

Atomic Theory Overview Avogadro’s Number Number of atoms needed to equal substance’s atomic mass in grams NA atoms of Carbon-12 = 12 grams NA == 6.0221367 x 10+23 Can calculate from Brownian Motion Variance of Gaussian distribution is a function of resistance in water, number of molecules

Blob.java API for representing particles (blobs) in water public Blob() constructor public void add(int i, int j) add pixel at i,j to Blob public int mass() number of pixels in Blob public double distanceTo(Blob b) Euclidean distance between the center of masses between Blobs public String toString() a string representation of this Blob public static void main(String[] args) unit tests all methods in the Blob data type Center of mass, and # of pixels

Blob.java Center of mass Only need three instance variables Do not store the positions of every pixel in the blob Two alternatives: number of points, x-coordinate center of mass, and y-coordinate center of mass) or number of points, sum of x-coordinates, and sum of y-coordinates) needed to compute the center-of-mass Center is not integer values! Center of mass, and # of pixels

Blob Challenges Format numbers in a nice way Thoroughly test String.format("%2d (%8.4f, %8.4f)", mass, cx, cy); (Use same format in System.out.printf()) E.g., "%6.3f" -> _2.354 E.g., "%10.4e" -> 1.2535e-23 Thoroughly test Create a simple main() Test ALL methods

BeadFinder.java Locate all blobs in a given image API And identify large blobs (called beads) API public BeadFinder(Picture picture, double threshold) Calculate luminance (see Luminance.java, 3.1) Include pixels with a luminance >= threshold Find blobs with DFS (see Percolation.java, 2.4) The hard part, next slide… public Blob[] getBeads(int minSize) Returns all beads with at least minSize pixels Array must be of size equal to number of beads

BeadFinder - Depth First Search Use boolean[][] array to mark visited Traverse image pixel by pixel Dark pixel Mark as visited, continue Light pixel Create new blob, call DFS DFS algorithm Base case: simply return if Pixel out-of-bounds Pixel has been visited Pixel is dark (and mark as visited) Add pixel to current blob, mark as visited Recursively visit up, down, left, and right neighbors

BeadFinder - Depth First Search Use boolean[][] array to mark visited Traverse image pixel by pixel Dark pixel Mark as visited, continue Light pixel Create new blob, call DFS DFS algorithm Base case: simply return if Pixel out-of-bounds Pixel has been visited Pixel is dark (and mark as visited) Add pixel to current blob, mark as visited Recursively visit up, down, left, and right neighbors

BeadFinder - Depth First Search Use boolean[][] array to mark visited Traverse image pixel by pixel Dark pixel Mark as visited, continue Light pixel Create new blob, call DFS DFS algorithm Base case: simply return if Pixel out-of-bounds Pixel has been visited Pixel is dark (and mark as visited) Add pixel to current blob, mark as visited Recursively visit up, down, left, and right neighbors

BeadFinder - Depth First Search Use boolean[][] array to mark visited Traverse image pixel by pixel Dark pixel Mark as visited, continue Light pixel Create new blob, call DFS DFS algorithm Base case: simply return if Pixel out-of-bounds Pixel has been visited Pixel is dark (and mark as visited) Add pixel to current blob, mark as visited Recursively visit up, down, left, and right neighbors

BeadFinder - Depth First Search Use boolean[][] array to mark visited Traverse image pixel by pixel Dark pixel Mark as visited, continue Light pixel Create new blob, call DFS DFS algorithm Base case: simply return if Pixel out-of-bounds Pixel has been visited Pixel is dark (and mark as visited) Add pixel to current blob, mark as visited Recursively visit up, down, left, and right neighbors

BeadFinder - Depth First Search Use boolean[][] array to mark visited Traverse image pixel by pixel Dark pixel Mark as visited, continue Light pixel Create new blob, call DFS DFS algorithm Base case: simply return if Pixel out-of-bounds Pixel has been visited Pixel is dark (and mark as visited) Add pixel to current blob, mark as visited Recursively visit up, down, left, and right neighbors

BeadFinder Challenges Data structure for the collection of blobs Store them any way you like But be aware of memory use and timing

BeadFinder Challenges Data structure for the collection of blobs Store them any way you like But be aware of memory use and timing Array of blobs? But how big should the array be? Linked list of blobs? Memory efficient, but harder to implement Avoid traversing whole list to add a blob! Anything else? Submit your (extra) object classes if not in 4.3

BeadTracker.java Track beads between successive images Single main function Take in a series of images Output distance traversed by all beads for each time-step For each bead found at time t+1, find closest bead at time t and calculate distance Not the other way around! Don’t include if distance > 25 pixels (new bead)

BeadTracker Challenges Reading multiple input files java-introcs BeadTracker run_1/*.jpg Expands files in alphabetical order End up as args[0], args[1], … Avoiding running out of memory How? Recompiling Recompile if Blob or BeadFinder change

BeadTracker Challenges Reading multiple input files java-introcs BeadTracker run_1/*.jpg Expands files in alphabetical order End up as args[0], args[1], … Avoiding running out of memory Do not open all picture files at same time Various ways to do this Recompiling Recompile if Blob or BeadFinder change

BeadTracker Challenges Avoid running out of memory (1) … File containing frame t0 File containing frame t1 File containing frame t2 File containing frame tn beads t0 beads t1 radial displacement0 Only need two open at a time.

BeadTracker Challenges Avoid running out of memory (1) … File containing frame t0 File containing frame t1 File containing frame t2 File containing frame tn beads t1 beads t2 radial displacement1 Only need two open at a time.

BeadTracker Challenges Avoid running out of memory (2) … File containing frame t0 File containing frame t1 File containing frame t2 File containing frame tn beads t0 beads t1 beads t2 radial displacement0 radial displacement1 No need to re-find beads – use the beads t1 found in radial displacement0 computation in the computation of radial displacement1

Avogadro.java Analyze Brownian motion of all calculated displacements Lots of crazy formulas, all given, pretty straightforward Be careful about units in the math, convert pixels to meters, etc. Can test without the other parts working We provide sample input files Can work on it while waiting for help

Conclusion: Final Tips Avoiding subtle bugs in BeadFinder Double check what happens at corner cases (e.g., at boundary pixels, or when luminance == tau, or mass == cutoff) Common errors in BeadFinder NullPointerException StackOverflowError (e.g., if no base case) No output (need to add prints) Look at checklist Q&A

Conclusion: Final Tips Testing with a main() Blob Test all methods BeadFinder, BeadTracker, and Avogadro Must have a main() that can handle I/O described in Testing section of checklist Timing analysis Look at feedback from earlier assignments BeadTracker is time sink, so analyze that How can you run 100 frames?