Пример #1
0
//double ** glassDynamics (const double * initialConditions, const int numNodes, const int dataPoints, const double stepSize, const double * thresholds, const	double * alphas, int (* discreteMapping) (const int, const int *), int (*Heaviside) (const int, const double *, const double *)) {
//void glassDynamics (const double * initialConditions, const int numNodes, const int dataPoints, const double stepSize, const double * thresholds, const	double * alphas, int (* discreteMapping) (const int, const int *), int (*Heaviside) (const int, const double *, const double *), double ** cS ) {
void glassDynamics
(const double * initialConditions, const int numNodes, const int dataPoints, const double stepSize, 
 const double * thresholds, const double * alphas, int (* discreteMapping) (const int, const int *),
 int nodeToTrack, double * cand)
{	
	double cS[2][numNodes];
	int dS[2][numNodes]; 
	
	// Copy the initial conditions 
	for (int i = 0; i < numNodes; i++) {
		cS[0][i] = initialConditions[i];
	}
	// Set the initial condition as the first point of the candidate 'cand'
	if (nodeToTrack > numNodes) {
		fprintf(stderr, "Invalid node to track. Aborting\n");
		exit(EXIT_FAILURE);
	}
	cand[0] = initialConditions[nodeToTrack];
	
	// Use Eulers method to solve the equations
	int t = 1; 
	
	while (t < dataPoints) {
		// Calcular la discretización de las variables continuas
		for (int i = 0; i < numNodes; i++) {
			dS[0][i] = Heaviside(i, cS[0], thresholds);
		}
		// Una vez discretizado, calcular el mapeo discreto.
		// Este valor es el que se usa para calcular la dinámica de Glass al tiempo t
		for (int i = 0; i < numNodes; i++) {
			dS[1][i] = discreteMapping(i,dS[0]);
		}
		// Resolver el sistema de ecuaciones diferenciales con el método de Euler simple
		for (int i = 0; i < numNodes; i++) {
			cS[1][i] = cS[0][i] + (alphas[i] * (dS[1][i] - cS[0][i]) * stepSize);
		}
		// Update the system
		cand[t] = cS[1][nodeToTrack];
		for (int i = 0; i < numNodes; i++) {
			cS[0][i] = cS[1][i];
		}
		t++;
	}
}
Пример #2
0
void fullGlassDynamics (const double * initialConditions, const int numNodes, const int dataPoints, const double stepSize, const double * thresholds, const	double * alphas, int (* discreteMapping) (const int, const int *), double *dyn) {	
	double cS[2][numNodes];
	int dS[2][numNodes]; 
	
	// Copy the initial conditions 
	for (int i = 0; i < numNodes; i++) {
		dyn[i] = initialConditions[i];
		cS[0][i] = initialConditions[i];
	}
		
	// Use Eulers method to solve the equations
	int t = 1, t2 = numNodes; 
	
	while (t < dataPoints) {
		// Calcular la discretización de las variables continuas
		for (int i = 0; i < numNodes; i++) {
			//dS[t-1][i] = Heaviside(i, cS[t-1], thresholds);
			dS[0][i] = Heaviside(i, cS[0], thresholds);
		}
		// Una vez discretizado, calcular el mapeo discreto.
		// Este valor es el que se usa para calcular la dinámica de Glass al tiempo t
		for (int i = 0; i < numNodes; i++) {
			dS[1][i] = discreteMapping(i, dS[0]);
		}
		// Resolver el sistema de ecuaciones diferenciales con el método de Euler simple
		for (int i = 0; i < numNodes; i++) {
			cS[1][i] = cS[0][i] + (alphas[i] * (dS[1][i] - cS[0][i]) * stepSize);
		}
		// Update the system
		for (int i = 0; i < numNodes; i++) {
			dyn[t2+i] = cS[1][i];
			cS[0][i] = cS[1][i];
		}
		t++;
		t2 += numNodes;
	}
}
Пример #3
0
Hashing_Result* HashingHist(PCANet* PcaNet, vector<int>& ImgIdx, vector<cv::Mat>& Imgs){
	Hashing_Result* ha_result = new Hashing_Result;

	int length = Imgs.size();
	int NumFilters =  PcaNet->NumFilters[PcaNet->NumStages - 1];
	int NumImgin0 = length / NumFilters;

	cv::Mat T;
	int row = Imgs[0].rows;
	int col = Imgs[0].cols;
	int depth = Imgs[0].depth();

	vector<double> map_weights;
	cv::Mat temp;
	for(int i=NumFilters - 1; i>=0; i--)
		map_weights.push_back(pow(2.0, (double)i));

	vector<int> Ro_BlockSize;
	double rate = 1 - PcaNet->BlkOverLapRatio;
	for(int i=0 ;i<PcaNet->HistBlockSize.size(); i++)
		Ro_BlockSize.push_back(round(PcaNet->HistBlockSize[i] * rate));
	
	
	cv::Mat BHist;

	int ImgIdx_length = ImgIdx.size();
	int* new_idx = new int[ImgIdx_length];
	for(int i=0; i<ImgIdx_length; i++)
		new_idx[ImgIdx[i]] = i;

	for(int i=0; i<NumImgin0; i++){
		T = cv::Mat::zeros(row, col, depth);	


		for(int j=0; j<NumFilters; j++){
			temp = Heaviside(Imgs[NumFilters * new_idx[i] + j]);
			temp = temp * map_weights[j];
			T = T + temp;
		}
		
		temp = im2col_general(T, PcaNet->HistBlockSize, Ro_BlockSize); 
		temp = Hist(temp, (int)(pow(2.0, NumFilters)) - 1);

		temp = bsxfun_times(temp, NumFilters);

		if(i == 0) BHist = temp;
		else hconcat(BHist, temp, BHist);
	}
	
	int rows = BHist.rows;
	int cols = BHist.cols;

	ha_result->Features.create(1, rows * cols, BHist.type()); 

	double *p_Fe = ha_result->Features.ptr<double>(0);
	double *p_Hi;
	for(int i=0; i<rows; i++){
		p_Hi = BHist.ptr<double>(i);
		for(int j=0; j<cols; j++){
			p_Fe[j * rows + i] = p_Hi[j];
		}
	}
	return ha_result;
}