Decision making.

Slides:



Advertisements
Similar presentations
Throwing and catching exceptions
Advertisements

Main memory.
For loops.
Templates.
Static variables.
Default values of parameters
The structured programming theorem
Pointers.
Dynamically allocating arrays
Anatomy of a program.
Switch statement.
Binary search.
Do-while loops.
Command-line arguments
Console input.
Dangling pointers.
Arithmetic operators.
Sorted arrays.
Floating-point primitive data types
Break statements.
Wild pointers.
Logical operators.
The comma as a separator and as an operator
Selection sort.
Bucket sort.
The call stack and recursion and parameters revisited
The ternary conditional operator
Dynamically allocating structures
Conditional statements
Memory leaks.
Bit-wise and bit-shift operators
Sorting algorithms.
Command-line arguments
Repetitious operations
Dynamically allocating arrays
Insertion sort.
Problems with pointers
A list-size member variable
Protecting pointers.
Dynamically allocating arrays
Code-development strategies
Anatomy of a program.
Selection sort.
Insertion sort.
Pointers as arguments and return values
Reference variables, pass-by-reference and return-by-reference
Addresses and pointers
Default values of parameters
Conditional statements
Recursive functions.
Class variables and class functions
Operator overloading.
Dynamic allocation of arrays
Insertion sort.
Sorted arrays.
Sorting algorithms.
Issues with classes.
Dangling pointers.
Counting sort.
Selection sort.
Searching and sorting arrays
Protecting pointers.
Arithmetic operators.
Data structures: class
An array class: constructor and destructor
Recursive binary search
The structured programming theorem
Recursive functions.
Algorithms and templates
Presentation transcript:

Decision making

Outline In this lesson, we will: Describe how human make decisions Contrast this with how computers make decisions

Decision making When humans make decisions, there are almost always many possible outcomes, and many possible factors Sometimes it is limited to a yes-no question: Should we go to Al Madina’s restaurant or not? Usually, however, there are multiple possibilities: Where do we want to go to dinner tonight, if anywhere? Even while driving there, you may change your mind There are numerous criteria which will determine your decisions How much do you anticipate savouring the meal? How much is in our bank account? What means of transportation are there, and how much will it cost? How much time will it take, and how much time will that take from other commitments (e.g., your ece 150 assignments)? Is it “worth” the time and money and lost opportunities?

Decision making When not constrained by mathematical algorithms, human decision making is often very vaguely defined and subject to numerous subconscious biases and whims This is normal—this makes you human Decisions are made on many factors or variables, each with slight different weights In many cases, it may be difficult, if not impossible, to make a best decision or correct decision Did we choose the “best” means of having dinner tonight?

Decision making There were arguments made by the ancient Greeks that statements may be either entirely true or false and not both Is the Earth orbiting the Sun? The correct answer is “no”, for an orbit suggests a perpetual trajectory around our Sun The Earth follows a trajectory that for some time will appear to orbit the Sun, but this must at some point end Are you tall? If you’re 5 ft, no; if you’re 6 ft, well, maybe; and if you’re 7 ft, yes Additionally, there are ambiguities when dealing with the real world Language is imprecise

Decision making In taking actions, however, it is sometimes necessary to reduce our decision to yes or no: Do I replace the brakes on my car or not? If yes, what quality of brakes should I purchase to replace the existing ones Do I replace the rotors and the pads, or just the pads True-or-false (Boolean-valued) decisions are core to engineering: You make a decision to act or not Your pay and licence is based on your decision

Decision making Some may have already seen the following flow chart:

Driving More realistically: when you are driving, you adjust your speed by Applying force to the gas pedal, Applying force to the brake pedal, Sometimes neither, and Usually not both. As you drive, you continually adjust the force taking into account The road conditions The density of traffic The actions of cars in your immediate vicinity Specifically the behavior of the cars in front of you

Driving Given n different drivers, put into the same situation, each will have wildly different driving habits Aggressive drivers Defensive drivers Other factors having nothing to do with the current road conditions may affect reactions What is your mood? Is there a medical emergency? Are you late?

Driving In C++, all decisions must be reduced to either Logical decisions Mathematical responses For example, you could define a mathematical function that takes three variables: double your_target_speed( double your_current_speed, double distance_to_next_car, double speed_of_next_car ); Distance is in meters (m) and speed is in meters per second (m/s) Always give units for all parameters

Aside: importance of units The Mars Climate Orbiter had two systems: The software provided by Lockheed Martin used U.S. customary units nasa software expected results in Metric When a thruster is fired, it produces a force The force varies as the thrust first fires up and then cuts off The integral of the force is the impulse The impulse is used to determine the trajectory The impulse was calculated in lbf·s The trajectory computation assumed the result was in N·s

Driving Returning the car: your target speed may be determined by: If the car ahead of you is more than 12 s ahead, just go 12 km/h faster than the speed limit For example, 12 s at 78 km/h is 260 m Usually enough distance to stop What if it is raining, there is ice on the road or the road is unplowed? If the car ahead of you is more than 20 s ahead, go the maximum speed depending on road conditions

Decision making In C++, the execution or non-execution of code is reduced to a test of Boolean-valued conditions that must be either true or false If you want something to depend on someone being “tall”, you must explicitly define what “tall” is Similarly, you must define what is “close” with respect to distance when driving a car Even when dealing with real numbers, it is necessary to reduce conditions to those that are either true or false: E.g., Fuzzy logic is a more complex means of a decision-making process, but even this model must be implemented in C++, which once again requires decisions to be based on logical decisions

Summary Following this lesson, you now: Understand that decision making must be reduced to statements that are either true or false The fuzzy thought processes of humans must be more clearly defined Think of autonomously driving vehicles… Know that you will have to restrict your design to that required by the language in question

References [1] Wikipedia https://en.wikipedia.org/wiki/Mars_Climate_Orbiter

Colophon These slides were prepared using the Georgia typeface. Mathematical equations use Times New Roman, and source code is presented using Consolas. The photographs of lilacs in bloom appearing on the title slide and accenting the top of each other slide were taken at the Royal Botanical Gardens on May 27, 2018 by Douglas Wilhelm Harder. Please see https://www.rbg.ca/ for more information.

Disclaimer These slides are provided for the ece 150 Fundamentals of Programming course taught at the University of Waterloo. The material in it reflects the authors’ best judgment in light of the information available to them at the time of preparation. Any reliance on these course slides by any party for any other purpose are the responsibility of such parties. The authors accept no responsibility for damages, if any, suffered by any party as a result of decisions made or actions based on these course slides for any other purpose than that for which it was intended.