资源说明:Clojure-based, R-like statistical computing and graphics environment for the JVM
* Overview * Getting started with Clojure * Getting started with Incanter ** Include in Clojure project ** Use standalone app ** Usage * Documentation and examples * Building Incanter * Dependencies h2. Overview and motivation _Incanter is a Clojure-based, R-like statistical computing and graphics environment for the JVM._ At the core of Incanter are the Parallel Colt numerics library, a multithreaded version of Colt, and the JFreeChart charting library, as well as several other Java and Clojure libraries. The motivation for creating Incanter is to provide a JVM-based statistical computing and graphics platform with R-like semantics and interactive-programming environment. Running on the JVM provides access to the large number of existing Java libraries for data access, data processing, and presentation. Clojure’s seamless integration with Java makes leveraging these libraries much simpler than is possible in R, and Incanter’s R-like semantics makes statistical programming much simpler than is possible in pure Java. Motivation for a Lisp-based R-like statistical environment can be found in the paper Back to the Future: Lisp as a Base for a Statistical Computing System by Ihaka and Lang (2008). Incanter is also inspired by the now dormant Lisp-Stat (see the special volume in the Journal of Statistical Software on Lisp-Stat: Past, Present, and Future from 2005). Motivation for a JVM-based Lisp can be found at the Clojure website, and screencasts of several excellent Clojure talks by the language’s creator, Rich Hickey, can be found at Clojure TV. h2. Getting started with Clojure For a great introduction to programming in Clojure, read "Clojure - Functional Programming for the JVM.":http://ociweb.com/mark/clojure/article.html by R. Mark Volkmann. For an even more extensive introduction, get one of the books on Clojure "Programming Clojure, 2ed":http://pragprog.com/book/shcloj2/programming-clojure by Stuart Halloway and Aaron Bedra, "The Joy of Clojure" by Michael Fogus and Chris Houser, "Clojure in Action" by Amit Rathore, "Practical Clojure" by Luke VanderHart and Stuart Sierra. *Other Clojure resources* * "Clojure website":http://clojure.org * "Getting Started with Clojure":https://clojure.org/guides/getting_started * "Clojure Google group":http://groups.google.com/group/ClojureTV * "clojure":https://www.youtube.com/user/ClojureTV * "Disclojure blog":http://disclojure.org/ * "Full Disclojure screencasts":http://vimeo.com/channels/fulldisclojure h2. Getting started with Incanter h4. Include in Clojure project Include all incanter modules at once in yourproject.clj
: bc[clojure]. :dependencies [[org.clojure/clojure "1.9.0"] [incanter "1.9.3"]] Or only the modules you need: bc. :dependencies [[org.clojure/clojure "1.9.0"] [incanter/incanter-core "1.9.3"] [incanter/incanter-charts "1.9.3"]] Start repl: bc. lein repl h4. Use standalone app Start by visiting the Incanter website for an overview, checkout the documentation page for a listing of HOW-TOs and examples, and then download either an Incanter executable or a pre-built version of the latest build of Incanter, which includes all the necessary dependencies, and unpack the file (if you would like to build it from source, read Building Incanter). You also might need to install libgfortran3 library that is required for jblas that is powering matrix operations (see jblas wiki for more details). Start the Clojure REPL (aka the shell) by double-clicking on the downloaded executable or, if you downloaded the pre-built distribution, running one of the scripts in the Incanter directory: @script/repl@ or @script\repl.bat@ on Windows. h4. Usage From the Clojure REPL, load the Incanter libraries:Try an example: sample 1,000 values from a standard-normal distribution and view a histogram:user=> (use '(incanter core stats charts io))
Try another simple example, a plot of the sine function over the range -10 to 10: bc. user=> (def my-plot (function-plot sin -10 10)) user=> (view my-plot) You can save plots into a png file:user=> (view (histogram (sample-normal 1000)))
Incanter can save charts into pdf or svg files. Checkuser=> (save my-plot "plot.png")
incanter.pdf/save-pdf
andincanter.svg/save-svg
functions. Let's play with some data now. We'll look at London weather for 2012: bc.. ; function that returns dataset containing weather in London for given month in 2012 (defn weather-for-month [month] (-> (format "https://www.wunderground.com/history/airport/EGLL/2012/%d/10/MonthlyHistory.html?format=1" month) (read-dataset :header true))) ; get weather data for each month in 2012 and build single dataset (def data (->> (range 1 13) (map weather-for-month) (apply conj-rows))) ; view dataset in a table and view histogram of mean temperature (view data) ; wunderground.com formats temperature depending on locale/location/whatever ; so you might need to use "Mean TemperatureF" otherwise you'll get NullPointerException. (view (histogram "Mean TemperatureC" :nbins 100 :data data)) ; function that given month "2012-9-20" extracts month and returns 9 (defn month [date] (Integer/parseInt (second (.split date "-")))) ; dataset that contains 2 columns: month and mean temperature for that month ; don't forget to change to "Mean TemperatureF" if you did so few steps back. (def grouped-by-month (->> (map (fn [date temp] {:month (month date) :temp temp}) ($ "GMT" data) ($ "Mean TemperatureC" data)) to-dataset ($rollup :mean :temp :month) ($order :month :asc))) ; view line chart that shows that August was the warmest month (view (line-chart :month :temp :data grouped-by-month)) p. The online documentation for most Incanter functions contain usage examples. The documentation can be viewed using Clojure's @doc@ function. For example, to view the documentation and usage examples for the @linear-model@ function, call @(doc linear-model)@ from the Clojure shell. Use @(find-doc "search term")@ to search the online documentation from the Clojure shell. The API documentation can also be found at http://incanter.github.io/incanter/. The Clojure Data Analysis Cookbook (published by Packt Publishing) contains several chapters dedicated to Incanter, including work with datasets, charting, etc. You can read the sample chapter that describes Incanter's datasets. There is dedicated mailing list for discussions about Incater. It's hosted on Google Groups. *More Incanter examples* * See the Data-Sorcery blog * See the Documentation table of contents h2. Documentation The following documentation covers the Incanter and Clojure APIs and the APIs of the underlying java libraries. *Incanter documentation* * "Doc Index":http://data-sorcery.org/contents/ * "API":http://incanter.github.io/incanter/ *Related API documentation* * "Clojure API":http://clojure.github.com/clojure/ * "Parallel Colt Java API":http://incanter.org/docs/parallelcolt/api/ * "JFreeChart Java API":http://www.jfree.org/jfreechart/api/javadoc/index.html * "Processing API":http://www.processing.org/reference/ h2. Building Incanter To build and test Incanter, you will need to have Leiningen and git installed: 1. Clone the repository with git: @git clone git://github.com/incanter/incanter.git@ 2. Install Leiningen (version 2.x) a. Download the lein script: @wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein@ (use lein.bat on Windows) b. Place it on your path and chmod it to be executable: @chmod +x lein@ c. Run: @lein self-install@ 3. Execute @lein sub install@ (or @lein modules install@) staying in the incanter directory - this will download all necessary dependencies, compile & install all Incanter's modules into local Maven repository. 4. Start a REPL: @lein repl@ (it also starts nRepl server), or start a Swank server: @lein ritz 4005@ Other tasks: * If you want to run the tests for each of Incanter's modules, use @lein sub test@ * Each of Incanter's modules are independent Leiningen projects. Just cd into modules/incanter-* and use Leiningen to build each one as a stand-alone library. * @lein sub install@ (or @lein modules install@) uses Leiningen to build all the modules and install them in your local ~/.m2 repository. h2. Incanter dependencies * "Clojure":https://github.com/clojure/clojure * "Parallel Colt":http://sites.google.com/site/piotrwendykier/software/parallelcolt ** "Netlib-Java":http://code.google.com/p/netlib-java/ (included with Parallel Colt) * "Clatrix":https://github.com/tel/clatrix ** "jblas":https://github.com/mikiobraun/jblas * "JFreeChart":http://www.jfree.org/jfreechart/ ** "JCommon":http://www.jfree.org/jcommon/ (included with JFreeChart) ** "GnuJaxp":http://www.gnu.org/software/classpathx/jaxp/jaxp.html (included with JFreeChart) * "OpenCSV":http://opencsv.sourceforge.net/ * "iText":http://itextpdf.com/ * "Congomongo":https://github.com/aboekhoff/congomongo * "JLaTeXMath":http://forge.scilab.org/index.php/p/jlatexmath/ * "Apache POI":http://poi.apache.org/ * "JLine":http://jline.sourceforge.net/ * "ClojureQL":https://clojureql.sabrecms.com/ * "Batik SVG Toolkit":https://xmlgraphics.apache.org/batik/
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。