/*
  File name: xpar.h
  Created by: Ljubomir Buturovic
  Created: 03/02/2005
  Purpose: declarations for xpar.c.
*/

/*
  Copyright 2004 Ljubomir J. Buturovic

  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.
*/

#include <stdio.h>

#define XPAR_FUNC_MSG " mean error rate: "

struct xpar_crit_parameters
{
  int            normalize;  /* 1: normalize input data */
  int            method;     /* learning algorithm */
  int            dr_method;  /* dimensionality reduction method */
  int            idr;        /* dimensionality */
  int            fscrit;     /* feature subset evaluation criterion */
  int            ***fsel;    /* optimal feature subset for a given experiment and CV subset */
                             /* e.g., fsel[2][3] is the list of optimal features for experiment 2, CV subset 3 */
  float          ****fext;   /* optimal feature mapping for a given experiment and CV subset */
                             /* e.g., fext[2][3] is the optimal mapping constructed in experiment 2, CV subset 3 */
  int            nmodels;    /* number of models for bagging/Adaboost methods */
  int            vid;        /* vertex ID */
  int            nexp;       /* number of experiments */
  int            nxval;      /* number of cross-validation subsets */
  float          eval;       /* the lowest function value so far */
  float          x1;         /* the arguments for which the value is achieved */
  float          x2;
  void           *options;   /* algorithm-specific parameters */
  struct dataset *dset;      /* the training set */
  unsigned int   seed;
  FILE           *outdev;    /* destination for output messages */
  FILE           *fdbg;      /* destination for debug messages */
};

/*
  Log cross-validation subset generated in experiment `ex',
  cross-validation subset `xval_idx'.

  The subsets generated by x_fsel() and xpar_func() must be identical.
*/
void log_subset(FILE *fdbg, char *func, struct dataset *learning_dset, int ex, int xval_idx);

/*
  Compute value of xpar() criterion function. xpar() is a wrapper
  around xlearn(), which computes cross-validation error rate for a
  given dimension reduction/classifier combination.

  xpar_func() uses rand() to partition input dataset into learning and
  validation subsets for cross-validation. The pseudo-random number
  generator is initialized using srand(parameters->seed) function
  call. Therefore, to reproduce the results for a given dataset, you
  need to give the same parameters->seed value.

  In case of error, set 'errc'. The errors are malloc() and xlearn()
  errors.
*/
float xpar_func(float *fvec, int n, int iteration, void *parameters, int *errc);

int xtest_optimal_malloc(float **tds_x, int tds_nv, int d, float **teds_x, 
			 int teds_nv, float ***x, float ***y, float **xmean,
			 float **std);

int ***fsel_free(int ***fsel, int nexp, int nxval);

void xpar_free(struct xpar_crit_parameters *xpar_parameters);

/*
  Compute optimal feature transformations/subsets for all experiments
  and all cross-validation subsets. We do it once at the beggining of
  the simplex/grid search, and subsequently just reuse the results.
*/
int compute_dr(struct xpar_crit_parameters *xpar_parameters, int dr_method, int idr, 
	       int fscrit, FILE *fdbg, int *errc);

/*
  Apply optimal parameters to test data set, display and save results.

  In case of success, set *errc to 0, otherwise set it to the error
  code.
*/
void xtest_optimal(struct xpar_crit_parameters *xpar_parameters, int *errc, char **xname);

/*
  Input model selection parameters common to all algorithms.
*/
void input_xpar(struct dataset *dset, struct xpar_crit_parameters *xpar_parameters);

/*
  Read MLP-specific model selection parameters.
*/
void input_xpar_mlp(int *nhl, int *nhh, int *hstep, int *nitl, int *nith, int *itstep);

/*
  Read k-NN-specific model selection parameters.
*/
void input_xpar_knn(struct dataset *dset, int nxval, int *kmin, int *kmax, int *kstep);

/*
  Create `xpar_crit_parameters' structure for `method'.
*/
struct xpar_crit_parameters *init_spar(int method, struct dataset *dset, FILE *fdbg);


syntax highlighted by Code2HTML, v. 0.9.1