예제 #1
0
CAutoencoder::CAutoencoder(int32_t num_inputs, CNeuralLayer* hidden_layer,
	CNeuralLayer* decoding_layer, float64_t sigma) : CNeuralNetwork()
{
	init();

	if (decoding_layer==NULL)
		decoding_layer = new CNeuralLinearLayer(num_inputs);

	CDynamicObjectArray* layers = new CDynamicObjectArray();
	layers->append_element(new CNeuralInputLayer(num_inputs));
	layers->append_element(hidden_layer);
	layers->append_element(decoding_layer);

	set_layers(layers);

	quick_connect();

	hidden_layer->autoencoder_position = NLAP_ENCODING;
	decoding_layer->autoencoder_position = NLAP_DECODING;

	initialize_neural_network(sigma);
}
예제 #2
0
CAutoencoder::CAutoencoder(
	int32_t input_width, int32_t input_height, int32_t input_num_channels,
	CNeuralConvolutionalLayer* hidden_layer,
	CNeuralConvolutionalLayer* decoding_layer,
	float64_t sigma)
	: CNeuralNetwork()
{
	init();

	CDynamicObjectArray* layers = new CDynamicObjectArray();
	layers->append_element(new CNeuralInputLayer(input_width, input_height, input_num_channels));
	layers->append_element(hidden_layer);
	layers->append_element(decoding_layer);

	set_layers(layers);

	quick_connect();

	hidden_layer->autoencoder_position = NLAP_ENCODING;
	decoding_layer->autoencoder_position = NLAP_DECODING;

	initialize_neural_network(sigma);
}
void test_leaf_sets_multiplication()
{
	SG_SPRINT("shogun\ntest_leaf_sets_multiplication()\n");
	SGVector<float64_t> param_vector(6);
	SGVector<float64_t>::range_fill_vector(param_vector.vector, param_vector.vlen);

	CDynamicObjectArray sets;
	CParameterCombination* new_root=new CParameterCombination();
	SG_REF(new_root);

	CDynamicObjectArray* current=new CDynamicObjectArray();
	sets.append_element(current);
	Parameter* p=new Parameter();
	p->add(&param_vector.vector[0], "0");
	CParameterCombination* pc=new CParameterCombination(p);
	current->append_element(pc);

	p=new Parameter();
	p->add(&param_vector.vector[1], "1");
	pc=new CParameterCombination(p);
	current->append_element(pc);

	/* first case: one element */
	CDynamicObjectArray* result_simple=
			CParameterCombination::leaf_sets_multiplication(sets, new_root);

	SG_SPRINT("one set\n");
	for (index_t i=0; i<result_simple->get_num_elements(); ++i)
	{
		CParameterCombination* tpc=(CParameterCombination*)
				result_simple->get_element(i);
		tpc->print_tree();
		SG_UNREF(tpc);
	}
	SG_UNREF(result_simple);

	/* now more elements are created */

	current=new CDynamicObjectArray();
	sets.append_element(current);
	p=new Parameter();
	p->add(&param_vector.vector[2], "2");
	pc=new CParameterCombination(p);
	current->append_element(pc);

	p=new Parameter();
	p->add(&param_vector.vector[3], "3");
	pc=new CParameterCombination(p);
	current->append_element(pc);

	current=new CDynamicObjectArray();
	sets.append_element(current);
	p=new Parameter();
	p->add(&param_vector.vector[4], "4");
	pc=new CParameterCombination(p);
	current->append_element(pc);

	p=new Parameter();
	p->add(&param_vector.vector[5], "5");
	pc=new CParameterCombination(p);
	current->append_element(pc);

	/* second case: more element */
	CDynamicObjectArray* result_complex=
			CParameterCombination::leaf_sets_multiplication(sets, new_root);

	SG_SPRINT("more sets\n");
	for (index_t i=0; i<result_complex->get_num_elements(); ++i)
	{
		CParameterCombination* tpc=(CParameterCombination*)
				result_complex->get_element(i);
		tpc->print_tree();
		SG_UNREF(tpc);
	}
	SG_UNREF(result_complex);

	SG_UNREF(new_root);
}
예제 #4
0
SGMatrix<float64_t> CLogDetEstimator::sample_without_averaging(
	index_t num_estimates)
{
	SG_DEBUG("Entering...\n")

	REQUIRE(m_operator_log, "Operator function is NULL\n");
	// call the precompute of operator function to compute all prerequisites
	m_operator_log->precompute();

	REQUIRE(m_trace_sampler, "Trace sampler is NULL\n");
	// call the precompute of the sampler
	m_trace_sampler->precompute();

	// for storing the aggregators that submit_jobs return
	CDynamicObjectArray aggregators;
	index_t num_trace_samples=m_trace_sampler->get_num_samples();

	for (index_t i=0; i<num_estimates; ++i)
	{
		for (index_t j=0; j<num_trace_samples; ++j)
		{
			// get the trace sampler vector
			SGVector<float64_t> s=m_trace_sampler->sample(j);
			// create jobs with the sample vector and store the aggregator
			CJobResultAggregator* agg=m_operator_log->submit_jobs(s);
			aggregators.append_element(agg);
			SG_UNREF(agg);
		}
	}

	REQUIRE(m_computation_engine, "Computation engine is NULL\n");
	// wait for all the jobs to be completed
	m_computation_engine->wait_for_all();

	// the samples matrix which stores the estimates without averaging
	// dimension: number of trace samples x number of log-det estimates
	SGMatrix<float64_t> samples(num_trace_samples, num_estimates);

	// use the aggregators to find the final result
	int32_t num_aggregates=aggregators.get_num_elements();
	for (int32_t i=0; i<num_aggregates; ++i)
	{
		CJobResultAggregator* agg=dynamic_cast<CJobResultAggregator*>
			(aggregators.get_element(i));
		if (!agg)
			SG_ERROR("Element is not CJobResultAggregator type!\n");

		// call finalize on all the aggregators
		agg->finalize();
		CScalarResult<float64_t>* r=dynamic_cast<CScalarResult<float64_t>*>
			(agg->get_final_result());
		if (!r)
			SG_ERROR("Result is not CScalarResult type!\n");

		// its important that we don't just unref the result here
		index_t idx_row=i%num_trace_samples;
		index_t idx_col=i/num_trace_samples;
		samples(idx_row, idx_col)=r->get_result();
		SG_UNREF(agg);
	}

	// clear all aggregators
	aggregators.clear_array();

	SG_DEBUG("Leaving\n")
	return samples;
}