Oct
23

sublime text 2 build configuration

Sublime is a great editor, it can deal with nearly all programming languages and expecially fit for web developer.

I tried the sublime for Python. For beginner, you should do the following settings:

  • Install the package control
    • usage: ctrl+shift+p  -> install packages
  • configure the your build system:
    • For example python 3:
      Tools -> Build System -> New Build System -> (create file: python3)

      {
          "cmd": ["python3", "-u", "$file"],
          "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
          "selector": "source.python",
          "encoding": "utf8",
          "path": "/Library/Frameworks/Python.framework/Versions/3.3/bin/"
      }
      
      • The file is in : %AppData%\Roaming\Sublime Text 2\Packages\User
    • or just install the package: ctrl+shift+p -> install packages -> python 3 & cython+
    • The customed build system file is located in %AppData%\Roaming\Sublime Text 2\Packages\Python3.sublime-build
  • If you want to delete the file, you can directly delete it or install a package with: PackageResourceViewer

References:

https://packagecontrol.io/packages/Python%203

http://stackoverflow.com/questions/23161604/how-to-set-which-version-of-python-sublime-text-uses

http://stackoverflow.com/questions/27338255/sublime-text-3-removing-build-systems

Oct
23

Configure Git for RStudio

There is an article from RStudio explained how to configure Git for RStudio. But it is not very detailed. I ran into many problem during the configuration and wasted a lot of time just for configuration.  So I decided to write down all the steps.

For https connection:

  1. install git
  2. RStudio -> Tools -> Global options -> Git/SVN -> configure the git: C:/Program Files/Git/mingw64/bin/git.exe
  3. RStudio -> Tools -> Project options -> Git/SVN  -> Choose Git
  4. Restart RStudio
  5. In this project, open the Shell: RStudio -> Tools -> Shell, configure your remote repository adress
    git remote add origin https://{username}:{password}@github.com/{username}/project.git
    or https://{username}@github.com/{username}/project.git
    git push -u origin master
  6. Notice: If you already setted the adress, you can change it with:
    git remote set-url origin https://{username}:{password}@github.com/{username}/project.git

For ssh connection:

  • do the same 1 to 4 steps like the https connection.
  • open shell: git remote add origin git@github.com/{username}/project.git
  • generate SSH key: Tools -> Global options -> Git/SVN -> SSH RSA Key -> Generate RSA Key
  • view public key -> copy it
  • Open your github etc repositories -> add the public key to your account
  • If you installed the Putty, you will get a big problem, the RStudio can not find the ssh.exe, So you have to specify the ssh path:
    set the evironment variable: systemsteuerung -> system und sicherheit -> system -> erweiterted Systemeinstellungen -> Erweitert -> Umgebungsvariablen -> “GIT_SSH”: C:\Program Files\Git\usr\bin\ssh.exe

There are several useful links for the configuration problems:

Oct
16

Animating a point walking flow with python

Using the SimpleGUICS2Pygame can animate the walking path easily. (The SimpleGUICS2Pygame is a implementation of simplegui.)

I wrote an small code for the simulation in codeskulptor, you can run it directly and see the effect:

http://www.codeskulptor.org/#user40_o37gkz7Wyy_11.py

But you need to install and import it at first:

  • installation:
    >>> pip install SimpleGUICS2Pygame
  • import:
    import SimpleGUICS2Pygame.simpleguics2pygame as simplegui

 

The most important part of this code is the timer_handler() function: which frequently updates the circle position.

Settings:

line 15: input your walking flow points

line 18: set your background image

line 21: set the smoothing of the animation: from 1 to 1000

Oct
16

solution for installing pygame

I have two computers, the one has windows system at home, the other has ubuntu system in my office. In each computer, I have two python, the one is normal python, the other is anaconda.

I try to install the pygame on both computer, then I got in chaos. My computer can not find it, even I installed pygame with pip several times.

After some effort, I got the solution:

download the pygame binary distribution for your operating system:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame

Windows:

  • For normal python: pip install your_download_path\downloaded_pygame
  • For anaconda python:
    • use the anaconda pip
    • pip install your_download_path\downloaded_pygame

