package agents.anac.y2015.Phoenix.GP;/* This file is part of the jgpml Project. * http://github.com/renzodenardi/jgpml * * Copyright (c) 2011 Renzo De Nardi and Hugo Gravato-Marques * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ import agents.Jama.Matrix; /** * Neural network covariance function with a single parameter for the distance * measure. The covariance function is parameterized as: *

* k(x^p,x^q) = sf2 * asin(x^p'*P*x^q / sqrt[(1+x^p'*P*x^p)*(1+x^q'*P*x^q)]) *

* where the x^p and x^q vectors on the right hand side have an added extra bias * entry with unit value. P is ell^-2 times the unit matrix and sf2 controls the * signal variance. The hyperparameters are: *

* [ log(ell) * log(sqrt(sf2) ] */ public class CovNNone implements CovarianceFunction{ double[][] k; double[][] q; public CovNNone(){} /** * Returns the number of hyperparameters of thisPhoenixAlpha.CovarianceFunction * * @return number of hyperparameters */ public int numParameters() { return 2; } /** * Compute covariance matrix of a dataset X * * @param loghyper column Matrix of hyperparameters * @param X input dataset * @return K covariance Matrix */ public Matrix compute(Matrix loghyper, Matrix X) { if(loghyper.getColumnDimension()!=1 || loghyper.getRowDimension()!=numParameters()) throw new IllegalArgumentException("Wrong number of hyperparameters, "+loghyper.getRowDimension()+" instead of "+numParameters()); final double ell = Math.exp(loghyper.get(0,0)); final double em2 = 1/(ell*ell); final double oneplusem2 = 1+em2; final double sf2 = Math.exp(2*loghyper.get(1,0)); final int m = X.getRowDimension(); final int n = X.getColumnDimension(); double[][] x= X.getArray(); // Matrix Xc= X.times(1/ell); // // Q = Xc.times(Xc.transpose()); // System.out.print("Q=");Q.print(Q.getColumnDimension(), 8); // Q = new Matrix(m,m); // double[][] q = Q.getArray(); q = new double[m][m]; for(int i=0;iMatrix of hyperparameters * @param X input dataset * @param Xstar test set * @return [K(Xstar,Xstar) K(X,Xstar)] */ public Matrix[] compute(Matrix loghyper, Matrix X, Matrix Xstar) { if(loghyper.getColumnDimension()!=1 || loghyper.getRowDimension()!=numParameters()) throw new IllegalArgumentException("Wrong number of hyperparameters, "+loghyper.getRowDimension()+" instead of "+numParameters()); final double ell = Math.exp(loghyper.get(0,0)); final double em2 = 1/(ell*ell); final double oneplusem2 = 1+em2; final double sf2 = Math.exp(2*loghyper.get(1,0)); final int m = X.getRowDimension(); final int n = X.getColumnDimension(); double[][] x= X.getArray(); final int mstar = Xstar.getRowDimension(); final int nstar = Xstar.getColumnDimension(); double[][] xstar= Xstar.getArray(); double[] sumxstardotTimesxstar = new double[mstar]; for(int i=0; iPhoenixAlpha.CovarianceFunction with respect * to the hyperparameter with index idx * * @param loghyper hyperparameters * @param X input dataset * @param index hyperparameter index * @return Matrix of derivatives */ public Matrix computeDerivatives(Matrix loghyper, Matrix X, int index) { if(loghyper.getColumnDimension()!=1 || loghyper.getRowDimension()!=numParameters()) throw new IllegalArgumentException("Wrong number of hyperparameters, "+loghyper.getRowDimension()+" instead of "+numParameters()); if(index>numParameters()-1) throw new IllegalArgumentException("Wrong hyperparameters index "+index+" it should be smaller or equal to "+(numParameters()-1)); final double ell = Math.exp(loghyper.get(0,0)); final double em2 = 1/(ell*ell); final double oneplusem2 = 1+em2; final double twosf2 = 2*Math.exp(2*loghyper.get(1,0)); final int m = X.getRowDimension(); final int n = X.getColumnDimension(); double[][] x= X.getArray(); // Matrix X = XX.times(1/ell); if(q==null || q.length!=m || q[0].length!=m) { q = new double[m][m]; for(int i=0;i