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.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
1 Video Processing Lecture on the image part (8+9) Automatic Perception Volker Krüger Aalborg Media Lab Aalborg University Copenhagen
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.
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.
CS 206 Introduction to Computer Science II 10 / 14 / 2009 Instructor: Michael Eckmann.
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.
Chapter 2 storing numbers and creating objects Pages in Horstmann.
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() –
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
ImageJ EE4H, M.Sc Computer Vision Dr. Mike Spann
ICS 145B -- L. Bic1 Project: Main Memory Management Textbook: pages ICS 145B L. Bic.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
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.
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.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
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.
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,
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
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.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
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
The need for Programming Languages
Chapter 7 User-Defined Methods.
Real-Time Soft Shadows with Adaptive Light Source Sampling
Lesson 1 - Sequencing.
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.
What/how do we care about a program?
Chapter 5 Ordered List.
Lesson Objectives Aims
Java Variables, Types, and Math Getting Started
COS 126 – Atomic Theory of Matter
CSE 143 Lecture 2 Collections and ArrayIntList
Sets, Maps and Hash Tables
Barb Ericson Georgia Institute of Technology April 2006
Observe Brownian motion of particles.
COS 126 – Atomic Theory of Matter
slides created by Ethan Apter
COS 126 – Atomic Theory of Matter
Data Structures & Algorithms
CSE 143 Lecture 2 ArrayIntList, binary search
State Machines 8-May-19.
State Machines 16-May-19.
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 Sequence of images Each image is a rectangle of pixels Each pixel is either light or dark Output Estimate of Avogadro’s number

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 Boltzmann Avogadro displacement data BeadTracker Track beads from one image to the next Pictures (frames) command line args

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

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?

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) current (beads timet+1) previous (beads timet)

BeadTracker Challenges Reading multiple input files java 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 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 – see (1) and (2) Recompiling Recompile if Blob or BeadFinder change

BeadTracker Challenges (1) Avoid running out of memory … File containing frame time0 File containing frame time1 File containing frame time2 File containing frame timen beads time0 beads time1 radial displacement0 Only need two open at a time

BeadTracker Challenges (1) Avoid running out of memory … File containing frame time0 File containing frame time1 File containing frame time2 File containing frame timen beads time1 beads time2 radial displacement1 Only need two open at a time

BeadTracker Challenges (2) Avoid running out of memory … File containing frame time0 File containing frame time1 File containing frame time2 File containing frame timen beads time0 beads time1 beads time2 radial displacement0 radial displacement1 No need to re-find beads – use the beads time1 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?