Пример #1
0
void CNN::backPropagate(mat& error, const mat& fin, const mat& fout,
    float learning_rate) {

  // Remove last column, which is bias in DNN.
  mat _fout(fout), _error(error);
  _fout.resize(_fout.getRows(), _fout.getCols() - 1);
  _error.resize(_error.getRows(), _error.getCols() - 1);

  int N = _transforms.back()->getNumOutputMaps();
  vector<mat> fouts = de_concat(~_fout, N),
	      errors = de_concat(~_error, N);

  vector<mat> fins;
  fins.push_back(~fin);

  _transforms.back()->backPropagate(errors, _houts.back(), fouts, learning_rate);

  for (int i=_transforms.size() - 2; i >= 1; --i)
    _transforms[i]->backPropagate(errors, _houts[i-1], _houts[i], learning_rate);

  _transforms[0]->backPropagate(errors, fins, _houts[0], learning_rate);

  // Concatenate
  error = ~concat(errors);
}
Пример #2
0
			void ParserFileTestTest::TestLogic(void) {
				ParserAPI test;
				TIME(test.ParseFile(FILE_PATH));
				if (test.HasError()) {
					__list_parsing_errors(test);
					ASSERT(!test.HasError()); // certain failure here, to stop the test
				}
				ASTNode* root = test.GetAST();
				ASSERT(root != 0x00);
				
				FileOutputStream _fout("treeVisualisation.txt", FileOutputStream::Mode::Truncate());
				FileOutputStream _foutxml("treeVisualisation.xml", FileOutputStream::Mode::Truncate());
				BufferedOutputStream fout(_fout);
				BufferedOutputStream foutxml(_foutxml);
				ASTTreeVisualisationVisitor visitor(fout);
				ASTMITTreeVisualizerXMLProducerVisitor mitvis(foutxml);
				TIME(root->Accept(&visitor))
				TIME(root->Accept(&mitvis))
				test.DeleteListAndAST();
			}