diff options
| author | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2010-11-14 17:15:48 +0000 | 
|---|---|---|
| committer | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2010-11-14 17:15:48 +0000 | 
| commit | d9f662d8857c1ae15d72d6212b616a10a5181f67 (patch) | |
| tree | 5a5e64e12c553d85a251c992ea1cdcbd89503f4c | |
| parent | cfcf2b9fc6b091c6db0997c2dea45b701955a696 (diff) | |
| download | opt-utilities-d9f662d8857c1ae15d72d6212b616a10a5181f67.tar.bz2 | |
git-svn-id: file:///home/svn/opt_utilities@143 ed2142bd-67ad-457f-ba7c-d818d4011675
| -rw-r--r-- | distributions/uniformed.hpp | 58 | ||||
| -rw-r--r-- | test/makefile | 2 | ||||
| -rw-r--r-- | test/many_dims.cpp | 18 | 
3 files changed, 76 insertions, 2 deletions
| diff --git a/distributions/uniformed.hpp b/distributions/uniformed.hpp new file mode 100644 index 0000000..ccafd01 --- /dev/null +++ b/distributions/uniformed.hpp @@ -0,0 +1,58 @@ +#ifndef UNIFORMED_MODEL_H_ +#define UNIFORMED_MODEL_H_ +#define OPT_HEADER +#include <core/fitter.hpp> +#include <cmath> +#include <misc/optvec.hpp> + +namespace opt_utilities +{ +  template <typename T> +  class uniformed +    :public model<optvec<T>,optvec<T>,optvec<T>,std::string> +  { +  private: +    uniformed* do_clone()const +    { +      return new uniformed<T>(*this); +    } + +    const char* do_get_type_name()const +    { +      return "1d normed gaussian"; +    } +  public: +    uniformed() +    { +      this->push_param_info(param_info<optvec<T> >("a",0.)); +      this->push_param_info(param_info<optvec<T> >("b",1.)); +    } + +     +  public: +    optvec<T> do_eval(const optvec<T>& x,const optvec<T>& param) +    { +      T a=get_element(param,0); +      T b=get_element(param,1); +      optvec<T> y; +      resize(y,get_size(x)); +      for(int i=0;i<get_size(x);++i) +	{ +	  T v=get_element(x,i); +	  set_element(y,i,(v-a)*(v-b)<0?1/abs(b-a):0); +	} +      return y; +    } + +  private: +    std::string do_get_information()const +    { +      return ""; +    } +  }; +} + + + +#endif +//EOF diff --git a/test/makefile b/test/makefile index 761475c..bebfc9c 100644 --- a/test/makefile +++ b/test/makefile @@ -6,7 +6,7 @@ test_optimizer:test_optimizer.cpp  	$(CXX) $< -o $@ -I .. -O3 -g  many_dims:many_dims.cpp -	$(CXX) $< -o $@ -I .. -O3 -g +	$(CXX) $< -o $@ -I .. -O3 -g -p  test_fitter:test_fitter.cpp  	$(CXX) $< -o $@ -I .. -O3 -g diff --git a/test/many_dims.cpp b/test/many_dims.cpp index a09e358..a142628 100644 --- a/test/many_dims.cpp +++ b/test/many_dims.cpp @@ -15,13 +15,28 @@ using namespace std;  class foo1    :public func_obj<double,vector<double> >  { +  long long n_eval; +public: +  foo1() +    :n_eval(0) +  { +  } + +  ~foo1() +  { +    cerr<<n_eval<<" evaluations done"<<endl; +  } +    foo1* do_clone()const    {      return new foo1(*this);    } +   +      double do_eval(const vector<double>& p)    { +    ++n_eval;      double result=0;      for(int i=0;i!=p.size();++i)        { @@ -123,7 +138,7 @@ class foo5  void test_opt(const func_obj<double,vector<double> >& fo,  	      const opt_method<double,vector<double> >& optm)  { -  const int problem_size=500000; +  const int problem_size=100000;    optimizer<double,vector<double> > opt;    opt.set_func_obj(fo); @@ -170,6 +185,7 @@ int main()    //powell_method<double,vector<double> > agam;    //aga_method<double,vector<double> > agam(100,50);    test_opt(foo1(),agam); +  //  test_opt(foo1(),agam);    //  test_opt(foo2(),agam);    //test_opt(foo3(),agam);    //test_opt(foo4(),agam); | 
