123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133(* File: cov_const.ml
OCaml-GPR - Gaussian Processes for OCaml
Copyright (C) 2009- Markus Mottl
email: markus.mottl@gmail.com
WWW: http://www.ocaml.info
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*)openCoreopenLacaml.DmoduleParams=structtypet={log_theta:float}endmoduleEval=structmoduleKernel=structtypeparams=Params.ttypet={params:params;const:float}letcreateparams={params;const=exp(-2.*.params.Params.log_theta)}letget_paramsk=k.paramsendmoduleInducing=structtypet=intletcalc_upperkm=Mat.makemmk.Kernel.constletget_n_pointsm=mendmoduleInput=structtypet=unitletevalk()m=Vec.makemk.Kernel.constletweighted_evalk()_~coeffs=k.Kernel.const*.Vec.sumcoeffsleteval_onek()=k.Kernel.constendmoduleInputs=structtypet=intletcreate=Array.lengthletget_n_pointsn=nletchoose_subset_inputsindexes=Bigarray.Array1.dimindexesletcreate_inducing_kerneln=nletcreate_default_kernel_params_inputs~n_inducing:_={Params.log_theta=0.}letcalc_upper=Inducing.calc_upperletcalc_diagkn=Vec.makenk.Kernel.constletcalc_crossk~inputs:n~inducing:m=Mat.makenmk.Kernel.constletweighted_evalk~inputs:_~inducing:_~coeffs=letres=copycoeffsinscalk.Kernel.constres;resendendmoduleDeriv=structmoduleEval=EvalmoduleHyper=structtypet=[`Log_theta]letget_all_kernel_inducing_inputs=[|`Log_theta|]letget_value{Eval.Kernel.params}_inducing_inputs=function|`Log_theta->params.Params.log_thetaletset_valueskernelinducinginputshypersvalues=let{Eval.Kernel.params}=kernelinletlog_theta_ref=refparams.Params.log_thetainletkernel_changed_ref=reffalseinfori=1toArray.lengthhypersdomatchhypers.(i-1)with|`Log_theta->log_theta_ref:=values.{i};kernel_changed_ref:=truedone;letnew_kernel=if!kernel_changed_refthenEval.Kernel.create{Params.log_theta=!log_theta_ref}elsekernelinnew_kernel,inducing,inputsendletcalc_const_derivk=-2.*.k.Eval.Kernel.constmoduleInducing=structtypeupper={m:int;deriv_const:float}letcalc_shared_upperkm=Eval.Inducing.calc_upperkm,{m;deriv_const=calc_const_derivk}letcalc_deriv_uppershared`Log_theta=`Constshared.deriv_constendmoduleInputs=structtypediag={diag_eval_inputs:Eval.Inputs.t;diag_const_deriv:float}typecross={cross_const_deriv:float}letcalc_shared_diagkdiag_eval_inputs=(Eval.Inputs.calc_diagkdiag_eval_inputs,{diag_eval_inputs;diag_const_deriv=calc_const_derivk})letcalc_shared_crossk~inputs~inducing=(Eval.Inputs.calc_crossk~inputs~inducing,{cross_const_deriv=calc_const_derivk})letcalc_deriv_diagdiag`Log_theta=`Constdiag.diag_const_derivletcalc_deriv_crosscross`Log_theta=`Constcross.cross_const_derivendend