Пример #1
0
void
ComputeLocalCostForNeurons(VG_RAM_WNN *vg_ram_wnn, int *query, int query_size, int *neuron_cost)
{
	int *data = vg_ram_wnn->memories;
	int data_size = vg_ram_wnn->memory_size;
	int number_of_neurons = vg_ram_wnn->number_of_neurons;
	int memory_bit_group_size = vg_ram_wnn->memory_bit_group_size;

	#pragma omp parallel default(none) \
	shared(data,query,data_size,query_size,memory_bit_group_size,number_of_neurons,neuron_cost)
	{
		for (int neuron = 0; neuron < number_of_neurons; neuron++)
		{
			//percorrer memoria do neuronio
			int *seqData = GetNeuronMemoryByNeuron(data, data_size, memory_bit_group_size, neuron);
			//percorrer amostras de testes e extrair features para memoria temporaria
			int *seqQuery = GetNeuronMemoryByNeuron(query, query_size, memory_bit_group_size, neuron);
			//calcular matriz de custo local para cada neuronio

			#pragma omp for
			for (int i = 0; i < query_size; i++)
			{
				for (int j = 0; j < data_size; j++)
				{
					int distance = HammingDistance(
							(unsigned int *)GetNeuronMemoryBySample(seqData, memory_bit_group_size, j),
							(unsigned int *)GetNeuronMemoryBySample(seqQuery, memory_bit_group_size, i),
							memory_bit_group_size);
					neuron_cost[index3D(neuron, i, j, query_size, data_size)] = distance;
				}
			}
		}
	}
}
Пример #2
0
void mexFunction(int nlhs, mxArray *plhs[], /* Output variables */ 
				 int nrhs, const mxArray *prhs[] /* Input variables */){
	
	//OUTPUT/INPUT PARAMETERS
	#define HIST_OUT plhs[0]
	#define INT_HIST_IN prhs[0]
	#define ROW_IN prhs[1]
	#define COL_IN prhs[2]
	#define BIN_IN prhs[3]
	#define X1_IN prhs[4]
	#define Y1_IN prhs[5]
	#define X2_IN prhs[6]
	#define Y2_IN prhs[7]
	
	//POINTER VARIABLES
	double *intHist, *hist;
	int i, j, k, x1, y1, x2, y2, Row, Col, Bin, histDims[3];

	//INPUT: Pointers
	intHist = mxGetPr(INT_HIST_IN); 
	Bin = (int)mxGetScalar(BIN_IN);
	Row = (int)mxGetScalar(ROW_IN);
	Col = (int)mxGetScalar(COL_IN);
	x1 = (int)mxGetScalar(X1_IN)-1;
	y1 = (int)mxGetScalar(Y1_IN)-1;
	x2 = (int)mxGetScalar(X2_IN)-1;
	y2 = (int)mxGetScalar(Y2_IN)-1;

	histDims[0] = Bin;
	histDims[1] = Bin;
	histDims[2] = Bin;
	
	//OUTPUT: Pointers
	HIST_OUT = mxCreateDoubleMatrix(Bin*Bin*Bin, 1, mxREAL);
	hist = mxGetPr(HIST_OUT);
	mxSetDimensions(HIST_OUT, histDims, 3);
	
	for(i=0; i<Bin; i++)
		for(j=0; j<Bin; j++)
			for(k=0; k<Bin; k++){
				hist[index3D(i,j,k,Bin,Bin,Bin)] = intHist[index5D(y2,x2,i,j,k,Row,Col,Bin,Bin,Bin)];
				if (y1-1 > 0) hist[index3D(i,j,k,Bin,Bin,Bin)] -= intHist[index5D(y1-1,x2,i,j,k,Row,Col,Bin,Bin,Bin)];
				if (x1-1 > 0) hist[index3D(i,j,k,Bin,Bin,Bin)] -= intHist[index5D(y2,x1-1,i,j,k,Row,Col,Bin,Bin,Bin)];
				if (y1-1 > 0 && x1-1 > 0) hist[index3D(i,j,k,Bin,Bin,Bin)] += intHist[index5D(y1-1,x1-1,i,j,k,Row,Col,Bin,Bin,Bin)];
			}
}
Пример #3
0
int run(gli::format Format, std::array<genType, 8> const & TestSamples)
{
    int Error = 0;

    gli::texture3d::extent_type const Extent(4, 4, 4);

    gli::texture3d TextureA(Format, Extent);
    TextureA.clear();
    for (std::size_t i = 0, n = 8; i < n; ++i)
        *(TextureA.data<genType>(0, 0, 1) + i) = TestSamples[i];

    gli::texture3d TextureB(Format, Extent);
    TextureB.clear();
    for (std::size_t z = 0; z < 2; ++z)
        for (std::size_t y = 0; y < 2; ++y)
            for (std::size_t x = 0; x < 2; ++x)
                TextureB.store(gli::texture3d::extent_type(x, y, z), 1, TestSamples[index3D(TextureB, 1, x, y, z)]);

    std::array<genType, 8> LoadedSamplesA;
    for (std::size_t z = 0; z < 2; ++z)
        for (std::size_t y = 0; y < 2; ++y)
            for (std::size_t x = 0; x < 2; ++x)
                LoadedSamplesA[index3D(TextureB, 1, x, y, z)] = TextureA.load<genType>(gli::texture3d::extent_type(x, y, z), 1);

    std::array<genType, 8> LoadedSamplesB;
    for (std::size_t z = 0; z < 2; ++z)
        for (std::size_t y = 0; y < 2; ++y)
            for (std::size_t x = 0; x < 2; ++x)
                LoadedSamplesB[index3D(TextureB, 1, x, y, z)] = TextureB.load<genType>(gli::texture3d::extent_type(x, y, z), 1);

    for (std::size_t i = 0, n = 8; i < n; ++i)
        Error += LoadedSamplesA[i] == TestSamples[i] ? 0 : 1;

    for (std::size_t i = 0, n = 8; i < n; ++i)
        Error += LoadedSamplesB[i] == TestSamples[i] ? 0 : 1;

    Error += TextureA == TextureB ? 0 : 1;

    gli::texture3d TextureC(TextureA, 1, 1);
    gli::texture3d TextureD(TextureB, 1, 1);

    Error += TextureC == TextureD ? 0 : 1;

    return Error;
}
Пример #4
0
void mexFunction(int nlhs, mxArray *plhs[], /* Output variables */ 
				 int nrhs, const mxArray *prhs[] /* Input variables */){
	
	//OUTPUT/INPUT PARAMETERS
	#define HIST_OUT plhs[0]
	#define IMG_IN prhs[0]
	#define ROW_IN prhs[1]
	#define COL_IN prhs[2]
	#define BIN_IN prhs[3]
	
	//POINTER VARIABLES
	double *imgBins, *intHist;
	int r, c, b, Row, Col, Bin, intHistDims[3];
	
	//INPUT: Pointers
	imgBins = mxGetPr(IMG_IN);    
	Row = (int)mxGetScalar(ROW_IN);
	Col = (int)mxGetScalar(COL_IN);
	Bin = (int)mxGetScalar(BIN_IN);
	
	intHistDims[0] = Row;
	intHistDims[1] = Col;
	intHistDims[2] = Bin;
	
	//OUTPUT: Pointers
	HIST_OUT = mxCreateDoubleMatrix(Row*Col*Bin, 1, mxREAL);
	intHist = mxGetPr(HIST_OUT);
	mxSetDimensions(HIST_OUT, intHistDims, 3);
	//memset(intHist, 0, sizeof(double)*Row*Col*Bin);
	
	/* IMAGE INTEGRAL HISTOGRAM */
	
	for(r=0; r<Row; r++){
		for(c=0; c<Col; c++){
			//INITIALIZE
			for(b=0; b<Bin; b++) intHist[index3D(r,c,b,Row,Col,Bin)] = 0;
			
			//CHECK IF IMG_IN_BINs == BIN_IN
			b = imgBins[index2D(r,c,Row,Col)];
			if (b > Bin) mexErrMsgTxt("IMG_IN Beans exceed BIN_IN");
			
			intHist[index3D(r,c,b-1,Row,Col,Bin)] = 1;
			for(b=0; b<Bin; b++){
				if (r > 0) 			intHist[index3D(r,c,b,Row,Col,Bin)] += intHist[index3D(r-1,c  ,b,Row,Col,Bin)];
				if (c > 0) 			intHist[index3D(r,c,b,Row,Col,Bin)] += intHist[index3D(r  ,c-1,b,Row,Col,Bin)];
				if (r > 0 && c > 0) intHist[index3D(r,c,b,Row,Col,Bin)] -= intHist[index3D(r-1,c-1,b,Row,Col,Bin)];
			}
		}
	}
}
Пример #5
0
void
ComputeMeanCostForNeurons(int *neuron_cost, int query_size, int data_size, int number_of_neurons, double *mean_cost)
{
	double sum;
	for(int i=0; i < query_size; i++)
	{
		for(int j=0; j < data_size; j++)
		{
			sum = 0.0;
			#pragma omp parallel for reduction(+:sum)
			for (int neuron = 0; neuron < number_of_neurons; neuron++)
				sum += (double)neuron_cost[index3D(neuron, i, j, query_size, data_size)];
			mean_cost[index2D(i, j, query_size, data_size)] = sum / (double)number_of_neurons;
		}
	}
}
Пример #6
0
void Map::place(Voxel& block)
{
	table[index3D(block.getMapX(), block.getMapY(), block.getMapZ())] = block;

	Voxel* b = &table[index3D(block.getMapX(), block.getMapY(), block.getMapZ())];
	int x = b->getMapX();
	int y = b->getMapY();
	int z = b->getMapZ();

	if(&table[index3D(x, y, z)] != nullptr)
	{
		voxelBatch->removeVoxel(&table[index3D(x, y, z)]);
	}

	if (!b->isAir())
	{
		voxelBatch->addVoxel(b);

		if (!outOfBounds(x + 1, y, z) && !table[index3D(x + 1, y, z)].isAir())
		{
			voxelBatch->removeVoxelFace(b, VOXEL_FACE_RIGHT);
			voxelBatch->removeVoxelFace(&table[index3D(x + 1, y, z)], VOXEL_FACE_LEFT);
		}

		if (!outOfBounds(x - 1, y, z) && !table[index3D(x - 1, y, z)].isAir())
		{
			voxelBatch->removeVoxelFace(b, VOXEL_FACE_LEFT);
			voxelBatch->removeVoxelFace(&table[index3D(x - 1, y, z)], VOXEL_FACE_RIGHT);
		}

		if (!outOfBounds(x, y + 1, z) && !table[index3D(x, y + 1, z)].isAir())
		{
			voxelBatch->removeVoxelFace(b, VOXEL_FACE_TOP);
			voxelBatch->removeVoxelFace(&table[index3D(x, y + 1, z)], VOXEL_FACE_BOTTOM);
		}

		if (!outOfBounds(x, y - 1, z) && !table[index3D(x, y - 1, z)].isAir())
		{
			voxelBatch->removeVoxelFace(b, VOXEL_FACE_BOTTOM);
			voxelBatch->removeVoxelFace(&table[index3D(x, y - 1, z)], VOXEL_FACE_TOP);
		}

		if (!outOfBounds(x, y, z + 1) && !table[index3D(x, y, z + 1)].isAir())
		{
			voxelBatch->removeVoxelFace(b, VOXEL_FACE_FRONT);
			voxelBatch->removeVoxelFace(&table[index3D(x, y, z + 1)], VOXEL_FACE_BACK);
		}

		if (!outOfBounds(x, y, z - 1) && !table[index3D(x, y, z - 1)].isAir())
		{
			voxelBatch->removeVoxelFace(b, VOXEL_FACE_BACK);
			voxelBatch->removeVoxelFace(&table[index3D(x, y, z - 1)], VOXEL_FACE_FRONT);
		}
	}
}
Пример #7
0
void Map::remove(int x, int y, int z)
{
	voxelBatch->removeVoxel(&table[index3D(x, y, z)]);

	if (!outOfBounds(x + 1, y, z) && !table[index3D(x + 1, y, z)].isAir())
		voxelBatch->addVoxelFace(&table[index3D(x + 1, y, z)], VOXEL_FACE_LEFT);
	
	if (!outOfBounds(x - 1, y, z) && !table[index3D(x - 1, y, z)].isAir())
		voxelBatch->addVoxelFace(&table[index3D(x - 1, y, z)], VOXEL_FACE_RIGHT);

	if (!outOfBounds(x, y + 1, z) && !table[index3D(x, y + 1, z)].isAir())
		voxelBatch->addVoxelFace(&table[index3D(x, y + 1, z)], VOXEL_FACE_BOTTOM);

	if (!outOfBounds(x, y - 1, z) && !table[index3D(x, y - 1, z)].isAir())
		voxelBatch->addVoxelFace(&table[index3D(x, y - 1, z)], VOXEL_FACE_TOP);

	if (!outOfBounds(x, y, z + 1) && !table[index3D(x, y, z + 1)].isAir())
		voxelBatch->addVoxelFace(&table[index3D(x, y, z + 1)], VOXEL_FACE_BACK);

	if (!outOfBounds(x, y, z - 1) && !table[index3D(x, y, z - 1)].isAir())
		voxelBatch->addVoxelFace(&table[index3D(x, y, z - 1)], VOXEL_FACE_FRONT);

	place(AirVoxel(x, y, z));
}