def testMethod2(): _fn = lib.getFunction("simulate_apple2", _fileName) try: _t = apply_function(_fn, (0.01, ), (float, )) except InvalidFunctionApplication as e: return False, e.message if assertlib.between(_t, 2.82, 2.86): return True, "" return False, f"Did not expect output {_t} (with input: 0.01)"
def testMethod(): try: _input = 1000.0, 200.0, 72.0, 0, 0.01 _fn = lib.getFunction("simulate_free_fall", _fileName) _xl, _tl = apply_function(_fn, _input, (list, list)) except InvalidFunctionApplication as e: return False, e.message except Exception as e: return False, f"An error occured while running the function: \n {type(e).__name__}: {str(e)}" if len(_xl) != len(_tl): return False, "Function is expected to return two lists of the same length." return validate_sim(_input, 12.77, _xl, _tl)
def testMethod(): try: _input = 3474, 0.01 _fn = lib.getFunction("simulate_ultimate_free_fall", _fileName) _rl, _vl, _tl = apply_function(_fn, _input, (list, list, list)) except InvalidFunctionApplication as e: return False, e.message except Exception as e: return False, f"An error occured while running the function: \n {type(e).__name__}: {str(e)}" if len(_rl) != len(_tl) or len(_vl) != len(_tl): return False, "Function is expected to return three lists of the same length." return validate_sim1(_input, (-3474, 3474, -4.315, 4.315), _rl, _vl)
def testMethod(): try: _input = 6.38e6, 0.01 _fn = lib.getFunction("simulate_ultimate_free_fall", _fileName) _rl, _vl, _tl = apply_function(_fn, _input, (list, list, list)) except InvalidFunctionApplication as e: return False, e.message except Exception as e: return False, f"An error occured while running the function: \n {type(e).__name__}: {str(e)}" if len(_rl) != len(_tl) or len(_vl) != len(_tl): return False, "Function is expected to return three lists of the same length." if not similar(_tl[-1], 5058.3, 4): return False, f"Did not expected the time of the simulated free fall to be {_tl[-1]} seconds." return True, ""
def testMethod(): try: _input = 100, 0.01 _fn = lib.getFunction("simulate_apple1", _fileName) _t, _v = apply_function(_fn, _input, (float, float)) except InvalidFunctionApplication as e: return False, e.message except Exception as e: return False, f"An error occured while running the function: \n {type(e).__name__}: {str(e)}" if similar(_v, 4.52, atol=0.1) or similar(_t, 159.47, atol=1): return False, "Did you mix up the order of the return values?" if similar(_v, 44.3, atol=0.3): return False, "Did you forget to convert to km/h?" if similar(_t, 4.52, atol=0.1) and similar(_v, 159.47, atol=1): return True, "" return False, f"Did not expect output {_t, _v} (with input {_input})"
def show_welcome_page(): st.title("Welcome.") st.markdown("You will find the following in this section:") st.markdown("1. The History of Monte Carlo Method \n " "2. A High Level Montel Carlo Process \n" "3. An Interactive Example") st.markdown( "If you are familiar with the basics, use the panel on the left to see some real-life examples." ) # HISTORY st.markdown("***") st.markdown("** The Short History **") st.video("https://youtu.be/ioVccVC_Smg") # SIMULATION ARCHITECTURE st.markdown("***") st.markdown("** The Monte Carlo Process**") st.markdown( "The goal of Monte Carlo Method is to **approximate an expected outcome** that is difficult to " "calculate precisely. In real life, it's often impossible to come up with a single equation to " "describe a system from inputs to outputs; even we can, it will be time consuming to " "calculate and analyze all possible outcome scenarios. " "As a practical alternative, Monte Carlo method allows us to take a **probability approach**." ) image = Image.open('./asset/monte-carlo-process.png') st.image(image, format='PNG', use_column_width=True) st.markdown("A more technical explanation ...") st.video("https://youtu.be/7TybpwBlcMk") # ILLUSTRATION OF PROBABILITY DISTRIBUTION st.markdown("***") st.markdown("**Step 1: Define input(s) with uncertainty ... **") value_range = st.slider("Pick the range of value that represent the input", min_value=20, max_value=100, value=(45, 60), step=1) shape = st.selectbox("Pick a distribution that represent the uncertainty", ("Normal", "Triangle", "Uniform")) N = st.slider("Choose how many samples (N): ", min_value=100, max_value=10000, value=500, step=100) st.markdown( f"We drew {N} samples " f"with an **uncertainty** represented by a **{shape}** distribution.") input_items = helpers.get_items(value_range, N, shape) hist_data = [input_items] group_label = ['Input'] fig = ff.create_distplot(hist_data, group_label, bin_size=[0.5]) st.plotly_chart(fig, use_container_width=True) st.markdown("**Step 2: Apply Some Transformation ...**") distribution = st.selectbox( "Pick a transformation", ("Secret Formula 1", "Secret Formula 2", "Secret Formula 3")) st.markdown( f"We apply **{distribution}** (some non-linear functions and randomness) to each of the input samples ..." ) output_items = helpers.apply_function(input_items, distribution) hist_data = [output_items] group_label = ['Output'] fig = ff.create_distplot(hist_data, group_label, bin_size=[0.1]) st.plotly_chart(fig, use_container_width=True) # ANALYZE RESULTS st.markdown("**Step 3: Analyze the Outcome ...**") st.markdown( "In this case, the results are not very sensible since it's a dummy example. " "Typically, we should ask the following quesitons: ") st.markdown( "1. what is the probability of achieving the acceptable outcomes? Is it good enough to proceed? \n" "2. what is the probability of achieving sub-optimal outcomes? And how do we hedge against that? \n" "3. what factor has the largest impact on the outcome? How can we influence it? \n" ) st.markdown("***") st.markdown( "**Next Step:** Use the panel on the left to learn key techniques of designing and analyzing simulations " "with three real-world business problems.") st.markdown("Each example focuses on a technique: ") st.markdown("1. CMO Lab: Influence Diagram \n" "2. COO Lab: Sensitivity Analysis \n" "3. CFO Lab: Optimization in Simulation \n" "4. CPO Lab: Machine Learning in Simulation") show_footer()