Linux:

Setting in Eclipse:
In eclipse, you can set the python interpreter by yourself

  • In menu: Project -> Properties ->  pyDev-Interpreter/Grammar -> Click here to configure an interpreter not listed -> New -> …
  • you can also set PYTHONPATH: Project -> Properties -> pyDev-PYTHONPATH (you can also set the external library here)

check the loaded packages in project:

  • In the “PyDev Package Explorer” viewer:
    • under all the project file, your can see your python interpreter name, double click, all the installed packages are listed here. 🙂

 

 

Aug
11

KNIME Notice

  • How to increase the memory of KNIME? Source
    • open knime.ini
    • -Xmx512m ->  -Xmx1g
    • -XX:MaxPermSize=256m -> 512m
    • main memory should bigger than 2 * (1g + 512m)
  • Multiple Criteria row filter:
    • Rule-based Row Filter/Splitter
Jul
31

trunc() and floor(), round() and signif() in R

floor takes a single numeric argument x and returns a numeric vector containing the largest integers not greater than the corresponding elements of x.

trunc takes a single numeric argument x and returns a numeric vector containing the integers formed by truncating the values in x toward 0.

round rounds the values in its first argument to the specified number of decimal places (default 0).

signif rounds the values in its first argument to the specified number of significant digits.

test:

————————–

> x <- c(-5.2, -3.8, 5.2, 3.8)

>floor(x)

-6 -4 5 3

>trunc(x)

-5 -3 5 3

> x <- 3.1415

—————————-

>round(x)

3

>round(x,3)

3.142

>signif(x,3)

3.14

Jul
25

Plot Histogram in R

Plot Histogram in R:

Method 1: hist(vector, breaks)

Take care for the parameter “breaks”:

according the help:

breaks: a single number giving the number of cells for the histogram.

Important: the number is a suggestion only! The breakpoints will be set to pretty values.

For example:

>data(“women”) #load dateset “women”

> hist(women$weight, breaks = 7)

histogram

 

 

 

 

 

 

If you want to have exact 7 bins, you should specify the position

>hist(women$weight, breaks=seq(min(women$weight), max(women$weight), l = 7))

histogram_exact_bins

 

 

 

 

 

 

 

so, you will get the exact 7 bins

May
24

matrix calculation in R and Python

  • Useful packages:
    • R: library(matrixcalc)
    • Python: numpy
  • Matrix generation:
    • R: matrix(1:6, 2, 3)
    • Python: np.arange(1,7).reshape(2,3)
  • construct a diagnal matrix:
    • R: advanced-R
      • diag(vector, nrow, ncol) #construct a matrix which diagonal elements is equal to the vector
      • diag(matrix) # a vector which elements is the diagonal elements of the matrix
    • Python: np.diag(vector)
      • np.diag(vector, k) # like the diag(vector) in R, k means the shift of the diagnoal
      • np.diag(matrix) #return a vector which values are the diagonal elements of the matrix
  • singular value decomposition:
    • R:
      • svd(matrix)
    • Python:
      • np.linalg.svd(matrix, full_matrices=True) #if full_matrices=False, the result will be the same as with R
  • resolve Ax=b
    • R: solve(A,b)
    • Python: np.linalg.solve(A,b)
May
12

How to install R-extention in RapidMiner for Ubuntu?

I found the easiest way to install R extention for Ubuntun

  • RapidMiner -> Marketplace -> R Extention
  • RStudio -> Tools -> Install Packages… -> Input in the field “Packages”: rJava, JavaGD
    Or input in R Console: install.packages(c(“rJava”,”JavaGD”))
  • Restart RapidMiner
  • you get a popup -> choose the jri file, the path is here:
    “/home/xxx/R/x86_64-pc-linux-gnu-library/3.0/rJava/jri/libjri.so”
  • Restart RapidMiner

This article is more detailed.

May
10

Start with R

Useful web sites for R:

About Package

  • install.packages(“ggplot2”), you can also install with RStudio menu: Tools -> Install Packages…
  • library(ggplot2)