<jupyter_start><jupyter_text>Modeling Steps 7 - 9**By Neuromatch Academy**__Content creators:__ <NAME>, <NAME>, <NAME>,  <NAME>, <NAME>__Production editors:__ <NAME> **Our 2021 Sponsors, including Presenting Sponsor Facebook Reality Labs** --- Step 7: Implementing the model<jupyter_code># @title Video 8: Implementing the modeling

from ipywidgets import widgets

out2 = widgets.Output()
with out2:
  from IPython.display import IFrame
  class BiliVideo(IFrame):
    def __init__(self, id, page=1, width=400, height=300, **kwargs):
      self.id=id
      src = 'https://player.bilibili.com/player.html?bvid={0}&page={1}'.format(id, page)
      super(BiliVideo, self).__init__(src, width, height, **kwargs)

  video = BiliVideo(id="BV1nX4y1w7uu", width=854, height=480, fs=1)
  print('Video available at https://www.bilibili.com/video/{0}'.format(video.id))
  display(video)

out1 = widgets.Output()
with out1:
  from IPython.display import YouTubeVideo
  video = YouTubeVideo(id="qxU5dJz5hG0", width=854, height=480, fs=1, rel=0)
  print('Video available at https://youtube.com/watch?v=' + video.id)
  display(video)

out = widgets.Tab([out1, out2])
out.set_title(0, 'Youtube')
out.set_title(1, 'Bilibili')

display(out)<jupyter_output><empty_output><jupyter_text>This is the step where you finally start writing code! Separately implement each box, icon, or flow relationship identified in Step 6. **Test** each of those model components separately! (This is called a *unit test*). Unit testing ensures that each model components works are expected/planned. **Guiding principles**:* Start with the easiest possible implementation  * Test functionality of model after each step before adding new model components (unit tests)  * Simple models can sometimes accomplish surprisingly much…* Add / remove different model elements  * Gain insight into working principles  * What’s crucial, what isn’t?  * Every component of the model must be crucial!* Make use of tools to evaluate model behavior  * E.g., graphical analysis, changing parameter sets, stability / equilibrium analyses, derive general solutions, asymptotes, periodic behaviour, etc.**Goal**: Understand how each model component works in isolation and what the resulting overall model behavior is.**Note**: if you're working with data, this step might also involve significant data wrangling to your dataset into a format usable by your model... **Make sure to avoid the pitfalls!**Click here for a recap on pitfallsBuilding the whole model at once without testing components  you will make mistakes. Debug model components as you go!  debugging a complex model is close to impossible. Is it not woring because individual components are not working? Or do components not "play nice" together?  Not testing if individual components are important  It's easy to add *useless* components to a model. They will be distracting for you and for readers  Not testing model functionality step by step as you  build up the model  You'd be surprised by what basic components often can alrealy achieve... E.g. our intuition is really bad when it comes to dynamical systems  Not using standard model testing tools  each field has developped specific mathematical tools to test model behaviors. You'll be expected to show such evaluations. Make use of them early on!   --- Step 8: Completing the model<jupyter_code># @title Video 9: Completing the modeling

from ipywidgets import widgets

out2 = widgets.Output()
with out2:
  from IPython.display import IFrame
  class BiliVideo(IFrame):
    def __init__(self, id, page=1, width=400, height=300, **kwargs):
      self.id=id
      src = 'https://player.bilibili.com/player.html?bvid={0}&page={1}'.format(id, page)
      super(BiliVideo, self).__init__(src, width, height, **kwargs)

  video = BiliVideo(id="BV1f44y1q7wm", width=854, height=480, fs=1)
  print('Video available at https://www.bilibili.com/video/{0}'.format(video.id))
  display(video)

out1 = widgets.Output()
with out1:
  from IPython.display import YouTubeVideo
  video = YouTubeVideo(id="ul4loI_JUW0", width=854, height=480, fs=1, rel=0)
  print('Video available at https://youtube.com/watch?v=' + video.id)
  display(video)

out = widgets.Tab([out1, out2])
out.set_title(0, 'Youtube')
out.set_title(1, 'Bilibili')

display(out)<jupyter_output><empty_output><jupyter_text>Determing what you're done modeling is a hard question. Referring back to your original goals will be crucial. This is also where a precise question and specific hypotheses expressed in mathematical relationships come in handy. **Note**: you can always keep improving our model, but at some point you need to decide that it is finished. Once you have a model that displays the properties of a system you are interested in, it should be possible to say something about your hypothesis and question. Keeping the model simple makes it easier to understand the phenomenon and answer the research question. **Guiding principles**:* Determine a criterion* Refer to steps 1 (goals) and 4 (hypotheses)  * Does the model answer the original question sufficiently?  * Does the model satisfy your own evaluation criteria?  * Does it speak to the hypotheses?* Can the model produce the parametric relationships hypothesized in step 4?Make sure the model can speak to the hypothesis. Eliminate all the parameters that do not speak to the hypothesis.**Goal**: Determine if you can answer your original research question and related hypotheses to your satisfaction. If the original goal has not been met you need to go back to the drawing board! **Make sure to avoid the pitfalls!**Click here for a recap on pitfallsForgetting to specify or use a criterion for model completion (in Step 1!)  This is crucial for you not to get lost in an endless loop of model improvements  Thinking the model can answer your question / hypotheses without checking  always check if all questions and hypotheses can be answered / tested  you will fail on your own benchmarks if you neglect this  You think you should further improve the model  This is only warranted if your model cannot answer your hypotheses / questions and/or meet your goals  remember: you can always improve a model, but you want to focus on the question / hypotheses / goals at hand!   --- Step 9: testing and evaluating the model<jupyter_code># @title Video 10: Evaluating the modeling

from ipywidgets import widgets

out2 = widgets.Output()
with out2:
  from IPython.display import IFrame
  class BiliVideo(IFrame):
    def __init__(self, id, page=1, width=400, height=300, **kwargs):
      self.id=id
      src = 'https://player.bilibili.com/player.html?bvid={0}&page={1}'.format(id, page)
      super(BiliVideo, self).__init__(src, width, height, **kwargs)

  video = BiliVideo(id="BV1Xv411J7Ls", width=854, height=480, fs=1)
  print('Video available at https://www.bilibili.com/video/{0}'.format(video.id))
  display(video)

out1 = widgets.Output()
with out1:
  from IPython.display import YouTubeVideo
  video = YouTubeVideo(id="X-R0hjID93M", width=854, height=480, fs=1, rel=0)
  print('Video available at https://youtube.com/watch?v=' + video.id)
  display(video)

out = widgets.Tab([out1, out2])
out.set_title(0, 'Youtube')
out.set_title(1, 'Bilibili')

display(out)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09050954539211646, 'fraction_numerical': 0.019090784232935035, 'mean_word_length': 4.963963963963964, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 9, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '129999', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 2138, 'n_tokens_neox': 2021, 'n_words': 877, 'path': 'projects/modelingsteps/ModelingSteps_7through9_DL.ipynb', 'repo_name': 'raghudiddigi/course-content-dl', 'size': '7322'}