User Tools

Site Tools


cs501r_f2017:lab04

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cs501r_f2017:lab04 [2017/09/16 20:25]
humphrey [Objective]
cs501r_f2017:lab04 [2021/06/30 23:42] (current)
Line 7: Line 7:
 ---- ----
 ====Deliverable==== ====Deliverable====
-Finish task 1 to 5, zip up all your code and ipython script together with the result of task 4, which is a tuple of 3 numbers (w1, w2, b), then submit that on learning suit. 😊+Finish task 1 to 5, zip up all your code and ipython script together with the result of task 4, which is a tuple of 3 numbers (w1, w2, b), then submit that on learning suit. Task 5(extra credit) worth 5% of the total grade of this lab.😊 
 + 
 +---- 
 + 
 +====Grading standards:​==== 
 + 
 +Your code will be graded on the following:​ 
 + 
 +  * 30% Correct implementation of data generator 
 +  * 30% Correct implementation of regression estimator 
 +  * 10% Correct implementation of multi values regression estimator 
 +  * 10% Fully vectorized code 
 +  * 20% Correct estimation of hidden parameters in foo.csv 
 +  * +5% Clean factorization of computation graphs into classes
  
 ---- ----
Line 13: Line 26:
  
 ===Key concepts:​=== ===Key concepts:​===
-Computation graphs: A computation graph is essentially an electric circuit, or you can think of it as a dynamical system if you are a math student. Given that, there are three things we want to do with it: first, feed it with some inputs; second, measure the readings of its output nodes; third, trigger some operations on occasions for more control on the graph/​circulatory/​system.+Computation graphs: A computation graph is essentially an electric circuit, or you can think of it as a dynamical system if you are a math student. Given that, there are three things we would like to do with it: first, feed it with some inputs; second, measure the readings of its output nodes; third, trigger some operations on occasions for more control on the system.
  
-Sessions: It provide ​a framework to send and read signals to/from a graph, and it has very similarly syntax as a file stream.+Sessions: It provides ​a framework to send and read signals to or from a graph, and it has very similarly syntax as a file stream.
  
 Placeholders:​ They are the input ports of a graph. Each time we run a computation graph with the goal of triggering an operation or measuring a set of nodes, it’s required to send in the request with an input dictionary, specifying what input values are used to generate the outputs. Placeholders:​ They are the input ports of a graph. Each time we run a computation graph with the goal of triggering an operation or measuring a set of nodes, it’s required to send in the request with an input dictionary, specifying what input values are used to generate the outputs.
Line 126: Line 139:
 </​code>​ </​code>​
  
-4. My computation graph visualization looks like this  +4. My computation graph visualization looks like the following: 
 +{{:​cs501r_f2017:​hint2.4.png?​800|}}
 ---- ----
 ====Understand vectors, matrices and tensors==== ====Understand vectors, matrices and tensors====
Line 189: Line 202:
  
 ===Task 4=== ===Task 4===
-==Read in the following csv file and guess the regression line behind the data.== +==Read in the following ​.csv file and guess the regression line behind the data.== 
 +[[cs501r_f2017:​lab04:​foo|foo.csv]]
  
 ===Hints:​=== ===Hints:​===
Line 200: Line 213:
  
 ===Key ideas:=== ===Key ideas:===
-Running ​opts vs creating ops:+Running ​ops vs creating ops: Every line of code describing some operations in tensorflow is essentially creating nodes and linking them to the rest of a computation graph. Hence putting tensorflow code into functions and calling them for each run will result in duplicated definition of variables. Now, the question we want to answer in this session is that how can we organize our computations into logical block of codes, namely functions and classes in OOP, while avoiding the flaw of mixing up processes of creating and running ops.
  
-decorator pattern:+magic methodsThey are methods of a class with double underscore before and after the definition of its name. The magic behind them is that their invocations are implicitly defined for all objects. For example, if we want to write a constructor for your class, you can simply override the __init__ method.
  
-@property annotation:+decorator pattern: A decorator function takes a function and its arguments then extend its behavior without changing the function'​s implementation. The @annotation in python does exactly that. 
 + 
 +@property annotation: ​While all variables in an object are visible to its users, we might still want to implement getters and setters with special behaviors, for example, bounds checking. The @property allows us to do exactly that.
  
  
 ===Related reading:=== ===Related reading:===
 https://​danijar.com/​structuring-your-tensorflow-models/​ https://​danijar.com/​structuring-your-tensorflow-models/​
 +https://​www.learnpython.org/​en/​Classes_and_Objects
 +https://​docs.python.org/​3/​reference/​datamodel.html#​special-method-names
 +https://​www.thecodeship.com/​patterns/​guide-to-python-function-decorators/​
 +https://​www.programiz.com/​python-programming/​property
    
  
Line 218: Line 237:
 1. I got the following computation graph which are scoped by functions 1. I got the following computation graph which are scoped by functions
  
-2. The article by Danijar have shed great insight about the topic. ​Solution ​to the problem should become trivial after reading his article.+{{:​cs501r_f2017:​hint5.1.png?​800|}} 
 + 
 +2. The article by Danijar have shed great insight about this topic. ​Solutions ​to the problem should become trivial after reading his article.
  
 3. @functools.wraps(function) can be replaced by @six.wraps(function) for python 2 compatibility after installing and importing the python library "​six"​ in your project environment. ​ 3. @functools.wraps(function) can be replaced by @six.wraps(function) for python 2 compatibility after installing and importing the python library "​six"​ in your project environment. ​
cs501r_f2017/lab04.1505593505.txt.gz · Last modified: 2021/06/30 23:40 (external edit)