Mar 29, 2016
Feb 6, 2016
Execute python code using ./
Step1: add #!/usr/local/bin/python in the first line of the code
Step2: in the bash, type chmod +x myscript.py
Step3: type ./myscript.py to execute the python code
Dec 19, 2015
Oct 26, 2015
Use Jazzy to generate Swift documentation.
Format:
- /// description
- - parameter param: description
- - returns: xxxxxxx
run Jazzy
$ jazzy --min-acl internal --swift-version 2.1
Oct 20, 2015
Embed images to latex
\graphicspath{ {pic/} } % The folder containing images.
\includegraphics[scale=0.5]{imageName} % Embed a image.
\includegraphics[scale=0.5]{imageName} % Embed a image.
Oct 18, 2015
CS229 Machine Learning - 3 (Linear regression, Probabilistic interpretation, Logistic regression, Newton's method)
Outline:
- Linear regression
- Probabilistic interpretation
- Logistic regression
- Newton's method
CS229 Machine Learning - 2 (Linear regression, Gradient descent, Normal equation)
Outline:
- Linear regression
- Gradient descent
- Normal equation
Oct 12, 2015
Sep 23, 2015
Elements of Reinforcement Learning
Elements of reinforcement learning:
- a policy: is a mapping from perceived states of the environment to actions to be taken when in those states.
- a reward function: defines the goal in a reinforcement learning problem. iIt maps each perceived state (or state-action pair) of the environment to a single number, a reward, indicating the intrinsic desirability of that state.
- a value function: specifies what is good in the long run. The value of a state is the total amount of reward an agent can expect to accumulate over the future, starting from that state.
- a model (optional)
reference: Reinforcement Learning: An Introduction, Richard S. Sutton and Andrew G. Barto
Sep 15, 2015
Install Maven on OSX causes Error
If you get error "Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0" when installing Maven on mac, try the following command (make sure you modify the version of jdk on your computer):
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
Aug 3, 2015
Jul 29, 2015
Jul 19, 2015
Use Sphinx to automatically create Python documents
Creating program documents is a tedious task. However, with the assistance of automatic tools for creating program documents, we can produce the documents in a very easy and quick way. (We still have to write the comments of program functions.)
Here are the steps of that I used Sphinx to create documents for my python project.
1. Install Sphinx
2. Create a directory (folder) for documents
Create a directory named "docs", and the structure of the "docs" and "src" directories is shown below:
Python Project/
|--------docs/
|--------src/(source code)
3. Create a Sphinx project
In the docs/ directory, perform the following command:
During the process, you will be asked several questions. The following are my answers to some of the questions (empty answer means using the default setting):
| |----- build
| |----- source
|--------src/(source code)
4. Modify docs/source/conf.py
In the conf.py file created in step 3, find the following comments.
Add a setting under the above comments so that Sphinx can find the source code.
5. Use sphinx-apidoc to create module_name.rst files
6. Create html files
In the docs directory, perform the following command to create the documents' html files.
Here are the steps of that I used Sphinx to create documents for my python project.
1. Install Sphinx
$ pip install sphinx 
2. Create a directory (folder) for documents
Create a directory named "docs", and the structure of the "docs" and "src" directories is shown below:
Python Project/
|--------docs/
|--------src/(source code)
3. Create a Sphinx project
In the docs/ directory, perform the following command:
$ sphinx-quickstart docs
During the process, you will be asked several questions. The following are my answers to some of the questions (empty answer means using the default setting):
Separate source and build directories (y/n) [n]: y
autodoc: automatically insert docstrings from modules (y/n) [n]: y
intersphinx: link between Sphinx documentation of different projects (y/n) [n]: y
ifconfig: conditional inclusion of content based on config values (y/n) [n]: y
viewcode: include links to the source code of documented Python objects (y/n) [n]: y
After step 3 is finished, the structure of the Sphinx project will be that as follows:
Python Project/
|--------docs/| |----- build
| |----- source
|--------src/(source code)
4. Modify docs/source/conf.py
In the conf.py file created in step 3, find the following comments.
# If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here.
Add a setting under the above comments so that Sphinx can find the source code.
sys.path.insert(0, os.path.abspath('../../src/'))
5. Use sphinx-apidoc to create module_name.rst files
$ sphinx-apidoc -o docs/source src
6. Create html files
In the docs directory, perform the following command to create the documents' html files.
$ make html
If the documents are successfully created, you can open the docs/build/html/index.html to read it.
Reference:
http://chimerhapsody.blogspot.com/2014/07/python.html
http://sphinx-doc.org/invocation.html#invocation-of-sphinx-apidoc
Jul 13, 2015
Be careful of implementing "binary search"
When using a binary search, we usually will calculate the middle of the search space by
mid = (start + end) / 2
However, if implement this calculation on a computer program, it might cause an overflow problem if the start and end are already too large. Therefore, instead of using (start + end) / 2, we could use
mid = start + (end - start) / 2
See more detail: http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html
mid = (start + end) / 2
However, if implement this calculation on a computer program, it might cause an overflow problem if the start and end are already too large. Therefore, instead of using (start + end) / 2, we could use
mid = start + (end - start) / 2
See more detail: http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html
Jul 8, 2015
The running time of a program in Java
$ time java yourProgram
sample output
sample output
real 0m0.127s
user 0m0.111s
sys 0m0.030s
Jul 7, 2015
Static and Dynamic Binding in Java
Static Binding or Early Binding
Reference:
http://beginnersbook.com/2013/04/java-static-dynamic-binding/
The binding which can be resolved at compile time by compiler is known as static or early binding. All the static, private and final methods have always been bonded at compile-time . Why binding of Static, final and private methods is always a static binding? You would understand it better after reading dynamic binding. Still let me explain this – Compiler knows that all such methods cannot be overridden and will always be accessed by object of local class. Hence compiler doesn’t have any difficulty to determine object of class (local class for sure). That’s the reason binding for such methods is static.Dynamic Binding or Late Binding
When compiler is not able to resolve the call/binding at compile time, such binding is known as Dynamic or late Binding.
Reference:
http://beginnersbook.com/2013/04/java-static-dynamic-binding/
The "finally" block in Java
The "finally" block will get executed if we insert a return statement inside the try block of a try-catch-finally. Even when we attempt to exit within the try block (via a return statement, a continue statement, a break statement or any exception), the finally block will still be executed.
Note that there are some cases in which the finally block will not get executed, such as the following:
Note that there are some cases in which the finally block will not get executed, such as the following:
- If the virtual machine exits during try/catch block execution.
- If the thread which is executing the try/catch block gets killed.
Jul 5, 2015
"final" in Java
"final" doesn't guarantee immutable. It only protect the reference, not the object it references to.
ex:
private final int[] x; //x cannot change, but x[0] can change.
ex:
private final int[] x; //x cannot change, but x[0] can change.
Subscribe to:
Posts (Atom)

