Code covered by the BSD License
 GenerateNewTerm(vars, max...GenerateNewTerm.m
 HasTerm(p1, p2, newTerm, ...HasTerm.m
 PolyFitScore(polyVec, pol...PolyFitScore: scores the polynomial fit to the data based on several
 crtpolyp(PopSize, polyStr...crtpolyp: generates a new population of chromosomes made up of
 gapolyfitn(indepvar, depv...gapolyfitn: optimises the functional form of a multidimensional
 gapolyfitnresplot(ObjV,Be...gapolyfitnresplot: This function plots some results of the gapolyfitn
 generategapolyfitnoptions...generategapolyfitnoptions: generates or completes an options structure
 gfit2(t,y,gFitMeasure,opt...GFIT2 Computes goodness of fit for regression model
 isoctave()
ISOCTAVE.M
 mutatepoly(OldChrom, poly...mutatepoly (highlevel polynomial mutation function)
 mutpoly(OldChrom, polyStr...mutpoly.m
 objpolyfit(Chrom, rtn_typ...objpolyfit: This function implements the polynomial form optimisation
 objpolyfit_MCore(Chrom, r...objpolyfit_MCore: This function implements the polynomial form
 polyVec2polyfit(indepvar,...polyVec2polyfit: converts an individual polynomial form in the format
 polyfitn(indepvar,depvar,...polyfitn: fits a general polynomial regression model in n dimensions
 polyvaln(polymodel,indepvar)polyvaln: evaluates a polynomial model as a function of its variables
 randMat(a, b, method, n, ...randMat: Generates a matrix of random numbers with uniform or normal
 recombinpoly(Chrom, polyS...recombimpoly: (polynomial recombination highlevel function)
 recpoly(OldChrom, polyStr...
 gapolyfitn_example_script.mgapolyfitn example script

View all files
gapolyfitn
by
Richard Crozier
06 Oct 2009
(Updated
17 Dec 2013)
optimises the functional form of a multidimensional polynomial fit to model data

polyVec2polyfit(indepvar, depvar, polyVec)

function p = polyVec2polyfit(indepvar, depvar, polyVec)
% polyVec2polyfit: converts an individual polynomial form in the format
% used by gapolyfitn to a full regression model
%
% Input:
%
% indepvar  (n x p) array of independent variables as columns
% n is the number of data points
% p is the dimension of the independent variable space
%
% depvar  (n x 1 or 1 x n) vector  dependent variable
% length(depvar) must be n. Only 1 dependent variable is
% allowed
%
% polyVec  Individual's chromosome encoded in the same manner as in the
% Chrom matrix (see gapolyfitn help) i.e. with the following
% format:
%
% [A p11 p12 p1n A p21 p22 p2n A p31 p32 pkn ... ]
%
% Where A is a placeholder value with value 1 or 0. If 1 the
% term is active and will be used, if 0 the term is inactive
% and will not be used (it will be deleted before performing a
% regression). The p values are the powers of each variable in
% that term.
%
% e.g.
%
% A A A A
% [1 2 4 4 1 3 1 5 0 6 2 2 1 0 4 0]
%
% encodes:
%
% a1*x1^2*x2^4*x3^4 + a2*x1^3*x2*x3^5 + a3*x2^4
%
% As the third term is inactive due to a zero in the
% placeholder position (shown above) and hence is ignored.
% Terms should not be repeated to avoid least square algoithm
% being overspecified
%
% These are transformed into a fomat suitable for polyfitn to
% perform generate a regression model.
%
% Output;
%
% polymodel  A structure containing the regression model in the format
% produced by polyfitn by John D'Erico
% polymodel.ModelTerms = list of terms in the model
% polymodel.Coefficients = regression coefficients
% polymodel.ParameterVar = variances of model coefficients
% polymodel.ParameterStd = standard deviation of model
% coefficients
% polymodel.R2 = R^2 for the regression model
% polymodel.RMSE = Root mean squared error
% polymodel.VarNames = Cell array of variable names as parsed
% from a char based model specification.
%
%
% Author: Richard Crozier
% Release Date: 06 OCT 2009
%
% determine the number of independent variables
vars = size(indepvar,2);
% reshape the polynomial to conform to polyfitn specifications
polyVec = reshape(polyVec',vars+1,[])';
% find and remove empty terms
[row, col] = find(polyVec(:,1) == 0);
polyVec(row,:) = [];
% remove coefficient/placeholder values, leaving only power terms
polyVec(:,1) = [];
% If this leaves nothing, use a term made up of all zeros, i.e. a
% constant only as polyfitn does not accept empty matrices
if isempty(polyVec)
polyVec = zeros(1,vars);
end
% Evaluate the polynomials by performing a least squares fit to
% find the best possible coefficients and RMSE
p = polyfitn(indepvar,depvar,double(polyVec));
end


Contact us