/*****************************************************************************
 This code is available for academic use
 under the LESSER GENERAL PUBLIC LICENSE 

 Weight Perturbation: enhancing local search strategies
 by perturbing the weights of training instances.
 Copyright (C) 2002  Gal Elidan, Matan Ninio, Nir Friedman and Dale Schuurmans

 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 Please cite using this refrence:
 
@incollection{Elidan+al:2002,
   author = "Gal Elidan and Matan Ninio and Nir Friedman and Dale Schuurmans",
   booktitle = "Proc. National Conference on Artificial Intelligence (AAAI-02)",
   pages = "132-139",
   year = "2002",
   title = "Data Perturbation for Escaping Local Maxima in Learning",
 }
 
 You can contact the authors at annealing@cs.huji.ac.il
 
*****************************************************************************/


#include <vector>
#include "testCommon.h"
#include "RandomProb.h"
#include <math.h>
#include <iostream>
#include <iomanip>

#define SIN_NUM 20
#define TINY 10e-7

/** This demo demonstrates gradient ascent for
    a 20 component sinc function. The function is

            sum(w(i)*cos*(pi*i*x/20)

    where i=1..20 and x is the current hypothesis
 */

int
main( int argc, char *argv[] )
{
  // initialize
  double x = 0.0;
  _RandomProbGenerator.Initialize(time(NULL));
  x = 0-_RandomProbGenerator.RandomDouble(SIN_NUM*2.0);
  vector<double> weights(SIN_NUM,1.0/SIN_NUM);

  cout.precision(3);
  cout.setf(ios::fixed, ios::floatfield );
  cout << "Starting at " << x << endl;

  double newx = sinc_func_max(weights,x);
  cout << "X="<< newx << " Y=" <<sinc_func(weights,newx)  << endl;
  x = newx;
  cout << endl << "Finished with X=" << x << " Y=" << sinc_func(weights,x) << endl;
}


