Beispiel #1
0
/*
 * Generates a random directed binary graph with a Toeplitz organization.
 */
MATRIX_T* BCT_NAMESPACE::maketoeplitzCIJ(int N, int K, FP_T s) {
	
	// profile = normpdf([1:N-1],0.5,s);
	VECTOR_T* indices = sequence(1, N - 1);
	VECTOR_T* profile = normpdf(indices, 0.5, s);
	VECTOR_ID(free)(indices);
	
	// template = toeplitz([0 profile],[0 profile]);
	VECTOR_T* temp = concatenate(0.0, profile);
	VECTOR_ID(free)(profile);
	profile = temp;
	MATRIX_T* _template = toeplitz(profile, profile);
	VECTOR_ID(free)(profile);
	
	// template = template.*(K./sum(sum(template)))
	VECTOR_T* sum__template = sum(_template);
	FP_T sum_sum__template = sum(sum__template);
	VECTOR_ID(free)(sum__template);
	MATRIX_ID(scale)(_template, (FP_T)K / sum_sum__template);
	
	// CIJ = zeros(N);
	MATRIX_T* CIJ = zeros(N);
	
	// while ((sum(sum(CIJ)) ~= K))
	VECTOR_T* sum_CIJ = sum(CIJ);
	FP_T sum_sum_CIJ = sum(sum_CIJ);
	VECTOR_ID(free)(sum_CIJ);
	while ((int)sum_sum_CIJ != K) {
		
		// CIJ = (rand(N)<template);
		MATRIX_T* rand_N = rand(N);
		MATRIX_ID(free)(CIJ);
		CIJ = compare_elements(rand_N, fp_less, _template);
		MATRIX_ID(free)(rand_N);
		
		sum_CIJ = sum(CIJ);
		sum_sum_CIJ = sum(sum_CIJ);
		VECTOR_ID(free)(sum_CIJ);
	}
	
	MATRIX_ID(free)(_template);
	return CIJ;
}
Beispiel #2
0
/**
 * Return the coefficients for CONV operator. The coefficient matrix is
 * constructed by creating a toeplitz matrix with the constant vector
 * in DATA as the columns. Multiplication by this matrix is equivalent
 * to convolution.
 *
 * Parameters: linOp LIN with type CONV. Data should should contain a
 *						 column vector that the variables are convolved with.
 *
 * Returns: vector of coefficients for convolution linOp
 */
std::vector<Matrix> get_conv_mat(LinOp &lin) {
	assert(lin.type == CONV);
	Matrix constant = get_constant_data(lin, false);
	int rows = lin.size[0];
	int nonzeros = constant.rows();
	int cols = lin.args[0]->size[0];

	Matrix toeplitz(rows, cols);

	std::vector<Triplet> tripletList;
	tripletList.reserve(nonzeros * cols);
	for (int col = 0; col < cols; col++) {
		int row_start = col;
		for ( int k = 0; k < constant.outerSize(); ++k ) {
			for ( Matrix::InnerIterator it(constant, k); it; ++it ) {
				int row_idx = row_start + it.row();
				tripletList.push_back(Triplet(row_idx, col, it.value()));
			}
		}
	}
	toeplitz.setFromTriplets(tripletList.begin(), tripletList.end());
	toeplitz.makeCompressed();
	return build_vector(toeplitz);
}