123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139(* File: cov_lin_one.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=matletget_n_points=Mat.dim2letcalc_upper{Kernel.const=alpha}inducing=letm=Mat.dim2inducinginsyrk~alpha~trans:`Tinducing~beta:1.~c:(Mat.makemmalpha)endmoduleInput=structtypet=vecleteval{Kernel.const=alpha}inputinducing=gemv~alpha~trans:`Tinducinginput~beta:1.~y:(Vec.make(Mat.dim2inducing)alpha)letweighted_evalkinputinducing~coeffs=dotcoeffs(evalkinputinducing)leteval_onekinput=k.Kernel.const*.(Vec.sqr_nrm2input+.1.)endmoduleInputs=structtypet=matletcreate=Mat.of_col_vecsletget_n_points=Mat.dim2letchoose_subsetinputsindexes=Utils.choose_colsinputsindexesletcreate_inducing_kernelinputs=inputsletcreate_default_kernel_params_inputs~n_inducing:_={Params.log_theta=0.}letcalc_upper=Inducing.calc_upperletcalc_diag{Kernel.const=alpha}inputs=Mat.syrk_diag~alpha~trans:`Tinputs~beta:1.~y:(Vec.make(Mat.dim2inputs)alpha)letcalc_cross{Kernel.const=alpha}~inputs~inducing=letm=Mat.dim2inducinginletn=Mat.dim2inputsingemm~alpha~transa:`Tinputsinducing~beta:1.~c:(Mat.makenmalpha)letweighted_evalk~inputs~inducing~coeffs=gemv(calc_crossk~inputs~inducing)coeffsendendmoduleDeriv=structmoduleEval=EvalmoduleHyper=structtypet=[`Log_theta]letget_all_kernel_inducing_inputs=[|`Log_theta|]letget_value{Eval.Kernel.params=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_deriv_common()`Log_theta=`Factor~-.2.moduleInducing=structtypeupper=unitletcalc_shared_upperkinducing=Eval.Inducing.calc_upperkinducing,()letcalc_deriv_upper=calc_deriv_commonendmoduleInputs=structtypediag=unittypecross=unitletcalc_shared_diagkdiag_eval_inputs=Eval.Inputs.calc_diagkdiag_eval_inputs,()letcalc_shared_crossk~inputs~inducing=Eval.Inputs.calc_crossk~inputs~inducing,()letcalc_deriv_diag=calc_deriv_commonletcalc_deriv_cross=calc_deriv_commonendend