コード例 #1
0
ファイル: GlobalFuncs.cpp プロジェクト: zeriyoshi/LunaDLL
void sendPUTRequest(const std::string& server, const std::string& data)
{
    HRESULT hr;
    CLSID clsid;
    IWinHttpRequest *pIWinHttpRequest = NULL;

    _variant_t varFalse(false);
    _variant_t varData(data.c_str());

    hr = CLSIDFromProgID(L"WinHttp.WinHttpRequest.5.1", &clsid);
    if (SUCCEEDED(hr)){
        hr = CoCreateInstance(clsid, NULL,
            CLSCTX_INPROC_SERVER,
            IID_IWinHttpRequest,
            (void **)&pIWinHttpRequest);
    }

    if (SUCCEEDED(hr)){
        hr = pIWinHttpRequest->SetTimeouts(1000, 1000, 2000, 1000);
    }

    if (SUCCEEDED(hr)){
        _bstr_t method("PUT");
        _bstr_t url(server.c_str());
        hr = pIWinHttpRequest->Open(method, url, varFalse);
    }

    if (SUCCEEDED(hr)){
        hr = pIWinHttpRequest->Send(varData);
    }

    pIWinHttpRequest->Release();
}
コード例 #2
0
  void dfgEm(DfgInfo & dfgInfo, string const & varDataFile, string const & facDataFile, string const & subVarDataFile, number_t minDeltaLogLik, unsigned maxIter, 
	     string const & logStateMapsFile, string const & logFactorPotentialsFile, string const & logVariablesFile, string const & logFactorGraphFile, string const & logFile)
  {
    DFG & dfg = dfgInfo.dfg;     // convenient
    AbstractBaseFactorSet & factorSet = dfgInfo.facSet;

    unsigned iter = 0;
    number_t logLik = 0;
    number_t prevLogLik = 0;
    number_t deltaLogLik = 0;

    // setup input data structures
    VarData varData(varDataFile, dfgInfo.varNames);
    FacData * facDataPtr = NULL;
    VarData * subVarDataPtr = NULL;
    if (facDataFile.size() != 0) {
      facDataPtr = new FacData(facDataFile, dfgInfo.facNames);
    }
    if (subVarDataFile.size() != 0) {
      subVarDataPtr = new VarData(subVarDataFile, dfgInfo.subNames);
    }
    else if( dfgInfo.subNames.size() > 0 ){
      errorAbort("DfgDataWrap.cpp::164::main There are subscribed factors but no subscribed variable file were provided");
    }

    // init variables
    // input data variables
    string idVar;
    vector<symbol_t> varVec( varData.count() ); // for input data
    // dfg variables    
    stateMaskVec_t stateMaskVec( dfgInfo.varNames.size() );
    vector<matrix_t> facExpCounts; // Expectation counts
    initAccFactorMarginals(facExpCounts, dfg);
    vector<xmatrix_t> tmpFacMar;  // workspace
    dfg.initFactorMarginals(tmpFacMar);
    xnumber_t normConst;

    // open log file
    ofstream f;
    if ( logFile.size() ) {
      f.open(logFile.c_str(), ios::out);
      if (!f)
	errorAbort("Cannot open file: " + logFile + "\n");
      
      f << "minDeltaLogLik: " << minDeltaLogLik << endl;
      f << "maxIter:        " << maxIter << endl;
      f << endl;
      f << "iter" << "\t" << "logLik" << "\t" << "deltaLogLik" << endl;
    }

    while ( ( (deltaLogLik > minDeltaLogLik) or iter == 0) and iter < maxIter) {
      logLik = 0;
      reset(facExpCounts);

      // reset varData and facData
      varData.reset(varDataFile, dfgInfo.varNames);
      if (facDataFile.size() != 0) {
	facDataPtr->reset(facDataFile, dfgInfo.facNames);
      }
      if (subVarDataFile.size() != 0) {
	subVarDataPtr->reset(subVarDataFile, dfgInfo.subNames);
      }
      unsigned lineCount = 0;
      while ( varData.next(idVar, varVec) ) {
	lineCount++;
	resetFactorPotential(facDataPtr, idVar, lineCount, dfgInfo.dfg);
	updateFactorPotentials(subVarDataPtr, idVar, lineCount, dfgInfo);
	dfgInfo.stateMaskMapSet.symbols2StateMasks( stateMaskVec, varVec, varData.map() );

	//	//debug begin
	//	string facName("CpG_P_1.likelihood");
	//	unsigned facIdx = find(dfgInfo.facNames.begin(), dfgInfo.facNames.end(), facName) - dfgInfo.facNames.begin();
	//	cout << "factor name: " << facName << "; facIdx: " << facIdx << "; potential " << dfg.getFactor(facIdx).potential <<  endl;
	//	//debug end

	calcFacAccMarAndNormConst(facExpCounts, tmpFacMar, normConst, stateMaskVec, dfg);

	logLik += - log(normConst);
      }

      factorSet.submitCounts(facExpCounts);
      factorSet.optimizeParameters();
      dfg.resetFactorPotentials( factorSet.mkFactorVec() );
      factorSet.clearCounts();

      deltaLogLik = abs(prevLogLik - logLik); // set at abs(-logLik) in iter 0

      if ( logFile.size() )
	f << iter << "\t" << logLik << "\t" << deltaLogLik << endl;


      if ( logStateMapsFile.size() )
	writeDfgInfo(dfgInfo, logStateMapsFile, logFactorPotentialsFile, logVariablesFile, logFactorGraphFile);

      //
      //      // debug
      //      cout << "from dfgEm:" << endl;
      //      cout << "iter:        " << iter << endl;
      //      cout << "logLik:      " << logLik << endl;
      //      cout << "prevLogLik:  " << prevLogLik << endl;
      //      cout << "deltaLogLik: " << deltaLogLik << endl;
      //      cout << "minDeltaLogLik: " << minDeltaLogLik << endl;
      //      cout << "maxIter: " << maxIter << endl;
      //      cout << "( ( (deltaLogLik > minDeltaLogLik) or iter == 0) and iter < maxIter): " << ( ( (deltaLogLik > minDeltaLogLik) or iter == 0) and iter < maxIter) << endl;
      //

      //      //debug begin
      //      cout << endl << "iteration #: " << iter << endl << endl;
      //      //debug end

      prevLogLik = logLik;
      iter++;
    }

    // clean up
    if (facDataPtr != NULL)
      delete facDataPtr;
  }
