// Construct from initializer list of layer sizes
	multilayer_perceptron(std::initializer_list<size_t> l)
		: size_layers_(l)
	{
		// Check that there are at least two layers
		if (count_layers() < 2)
			throw std::invalid_argument("Number of layers to multilayer_perceptron must be greater than 1.");

		// Fill out weights and bias offsets, and calculate number of parameters
		count_parameters_ = 0;
		weight_offsets.resize(count_weights_layers());
		bias_offsets.resize(count_weights_layers());
		for (unsigned int i = 0; i < count_layers() - 1; i++) {
			weight_offsets[i] = count_parameters_;
			count_parameters_ += size_layers_[i] * size_layers_[i + 1];

			bias_offsets[i] = count_parameters_;
			count_parameters_ += size_layers_[i + 1];
		}

		// Allocate memory for hidden layers
		activations_.reserve(count_weights_layers());
		deltas_.reserve(count_weights_layers());
		for (unsigned int i = 1; i < count_weights_layers(); i++) {
			activations_.emplace_back(size_layers_[i]);
			deltas_.emplace_back(size_layers_[i]);
		}

		// Temporary variable used for storing output result
		outputs_.resize(count_outputs());
		temp_.resize(count_outputs());
		temp2_.resize(count_outputs());
		temp3_.resize(count_outputs());
		temp_gradient_.resize(count_parameters());
	}
	// Get the maximum entry of an output
	size_t get_nonzero_idx(const Eigen::VectorXd& inputs)
	{
		// TODO: Can this be replaced by a standard library algorithm? Iterate over vector
		for (size_t idx = 0; idx < count_outputs(); idx++) {
			if (inputs[idx] != 0)
				return idx;
		}
		return 0;
	}
Ejemplo n.º 3
0
static void
setup_from_config (MateRRLabeler *labeler)
{
	labeler->priv->num_outputs = count_outputs (labeler->priv->config);

	make_palette (labeler);

	create_label_windows (labeler);
}
static void
setup_from_config (CcRRLabeler *labeler)
{
	labeler->priv->num_outputs = count_outputs (labeler->priv->config);

	make_palette (labeler);

	cc_rr_labeler_show (labeler);
}
	// Get the maximum entry of an output
	double get_maximum(const Eigen::VectorXd& inputs)
	{
		// Find the maximum element, which denotes the class with the highest probability
		// TODO: Can this be replaced by a standard library algorithm? Iterate over vector
		double class_idx = 0, class_probability = 0;
		for (size_t idx = 0; idx < count_outputs(); idx++) {
			if (inputs[idx] > class_probability) {
				class_probability = inputs[idx];
				class_idx = idx;
			}
		}
		return class_idx;
	}
Ejemplo n.º 6
0
/**
 * Render using the program and verify that it outputs the proper data
 * to the transform feedback buffer.
 *
 * The program should already be linked and stored in the global \c
 * prog.
 */
static enum piglit_result
test_xfb(bool use_rasterizer_discard)
{
	GLuint buf;
	void *initial_data;
	const void *readback;
	unsigned expected_num_outputs = count_outputs();
	unsigned buf_size
		= expected_num_outputs * NUM_VERTICES * sizeof(float);
	bool pass = true;

	/* Create transform feedback buffer and pre-load it with
	 * garbage.
	 */
	glGenBuffers(1, &buf);
	initial_data = malloc(buf_size);
	memset(initial_data, 0xcc, buf_size);
	glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
	glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, buf_size, initial_data,
		     GL_STREAM_READ);
	free(initial_data);

	/* Draw a quad filling the window, with transform feedback
	 * enabled.
	 */
	glUseProgram(prog);
	glBeginTransformFeedback(GL_TRIANGLES);
	if (use_rasterizer_discard)
		glEnable(GL_RASTERIZER_DISCARD);
	draw_rect(-1, -1, 2, 2);
	if (use_rasterizer_discard)
		glDisable(GL_RASTERIZER_DISCARD);
	glEndTransformFeedback();
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	/* Inspect transform feedback output. */
	readback = glMapBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf_size,
				    GL_MAP_READ_BIT);
	pass = check_outputs(readback) && pass;
	glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER);

	glDeleteBuffers(1, &buf);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}