void CreateScene::visit(ColladaTranslate* translate) { math::Vector3 t; translate->getTranslation(t.vector); concatMatrix(math::Matrix4::translateMatrix(t)); }
void CreateScene::visit(ColladaScale* scale) { math::Vector3 s; scale->getScale(s.vector); concatMatrix(math::Matrix4::scaleMatrix(s)); }
void CreateScene::visit(ColladaMatrix* colladaMatrix) { math::Matrix4 transformation; colladaMatrix->getMatrix(transformation.matrix); concatMatrix(transformation.transpose()); }
//递归求导 void RAE::trainRecError(Node* node, MatrixLBFGS delta_parent, int freq) { Node* tmpNode = this->RAETree->getRoot(); //更新w2, b2 while(tmpNode->getNodeType() != BASED_NODE) { MatrixLBFGS c = concatMatrix(tmpNode->getLeftChildNode()->getVector(),tmpNode->getRightChildNode()->getVector()); MatrixLBFGS cRec = concatMatrix(tmpNode->leftReconst,tmpNode->rightReconst); for(int row = 0; row < weights2.rows(); row++) { lbfgsfloatval_t result = (cRec(0, row)-c(0, row)) * (1-pow(cRec(0, row), 2)); for(int col = 0; col < weights2.cols(); col++) { delWeight2(row, col) = delWeight2(row,col) + freq * ALPHA * result * tmpNode->getVector()(0, col); } delWeight2_b(0, row) = freq * ALPHA * result + delWeight2_b(0, row); } tmpNode = tmpNode->getLeftChildNode(); } //仅对每一对重构中的权重求导 tmpNode = this->RAETree->getRoot(); while(tmpNode->getNodeType() != BASED_NODE) { MatrixLBFGS c = concatMatrix(tmpNode->getLeftChildNode()->getVector(),tmpNode->getRightChildNode()->getVector()); MatrixLBFGS cRec = concatMatrix(tmpNode->leftReconst,tmpNode->rightReconst); MatrixLBFGS tmpDelWb = MatrixLBFGS(1, 2*vecSize); for(int row = 0; row < weights2.rows(); row++) { lbfgsfloatval_t result = (cRec(0, row)-c(0, row)) * (1-pow(cRec(0, row), 2)); tmpDelWb(0, row) = ALPHA * result; } tmpDelWb = tmpDelWb*weights2; recurDel(tmpNode, tmpDelWb, freq); tmpNode = tmpNode->getLeftChildNode(); } }
void CreateScene::visit(ColladaRotate* rotate) { math::Vector3 axis; rotate->getAxis(axis.vector); math::Quaternion quat(math::AxisAngle(rotate->getAngle(), axis)); concatMatrix(math::Matrix4::rotationMatrix(quat)); }
//不包含Erec的递归求导 void RAE::recurDel(Node* n, MatrixLBFGS derivation, int freq) { if(n->getNodeType() == BASED_NODE) { return; } MatrixLBFGS con = concatMatrix(n->getLeftChildNode()->getVector(), n->getRightChildNode()->getVector()); for(int col = 0; col < derivation.cols(); col++) { derivation(0, col) *= (1-pow(n->getVector()(0, col), 2)); } for(int row = 0; row < delWeight1.rows(); row++) { for(int col = 0; col < delWeight1.cols(); col++) { delWeight1(row, col) += freq * derivation(0, row)*con(0, col); } delWeight1_b(0, row) += freq * derivation(0, row); } MatrixLBFGS der = MatrixLBFGS(1 ,vecSize); MatrixLBFGS tmp = derivation * weights1; if(n->leftChild->getNodeType() != BASED_NODE) { for(int col = 0; col < vecSize; col++) { der(0, col) = tmp(0, col); } } else { for(int col = 0; col < vecSize; col++) { der(0, col) = tmp(0, col+vecSize); } } recurDel(n->getLeftChildNode(), der); }