User Tools

Site Tools


study:data_analysis:parallel_data

This is an old revision of the document!


<markdown> Improving Performance with Parallel Programming

# Maldelbrot set

![!leiningen-banner.png](http://leiningen.org/img/leiningen-banner.png)

* leiningen: https://github.com/technomancy/leiningen - Java 프로젝트 매니저인, ant와 maven은 XML을 가지고 프로젝트를 관리한다. - 하지만, XML은 보고 수정하기 힘들다! - Leiningen은 프로젝트관리 파일 자체가 .clj 파일이다. - 참고: http://clojure.or.kr/wiki/doku.php?id=lecture:clojure:%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8&s[]=lein

</markdown>

(defn get-escape-point
  ([scaled-x scaled-y max-iterations]
   (loop [x 0, y 0, iteration 0]
     (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]} )

<markdown>

</markdown>

study/data_analysis/parallel_data.1378476816.txt.gz · Last modified: 2019/02/04 14:26 (external edit)