Example #1
0
void
Oracle::operator()(
			const std::vector<double>& weights,
			double&                    value,
			std::vector<double>&       gradient) {

	updateCosts(weights);

	MultiCut::Status status = _mostViolatedMulticut.solve();

	std::stringstream filename;
	filename << "most-violated_" << std::setw(6) << std::setfill('0') << _iteration << ".tif";
	_mostViolatedMulticut.storeSolution(filename.str(), true);

	if (status != MultiCut::SolutionFound)
		UTIL_THROW_EXCEPTION(
				Exception,
				"solution not found");

	value = _constant - _mostViolatedMulticut.getValue();

	// value = E(y',w) - E(y*,w) + Δ(y',y*)
	//       = B_c - <wΦ,y*> + <Δ_l,y*> + Δ_c

	// loss   = value - B_c + <wΦ,y*>
	// margin = value - loss

	double mostViolatedEnergy = 0;
	for (Crag::NodeIt n(_crag); n != lemon::INVALID; ++n)
		if (_mostViolatedMulticut.getSelectedRegions()[n])
			mostViolatedEnergy += nodeCost(weights, _nodeFeatures[n]);
	for (Crag::EdgeIt e(_crag); e != lemon::INVALID; ++e)
		if (_mostViolatedMulticut.getMergedEdges()[e])
			mostViolatedEnergy += edgeCost(weights, _edgeFeatures[e]);

	double loss   = value - _B_c + mostViolatedEnergy;
	double margin = value - loss;

	LOG_USER(oraclelog) << "Δ(y*)         = " << loss << std::endl;
	LOG_USER(oraclelog) << "E(y') - E(y*) = " << margin << std::endl;

	accumulateGradient(gradient);

	if (optionStoreEachCurrentlyBest) {

		_currentBestMulticut.solve();

		std::stringstream filename;
		filename << "current-best_" << std::setw(6) << std::setfill('0') << _iteration << ".tif";
		_currentBestMulticut.storeSolution(filename.str(), true);
	}

	_iteration++;
}
Example #2
0
bool updateCostsNode1(int sourceid, int mincosts[4])
{
  return updateCosts(&dt1, sourceid, mincosts);
}