User Tools

Site Tools


study:data_analysis:parallel_data

Differences

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

Link to this comparison view

Next revision
Previous revision
study:data_analysis:parallel_data [2013/09/06 14:08]
okie 새로 만듦
study:data_analysis:parallel_data [2019/02/04 14:26] (current)
Line 1: Line 1:
 <​markdown>​ <​markdown>​
-Importing Data for Analysis+Improving Performance with Parallel Programming
 =========================== ===========================
  
 +# Parallel processing with pmap
  
-# Creating a new project+![!mandelbrot.png](http://​upload.wikimedia.org/​wikipedia/​commons/​thumb/​2/​21/​Mandel_zoom_00_mandelbrot_set.jpg/​800px-Mandel_zoom_00_mandelbrot_set.jpg)
  
-![!leiningen-banner.png](http://leiningen.org/​img/​leiningen-banner.png)+* Mandelbrot Set 
 +</​markdown><​code>​ 
 + Z0 = 0 (단, Z은 복소수.
 + ​Z'​ = Z^2 + C 
 + 를 만족하는 복소수 C의 집합을 Mandelbrot set 이라고 한다. 
 +  
 + Z = X + Yi 
 + C = A + Bi 이라고 하면, 
 + ​Z'​ = Z^2 + C = (X+Yi)(X+Yi) + (A+Bi) 
 + ​Z'​ = X^2 - Y^2 + A + i(2XY + B) 
 +  
 + ​Z'​의 절대값이 2를 넘지 않아야 발산하지 않는다. 
 + ​A ​-2.5 ~ 1.0 
 + B : -1.0 ~ 1.0 
 + ​범위내에서 발산하지 않는 값을 찾아낼 수 있다. 
 +  
 + ​Mandeldelbrot set을 image로 표현하기 위해서는 
 + 각 좌표값을 A, B범위에 맞춰서 scaling 해서 발산여부를 확인한다.  
 +</​code><​markdown>​
  
-* leiningen: https://github.com/​technomancy/​leiningen +</markdown><​code clojure> 
- ​- ​Java 프로젝트 매니저인,​ ant와 maven은 XML을 가지고 프로젝트를 관리한다. +(defn get-escape-point 
- ​- ​하지만XML은 보고 수정하기 힘들다! +  ​([scaled-x scaled-y max-iterations] 
- ​- ​Leiningen은 프로젝트관리 파일 자체가 .clj 파일이다. +   (loop [x 0y 0, iteration 0] 
- ​- ​참고: http://​clojure.or.kr/​wiki/​doku.php?​id=lecture:​clojure:​%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8&​s[]=lein+     (let [x2 (* x x) 
 +           y2 (* y y)] 
 +       (if (and (< (+ x2 y2) 4) 
 +                (< iteration max-iterations)) 
 +         (recur (+ (x2 y2) scaled-x) 
 +                (+ (* 2 x y) scaled-y) 
 +                (inc iteration)) 
 +         ​iteration)))))
  
 +(defn scale-to
 +  ([pixel maximum [lower upper]]
 +   (+ (* (/ pixel maximum) (Math/abs (- upper lower))) lower)))
 +
 +(defn scale-point
 +  ([pixel-x pixel-y max-x max-y set-range]
 +   ​[(scale-to pixel-x max-x (:x set-range))
 +    (scale-to pixel-y max-y (:y set-range))]))
 +
 +(defn output-points
 +  ([max-x max-y]
 +   (let [range-y (range max-y)]
 +     ​(mapcat (fn [x] (map #(vector x %) range-y))
 +             ​(range max-x)))))
 +
 +(defn mandelbrot-pixel
 +  ([max-x max-y max-iterations set-range]
 +   ​(partial mandelbrot-pixel
 +            max-x max-y max-iterations set-range))
 +  ([max-x max-y max-iterations set-range [pixel-x pixel-y]]
 +   (let [[x y] (scale-point pixel-x pixel-y max-x max-y
 +                            set-range)]
 +     ​(get-escape-point x y max-iterations))))
 +
 +(defn mandelbrot
 +  ([mapper max-iterations max-x max-y set-range]
 +   ​(doall
 +     ​(mapper (mandelbrot-pixel
 +               max-x max-y max-iterations set-range)
 +             ​(output-points max-x max-y)))))
 +
 +
 +(def mandelbrot-range
 +  {:x [-2.5, 1.0], :y [-1.0, 1.0]} )
 +
 +</​code><​markdown>​
 +
 +</​markdown><​code>​
 +(def iteration 500)
 +(def resolution 500)
 +
 +(def m (time (mandelbrot map iteration resolution resolution mandelbrot-range)))
 +;;"​Elapsed time: 17991.922 msecs"
 +
 +(def m (time (mandelbrot pmap iteration resolution resolution mandelbrot-range)))
 +;;"​Elapsed time: 11562.502 msecs"
 +
 +(def m (time (mandelbrot map (* 2 iteration) resolution resolution mandelbrot-range)))
 +;;"​Elapsed time: 26766.022 msecs"
 +
 +(def m (time (mandelbrot pmap (* 2 iteration) resolution resolution mandelbrot-range)))
 +;;"​Elapsed time: 17194.2 msecs"
 +
 +</​code><​markdown> ​       ​
 +
 +</​markdown>​
study/data_analysis/parallel_data.1378476534.txt.gz · Last modified: 2019/02/04 14:26 (external edit)