예제 #1
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    if (nrhs != 4)
    {
        mexPrintf("Usage: alpha = LineSearch(prevScores, newScores, labels, lossType)\n");
        mexErrMsgTxt("Incorrect input format\n");
    }

#define mPrevScores (prhs[0])
#define mNewScores (prhs[1])
#define mLabels (prhs[2])
#define mLossType (prhs[3])

    if (nlhs != 1)
        mexErrMsgTxt("One output arg expected");

    char lossName[40];
    if ( mxGetString(mLossType, lossName, sizeof(lossName)) != 0 )
        mexErrMsgTxt("Error reading options.loss");

    SQB::LossType sqbLoss = SQB::ExpLoss;

    if (strcmp(lossName, "exploss") == 0)
        sqbLoss = SQB::ExpLoss;
    else if ( strcmp(lossName, "logloss") == 0 )
        sqbLoss = SQB::LogLoss;
    else if ( strcmp(lossName, "squaredloss") == 0 )
        sqbLoss = SQB::SquaredLoss;
    else
        mexErrMsgTxt("options.loss contains an invalid value");


    MatlabInputMatrix<WeightsType> pPrev( mPrevScores, 0, 1, "prevScores" );
    MatlabInputMatrix<WeightsType> pNew( mNewScores, pPrev.rows(), 1, "newScores" );
    MatlabInputMatrix<WeightsType> pLabels( mLabels, pPrev.rows(), 1, "labels" );

    // create mappings
    ArrayMapType prevMap( pPrev.data(), pPrev.rows(), pPrev.cols() );
    ArrayMapType newMap( pNew.data(), pNew.rows(), pNew.cols() );
    ArrayMapType labelsMap( pLabels.data(), pLabels.rows(), pLabels.cols() );



    SQB::LineSearch< ArrayType, ArrayMapType >  LS( prevMap, newMap, labelsMap, sqbLoss );

    WeightsType alpha = LS.run();

    MatlabOutputMatrix<WeightsType>   outMatrix( &plhs[0], 1, 1 );
    outMatrix.data()[0] = alpha;
}
예제 #2
0
/**
 * Create a EdgeStub for the edge before the intersection eiCurr.
 * The previous intersection is provided
 * in case it is the endpoint for the stub edge.
 * Otherwise, the previous point from the parent edge will be the endpoint.
 *
 * eiCurr will always be an EdgeIntersection, but eiPrev may be null.
 */
void
EdgeEndBuilder::createEdgeEndForPrev(Edge *edge, vector<EdgeEnd*> *l,
		EdgeIntersection *eiCurr, EdgeIntersection *eiPrev)
{
	auto iPrev = eiCurr->segmentIndex;
	if (eiCurr->dist==0.0) {
		// if at the start of the edge there is no previous edge
		if (iPrev==0) return;
		iPrev--;
	}
	Coordinate pPrev(edge->getCoordinate(iPrev));
	// if prev intersection is past the previous vertex, use it instead
	if (eiPrev!=nullptr && eiPrev->segmentIndex>=iPrev)
		pPrev=eiPrev->coord;
	Label label( edge->getLabel() );
	// since edgeStub is oriented opposite to it's parent edge, have to flip sides for edge label
	label.flip();
	EdgeEnd *e=new EdgeEnd(edge,eiCurr->coord,pPrev,label);
	//e.print(System.out);  System.out.println();
	l->push_back(e);
}