Exemplo n.º 1
0
/// Decodes beliefs to predict observations
void ObservationModel::beliefsToObservations(const GVec& beliefs, GVec& observations)
{
	observations.resize(decoder.outputLayer().outputs());
	if(tutor)
		tutor->state_to_observations(beliefs, observations);
	else
	{
		decoder.forwardProp(beliefs);
		observations.copy(decoder.outputLayer().activation());
	}
}
Exemplo n.º 2
0
/// Encodes observations to predict beliefs
void ObservationModel::observationsToBeliefs(const GVec& observations, GVec& beliefs)
{
	beliefs.resize(encoder.outputLayer().outputs());
	if(tutor)
		tutor->observations_to_state(observations, beliefs);
	else
	{
		beliefs.put(0, observations, 0, beliefs.size());
		encoder.forwardProp(observations);
		beliefs.copy(encoder.outputLayer().activation());
	}
}
Exemplo n.º 3
0
// virtual
void GWag::trainInner(const GMatrix& features, const GMatrix& labels)
{
	GNeuralNetLearner* pTemp = NULL;
	std::unique_ptr<GNeuralNetLearner> hTemp;
	size_t weights = 0;
	GVec pWeightBuf;
	GVec pWeightBuf2;
	for(size_t i = 0; i < m_models; i++)
	{
		m_pNN->train(features, labels);
		if(pTemp)
		{
			// Average m_pNN with pTemp
			if(!m_noAlign)
				m_pNN->nn().align(pTemp->nn());
			pTemp->nn().weightsToVector(pWeightBuf.data());
			m_pNN->nn().weightsToVector(pWeightBuf2.data());
			pWeightBuf *= (double(i) / (i + 1));
			pWeightBuf.addScaled(1.0 / (i + 1), pWeightBuf2);
			pTemp->nn().vectorToWeights(pWeightBuf.data());
		}
		else
		{
			// Copy the m_pNN
			GDom doc;
			GDomNode* pNode = m_pNN->serialize(&doc);
			GLearnerLoader ll;
			pTemp = new GNeuralNetLearner(pNode);
			hTemp.reset(pTemp);
			weights = pTemp->nn().weightCount();
			pWeightBuf.resize(weights);
			pWeightBuf2.resize(weights);
		}
	}
	pTemp->nn().weightsToVector(pWeightBuf.data());
	m_pNN->nn().vectorToWeights(pWeightBuf.data());
}
Exemplo n.º 4
0
	GEnsemblePredictWorker(GMasterThread& master, GEnsemble* pEnsemble, size_t outDims)
	: GWorkerThread(master), m_pEnsemble(pEnsemble)
	{
		m_prediction.resize(outDims);
	}
Exemplo n.º 5
0
	GEvolutionaryOptimizerNode(size_t dims)
	{
		m_pVector.resize(dims);
	}