function [Criterion,MSE,Comp,Model,y,total_out,w]=evaluate_model(InpPat,TarPat,Model) % [Criterion,MSE,Comp]=evaluate_model(InpPat,TarPat,Model) % % Estimates the parameters of the current model using a pseudo-inverse, and computes the BIC % % Input parameters: InpPat - Input Matrix % TarPat - Desired output vector % Model - model to be evaluated % % Output parameters: Criterion - Bayesian Information Criterion - Criterion=n_pat*ln(MSE)+Comp*ln(n_pat) % MSE - Mean-Square-Error % Comp - Complexity of the model (total number of basis functions % % Written by A. Ruano 16.6.99 % [n_pat,n_inp]=size(InpPat); n_s_b=Model.n_s_m; total_out=[]; for i=1:n_s_b Sub_model=getfield(Model,'Sub_Model',{i}); [y,out,w]=train_B_splines(InpPat(:,Sub_model.var),TarPat,Sub_model.x_min,Sub_model.x_max,... Sub_model.order,Sub_model.Knots,Sub_model.n_Knots,Sub_model.n_fun,0); [n_pat,m]=size(out); a_w(1:m,i)=ones(m,1); for j=1:m if sum(zeros(n_pat,1)-out(:,j))==0 % null column a_w(j,i)=0; else total_out=[total_out out(:,j)]; end end end w=pinv(total_out)*TarPat; y=total_out*w; pos=1; Comp=0; for i=1:n_s_b ww=zeros(length(Model.Sub_Model(i).w),1); m=length(ww); for j=1:m if a_w(j,i)==1 ww(j)=w(pos); pos=pos+1; else ww(j)=0; end end Model.Sub_Model(i).w=ww; Model.Sub_Model(i).a_w=a_w(1:m,i);; Comp=Comp+sum(a_w(1:m,i)); end MSE=(norm(TarPat-y)^2)/n_pat; Criterion=n_pat*log(MSE)+Comp*log(n_pat); Model.crit=Criterion;