Monday, July 25, 2016

3, 6, 9 게임 - Java (korean)

임의의 양의 정수를 정하고 그 수까지 3, 6, 9 게임을 수행

* 해당 숫자에서 3, 6, 9를 포함하고 있는 개수만큼 박수를 침


import java.util.ArrayList;
import java.util.List;

public class dateTest1 {
    public static void main(String[] args) {
        int a = 372;
        List  tsn = new ArrayList();
        tsn.add(3);
        tsn.add(6);
        tsn.add(9);
        boolean clap = false;
        for(int i=1 ; i<=a ; i++) {
            int temp = i;
            while(temp > 0) {
                if(tsn.contains(temp%10)){
                    System.out.print("짝!");
                    clap = true;
                }
                temp = temp/10;
            }
         if(clap) {
              System.out.println();
              clap = false;
              continue;
         } else   
             System.out.println(i);
        }
    }
}




Sunday, July 24, 2016

Import Project from Bitbucket to Eclipse

how to import project to eclipse (by clone),
when you already have project repository on bitbucket


1. File -> Import -> Git -> Project from Git


2. select URI


3. get URI from bitbucket


4. ctrl+v


5. select branches


6. select local directory


7. choose option you want (choose second in my case)



8. following steps are like 'Create Java Project'


9. restart eclipse, check repository and branches


10. right click on project -> Team -> Commit
- select changed files and drag&drop like direction
- summary or memo on commit message
- click 'Commit and Push'


11. OK







Tuesday, July 19, 2016

Create Bitbucket Repository and Connect Eclipse

Ubuntu 14.04
Eclipse Mars 4.5.2


1. join bitbucket and create repository
- dashboard -> repositories -> create repository


- create (can create private repositories only five)



2. install git plug-in on eclipse
- Help -> Install New Software
- fill in ' Work with: http://download.eclipse.org/egit/updates ' or just hit 'git'
- check the box 'Eclipse Git Team Provider'


- next -> next -> I accept  the terms of license agreement -> finish (take few minute.....)
- restart eclipse and can see in import menu


3. create project and connect with bitbucket
- create project and right click on it
- Team -> Share Project


- check 'Use or create repository in parent folder of project'
- choose project you want (already existed....)


- if you can not check, click 'Create Repository' and choose again


4. commit and push
- right click on project -> Team -> Commit
- select and move source files from 'unstaged changes' to 'staged changes'
- commit message is optional


- commit, maybe get error
- right click on project -> Team -> Push Branch 'master'


- fill clone url in ' Location -> URI : ', get from bitbucket


- hit user and password -> next


- next -> finish



- refresh dashboard of bitbucket
- can find commits




ref : http://embedded.kookmin.ac.kr/lectureMobile/index.php/Eclipse_%2B_Github_%EC%82%AC%EC%9A%A9%EB%B2%95


Monday, July 18, 2016

Install Git on Ubintu

2 ways are installing git on ubuntu

A. Installation
1. Using apt-get - it's simple, but not latest version.
$ sudo apt-get install git

2. Download and install manually - it can use latest version.
- install libraries
$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
    libz-dev libssl-dev