コード例 #3
0
ファイル: AM1DExpressionAB.cpp プロジェクト: Cpppro/acquaman
bool AM1DExpressionAB::values(const AMnDIndex &indexStart, const AMnDIndex &indexEnd, double *outputValues) const
{
	if(!isValid())	// will catch most invalid situations: non matching sizes, invalid inputs, invalid expressions.
		return false;

	if(indexStart.rank() != 1 || indexEnd.rank() != 1)
		return false;

#ifdef AM_ENABLE_BOUNDS_CHECKING
		if((unsigned)indexEnd.i() >= (unsigned)size_ || indexStart.i() > indexEnd.i())
			return false;
#endif

	int totalSize = indexEnd.i() - indexStart.i() + 1;
	int offset = indexStart.i();

	// can we get it directly? Single-value expressions don't require the parser.
	if(direct_) {
		// info on which variable to use is contained in directVar_.
		if(directVar_.useAxisValue) {
			for(int i=0; i<totalSize; i++)
				outputValues[i] = sources_.at(directVar_.sourceIndex)->axisValue(0, i+offset);	/// \todo Create a AMDataSource::axisValues().
			return true;
		}
		else {
			return sources_.at(directVar_.sourceIndex)->values(indexStart, indexEnd, outputValues);
		}
	}

	// otherwise we need the parser
	else {
		// block-copy all of the input data sources (that are actually used in the expression) into allVarData.
		QList<QVector<double> > allVarData;
		for(int v=0; v<usedVariables_.count(); ++v) {
			QVector<double> varData(totalSize);

			AMParserVariable* usedVar = usedVariables_.at(v);
			if(usedVar->useAxisValue) {
				for(int i=0; i<totalSize; i++)
					varData[i] = sources_.at(usedVar->sourceIndex)->axisValue(0, i+offset);
			}
			else {
				bool success = sources_.at(usedVar->sourceIndex)->values(indexStart, indexEnd, varData.data());
				if(!success)
					return false;
			}
			allVarData << varData;
		}

		// loop through and parse all values
		for(int i=0; i<totalSize; ++i) {	// loop through points

			for(int v=0,cc=usedVariables_.count(); v<cc; ++v) {
				usedVariables_.at(v)->value = allVarData.at(v).at(i);
			}

			// evaluate using the parser:
			double rv;
			try {
				rv = parser_.Eval();
			}
			catch(mu::Parser::exception_type& e) {
				QString explanation = QString("AM1DExpressionAB Analysis Block: error evaluating value: %1: '%2'.  We found '%3' at position %4.").arg(QString::fromStdString(e.GetMsg()), QString::fromStdString(e.GetExpr()), QString::fromStdString(e.GetToken())).arg(e.GetPos());
				AMErrorMon::report(AMErrorReport(this, AMErrorReport::Debug, e.GetCode(), explanation));
				return false;
			}

			if (rv == std::numeric_limits<qreal>::infinity() || rv == -std::numeric_limits<qreal>::infinity() || rv == std::numeric_limits<qreal>::quiet_NaN())
				rv = 0;

			outputValues[i] = rv;
		}

		return true;
	}
}