Markus Mottl avatar Markus Mottl committed c8c679d

Added testing for derivatives of inducing points

Comments (0)

Files changed (1)

 open Test_kernels.SE_iso
 open Gen_data
 
+(*
 let main () =
   let sigma2 = noise_sigma2 in
 
-  let epsilon = 10e-6 in
+  let epsilon = 1e-6 in
 
   let module Eval = FITC.Eval in
   let module Deriv = FITC.Deriv in
   printf "log evidence: %f\n%!" f1;
   printf "dlog_evidence: %f\n%!" deriv;
   printf "dfinite:   %f\n%!" ((f2 -. f1) /. epsilon)
+*)
+
+let main () =
+  Lacaml.Io.Context.set_dim_defaults (Some (Context.create 5));
+
+  let sigma2 = noise_sigma2 in
+
+  let epsilon = 1e-6 in
+
+  let module Eval = FITC.Eval in
+  let module Deriv = FITC.Deriv in
+
+  Utils.print_mat "inducing_inputs" inducing_inputs;
+  let run () =
+    let eval_prep_inducing = Eval.Inducing.Prepared.calc inducing_inputs in
+    let deriv_prep_inducing = Deriv.Inducing.Prepared.calc eval_prep_inducing in
+    let inducing = Deriv.Inducing.calc kernel deriv_prep_inducing in
+    let eval_prep_inputs =
+      Eval.Inputs.Prepared.calc eval_prep_inducing training_inputs
+    in
+    let deriv_prep_inputs =
+      Deriv.Inputs.Prepared.calc deriv_prep_inducing eval_prep_inputs
+    in
+    let inputs = Deriv.Inputs.calc inducing deriv_prep_inputs in
+    let model = Deriv.Model.calc ~sigma2 inputs in
+
+    let hyper_model = Deriv.Model.prepare_hyper model in
+    let mev, _model_log_evidence =
+      Deriv.Model.calc_log_evidence hyper_model (`Inducing_hyper {
+        Cov_se_iso.ind = 3; dim = 1 })
+    in
+
+    let mf = Eval.Model.calc_log_evidence (Deriv.Model.calc_eval model) in
+    mev, mf
+  in
+
+  let mev, mf1 = run () in
+  inducing_inputs.{1, 3} <- inducing_inputs.{1, 3} +. epsilon;
+  let _, mf2 = run () in
+
+  printf "mdlog_evidence: %f\n%!" mev;
+  printf "mdfinite:   %f\n%!" ((mf2 -. mf1) /. epsilon)
 
 let () = main ()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.