(ns us.menzies.plot (:import (us.menzies.plot PlotWindow) (java.awt.event ActionListener ActionEvent) (javax.swing SwingUtilities) (java.util Random))) (def *plot-window*) (load-file "seheult.clj") (load-file "DistanceFunctions.clj") (load-file "FastMap.clj") (load-file "k-means.clj") (load-file "EqualFrequencyBinning.clj") (load-file "ContrastSetLearning.clj") (load-file "walsh.clj") (load-file "grove.clj") (load-file "evett.clj") (defn plot ([x y z] (.plot *plot-window* x y z)) ([x y z obj] (.plot *plot-window* x y z obj))) (defn plot-all ([lst] (plot-all lst (.createPoint *plot-window*))) ([lst obj] (doseq [each lst] (.plot *plot-window* (first each) (second each) (last each))))) (defn plot-plane ([] (plot-plane 1000)) ([n] (plot-plane n 0.5)) ([n y] (let [random (Random.)] (dotimes [_ n] (plot (.nextFloat random) y (.nextFloat random)))))) (defn get-samples [] (.getSamples *plot-window*)) (defn get-is-fastmap-selected [] (.isFastmapSelected *plot-window*)) (defn get-selected-item [] (.getSelectedModel *plot-window*)) (defn run-model ([modelfunc] (run-model modelfunc (get-is-fastmap-selected))) ([modelfunc dofastmap] (let [modelresults (modelfunc (get-samples))] (if dofastmap (FastMap modelresults 2) modelresults)))) (defn plot-model ([modelfunc] (plot-model modelfunc (get-is-fastmap-selected))) ([modelfunc dofastmap] (plot-all (run-model modelfunc dofastmap)))) (defn handle-button-press [evt] (.erasePlot *plot-window*) (let [cmd (get-selected-item)] (cond (.equals cmd "Model - Evett") (plot-model random-evett) (.equals cmd "Model - Grove") (plot-model random-grove) (.equals cmd "Model - Seheult") (plot-model random-seheult) (.equals cmd "Model - Walsh") (plot-model random-walsh)))) (defn add-action-listeners [] (.addPlotButtonActionListener *plot-window* (proxy [ActionListener] [] (actionPerformed [evt] (.start (Thread. (proxy [Runnable] [] (run [] (handle-button-press evt))))))))) (defn start-gui [] (SwingUtilities/invokeLater (proxy [Runnable] [] (run [] (def *plot-window* (PlotWindow.)) (add-action-listeners) (.setVisible *plot-window* true))))) (start-gui)