computer science

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Some Python function from the random module cont'd

# random char from string random.choice("abcdefghij") #shuffles the items random.shuffle(items) #3 samples without replacement - takes n items random.sample([1,2,3,4,5,6], 3) result = [4, 1, 5]

Clock Speed is No Longer Increasing

- 1 MHz is 1,000,000 cycles/second - Computers run with a "clock" that synchronizes operations. - At each rising edge all signals through one love of gates ect.

Simulating a Deck of Cards

- A deck of cards is made up of 52 cards, where each cards has a suit and a rank: - Suits: Spades, Hearts, Diamonds, Clubs. - Ranks: 2,3,4,5,6,7,8,9,10, J, Q, A. - A standard deck of cards has 1 of each combination of suit and rank.

Distributed Systems:

- A distributed system is an application that : - consists of processes that execute on multiple computers connected through a network and - cooperate to accomplish a task. -Advantages - open - add new parts and interact with remote users. - Scalable - system can be altered to accommodate changes in numbers of users , resources, computer systems.

Model Assumptions:

- A person starts off as healthy. - Each day, a healthy person comes in contact with 4 random people. If any of these random people is contagious, then the healthy person becomes infected. - it takes one day for the infected person to become contagious. - After a person has been contagious for 4 days, then the person is non contagious and cannot spread the virus nor can the person get the virus again due to immunity.

Internet Protocol

- A protocol is a standard for communicating messages between networked computers. - An IP address in each packet determine the intended destination of the packet. - A domain name server translated machine names to equivalent IP addresses to make it easier for users to indicate message destinations.

Communication Protocol

- Agreement between communicating parties: Syntax: how are the messages' contents organized? Semantics: what do the messages mean? Synchronization: when are messages sent? - Something standardized as a "Request for Comments (RFC)" by the Internet Engineering Task Force (IETF)

Large Scale Simulations

- Computing power of today enables large scale simulations. - Department of Defense Battle simulations. - Blue Brain Project at EPFL to reverse engineer the human brain. - National Center for Atmospheric Research, 1000 years of climate changes.

Structure of the Internet

- Core: - routers - gateways - Internet Service Provider (ISP) - domain name server - Edges - individual users - private networks.

Obtaining Random Sequences:

- Definition we adopt: A sequence is random if for any value in the sequence, the next value in the sequence is totally independent of the current value. - if we need random values in a computation how can we obtain them?

Pipelining in Computing

- Fetch instruction from memory - Decode the instruction - Read data from registers - execute the instruction. - Write the result into a register.

Example: Flu Virus Simulation

- Goal develop a simple graphical simulation that shows how disease spreads through a population. - agent based - abstract - Dynamic - Stochastic - Discrete.

The Internet

- In 1984, the US military portion of the ARPANet was broken off as a separate network, the MILNET. - During the 1980s , the connections expanded to more educational institutions and companies. - The National Science Foundation, became heavily involved in the Internet in the mid 1980s. - The NSFNet backbone, intended to connect and provide access to a number of supercomputing centers establishes by the NSF, was established in 1986, and became the Internet by the end of the 1980s.

Classless Addressing

