(ns code.privacy.morph_v1 (:use (code.utils utils preprocess)) (:use (code.pls cliff ncliff)) (:use (incanter core stats))) (def *i*) (def *ans*) (defn jiggle5 [X sav r distance-fn] (let [separate-X (sort-by first (group-by last X)) buggy (matrix (second (second separate-X))) clean (matrix (second (first separate-X)))] (loop [x X result1 []] (if (empty? x) (matrix result1) (recur (rest x) (conj result1 (let [near-x (if (= (last (first x)) (last (first clean))) (first (get-nearest (first x) (if (= (nrow buggy) 1) [buggy] buggy) distance-fn)) (first (get-nearest (first x) (if (= (nrow clean) 1) [clean] clean) distance-fn))) nudge1 (fn [] (+ (first r) (rand (second r)))) nudge (nudge1) new-x (fn [] (loop [x1 0 result []] (if (= (count (first x)) x1) result (recur (inc x1) (conj result (if (member? x1 sav) (nth (first x) x1) (if (= (rand-int 2) 0) (let [big (+ (nth (first x) x1) (* (abs (- (nth (first x) x1) (nth near-x x1))) nudge)) big1 (if (> big (apply max (nth (to-vect (trans X)) x1))) (apply max (nth (to-vect (trans X)) x1)) big)] big) (let [small (- (nth (first x) x1) (* (abs (- (nth (first x) x1) (nth near-x x1))) nudge)) small1 (if (< small (apply min (nth (to-vect (trans X)) x1))) (apply min (nth (to-vect (trans X)) x1)) small)] small1) )))))))] (new-x)))))))) ; (binding [*i* 0 ; *ans* (new-x)] ; (while (= *i* 0) ; (if (member? *ans* X) ; (set! *i* 0) ; (set! *i* 1)) ; (set! *ans* (new-x))) ; *ans*)))))))) (defn morph1 [_ data sav r _ _ distance-fn] "Returns data which includes instances pruned by ncliff, and the unpruned instances which has been changed by the get-fakes function. Example: (morph1 9 (pre-data ant13) [10 20] [0.1501 0.3501] 9 numeric 9) " (jiggle5 data sav r distance-fn))