当前位置: 首页>>代码示例>>C++>>正文


C++ TheMatrix::Dot方法代码示例

本文整理汇总了C++中TheMatrix::Dot方法的典型用法代码示例。如果您正苦于以下问题:C++ TheMatrix::Dot方法的具体用法?C++ TheMatrix::Dot怎么用?C++ TheMatrix::Dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TheMatrix的用法示例。


在下文中一共展示了TheMatrix::Dot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ComputeLoss

/** Flag = 0: marginloss, no label loss. The label loss will always be zero
           1: marginloss, and label loss.
*/
void CSMMMulticlassLoss::ComputeLoss(vector<unsigned int> y, vector<unsigned int> ylabel, vector<unsigned int> ybar, vector<unsigned int> ybarlabel, const CSeqMulticlassFeature::seqfeature_struct &x, const TheMatrix &w, double & marginloss, double & labelloss, int flag)
{
    unsigned int i;
    double w_dot_phi1 = 0;
    double w_dot_phi2 = 0;
    marginloss = 0;

    unsigned int start;
    if(is_first_phi1_used)
	start = 0;
    else
	start = 1;
    for(i=start; i < ybar.size(); i++)
    {
       _data->TensorPhi1(x.phi_1[ybar[i]],ybarlabel[i],0,tphi_1);
       //tphi_1->Print();
       w.Dot(*(tphi_1), w_dot_phi1);
       marginloss += w_dot_phi1;
       //printf("%d(%d):%2.4f\t",ybar[i],ybarlabel[i],marginloss);
    }	
    for(i=1;i<ybar.size();i++)
    {
       int vb = 0;
       _data->TensorPhi2(x.phi_2[ybar[i-1]][ybar[i]-ybar[i-1]-1], ybarlabel[i-1], ybarlabel[i], 0,vb,tphi_2);
       w.Dot(*(tphi_2), w_dot_phi2);
       marginloss += w_dot_phi2;
    }
    
    if(ybar.size() > 0)
    {
       
       //grad.Add(*(X[i].phi_2[ybar[ybar.size()-1]][X[i].len-1 - ybar[ybar.size()-1]-1]));////       
       _data->TensorPhi2(x.phi_2[ybar[ybar.size()-1]][x.len - ybar[ybar.size()-1]-1 ], ybarlabel[ybar.size()-1], 0, 0,0,tphi_2);
       w.Dot(*(tphi_2), w_dot_phi2);
       marginloss += w_dot_phi2;
    }
    
    //vector <unsigned int> yss = Boundry2StatSequence(y,ylabel,x.len);
    //vector <unsigned int> ybarss = Boundry2StatSequence(ybar,ybarlabel,x.len);
    //labelloss = Labelloss(yss,ybarss);
    labelloss = AllDelta(ybar,y,ybarlabel,ylabel,x.len);
}
开发者ID:funkey,项目名称:bmrm,代码行数:45,代码来源:smmmulticlassloss.cpp

示例2: find_best_label_grammer

/** find best label (without label loss): g(w) := max_y' <w,\phi(x,y')>
 *
 *  @param x [read] sequence
 *  @param w [read] weight vector
 *  @param ybar [write] found best label
 *  @param marginloss [write] margin loss <w,\Phi(x,y')> w.r.t to best y'
 */
void CSMMMulticlassLoss::find_best_label_grammer(const CSeqMulticlassFeature::seqfeature_struct &x, const TheMatrix &w, vector<unsigned int> &ybar, vector<unsigned int> &ybarlabel, double &marginloss, unsigned int personid, unsigned int classNum)
{
    using namespace std;
    
    // reset return values
    marginloss = 0;        
    ybar.clear();
    ybarlabel.clear();
    
    /** The margin value vector used in dynamic programming
     */	
    vector< vector<double> > M (x.len+1,vector<double> (classNum,0));
    
    /** The back pointers vector used in dynamic programming to retrieve the optimal path
     */
    // The positions
    vector< vector<int> > A (x.len+1,vector<int> (classNum,-1));
    // The class labels
    vector< vector<int> > C (x.len+1,vector<int> (classNum,0));
    
    
    double maxval = -SML::INFTY;
    double w_dot_phi1 = 0;
    double w_dot_phi2 = 0;
    double marginval = 0;
    unsigned int right = 0;
    unsigned int left = 0;
    unsigned int start = 0;
    unsigned int end = 0;
    unsigned int classID = 0;
    unsigned int classIDPrev = 0;
    
    double sum = 0;
    
    // compute DP statistics for positions 1 to len-1
    for(classID=0;classID<classNum;classID++)
    {
	A[1][classID] = 0;
	//C[1][classID] = 0;
    }
    
    if(is_first_phi1_used)
    {
	right =0;
	for(classID=0;classID<classNum;classID++)
	{
	    maxval = -SML::INFTY;
	    w_dot_phi1 = 0.0;
	    _data->TensorPhi1(x.phi_1[right],classID,0,tphi_1);
	    //tphi_1->Print();
	    w.Dot(*(tphi_1), w_dot_phi1);
	    marginval = w_dot_phi1;   					
	    sum = marginval;
	    if(sum > maxval)
	    {
		M[right][classID] = marginval;			
		maxval = sum;
	    }
	}
    }
    for(right=1; right < x.len+1; right++)
    {
	for(classID=0;classID<classNum;classID++)
	{		
	    // \Phi = (phi1, phi2[left,right])
	    // <w, \Phi> = <w,phi1> + <w,phi[left,right]>                
	    maxval = -SML::INFTY;
	    w_dot_phi1 = 0.0;
	    
	    if(right<x.len)
	    {
		_data->TensorPhi1(x.phi_1[right],classID,0,tphi_1);
		w.Dot(*(tphi_1), w_dot_phi1);
	    }		

	    start = max(0,int(right-maxDuration));
	    //end = right;//-minDuration+1;
	    if(lastDuration>0)
	    {			
		unsigned int lastpos = x.len-lastDuration+1 ;
		end = MIN(right,lastpos);
	    }
	    else
		end = right;
	    for(left=start; left < end; left++)
	    {
		classIDPrev = classID;
		int vb = 0;
		_data->TensorPhi2(x.phi_2[left][right-left-1], classIDPrev, classID, 0,vb,tphi_2);
		w.Dot(*(tphi_2), w_dot_phi2); 
		marginval = w_dot_phi1 + w_dot_phi2;   
		sum = M[left][classIDPrev]+marginval;
		if(sum > maxval)
//.........这里部分代码省略.........
开发者ID:funkey,项目名称:bmrm,代码行数:101,代码来源:smmmulticlassloss.cpp


注:本文中的TheMatrix::Dot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。