- In 1993, the Internet switched to classes internet-domain routing. In this scheme, the network part is an arbitrary length prefix of the address, such as 10.10.1.32/27, which has a 27-bit network part and a 5-bit address part(So there can only be 32 machines on that network). - IPv6 also follows classless routing, but the standard subnetworks size is 64-bits (Which allows using the MAC address manufactured into each ethernet card as the local part. Normally 48-bit prefixes of IPv6 are assigned to individual organizations, allowing each organization to have 65,535 subnetworks, with up to 2^64 machines per subnetwork.

Moore's Law

- Multi Core executing simultaneously - prediction: thousands of cores. - new processors are multicore.

Obtaining Random Sequences

- Pre computed random sequences: For example, A Million Random Digits with 100,000 Normal Devaites( 1955): a 400 page reference book by the RAND corporation. - 2500 random digits on each page - Generated from random electronic pulses. - True Random Number Generators (TRNG): extract randomness from physical phenomena such as atmospheric nice, times for radioactive decay. - Pseudo-random Number Generators (PRNG): use a formula to generate numbers in a deterministic way but the numbers appears to be random.

Python's Random Module

- Python uses the Mersenne Twister as the core generator. It produces 53-bit precision floats and has a period of 2^19937-1 - Almost all modules functions depend on the basic function random( ), which generates a random float uniformly in the semi-open range [0.0, 1.0)

Routers

- Routers are considered to be very simple devices who sole purpose is to route data traffic. - The end to end principle in the internet. - Routers only implement IP routing packets. It is up to the end units to run the more involved TCP to check for transmission errors, omissions and duplications.

Bitmap Images

- Screen consists of individual pixels: pixel = picture elements. - arranged into rows and columns: - projector 1024 X 768 - 720p = 1280 X 720 - 1080p = 1920 X 1080 Bitmap as 3-D Python Lists: bitmap = [[ [255, 0, 0], [0, 255, 0]], [[0, 0, 255], [255, 255, 255]], [[0, 0, 0], [0,0,0] ]] individual arrays within the 2-d array. Accessing them requires three calls. Ask about 3d lists. ask about this look at the pa.

TCP , IP, UDP

- TCP - Transmits the packets, but also verifies that they were sent properly, slower than UDP, sends back a packet to verify that the correct packet was sent. TCP values Accuracy. - IP - main protocol used by all protocols. IP tags packets with the correct destination IP address they need to go to. It routes the packets to the correct destination Ip Address. - UDP - simply transmits the packets, doesn't check for accuracy, super fast, less accurate than TCP.

Transfer Control Protocol

- TCP is the main protocol used on the Internet to transmit messages using packets. - used for the web, email and file transfer. - TCP can detect if a packet is lost, delivered out of order or duplicated. - TCP is optimized for accurate delivery rather than timely delivery. - for streaming data, other protocols are used(e.g. UDP) where packet loss is not as critical.

Uses of Simulation:

- Testing - safety engineering usability testing. - Predicting - understanding how natural nahum systems work to predict future behavior. - Training - providing lifelike but controlled experiences for learners in education, occupational and military situations.

What is the Internet?

- The Internet is a system to deliver data (bits) from one computational device to another. - No one entity controls/ owns the internet - The Internet is governed by protocols and standards that are commonly agreed to by developers of network software and applications. - Started at ARPANET in 1969 for DARPA: UCLA, Stanford Research Institue, UCSB, U of Utah.

Is randint truly random?

- The function randint uses some algorithm to determine the next integer to return. - If we knew what the algorithm was, then the numbers generated would not be truly random. - We call randint a : pseudo-random number-generator. or (PRNG) since it generates numbers that appear random but are not truly random.

Simulation:

- The imitative representation of the function of one system or process by means of the functioning of another for example a computer program. - Simulation involves developing a model of a system and experimental manipulation of the model to observe the results. - accelerated results, easy to control via parameters, usually cheaper. vs. Real experiment.s - very time consuming, difficult to control, potentially dangerous, potentially unethical, expensive.

TCP and "Handshaking"

- The process of two parties determine that each has received the other's transmission correctly iso called handshaking. - Alice sends several packets to Bob using TCP - Each packet includes parity information so Bob can check its accuracy. - When Bob receives a packet, it it is ok, Bob sends an acknowledgement packet back to Alice. - If Bob is missing a packet, he cans end a request for a retransmission of the packet. - If Alice doesn't get an acknowledgement within a set period of time, she can retransmit the packet.

Network Address Translation (NAT)

- To accommodate more users on the Internet, NAT is used. - The gateway assigns an additional code called a port for each user, Packets are tagged with the port. - The gateway knows where to route the message on the private network, but all messages from that private network share the same single IP address.

Why do Simulations?

- To predict the behavior of a system. : : will this building survive an earthquake? - To test a theory against data. : Do the predictions generated by these equations match what we observe in the real world? - To explore consequences of assumptions : How quickly does the flu virus spread?

Packet Switching

- Two networks notes (eg. computers) send messages by breaking the message up into small packets and sending each packet on to the network with a serial number and destination address. Packets must have "Serial Number" and "Destination Address". - Routers in the network use a buffer(queue to hold packets until they can be routed toward their destination. - Packets may be received at the destination in any order and may get lost and retransmitted. Serial numbers are used to put packets back into order at the destination.

Coordinate System

- When drawing on a canvas, the location of the origin is at the Top Left, not bottom left. - x increases left to right - y increases top to bottom. - Coordinates are based on PIXELS, not on other units like inches or millimeters.

LCMs in the Real World

- glib (used by the c compile in gcc): a = 1103515245, m = 2 ^32 c = 12345. - Numerical Recipes(popular book on numerical methods and analysis): a = 1664525, m = 2^32 c = 1013904223 -Random class in Java: a = 25214903917, c = 11, m = 2 ^48

Linear Congruential Generator (LCG)

- more general version of the PRNG used in these examples is called a linear congruential generator. - given the current value Xi of PRNG using the linear congruential generator method, we can compute the next value in the sequence Xi+1, using the formula Xi+1 = (a*Xi + c) modulo m

Distributed Computing - Examples of Failures:

- permanent netowrk failures. - dropped messages between sender and receiver - an individual computer breaks. - a process crashes or goes onto an infinite loop.

Creating a PRNG

- prng(15): [0,7,2,9,4,11,6,1,8,3,10,5,0,7,2] - Now does this sequence look random to you ? - what do you think the 16th number in the sequence is? 9

Random numbers in Python

- to generate random numbers in python, we can use the randint function from the random module. - the randint(a,b) returns an integer n such a<= n <= b

Randomness in Computing

-Determinism in all algorithms and programs we have seen so far, given an input and a sequence of steps, we get a unique answer. The result is predictable. -However, some computations need steps that have unpredictable outcomes :games cryptography, modeling and large data sets -We use the word "randomness" for unpredictability, having no pattern.

Health States

0 white healthy 1 pink infected 2 red contagious (day 1) 3 red contagious(day 2) 4 red contagious(day 3) 5 red contagious(day 4 6 purple immune(non contagious) Healthy = 0 Infected = 1 Day1 = 2 Day2 = 3 Day3 = 4 Day 4 = 5 Immune = 6

Critical Section

A critical Section is a section of computer code that bus only be executed by one process or thread at a time. Examples: - A printer queue receiving file to be printed. - Code to set a seat as reserved. - Web server that generates and returns a web page showing current registration in course.

Models

A model is an abstraction of the real system. It represents the system and rules that govern the behavior of the system. - The model represents the system itself, whereas the simulation represents the operation of the system over time. Concerns: - Achieve a certain level of accuracy while keeping the complexity manageable. - Parts of the system may be stochastic ( may exhibit random behavior).

PRNG Period

Lets define the pong period as the number of values in a pseudo-random number generator sequence before the sequence repeats. next number = (last number + 7)mod 12

Concurrency

Matrix Multiplication with pipelining, ask him about it.

Shared Computing Resource

Memory Tape drives disk drives printers communication ports input devices keyboard mouse

Transistor Counts

Moors Law, Transistor count has been steadily increasing. Transistors have been doubling every two years, as well as processor speed.

Multitasking & Operating Systems:

Multitasking - The coordination of several computational processes on one processor or several cores. - your processor or processes are doing more than one process. An Operating system(OS) - is the system software responsible for the direct control and management of hardware and basic system operations. An Os provides a foundation upon which to run application software such as word processing programs, web browser, ect.

Multi Tasking Vs Concurrency

Multitasking - switching tasks really fast so it looks like you are doing two things at the same time when in reality you are not. - done by switching allocation of resources really fast. Concurrency - doing multiple tasks at the same time. For instance, with sorting networks you can have the sources execute at the same time.. pipelining - once the task is finished the previous task can come.

Defining Randomness

Philosophical question: are there any events that are really random?

Physical Models

Physical Models: small replicas. - may not exist, maybe unsafe to work with, expensive to build and modify. - Some change too slowly over time. - Mississippi River Basin Model. -Scale model for eh solar system in the desert.

Pipelining

Pipelining is similar to an assembly line - instead of completing one computation before starting another, each computation is split into a simpler sub-steps, and computations are started as others are in progress. Matrix multiplication - what is that ? How does one do that?

Render Farms

Rendering - Flatten a 3d space to a 2d - lighting (raytracing) - Potential concurrency - frames - pixels within a frame Toy Story (1995) - about 4 hrs for each frame - 80 SPARCstation 20 systems. - 1 SPARCserver 1000 systems.

Fault Tolerance

The Internet is subject to fault at individual nodes. The protocols are designed to allow data traffic to be rerouted if nodes go down or become too overloaded. - World Trade Center Attack (9/11/2001). - New Orleans and Hurricane Katrina (2005). - Hunching earthquake (2006) - Qatar Internet blackout (2008)

IPv4 Address Assignment

The original IPv4 had several classes of addresses: - Class A 0 + 7-bit network + 240bit address Accommodates up to 2^24 unique IP addresses in a company or location. - Class B 10 + 14 bit network + 16-bit address Accommodates up to 2^8 unique IP addresses in company or location. - Class C 110 + 21-bit networks + 8-bit addr. Accommodates up to 2^8 unique IP addresses in a company or location.

Circuit Switching

Two networks notes e.g. phones establish a dedicated connection via one or more switching stations.

Operating System "Flavors"

Unix - System V, BSD, Linux - Proprietary: Solaris, Mac OS Windows: - Windows 7 - Windows 8 - Windows 10

Problems with Pipelining.

What if the result of the current instruction is needed as data for the next instruction? - reorder instruction so the next instruction comes later, when the current instructions results are ready if possible. - what if the next instruction depends on the results, of a comparison? - set up two pipelines one with each of the possible next instructions until we know which one to use.

Image Processing:

What order are the pixels processed? - row by row, one pixel at a time. Does this matter? - not really: all pixel computations are independent of one another. - if we have multiple processors (cores), we should have each work on part of the image independently --> faster results. - Graphical Processing Units (GPU).

Rolling a Die

from random import randint def roll( ): return randint(0,15110)% 6 + 1 or def roll( ): return randint(1,6)

Some Python functions from the random module

import random from import random* random.random( ) #random float [0.0,1.0) random.uniform(1,10) #random float [1,10)

Creating a window for Drawing:

import tkinter window = tinter.Tk() c = tkinger.Canvas(window, width = 1000, height = 1000) c.pack() - The window is what pops upon on your computer - The canvas is what we create graphics on within the window. - packing the canvas tells it to occupy the entire window.

Example

look at more programming examples.

NetLogo

netlogoweb.org - Modeling environment run int eh browser that lets you create simulations, varying numerous parameters. - Art - biology - Chemistry and physics - computer science - Earth Science. - Math - Social Science.

Clock Speed

Clock Speed is No Longer Increasing.

Computational Sciences

Computational sciences use computational model as the basis of obtaining scientific knowledge: - computational Biology - computational physics. - computational Chemistry - Computational Neuroscience.

IP Addresses (IPv4)

Computers on the internet are assigned an IP Address ________._____.____.____ Four numbers between 0 and 255 exclusive, examples. 128.2.13.163 This means that each part of the address is an 8 bit value and an IP address is 32 bits. supports upto 2^32 computers on the network at the same tiem. ISPs can reassign IP addresses dynamically.

Concurrency Real Stuff

Concurrency is the process of performing more than one process at a time. computing has many ways to implement concurrency: - pipelining - parallel processing - multitasking - distributed computing.

Simulation Tradeoffs

Agent-based vs. Equation-based: - how different individuals/ units interact with each other or how a system's global behavior is derived from mathematical models. Abstract vs. Accurate: - minimal relevant factors or complex components? Static vs. Dynamic: - Snapshots of single point of time or changes over time? Deterministic vs. Stochastic: - no randomness or random elements? Continous vs. Discrete. - does time advance smoothly or in steps?

ISPs

An Internet Service Provider (ISP) is a company that provides access for users to the Internet. - At&T, Comcast, EarthLink, Verizon, ect. - access can be provided via copper cable, wireless transmission, fiber optic cable, ect. - In rural areas, an ISP may be a company providing Internet services by satellite. - Universities like CMU and big companies like Googles and Microsoft are their own ISPs.

Examples of Protocols:

Application: - Hypertext Transfer Protocol (HTTP) - Simple Mail Transfer Protocol (SMTP) - Domain Name System (DNS) XYZ.com ---> w.x.y.z. - Secure Shell (SSH) Protocol ssh unix.andrew.cmu.edu - Voice Over IP (Phone calls) Session Initiation Protocol (SIP) Real-time Transport Protocol (RTP) Transport: - Transmission Control Protocol (TCP) - User Datagram Protocol (UDP) Internet : - IPv4 - IPv6 Link 1000BaseT - Gigabit Ethernet Data over Cable Service Interface Specification - Cable Modems Long Term Evolution (LTE) - 4g cell phone 802.11N(Wi-Fi) - Wireless Ethernet.

Critical Section

Cars may not make turns through this intersection. They may only proceed straight ahead, if there is no car to its left and no car to its right. Otherwise it must wait some random amount of seconds and then check again to see if its safe to proceed. If not it waits again and so on. (Ask About This) (Ask about Deadlock)

Deadlock

Deadlock is the condition when two or more processes are all waiting for some share resources that other processes of the group hold causing all processes to wait forever without proceeding. Deadlock can occur at 4 way stop, and the Dining philosopher's problem. - Each philosopher thinks for a while, then picks up his left fork , then picks up his right fork, then eats, then puts down his left fork, then puts down his right fork, - we assume here that each philosopher thinks and eats for random times, and a philosopher cannot be interrupted while he picks up or puts down a single fork. Each fork models a "resource" on a computer controlled by an OS. none of the philosophers can ever eat they all die, because when each of them pick up the left fork no more forks are left and when they try to pick up the right fork, the other fork they need for eating, they can't cuz there are no forks left, so they stand still, they never ever overcome the, because there are not enough forks to go around and only if one of the philosophers give up the fork would they ever fix it. Ask about critical sections.

Challenge of Distributed Computing: Reliability in Context of Failure

Design distributed systems with the expectation of failure. you have to say failure happens all the time. you design for failure. It is your number one concern ken arnold.

Single Core Multitasking

Each unblocked application runs for a very short time on the computer's processor and then another process runs, then another. This is done at such a fast rate that it appears to the computer user that all applications are running at the same time. - How do actors appear to move in a motion picture?

Layers of the TCP/IP Reference Model

Host A -->Router-->Router-->Host B Appli - Process 2 Process - Appli Transport - Host 2 Host -Transport Internet Internet Internet Internet Link Link Link Link Ethernet Fiber/Satellite, Ethernet ------------------------------------- Application Layer - handles requests form the user for data on the Internet. Transport Layer - Handles splitting messages into packets for delivery. Internet Layer - Handles the task of sending packets across one or more networks. Links Layer - Handles the physical transfer and reception bits.

New IP (IPv6)

IPv6 uses 128-bit addresses. - supports 2^128 unique computer addresses - = 3.4 * 10 ^38 - Allows for many more devices (cell phones, video game machines, appliances, automobiles, etc.) - Designed to deal with the use of all available addresses in IPv4.

TCP vs. UDP vs. IP

Internet Protocol (IP): - Delivers packets ot IP address - best effort delivery User Datagram Protocol (UDP): - delivers packets to port at IP Address - port identifies user - still best effort delivery. Transmission Control Protocol (TCP) - Creates a reliable bi-directional stream (source address/ and destination address/port). - acknowledgement, resend, reassembly in correct order. - error detection. - connection must be opened and close (established with three way handshake. - flow / congestion control

Packets

Serial number to organize all of them. Destination Address - the ip address it should go to.

Net Neutrality

Should different kinds of packets be treated differently? The principles of Net Neutrality advocates no restrictions by ISPs or governments on consumer's access to networks that participate in the Internet. All like internet content must be treated alike and move at the same speed over the network. The owners of the Internet's wires cannot discriminate. This is the simple but brilliant "end to end" design of the Internet that has made it such power force for economic and social good. - Lawrence Lessig and Robert W. McChesney.

3d Array

array name[ ] [ ] [ ] you have a 2darray with depth now. imagine pushing an array inward, its now a 3d object.

Drawing Rectangle

c.create_rectangle(20,190, 190, 230)

Circles

canvas_name.create_oval(x0, y0, x1, y1, optional params). - Draw an oval inscribed in a bounding box from top left (x0, y0 to bottom right (x1, y1). to units in pixels.

Polygons

canvas_name.create_polygon(x0, y0, x1, y1, xn, yn, optional_params). fill = "color".

Drawing Rectangles:

canvas_name.create_rectangel(x0, y0, x1, y1, optional_params) - Draw a rectangle from top left(x0, y0) to bottom right(x1, y1) in units of pixels. - optional parameters: fill = "color", default: none, outline = "color", default: black. width = numpixesl (default 1)

Text on the canvas

canvas_name.create_text(,,xn, yn, optinal params). - Draw a text object centers on the given x and y coordinates. - example code. c.create_text(20, 100, text = "CMU").

Creating a PRNG

consider a pseudo-random number generator prong that takes an argument specifying the length of a random number sequence and returns list with the many random numbers.

Moores law

cpu speed grows exponentially. number of transistors doubles approximately every two years.

Rank

def get_rank(card): ranklist = ["2", ... , "A"] return ranklist.index(card[0])

Looking at prng1

def prng1(n):

Another PRNG

def prng2(n): seq = [0] for i in range(1, n): seq.append((seq[-1] + 8 ) % 12) return seq prong(15): [0, 8, 4, 0, 8]

Another Die

def roll( ): #wrong return randint(0, 90) def roll( ): #right return randint(0, 9) * 10

Abstraction

you are trying to create a simplified object. When you are doing abstraction you are trying to create a smaller snapshot of the internal. The two 8 input sorting network is two 4 unit networks that happen to each contain 2 2 unit sorting networks. dont circle outputs. abstraction we look at things on the whole we don't look at the internals we look at each thing as separated systems. and as we go more internally we are fine.


संबंधित स्टडी सेट्स

Chapter 25: Metabolism and Nutrition

View Set

Diabetes Mellitus NCLEX Style Questions

View Set

Social Psychology Key Question: HOW CAN KNOWLEDGE OF SOCIAL PSYCHOLOGY BE USED TO REDUCE PREJUDICE IN SITUATIONS SUCH AS CROWD BEHAVIOUR OR RIOTING?

View Set

SOC 100 Exam 2 Practice Questions

View Set

Chapter 9 - Prioritization, Delegation, and Assignment

View Set

Phase 1 Class one from Air Assault Course

View Set