Exemple #1
0
bool HesperisIO::AddTransform(const MDagPath & path, HesperisFile * file, const std::string & beheadName)
{
	MFnDagNode fdg(path);
	if(fdg.parentCount() < 1) return false;
	
	MGlobal::displayInfo(MString("hes io add transform ")+path.fullPathName());

	MObject oparent = fdg.parent(0);
	MFnDagNode fp(oparent);
	MDagPath pp;
	fp.getPath(pp);
	AddTransform(pp, file, beheadName);
	
	std::string nodeName = path.fullPathName().asChar();
	if(beheadName.size() > 1) SHelper::behead(nodeName, beheadName);
// todo extract tm    
	file->addTransform(nodeName, new BaseTransform);
	return true;
}
Exemple #2
0
bool HesperisIO::AddTransform(const MDagPath & path, HesperisFile * file )
{
	const std::string nodeName = H5PathNameTo(path);
	if(nodeName.size() < 2 ) return false;
	
	MFnDagNode fdg(path);
	if(fdg.parentCount() < 1) return false;
	
// AHelper::Info<MString>("hes io add transform ", path.fullPathName());

	MObject oparent = fdg.parent(0);
	MFnDagNode fp(oparent);
	MDagPath pp;
	fp.getPath(pp);
	AddTransform(pp, file);
	
// todo extract tm    
	file->addTransform( nodeName, new BaseTransform );
	return true;
}
Exemple #3
0
// Validate gradients with finite differences.
void GPCMOptimization::validateGradients(
    GPCMOptimizable *model                  // Model to validate gradients for.
    )
{
    // Compute gradient.
    clearGradients();
    double center = model->recompute(true);
    double centerc = 0.0;
    packGradients(x,g);

//	std::cout << x << std::endl;
    // Optionally compute the constraint gradient.
    VectorXd cg(g.rows());
    if (model->hasConstraint())
    {
        clearGradients();
        centerc = model->recomputeConstraint(true);
        packGradients(x,cg);
    }

    // Take samples to evaluate finite differences.
    VectorXd pt = x;
    VectorXd fdg(params);
    VectorXd fdgc(params);
    for (int i = 0; i < params; i++)
    {
        // Evaluate upper and lower values.
        pt.noalias() = x + VectorXd::Unit(params,i)*FD_EPSILON;
        unpackVariables(pt);
        double valp = model->recompute(false);
        double valpc = model->recomputeConstraint(false);
        pt.noalias() = x - VectorXd::Unit(params,i)*FD_EPSILON;
        unpackVariables(pt);
        double valm = model->recompute(false);
        double valmc = model->recomputeConstraint(false);
        fdg(i) = 0.5*(valp-valm)/FD_EPSILON;
        fdgc(i) = 0.5*(valpc-valmc)/FD_EPSILON;
        DBPRINTLN("Computed finite difference for dimension " << i << " of " << params << ": " << fdg(i));
    }
//	std::cout << x << std::endl;
    // Reset variables.
    unpackVariables(x);

    // Construct gradient names.
    std::vector<std::string> varname(x.rows());
    for (std::vector<GPCMOptVariable>::iterator itr = variables.begin();
         itr != variables.end(); itr++)
    {
        for (int i = itr->getIndex(); i < itr->getIndex()+itr->getParamCount(); i++)
        {
            varname[i] = itr->getName();
            if (itr->getParamCount() > 1)
                varname[i] += std::string(" ") +
                    boost::lexical_cast<std::string>(i-itr->getIndex());
        }
    }

    // Print gradients.
    int idx;
    DBPRINTLN("True gradient / finite-difference gradient:");
    for (int i = 0; i < params; i++)
    {
        if (model->hasConstraint())
        {
            DBPRINTLN(std::setw(10) << g(i) << " " <<
                      std::setw(10) << fdg(i) <<
                      std::setw(10) << cg(i) << " " <<
                      std::setw(10) << fdgc(i) <<
                      std::setw(10) << "(" << x(i) << ")" << "   " << varname[i]);
        }
        else
        {
            DBPRINTLN(std::setw(10) << g(i) << " " <<
                      std::setw(10) << fdg(i) <<
                      std::setw(10) << "(" << x(i) << ")" << "   " << varname[i]);
        }
    }

    // Check objective gradient.
    double maxDiff = (g-fdg).array().abs().matrix().maxCoeff(&idx);
    if (maxDiff >= 0.1)
        DBWARNING("Gradients appear significantly different!");
    DBPRINTLN("Max difference: " << maxDiff);
    DBPRINTLN("Max difference at index " << idx << ":" << std::endl << std::setw(10) << g(idx)
        << " " << std::setw(10) << fdg(idx) << "   " << varname[idx]);

    if (model->hasConstraint())
    {
        // Check constraint gradient.
        maxDiff = (cg-fdgc).array().abs().matrix().maxCoeff(&idx);
        if (maxDiff >= 0.1)
            DBWARNING("Constraint gradients appear significantly different!");
        DBPRINTLN("Max constraint difference: " << maxDiff);
        DBPRINTLN("Max constraint difference at index " << idx << ":" << std::endl << std::setw(10) << cg(idx)
            << " " << std::setw(10) << fdgc(idx) << "   " << varname[idx]);
    }
}