- if you want various documents format, need to these libraries
$ sudo apt-get install asciidoc xmlto docbook2x
- download latest release version from follows
Kernel.org( https://www.kernel.org/pub/software/scm/git/ )
GitHub mirror( https://github.com/git/git/releases )
- compile and install
$ tar -zxf git-1.9.1.tar.gz
$ cd git-1.9.1
$ make configure
$ ./configure --prefix=/usr
$ make all doc info
$ sudo make install install-doc install-html install-info


B. Configuration setting
- user
$ git config --global user.name "user name"
$ git config --global user.email emailaddress@email.com
- editor
$ git config --global core.editor editorname
- checking config settings
$ git config --list
- usage help
$ git help 
$ git  --help
$ man git-
ex) $ git help config


C. Generate project
- generate folder
$ mkdir testGitProject
- generate git repository in above folder
$ git init
- add and commit
$ git add *.c
$ git add LICENSE
$ git commit -m 'message about this project version'


D. Clone remote repository
- follow command makes directory named "libgit2" and generate .git in "libgit2". And clone repository
$ git clone https://github.com/libgit2/libgit2
- only differ name of directory "mylibgit", others are same
$ git clone https://github.com/libgit2/libgit2 mylibgit


E. other commands
- check state of repository
$ git status
- commit
$ git commit
- view log
$ git log
- fetch or pull remote repository (pull = fetch + merge)
$ git fetch [remote-name]
$ git pull [remote-name]
- push
$ git push origin master


ref : https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
ref : http://yokang90.tistory.com/47

Thursday, July 14, 2016

Ubuntu Commands and Tips #2

Memo - commands and tips in ubuntu


1. Network setting on ubuntu : when you can't connect lan(wired) network
- open follows
$ sudo gedit /etc/network/interfaces
- text in file
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface

auto lo
iface lo inet loopback
- case1_auto : add as follows under text in file
auto eth0
iface eth0 inet dhcp
- case2_manual : add as follows
auto eth0
iface eth0 inet static
        address 192.168.0.2
        netmask 255.255.255.0
        gateway 192.168.0.1
        dns-nameservers ~~~~~
- save and network restart
$ sudo ifdown eth0
$ sudo ifup eth0
ref : http://blog.iolate.kr/89
ref : http://promobile.tistory.com/300


2. Error : " ubuntu wired network unmanaged "
- open follows
$ sudo gedit /etc/NetworkManager/NetworkManager.conf
- file contains, set "managed=true"
[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=false
- save and restart network manager
$ /etc/init.d/network-manager restart
ref : https://wishkane.wordpress.com/2013/07/11/ubuntu-network-manager-wired-networks-are-unmanaged/


3. Activate workspaces
- System Settings -> Appearance -> Behavior
- check "Enable workspaces"


4. 우분투 한글 및 한글 키보드 설정
- System Setting -> Language Support -> Language Support install
- System Setting -> Text Entry -> 왼쪽 하단에 '+'를 이용해서 'Korean(Hangul)' 이라고 되어있는 항목을 추가
(되도록이면 영어 - 한국어 순으로 설정)
- System Setting -> Keyboard -> Shortcuts -> Typing -> Compose Key를 'Disabled'에서 'Right Alt'로 변경
- terminal에 아래의 내용을 입력 (한/영 키 사용 위함)
$ sudo apt-get install dconf-editor
- 설치가 완료되면 org -> gnome -> desktop -> wm -> keybindings -> switch-input-source의 값을 'Hangul'이라고 입력



Wednesday, July 13, 2016

Ubuntu Commands and Tips #1

Memo - commands and tips in ubuntu


1. Check protocol / ip / port/ program id
$ sudo netstat -tnlp
*options : -t(connected TCP protocol) -n(numeric address) -l(port, state : 'LISTEN') -p(program id)


2. Process Termination
$ sudo kill PID


ref : http://zetawiki.com/wiki/%EB%A6%AC%EB%88%85%EC%8A%A4_%EA%B2%8C%EC%9D%B4%ED%8A%B8%EC%9B%A8%EC%9D%B4_%ED%99%95%EC%9D%B8
ref : http://kjvvv.kr/14174
ref : http://linuxism.tistory.com/48


3. Change the command-line prompt color
$ sudo gedit ~/.bashrc
and find this line
#force_color_prompt=yes
remove hash -> 'force_color_prompt=yes'

want to further changes.
ref : https://ubuntugenius.wordpress.com/2011/07/11/how-to-change-the-command-line-prompt-colour-in-the-ubuntulinux-terminal/


4. Back-up application : TimeShift
- installation
$ sudo apt-add-repository -y ppa:teejee2008/ppa
$ sudo aptitude update
$ sudo aptitude install timeshift
ref : https://launchpad.net/timeshift


5. Error : " Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/Release Unable to find expected entry ‘main/binary-i386/Packages’ in Release file (Wrong sources.list entry or malformed file) "
- sol
$ sudo gedit /etc/apt/sources.list.d/google-chrome.list
and find the line add [amd64] like follows, Do not edit or replace any other text in this file
deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main
$ sudo apt-get update
ref : http://www.omgubuntu.co.uk/2016/03/fix-failed-to-fetch-google-chrome-apt-error-ubuntu


6. Error : " W: There is no public key available for the following key IDs: 1397BC53640DB551 "
- sol
$ sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 1397BC53640DB551
$ sudo apt-get update
ref : http://askubuntu.com/questions/520718/no-public-key-available-while-upgrading-using-update-manager


7. Error : " W: GPG error: http://http.debian.net wheezy-backports InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 8B48AD6246925553 NO_PUBKEY 7638D0442B90D010 "
- sol.1
do same as above process
- sol.2
do as follows(reference)
ref : http://askubuntu.com/questions/13065/how-do-i-fix-the-gpg-error-no-pubkey





Monday, July 11, 2016

Errors and Problems - text, image, title clipping

Memo - occurred errors & exceptions

Linux 14.04
Eclipse Mars 4.5.2
Jsoup


1. DB Connection
- call URL data
Error : exception in thread main java.net.sockettimeoutexception read timed out
ref : http://stackoverflow.com/questions/6571548/i-get-a-sockettimeoutexception-in-jsoup-read-timed-out

- insert userAgent
Error : exception in thread main org.jsoup.httpstatusexception http error fetching url. status=403
ref : http://stackoverflow.com/questions/14467459/403-error-while-getting-the-google-result-using-jsoup

- url of pdf
Error : org.jsoup.unsupportedmimetypeexception unhandled content type. must be text/*
ref : http://stackoverflow.com/questions/16327105/connection-error-org-jsoup-unsupportedmimetypeexception-unhandled-content-typ



2. Jsoup
Error : jsoup java.util.zip.zipexception not in gzip format
ref : http://stackoverflow.com/questions/13018732/java-util-zip-zipexception-not-in-gzip-format
ref : https://github.com/MrL1605/Pronto-Auth/blob/master/logout.java
Jsoup.connect(url).userAgent(~~~)
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,**;q=0.8")
.header("Accept-Encoding", "gzip, deflate")


Error : java.io.ioexception too many redirects occurred trying to load url
ref : http://stackoverflow.com/questions/7765316/too-many-redirects-occurred-trying-to-load-url-there-arent-any-redirects
ref : https://github.com/MrL1605/Pronto-Auth/blob/master/logout.java
.userAgent("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0")


Error : exception in thread main org.jsoup.unsupportedmimetypeexception unhandled content type
ref : http://stackoverflow.com/questions/16327105/connection-error-org-jsoup-unsupportedmimetypeexception-unhandled-content-typ
Jsoup.connect(articleURL)~~~ .ignoreContentType(true)


Error : javax net ssl sslhandshakeexception sun security validator validatorexception pkix path building failed
ref : https://www.lesstif.com/pages/viewpage.action?pageId=12451848
$ wget https://java-use-examples.googlecode.com/svn/trunk/src/com/aw/ad/util/InstallCert.java

$ gedit InstallCert.java
remove line "package com.aw.ad.util;" top
$ javac InstallCert.java

$ java -cp ./ InstallCert undertheradar.co.kr
Enter certificate to add to trusted keystore or 'q' to quit: [1]
Added certificate to keystore 'jssecacerts' using alias 'undertheradar.co.kr-1
$ keytool -exportcert -keystore jssecacerts -storepass changeit -file output.cert -alias undertheradar.co.kr-1

$ sudo keytool -importcert -keystore /usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts -storepass changeit -file output.cert -alias undertheradar.co.kr-1


Tuesday, June 7, 2016

Restricted Boltzmann Machine #1 (Korean)

기계학습 알고리즘 첫 번째
Restricted Boltzmann Machine(제한 볼츠만 머신), RBM의 개념에 대해서.

RBM에 대해 이야기하기 전에, 우선 Energy based model과 Free energy, BM(Boltzmann Machine)에 대해서 먼저 이야기 해보겠습니다.



- Energy Based Model
확률모델링을 비롯해 기계학습 모델들은 변수들 사이의 상관관계를 수치적으로 계산하는 것에서 시작합니다. Energy based model은 이런 변수들 사이의 상관관계를 에너지로 인코딩하며, 에너지가 낮을수록 연관성이 높음을 의미합니다. 주어진 데이터(x)에 대해서 가능한 모든 출력변수(y)들의 배열들{(x, y)....}의 에너지인 E(x,y)는 각 배열의 연관성을 의미하며 모델이 제시하는 출력값은 에너지값이 가장 작은 배열의 출력변수(y)가 됩니다. 즉 모델은 가능한 모든 배열에 대한 에너지값을 알고 있어야 하며, 이 모든 배열에 대한 에너지값을 정해주는 수학적인 함수가 필요합니다. 학습이란, 주어진 학습데이터들에 대해서 좋은 에너지 함수가 되도록 에너지 함수의 파라미터를 수정하는 과정을 의미합니다. 이러한 에너지 함수를 정의하고 좋은 에너지 함수를 측정하기 위해 손실함수를 정의해서, 손실함수를 최소화 시키는 방향으로 기계학습이 진행됩니다.



Energy based model은 energy function을 통해서 확률 분포를 정의하는 특징이 있고 아래와 같이 확률을 정의합니다.

Z = partition function

위의 식은 다시 Visible - x와 hidden - h에 맞게 아래와 같이 표현할 수 있습니다.


그리고 이 식을 위의 식과 유사한 형태로 표현하기 위해 free energy 개념과 식을 사용합니다.



- Free energy
어떤 시스템 내부에 가지고 있는 에너지 중 실제로 일로 변환될 수 있는 '자유로운' 에너지를 뜻합니다.

Free energy는 아래와 같이 정의합니다.


그리고 확률을 에너지로 표현한 식에 대입하여 아래와 같이 표현할 수 있습니다.


Energy based model은 gradient descent를 수행함으로써 모델을 학습하고, training data set에 기반한 Negative log-likelihood 값에 대해 최적화를 합니다.

아래와 같이 log-likelihood와 negative log-likelihood를 정의하고

gradient descent의 정도로 와 위에 free energy 식을 이용하여 아래와 같이 전개할 수 있습니다.



Energy based model과 Free energy에 대해서 간단하게 알아보았고, 이어서 Boltzmann Machine과 Restricted Boltzmann Machine의 개념에 대해 간략하게 소개하겠습니다.



- Boltzmann Machine
BM은 stochastic recurrent neural network로, 에너지 모델을 확률로 해석한 모델이고 Geoffrey Hinton과 Terry Sejnowski에 의해 1985년 제안되었습니다. 각각 하나의 visible layer와 hidden layer로 구성되며, 이 네트워크를 하나의 에너지 모델로 간주합니다. visible layer와 hidden layer가 학습과정에서 에너지 함수를 이용하여 학습하게 됩니다.


BM & energy function
ref : [hugo larochelle youtube channel]

하지만 그림과 같이 unconstrained connectivity(fully connected) 때문에 weight를 구하는 계산과정이 너무 복잡하고 그로 인해 기계학습이나 추론 분야에서 실제적인 문제를 해결하는데 유용하지 않았습니다. 이러한 Boltzmann Machine의 단점을 보완하는 방법으로 연결에 제약을 둠으로써(같은 layer간의 노드연결을 없앰) 실제적인 문제 해결에 이용하기 위해 고안된 것이 바로 Restricted Boltzmann Machine입니다.


RBM & energy function
ref : [hugo larochelle youtube channel]



- Restricted Boltzmann Machine
bidirectional link로 서로 연결된 노드(unit)들로 구성되어 있으며 노드들은 on/off 상태를, 링크들은 weight(real value)를 가집니다. 같은 layer의 노드들 끼리 연결되는 링크는 없고, 링크에 주어진 weight는 양방향으로 노드에 동일하게 적용됩니다. BM과 마찬가지로 열역학 법칙(에너지는 높은 곳에서 낮은 곳으로 이동)처럼 확률이 낮은 상태에서 높은 상태로 학습됩니다.


아래는 RBM의 Energy function입니다.


Energy function을 확률로 풀이한 것입니다.


ref : [hugo larochelle youtube channel]

RBM도 마찬가지로 log-likelihood의 gradient descent를 수행함으로써 네트워크를 학습합니다. 학습 과정에서 Markov chain을 수렴할 때까지 반복함으로써 p(x)로부터의 표본들을 구하는 Gibbs sampling을 사용합니다. 하지만 표본을 추출하기 위해 sampling을 수렴할 때 까지 반복하는 것은 비효율적이기 때문에, 표본 추출 시 속도 개선을 위해 contrastive divergence 방식을 사용합니다.




개인적으로 공부하면서 그냥 정리한 것입니다.
누군가에게 도움이 될만한 포스팅이라기 보다는....ㅎㅎ
잘못된 것이 있으면 리플로 알려주세요~


Thursday, March 24, 2016

Compress and Extract file or directory on Ubuntu

Way to compress and extract file or directory in command line.

1. Compress file or directory
$ tar czvf Comptarget.tar.gz /target
- All contents compress under '/target' will be named as 'Comptarget.tar.gz'


2. Split and Compress file or directory
$ tar czvf - /target | split -b 500mb - Comptarget.tar.gz
- You need to split file or directory if target is too big.
- Can compress target and split it by 500mb.
- Output files will be named as Comptarget.tar.gz*
$ tar czvf Comptarget.tar.gz /target
$ split -b 500mb Comptarget.tar.gz
- Same action above line.


3. Merge compressed Compressed.tar.gz*
$ cat Comptarget.tar.gz* > Comptarget.tar.gz
- Merge split files.


4. Merge and extract Compressed.tar.gz*
$ cat Comptarget.tar.gz* > tar xzvf -
- Can merge and extract in an action.


Ref : http://yoonperl.tistory.com/165

Monday, January 11, 2016

Install Ubuntu 14.04.3 from USB


[Conditions]
1. If you want to change your OS from Windows to Ubuntu.
2. 64bit
3. ver. 14.04.3 LTS Desktop
4. live in Korea but installing Ubuntu ENG ver


follow the steps below

1. Download Ubuntu desktop(choose your flavour)
get here : http://www.ubuntu.com/download/desktop

2. Need utility likes UUI(Universal USB Installer) for making bootable USB flash drive.
get here : http://www.pendrivelinux.com/universal-usb-installer-easy-as-1-2-3/

3. Make Bootable USB
- select "Ubuntu" at first dropdown box
- find your ubuntu iso file downloaded
- choose your USB drive
complete screen
ref : http://www.pendrivelinux.com/universal-usb-installer-easy-as-1-2-3/

4. Choose USB drive when your PC boot

5. Follow these steps
- select first option "Install Ububtu"
- recommend do not "V" check any box(faster)
- choose options, you want. and fill in, wait installing

6. If you can see 'log-in' screen, installing is completed


*** I recommend to back up(snapshot using utility likes timeshift) when you complete install before change some conditions.