Ejemplo n.º 1
0
int main()
{
    std::fstream blueTooth("/dev/rfcomm0");
    std::size_t direction = 0;

    std::thread back_ground(navigation::play, &direction);

    navigation::Queue data(5);
    std::string raw_data;
    while(blueTooth >> raw_data)
    {
        navigation::sample smp(raw_data);
        data << smp.result();

        direction = data.suggest();

        std::cout   << "\nraw : "
                    << "\033[1;31m"
                    <<raw_data
                    << "\033[0m\n";

        std::cout   << "smp : "
                    << "\033[1;33m"
                    << smp.result()
                    << "\033[0m\n";

        std::cout   << "direction suggest: "
                    << "\033[1;32m"
                    << data.suggest()
                    << "\033[0m\n";
    }

    back_ground.join();
}
Ejemplo n.º 2
0
void HenleyTest::TwoIdenticalComponentsThreeStates(double mean, double cov, double muTime)
	{
		JaggedMatrix *jm = 
			new JaggedMatrix(3);

		jm->AddDistribution(0,1, muTime, 1.0, DistributionFactory::Weibull);
		jm->AddDistribution(0,1, muTime, 1.0, DistributionFactory::Weibull);
		jm->AddDistribution(1,0, mean, cov, DistributionFactory::Weibull);

		jm->AddDistribution(1,2, muTime, 1.0, DistributionFactory::Weibull);
		jm->AddDistribution(2,1, mean, cov, DistributionFactory::Weibull);

		jm->Display();
		

		SemiMarkovModel smp(jm);
		smp.SetModelInput(_missionTime, _NSteps);

		smp.IntegralSystemEquations("HenleyTest\\matlab\\ThreeStatesEqn.txt");

		smp.RegisterHandlers(NULL, NULL);
		smp.SetupMatrices();
		smp.ComputeStateProbabilities();

		_phi = smp.GetStateProbability(-1,0);
		_time = smp.GetTimeVector();

		TestResults sysresults("HenleyTest\\matlab\\IdenticalExpExpSystem.dat");
		sysresults.AddResult(_time);
		sysresults.AddResult(_phi);
		sysresults.Serialize();


	}
