Hack #1 - Class Notes

Write any extra notes you have here

Simulations Notes


  • title: Simulations Notes
  • toc: true
  • comments: true
  • categories: [Blog]

Notes

  • The main difference between simulations and experiments is that simulations replicate real world scenarios digitally while experiments are held in the real world
  • Simulations usually are less expensive than running an experiment because the expenses needed for acquiring equipment are not present when running a simulation
  • Since experiments and done in the real world, they provide actual results while simulations use models based on collected data to provide estimations of what is expected to happen
  • Simulations can provide estimations for events that can't be recreated in the real world because simulations don't run the risk of safety issues and they can be done without equipment that would be needed for experimentation
  • Once created, simulations are easier to repeat to obtain more estimations when compared to experiments because experiments often take a long time to set up and execute
  • Simulation are a way to simulate real-world environments to test safety or logistics. It's important to use random numbers, consider biases, and consider if a simulation is the best solution.
  • When making a simulation you should consider removing details, which could be done using pseudo-random number generators, and using other ideas from previous college board lessons; like procedure, flowcharts and conditionals

Hack #2 - Functions Classwork

import random
otherclothes = ["white hat", "blue shirt", "purple socks"]
myclothes = ["red shoes", "green pants", "tie", "belt"]

def mycloset():
    my = myclothes[(random.randint(0,(len(myclothes) - 1)))]
    other = otherclothes[random.randint(0,(len(otherclothes) - 1))]
    i = input("do you want to trash or add clothes")
    print("closet before trashing/adding: " + str(myclothes))
    if i == "trash":
        myclothes.remove(my)
        print("closet after removing an item: " + str(myclothes))
    elif i == "add":
        myclothes.append(other)
        print("closet after adding an item: " + str(myclothes))
    else:
        print("not a valid input")

mycloset()
closet before trashing/adding: ['red shoes', 'green pants', 'tie', 'belt']
closet after removing an item: ['red shoes', 'green pants', 'tie']
import random

def coinflip():         #def function 
    randomflip = random.randint(0,3) #picks either 0 or 1 randomly (50/50 chance of either) 
    if randomflip == 0 or 1: #assigning 0 to be heads--> if 0 is chosen then it will print, "Heads"
        print("Heads")
    else:
        if randomflip == 2: #assigning 1 to be tails--> if 1 is chosen then it will print, "Tails"
            print("Tails")

#Tossing the coin 5 times:
t1 = coinflip()
t2 = coinflip()
t3 = coinflip()
t4 = coinflip()
t5 = coinflip()
Heads
Heads
Heads
Heads
Heads

Hack #3 - Binary Simulation Problem

import random

dec = 0

def randomnum(): # function for generating random int
    ran = random.randint(1,255)
    return(ran)

def converttobin(n): # function for converting decimal to binary
    bin = ""
    i = 7

    while i >= 0:
        if n % (2**i) == n:
            bin = bin + "0"
            i -= 1
        else:
            bin = bin + "1"
            n -= 2**i
            i -= 1

    return(bin)


survivorstatus = ["hykeem", "kendrick", "don", "travis" , "ye", "jeffrey", "quavo", "offset"]

def survivors(binary): # function to assign position
    i = 0
    print("inital survivors: " + str(survivorstatus))
    while i < len(survivorstatus):
        if binary[i] == "0":
            rem = survivorstatus[i]
            survivorstatus.remove(rem)
            i += 1
        else:
            i += 1
    print("final survivors: " + str(survivorstatus))

ran1 = randomnum()
bin1 = converttobin(ran1)
survivors(bin1)
inital survivors: ['hykeem', 'kendrick', 'don', 'travis', 'ye', 'jeffrey', 'quavo', 'offset']
final survivors: ['kendrick', 'travis', 'jeffrey', 'offset']

Hack #4 - Thinking through a problem

  • create your own simulation involving a dice roll
  • should include randomization and a function for rolling + multiple trials
import random 

def roll():
    x = random.randint(1,6)
    return(str(x))

a = roll()
b = roll()
c = roll()
d = roll()

print(a)
print(b)
print(c)
print(d)
1
3
5
5

Hack 5 - Applying your knowledge to situation based problems

