void CGaussianProcessRegression::update_kernel_matrices()
{
	CKernel* kernel = NULL;

	if (m_method)
		kernel = m_method->get_kernel();

	if (kernel)
	{
		float64_t m_scale = m_method->get_scale();

		CFeatures* latent_features = m_method->get_latent_features();
		
		if (latent_features)
			kernel->init(latent_features, m_data);
		else
			kernel->init(m_data, m_data);

		//K(X_test, X_train)
		m_k_trts = kernel->get_kernel_matrix();

		for (index_t i = 0; i < m_k_trts.num_rows; i++)
		{
			for (index_t j = 0; j < m_k_trts.num_cols; j++)
				m_k_trts(i,j) *= (m_scale*m_scale);
		}

		kernel->init(m_data, m_data);

		m_k_tsts = kernel->get_kernel_matrix();

		for (index_t i = 0; i < m_k_tsts.num_rows; i++)
		{
			for (index_t j = 0; j < m_k_tsts.num_cols; j++)
				m_k_tsts(i,j) *= (m_scale*m_scale);
		}
		
		kernel->remove_lhs_and_rhs();

		SG_UNREF(kernel);
		SG_UNREF(latent_features);
	}
}
Example #2
0
void CGaussianProcessRegression::update_kernel_matrices()
{
	CKernel* kernel = NULL;

	if (m_method)
		kernel = m_method->get_kernel();

	if (kernel)
	{
		float64_t m_scale = m_method->get_scale();

		kernel->cleanup();

		kernel->init(m_features, m_data);

		//K(X_test, X_train)
		m_k_trts = kernel->get_kernel_matrix();

		for (index_t i = 0; i < m_k_trts.num_rows; i++)
		{
			for (index_t j = 0; j < m_k_trts.num_cols; j++)
				m_k_trts(i,j) *= (m_scale*m_scale);
		}

		kernel->cleanup();

		kernel->init(m_data, m_data);

		m_k_tsts = kernel->get_kernel_matrix();

		for (index_t i = 0; i < m_k_tsts.num_rows; i++)
		{
			for (index_t j = 0; j < m_k_tsts.num_cols; j++)
				m_k_tsts(i,j) *= (m_scale*m_scale);
		}

		SG_UNREF(kernel);
	}
}
Example #3
0
SGMatrix<float64_t> CCombinedKernel::get_parameter_gradient(TParameter* param,
		CSGObject* obj, index_t index)
{
	SGMatrix<float64_t> result(0,0);

	if (strcmp(param->m_name, "combined_kernel_weight") == 0)
	{
		CListElement* current = NULL ;
		CKernel* k = get_first_kernel(current);

		if (append_subkernel_weights)
		{
			while(k)
			{
				result = k->get_parameter_gradient(param, obj, index);

				SG_UNREF(k);

				if (result.num_cols*result.num_rows > 0)
					return result;

				k = get_next_kernel(current);
			}
		}

		else
		{
			while(k)
			{
				if(obj == k)
				{
					result = k->get_kernel_matrix();
					SG_UNREF(k);
					return result;
				}

				SG_UNREF(k);

				k = get_next_kernel(current);
			}
		}
	}

	else
	{
		CListElement* current = NULL ;
		CKernel* k = get_first_kernel(current);
		float64_t coeff;
		while(k)
		{
			SGMatrix<float64_t> derivative =
					k->get_parameter_gradient(param, obj, index);

			coeff = 1.0;

			if (!append_subkernel_weights)
				coeff = k->get_combined_kernel_weight();


			for (index_t g = 0; g < derivative.num_rows; g++)
			{
				for (index_t h = 0; h < derivative.num_cols; h++)
					derivative(g,h) *= coeff;
			}

			if (derivative.num_cols*derivative.num_rows > 0)
			{
				if (result.num_cols == 0 && result.num_rows == 0)
					result = derivative;

				else
				{
					for (index_t g = 0; g < derivative.num_rows; g++)
					{
						for (index_t h = 0; h < derivative.num_cols; h++)
							result(g,h) += derivative(g,h);
					}
				}
			}

			SG_UNREF(k);
			k = get_next_kernel(current);
		}
	}

	return result;
}