Ejemplo n.º 3
0
int main()
{
    dap::Samples<int> smp(16);
    dap::Handler<int> handler(smp);

    for(unsigned i = 0; i != smp.size(); ++i)
        smp << i*2;
    handler.refresh();

    std::cout << handler.get_average()  << std::endl;
    std::cout << handler.get_variance() << std::endl;
    std::cout << handler.get_steady_level()  << std::endl;

    return 0;
}
Ejemplo n.º 4
0
ObjectSettings
AmbientSound::get_settings() {
  new_size.x = bbox.get_width();
  new_size.y = bbox.get_height();
  ObjectSettings result = MovingObject::get_settings();

  ObjectOption smp(MN_FILE, _("Sound"), &sample, "sample");
  smp.select.push_back(".wav");
  smp.select.push_back(".ogg");
  result.options.push_back(smp);
  result.options.push_back( ObjectOption(MN_NUMFIELD, _("Width"), &new_size.x, "width"));
  result.options.push_back( ObjectOption(MN_NUMFIELD, _("Height"), &new_size.y, "height"));
  result.options.push_back( ObjectOption(MN_NUMFIELD, _("Distance factor"), &distance_factor, "distance_factor"));
  result.options.push_back( ObjectOption(MN_NUMFIELD, _("Distance bias"), &distance_bias, "distance_bias"));
  result.options.push_back( ObjectOption(MN_NUMFIELD, _("Volume"), &maximumvolume, "volume"));
  return result;
}
Ejemplo n.º 5
0
int main()
{
    // get and attach shared memory for 100 ints:
    std::shared_ptr<int> smp(getSharedIntMemory(100));
    
    // init the shared memory
    for (int i=0; i<100; ++i) {
        smp.get()[i] = i*42;
    }

    // deal with shared memory somewhere else:
    //...
    std::cout << "<return>" << std::endl;
    std::cin.get(); 

    // release shared memory here:
    smp.reset();
    //...
}
Ejemplo n.º 6
0
void dilate(const imageb* input, imageb* output, const imageb* kernel, int centerx, int centery) {
	const int kw = kernel->getWidth();
	const int kh = kernel->getHeight();
	const int iw = input->getWidth();
	const int ih = input->getHeight();
	NearestNeighborSampler<bool> smp(input, EDGE_ZERO);
	// loop image
	#pragma omp parallel for
	for (int j = 0; j < ih; j++) {
		for (int i = 0; i < iw; i++) {
			// loop kernel
			bool sum = false; // reduction init
			for (int y = 0; y < kh; y++) {
				for (int x = 0; x < kw; x++) {
					sum = sum || (smp.get(i - centerx + x, j - centery + y) && kernel->get(x, y));
				}
			}
			output->set(i, j, sum);
		}
	}
}
Ejemplo n.º 7
0
void convolve(const imagev3* input, imagev3* output, const imagev3* kernel) {
	const int kw = kernel->getWidth();
	const int kh = kernel->getHeight();
	const int iw = input->getWidth();
	const int ih = input->getHeight();
	NearestNeighborSampler<la::v3> smp(input, EDGE_CLAMP);
	// loop image
	#pragma omp parallel for
	for (int j = 0; j < ih; j++) {
		for (int i = 0; i < iw; i++) {
			// loop kernel
			la::v3 sum;
			for (int y = 0; y < kh; y++) {
				for (int x = 0; x < kw; x++) {
					sum += smp.get(i - kw / 2 + x, j - kh / 2 + y) * kernel->get(x, y);
				}
			}
			output->set(i, j, sum);
		}
	}
}
Ejemplo n.º 8
0
	typename std::remove_reference<P>::type 
	optimize_NM(F&& func, P const& initial, C config) {
		typedef typename std::remove_reference<P>::type point_type;
		
		simplex<point_type> smp(func, initial, 0.05);

		double const alpha = config.reflection_coeff();
		double const beta  = config.expansion_coeff();
		double const gamma = config.contraction_coeff();
		double const delta = config.reduction_coeff();
	
		P xr = initial.copy();
		P xe = initial.copy();
		P xc = initial.copy();

		size_t iter = 0;
		while (iter++ < config.num_iterations()) {
			// Step 1: "sorting" and centroid comptation
			smp.update();

			if (smp.get_point_spreading() < 1.e-12) 
				break;

			auto const& x0 = smp.centroid();
			auto& p2 = smp.template get_reference<2>();
			auto& p1 = smp.template get_reference<1>();
			auto& p0 = smp.template get_reference<0>();

			// Reflection step
			xr = x0 + alpha * (x0 - p2.point);
			double const fr = func(xr);

			if ((p0.value <= fr) && (fr <= p1.value)) {
				copy(p2.point, xr);
				p2.value = fr;
				continue;
			}


			// Expansion step
			if (fr < p0.value) {
				xe = x0 + beta * (xr - x0);
				double const fe = func(xe);
				if (fe < fr) {
					copy(p2.point, xe);
					p2.value = fe;
				} else {
					copy(p2.point, xr);
					p2.value = fr;
				}
				continue;
			}

			// Contraction step
			xc = (fr < p2.value) 
				? x0 + gamma * (xr - x0)
				: x0 + gamma * (p2.point - x0);
			double const fc = func(xc);
			if (fc < fr) {
				copy(p2.point, xc);
				p2.value = fc;
				continue;
			}

			// Reduction step
			for (size_t i = 0; i < smp.size(); ++i) {
				auto& pt = smp[i];
				if (&pt != &p0) {
					pt.point = pt.point + delta * (pt.point - p0.point);
					pt.value = func(pt.point);
				}
			}
		}

		return smp.centroid().copy();
	}