(ns code.experiments.privacy (:use (code.utils utils preprocess)) (:use (code.pls cliff ncliff)) (:use (code.data data)) (:use (code.privacy datafly query_generator query_sad)) (:use (incanter core stats))) (declare get-acc) (def pmc (matrix [[0 0 0 0]])) ; "/home/fayola/ourprivacy/results/privacy/" (defn privacy-experiment [treatments data1 distance-fn result-pathname query-size & options] (let [opts (when options (apply assoc {} options)) data (pre-data (eval data1)) sav (or (:sav opts) [10 20]) q (or (:q opts) 4) notqids (or (:notqids opts) (filter #(not (member? % (datafly-qis data q sav))) (range (ncol data)))) num (or (:num opts) 10) n (or (:n opts) 10) r (or (:r opts) [0.1501 0.3501]) pro (or (:pro opts) ncliff) opro (or (:opro opts) ocliff) mybin (bind-columns (trans (butlast (efb2 data))) (sel data :cols (dec (ncol data)))) m (to-vect (trans mybin)) p (to-vect (trans data)) train0 (fn [dat] (loop [i 0 result []] (if (= i (ncol dat)) (trans result) (recur (inc i) (conj result (if (member? i (butlast sav)) (nth m i) (nth (trans dat) i))))))) train (train0 data) privs (map #((eval %) n (train0 data) sav r pro opro distance-fn) treatments) que (get-queries mybin 1000 query-size notqids) ans (loop [priv privs result []] (if (empty? priv) result (recur (rest priv) (conj result (bind-rows (query-scores que mybin train query-score3 (first sav) query-size 4) (query-scores que mybin (first priv) query-score3 (first sav) query-size 10)))))) scores (loop [a ans result []] (if (empty? a) (matrix [result]) (recur (rest a) (conj result (get-acc (sel (first a) :cols 3) (sel (first a) :cols 4) (sel (first a) :cols 5))))))] [(file-result (str result-pathname"/" data1"/"data1"-query-results-m-" query-size ".txt") scores) (loop [a ans treatment treatments result []] (if (empty? a) result (recur (rest a) (rest treatment) (conj result (save (first a) (str result-pathname"/" data1"/"data1"-query-results-"(first treatment)"-m-" query-size ".csv") :delim \,))))) scores])) ;util fnc ;when result is 0 IPR = 100 (defn get-acc [want-got res2 res3] (let [n (/ (nrow (to-vect want-got)) 2) want (apply vector (take n want-got)) got (apply vector (drop n want-got)) together (map #(vector %1 %2) want got)] (loop [t together r2 res2 r3 res3 result 0] (if (empty? t) (if (= result 0) 100 (/ 100 (* (/ result (* 2 n)) 100.0))) (recur (rest t) (rest r2) (rest r3) (if (and (= (first (first t)) (second (first t))) (> (first r2) (first r3))) (inc result) result)))))) (defn run-privacy-experiment [query-size] (let [test-names ['ant13 'arc 'camel10 'poi15 'redaktor 'skarbonka 'tomcat 'velocity14 'xalan24 'xerces12]] (loop [t test-names result []] (if (empty? t) (save (bind-columns (matrix (range (count result))) (matrix result)) (str "/home/fayola/ourprivacy/results/privacy/results/query-results-all-m-" query-size ".txt") :delim \space) (recur (rest t) (conj result (last (privacy-experiment ['morph1 'morph3 'morph10 'morph20 'morph40 'swap10 'swap20 'swap40 'datafly2 'datafly4] (first t) numeric "/home/fayola/ourprivacy/results/privacy/" query-size))))))))