~swaits/differential-evolution

c194ae5fc5fb8b78d954c9fa85ab228d63b13676 — swaits 17 years ago 3f5fdb3
made random seed off clock.  other minor tweaks to polynomial problem.
3 files changed, 10 insertions(+), 3 deletions(-)

M derand.h
M derand.inl
M polyapprox.cpp
M derand.h => derand.h +2 -0
@@ 12,6 12,8 @@ namespace DE
	class Random
	{
	public:

		Random();
	
		void Seed(u32 seed);
		

M derand.inl => derand.inl +5 -0
@@ 1,11 1,16 @@
#ifndef __derand_inl__
#define __derand_inl__

#include <ctime>

#if !(defined(__derand_h__))
#	 error "derand.inl should only be included by derand.h"
#endif

inline DE::Random::Random()
{
	Seed(static_cast<u32>(clock()));
}

inline void DE::Random::Seed(u32 seed)
{

M polyapprox.cpp => polyapprox.cpp +3 -3
@@ 4,7 4,7 @@
#include "de.h"

// the order of the polynomial (actually the number of coefficients, i.e. 1 = constant, 2 = line, etc.)
#define NUM_COEFFICIENTS 6
#define NUM_COEFFICIENTS 8

// the function we're searching for
double TargetFunction(double x)


@@ 45,7 45,7 @@ class PolySearch: public DE::Engine<NUM_COEFFICIENTS>
			unsigned int test_count = 0;

			// accumulate squared error
			for ( double i=-7.9287;i<=7.9287;i+=0.001 )
			for ( double i=-1.25;i<=1.25;i+=0.001 )
			{
				// test
				double test   = CalculatePolynomial(i,NUM_COEFFICIENTS,testcase);


@@ 86,7 86,7 @@ int main()
	de.Reset();

	// run the DE
	de.Solve(1000);
	de.Solve(1500);

	// output winner in polynomial form
	printf("Best Polynomial Found\n=====================\ny =");