Commits

Oliver Gu committed b6b7e2c

SVR example uses Archimedes for plotting.

  • Participants
  • Parent commits 6282fe3

Comments (0)

Files changed (5)

 (* OASIS_START *)
-(* DO NOT EDIT (digest: 0da94f6a806e2169c92934136b9aa7e7) *)
+(* DO NOT EDIT (digest: d9a04327e5daf42539236081ca25409d) *)
 This is the INSTALL file for the libsvm-ocaml distribution.
 
 This package uses OASIS to generate its build system. See section OASIS for
 * core for library svm
 * lacaml for library svm
 * sexplib for executable svm_cli
+* gsl for executable log
+* archimedes for executable log
 
 Installing
 ==========
   BuildDepends:   libsvm,sexplib,sexplib.syntax
   CompiledObject: native
 
-# Executable log
-#   Path:           examples
-#   MainIs:         log.ml
-#   Install:        false
-#   BuildDepends:   libsvm,gsl,gnuplot
-#   CompiledObject: byte
+Executable log
+  Path:           examples
+  MainIs:         log.ml
+  Install:        false
+  BuildDepends:   libsvm,gsl,archimedes
+  CompiledObject: native
 
 # Tests
 
 <examples/svm_cli.ml{,i}>: syntax_camlp4o
 
 # OASIS_START
-# DO NOT EDIT (digest: 9b011639adf988aec7940bd79876ae3a)
+# DO NOT EDIT (digest: 84680b9f13d00f7e7fb506f73f43a830)
 # Ignore VCS directories, you can use the same kind of rule outside 
 # OASIS_START/STOP if you want to exclude directories that contains 
 # useless stuff for the build process
 "examples/svm_cli.native": pkg_sexplib.syntax
 "examples/svm_cli.native": pkg_core
 "examples/svm_cli.native": pkg_lacaml
-<examples/*.ml{,i}>: use_svm
 <examples/*.ml{,i}>: pkg_sexplib
 <examples/*.ml{,i}>: pkg_sexplib.syntax
+# Executable log
+"examples/log.native": use_svm
+"examples/log.native": pkg_gsl
+"examples/log.native": pkg_archimedes
+"examples/log.native": pkg_core
+"examples/log.native": pkg_lacaml
+<examples/*.ml{,i}>: use_svm
+<examples/*.ml{,i}>: pkg_gsl
+<examples/*.ml{,i}>: pkg_archimedes
 <examples/*.ml{,i}>: pkg_core
 <examples/*.ml{,i}>: pkg_lacaml
 # Executable svm_test

File examples/log.ml

 open Lacaml.D
 open Libsvm
 
-(* In order to compile this program, install the additional packages:
-   1. gsl-ocaml: https://bitbucket.org/mmottl/gsl-ocaml or type 'opam install gsl-ocaml'
-   2. ocaml-gnuplot: http://sourceforge.net/projects/ocaml-gnuplot/
-*)
-module Gp = Gnuplot.Array
+module A = Archimedes
 
-let red = 0xFF0000
-let green = 0x00AA00
-let blue = 0x0000FF
+(* This program uses Support Vector Regression to approximate
+   the log function (green) from its noisy observations (red). *)
 
 let a = 0.1
-let b = 5.0
+let b = 6.0
 let n_inputs = 99
 let sigma = 0.2
 
   let targets = Vec.add (Vec.map log inputs) noise in
   Mat.from_col_vec inputs, targets
 
-let plot g ~x ~y ~color =
-  Gp.color g color;
-  Gp.xy g (Vec.to_array x) (Vec.to_array y) ~style:Gp.Points
-
 let () =
   let inputs, targets = gen_data () in
   let problem = Svm.Problem.create ~x:inputs ~y:targets in
   let model = Svm.train ~svm_type:`NU_SVR problem in
   let preds = Svm.predict model ~x:inputs in
   let inputs = Mat.as_vec inputs in
-  let g = Gp.init ~xsize:500. ~ysize:300. Gp.Wxt in
-  Gp.box g;
-  Gp.title g "log";
-  Gp.pen g 3;
-  Gp.pen_width g 2.;
-  Gp.color g green;
-  Gp.fx g log a b;
-  plot g ~x:inputs ~y:targets ~color:red;
-  plot g ~x:inputs ~y:preds ~color:blue;
-  Gp.close g
+  let p = A.init [] ~w:600. ~h:600. in
+  A.Axes.box p;
+  A.set_line_width p 2.;
+  A.set_color p A.Color.green;
+  A.fx p log a b;
+  A.set_color p A.Color.red;
+  A.Vec.xy p inputs targets;
+  A.set_color p A.Color.blue;
+  A.Vec.xy p inputs preds;
+  A.close p
 (* setup.ml generated for the first time by OASIS v0.2.0 *)
 
 (* OASIS_START *)
-(* DO NOT EDIT (digest: 66eac9efdc29568e51aacfa8c94ddf43) *)
+(* DO NOT EDIT (digest: d105e62e22b2819187c4dd60a7e3d61e) *)
 (*
    Regenerated by OASIS v0.3.0
    Visit http://oasis.forge.ocamlcore.org for more information and
                    {exec_custom = false; exec_main_is = "svm_cli.ml"; });
                Executable
                  ({
+                     cs_name = "log";
+                     cs_data = PropList.Data.create ();
+                     cs_plugin_data = [];
+                     },
+                   {
+                      bs_build = [(OASISExpr.EBool true, true)];
+                      bs_install = [(OASISExpr.EBool true, false)];
+                      bs_path = "examples";
+                      bs_compiled_object = Native;
+                      bs_build_depends =
+                        [
+                           InternalLibrary "svm";
+                           FindlibPackage ("gsl", None);
+                           FindlibPackage ("archimedes", None)
+                        ];
+                      bs_build_tools =
+                        [ExternalTool "ocamldoc"; ExternalTool "ocamlbuild"];
+                      bs_c_sources = [];
+                      bs_data_files = [];
+                      bs_ccopt = [(OASISExpr.EBool true, [])];
+                      bs_cclib = [(OASISExpr.EBool true, [])];
+                      bs_dlllib = [(OASISExpr.EBool true, [])];
+                      bs_dllpath = [(OASISExpr.EBool true, [])];
+                      bs_byteopt = [(OASISExpr.EBool true, [])];
+                      bs_nativeopt = [(OASISExpr.EBool true, [])];
+                      },
+                   {exec_custom = false; exec_main_is = "log.ml"; });
+               Executable
+                 ({
                      cs_name = "svm_test";
                      cs_data = PropList.Data.create ();
                      cs_plugin_data = [];
           };
      oasis_fn = Some "_oasis";
      oasis_version = "0.3.0";
-     oasis_digest = Some "1oY\187\132\137\169HT\211\247\235\246w%\227";
+     oasis_digest = Some "\145E\240\n\131v3E2\159\210\168;\229\141\237";
      oasis_exec = None;
      oasis_setup_args = [];
      setup_update = false;
 
 let setup () = BaseSetup.setup setup_t;;
 
-# 6006 "setup.ml"
+# 6035 "setup.ml"
 (* OASIS_STOP *)
 let () = setup ();;