Using the questions bank below, create a quiz that presents the user a random question and calculates the user's score. You can use the template below or make your own. Making your own using a loop can give you extra points.

  1. A researcher gathers data about the effect of Advanced Placement®︎ classes on students' success in college and career, and develops a simulation to show how a sequence of AP classes affect a hypothetical student's pathway.Several school administrators are concerned that the simulation contains bias favoring high-income students, however.
    • answer options:
      1. The simulation is an abstraction and therefore cannot contain any bias
      2. The simulation may accidentally contain bias due to the exclusion of details.
      3. If the simulation is found to contain bias, then it is not possible to remove the bias from the simulation.
      4. The only way for the simulation to be biased is if the researcher intentionally used data that favored their desired output.
  2. Jack is trying to plan his financial future using an online tool. The tool starts off by asking him to input details about his current finances and career. It then lets him choose different future scenarios, such as having children. For each scenario chosen, the tool does some calculations and outputs his projected savings at the ages of 35, 45, and 55.Would that be considered a simulation and why?
    • answer options
      1. No, it's not a simulation because it does not include a visualization of the results.
      2. No, it's not a simulation because it does not include all the details of his life history and the future financial environment.
      3. Yes, it's a simulation because it runs on a computer and includes both user input and computed output.
      4. Yes, it's a simulation because it is an abstraction of a real world scenario that enables the drawing of inferences.
  3. Sylvia is an industrial engineer working for a sporting goods company. She is developing a baseball bat that can hit balls with higher accuracy and asks their software engineering team to develop a simulation to verify the design.Which of the following details is most important to include in this simulation?
    • answer options
      1. Realistic sound effects based on the material of the baseball bat and the velocity of the hit
      2. A depiction of an audience in the stands with lifelike behavior in response to hit accuracy
      3. Accurate accounting for the effects of wind conditions on the movement of the ball
      4. A baseball field that is textured to differentiate between the grass and the dirt
  4. Ashlynn is an industrial engineer who is trying to design a safer parachute. She creates a computer simulation of the parachute opening at different heights and in different environmental conditions.What are advantages of running the simulation versus an actual experiment?
    • answer options
      1. The simulation will not contain any bias that favors one body type over another, while an experiment will be biased.
      2. The simulation can be run more safely than an actual experiment
      3. The simulation will accurately predict the parachute's safety level, while an experiment may be inaccurate due to faulty experimental design.
      4. The simulation can test the parachute design in a wide range of environmental conditions that may be difficult to reliably reproduce in an experiment.
    • this question has 2 correct answers
  5. YOUR OWN QUESTION; can be situational, pseudo code based, or vocab/concept based
  6. YOUR OWN QUESTION; can be situational, pseudo code based, or vocab/concept based
questions = [
    
    ((3,0), "A researcher gathers data about the effect of Advanced Placement classes on students' success in college and career, and develops a simulation to show how a sequence of AP classes affect a hypothetical student's pathway.Several school administrators are concerned that the simulation contains bias favoring high-income students, however.", 
    "The simulation is an abstraction and therefore cannot contain any bias", 
    "The simulation may accidentally contain bias due to the exclusion of details.", 
    "If the simulation is found to contain bias, then it is not possible to remove the bias from the simulation.",
    "The only way for the simulation to be biased is if the researcher intentionally used data that favored their desired output."),
    
    ((4,0), "Jack is trying to plan his financial future using an online tool. The tool starts off by asking him to input details about his current finances and career. It then lets him choose different future scenarios, such as having children. For each scenario chosen, the tool does some calculations and outputs his projected savings at the ages of 35, 45, and 55.Would that be considered a simulation and why?",
    "No, it's not a simulation because it does not include a visualization of the results.", 
    "No, it's not a simulation because it does not include all the details of his life history and the future financial environment.", 
    "Yes, it's a simulation because it runs on a computer and includes both user input and computed output.",
    "Yes, it's a simulation because it is an abstraction of a real world scenario that enables the drawing of inferences."),

    ((1,0), "Sylvia is an industrial engineer working for a sporting goods company. She is developing a baseball bat that can hit balls with higher accuracy and asks their software engineering team to develop a simulation to verify the design.Which of the following details is most important to include in this simulation?", 
    "Realistic sound effects based on the material of the baseball bat and the velocity of the hit", 
    "A depiction of an audience in the stands with lifelike behavior in response to hit accuracy", 
    "Accurate accounting for the effects of wind conditions on the movement of the ball",
    "A baseball field that is textured to differentiate between the grass and the dirt"),

    ((2,4), "Ashlynn is an industrial engineer who is trying to design a safer parachute. She creates a computer simulation of the parachute opening at different heights and in different environmental conditions.What are advantages of running the simulation versus an actual experiment?", 
    "The simulation will not contain any bias that favors one body type over another, while an experiment will be biased.", 
    "The simulation can be run more safely than an actual experiment", 
    "The simulation will accurately predict the parachute's safety level, while an experiment may be inaccurate due to faulty experimental design.",
    "The simulation can test the parachute design in a wide range of environmental conditions that may be difficult to reliably reproduce in an experiment."),

    ((1,0), "what function is used to add?", 
    "+", 
    "-", 
    "*",
    "%"),

    ((1,0), "what function is used to subtract?", 
    "-", 
    "+", 
    "*",
    "/")
]

def questionloop(qlist):
    score = 0
    for sub in qlist:
        print("question: " + sub[1])
        print("answer 1: " + sub[2])
        print("answer 2: " + sub[3])
        print("answer 3: " + sub[4])
        print("answer 4: " + sub[5])
        res = input("Choose an answer number: ")
        if int(res) == sub[0][0]:
            score += 1
            continue
        elif int(res) == sub[0][1]:
            score += 1
        else:
            continue

    percent = score * 100 / 6
    passfail = ""

    if percent < 70:
        passfail = "failed"
    else:
        passfail = "passed"

    print("You " + str(passfail) + " the test with " + str(percent) + "%.")

questionloop(questions)
question: A researcher gathers data about the effect of Advanced Placement classes on students' success in college and career, and develops a simulation to show how a sequence of AP classes affect a hypothetical student's pathway.Several school administrators are concerned that the simulation contains bias favoring high-income students, however.
answer 1: The simulation is an abstraction and therefore cannot contain any bias
answer 2: The simulation may accidentally contain bias due to the exclusion of details.
answer 3: If the simulation is found to contain bias, then it is not possible to remove the bias from the simulation.
answer 4: The only way for the simulation to be biased is if the researcher intentionally used data that favored their desired output.
question: Jack is trying to plan his financial future using an online tool. The tool starts off by asking him to input details about his current finances and career. It then lets him choose different future scenarios, such as having children. For each scenario chosen, the tool does some calculations and outputs his projected savings at the ages of 35, 45, and 55.Would that be considered a simulation and why?
answer 1: No, it's not a simulation because it does not include a visualization of the results.
answer 2: No, it's not a simulation because it does not include all the details of his life history and the future financial environment.
answer 3: Yes, it's a simulation because it runs on a computer and includes both user input and computed output.
answer 4: Yes, it's a simulation because it is an abstraction of a real world scenario that enables the drawing of inferences.
question: Sylvia is an industrial engineer working for a sporting goods company. She is developing a baseball bat that can hit balls with higher accuracy and asks their software engineering team to develop a simulation to verify the design.Which of the following details is most important to include in this simulation?
answer 1: Realistic sound effects based on the material of the baseball bat and the velocity of the hit
answer 2: A depiction of an audience in the stands with lifelike behavior in response to hit accuracy
answer 3: Accurate accounting for the effects of wind conditions on the movement of the ball
answer 4: A baseball field that is textured to differentiate between the grass and the dirt
question: Ashlynn is an industrial engineer who is trying to design a safer parachute. She creates a computer simulation of the parachute opening at different heights and in different environmental conditions.What are advantages of running the simulation versus an actual experiment?
answer 1: The simulation will not contain any bias that favors one body type over another, while an experiment will be biased.
answer 2: The simulation can be run more safely than an actual experiment
answer 3: The simulation will accurately predict the parachute's safety level, while an experiment may be inaccurate due to faulty experimental design.
answer 4: The simulation can test the parachute design in a wide range of environmental conditions that may be difficult to reliably reproduce in an experiment.
question: what function is used to add?
answer 1: +
answer 2: -
answer 3: *
answer 4: %
question: what function is used to subtract?
answer 1: -
answer 2: +
answer 3: *
answer 4: /
You failed the test with 50.0%.

Hack #6 / Challenge - Taking real life problems and implementing them into code

Create your own simulation based on your experiences/knowledge! Be creative! Think about instances in your own life, science, puzzles that can be made into simulations

Some ideas to get your brain running: A simulation that breeds two plants and tells you phenotypes of offspring, an adventure simulation...

import random

genotypes = ["RR", "Rr", "rr"]

def breed(parent1, parent2):
  genotype1 = random.choice(parent1)
  genotype2 = random.choice(parent2)
  
  offspring_genotype = genotype1 + genotype2

  return offspring_genotype

def determine_phenotype(genotype):
  if genotype == "RR" or genotype == "Rr":
    return "red"
  elif genotype == "rr":
    return "white"

parent1 = ["RR", "Rr"]
parent2 = ["RR", "rr"]

offspring_genotype = breed(parent1, parent2)

offspring_phenotype = determine_phenotype(offspring_genotype)

print(f"The offspring has a {offspring_phenotype} phenotype.")
The offspring has a None phenotype.