Ejemplo n.º 1
0
void DataSignal :: WriteSmartPeakInfoToXML (RGTextOutput& text, const RGString& indent, const RGString& bracketTag, const RGString& locationTag) {

	int peak;
	Endl endLine;
	RGString suffix;
	
//	if (HasCrossChannelSignalLink ()) {

		if (HasAlleleName () && (!mDoNotCall)) {

			peak = (int) floor (Peak () + 0.5);

			if (mOffGrid)
				suffix = " OL";

			text << indent << "<" << bracketTag << ">" << endLine;
			text << indent << "\t<mean>" << GetMean () << "</mean>" << endLine;
			text << indent << "\t<height>" << peak << "</height>" << endLine;
			text << indent << "\t<BPS>" << GetBioID () << "</BPS>" << endLine;
//			text << indent << "\t<" << locationTag << ">" << (int) floor (GetApproximateBioID () + 0.5) << "</" << locationTag << ">" << endLine;
			text << indent << "\t<" << locationTag << ">" << GetApproximateBioID () << "</" << locationTag << ">" << endLine;
			text << indent << "\t<PeakArea>" << TheoreticalArea () << "</PeakArea>" << endLine;
			text << indent << "\t<allele>" << GetAlleleName () << suffix << "</allele>" << endLine;
			text << indent << "\t<width>" << 4.0 * GetStandardDeviation () << "</width>" << endLine;
			text << indent << "\t<fit>" << GetCurveFit () << "</fit>" << endLine;
			text << indent << "</" + bracketTag << ">" << endLine;
		}
//	}
}
Ejemplo n.º 2
0
bool DataSignal :: ReportSmartNoticeObjects (RGTextOutput& text, const RGString& indent, const RGString& delim) {

	if (NumberOfSmartNoticeObjects () > 0) {

		int msgLevel = GetHighestMessageLevelWithRestrictionSM ();
		RGDListIterator it (*mSmartMessageReporters);
		SmartMessageReporter* nextNotice;
		text.SetOutputLevel (msgLevel);

		if (!text.TestCurrentLevel ()) {

			text.ResetOutputLevel ();
			return false;
		}

		Endl endLine;
		text << endLine;
		text << indent << "Notices for curve with (Mean, Sigma, Peak, 2Content, Fit) = " << delim << delim << delim << delim << delim << delim;
		text << GetMean () << delim << GetStandardDeviation () << delim << Peak () << delim << GetScale (2) << delim << Fit << endLine;

		while (nextNotice = (SmartMessageReporter*) it ())
			text << indent << nextNotice->GetMessage () << nextNotice->GetMessageData () << endLine;

		text.ResetOutputLevel ();
		text.Write (1, "\n");
	}

	else
		return false;

	return true;
}
Ejemplo n.º 3
0
void RejectOutlierMatches(vector<Point3f> &matches1, vector<Point3f> &matches2, vector<float> &matchDistances, float maxStdDev)
{
	float distanceStandardDev = GetStandardDeviation(matchDistances);

	vector<Point3f> filteredMatches1;
	vector<Point3f> filteredMatches2;
	for (size_t i = 0; i < matches1.size(); i++)
	{
		if (matchDistances[i] > maxStdDev * distanceStandardDev)
			continue;

		filteredMatches1.push_back(matches1[i]);
		filteredMatches2.push_back(matches2[i]);
	}

	matches1 = filteredMatches1;
	matches2 = filteredMatches2;
}
Ejemplo n.º 4
0
void DataSignal :: WriteSmartArtifactInfoToXML (RGTextOutput& text, const RGString& indent, const RGString& bracketTag, const RGString& locationTag) {

	int peak;
	Endl endLine;
	RGString suffix;
	RGString label;
	SmartMessageReporter* notice;
	int i;
	RGString virtualAllele;
	int reportedMessageLevel;

	reportedMessageLevel = GetHighestMessageLevelWithRestrictionSM ();
	bool thisIsFirstNotice = true;

	if ((!DontLook ()) && (NumberOfSmartNoticeObjects () != 0)) {
	
		peak = (int) floor (Peak () + 0.5);

		if (mOffGrid)
			suffix = " OL";

		virtualAllele = GetVirtualAlleleName ();

		RGDListIterator it (*mSmartMessageReporters);
		i = 0;

		while (notice = (SmartMessageReporter*) it ()) {

			if (!notice->GetDisplayOsirisInfo ())
				continue;

			if (thisIsFirstNotice) {

				text << indent << "<" << bracketTag << ">" << endLine;
				text << indent << "\t<level>" << reportedMessageLevel << "</level>" << endLine;
				text << indent << "\t<mean>" << GetMean () << "</mean>" << endLine;
				text << indent << "\t<height>" << peak << "</height>" << endLine;
//				text << indent << "\t<" << locationTag << ">" << (int) floor (GetApproximateBioID () + 0.5) << "</" << locationTag << ">" << endLine;
				text << indent << "\t<" << locationTag << ">" << GetApproximateBioID () << "</" << locationTag << ">" << endLine;
				text << indent << "\t<PeakArea>" << TheoreticalArea () << "</PeakArea>" << endLine;

				if (virtualAllele.Length () > 0)
					text << indent << "\t<equivAllele>" << virtualAllele << suffix << "</equivAllele>" << endLine;

				text << indent << "\t<width>" << 4.0 * GetStandardDeviation () << "</width>" << endLine;
				text << indent << "\t<fit>" << GetCurveFit () << "</fit>" << endLine;
				label = indent + "\t<label>";
				thisIsFirstNotice = false;
			}

			if (i > 0)
				label << "&#10;";

			label += notice->GetMessage ();
			label += notice->GetMessageData ();
			i++;
		}

		RGString temp = GetVirtualAlleleName () + suffix;

		if (temp.Length () > 0) {

			if (i > 0)
				label << "&#10;";

			label += "Allele " + temp;
		}

		if (i > 0) {

			label << "</label>";
			text << label << endLine;
			text << indent << "</" + bracketTag << ">" << endLine;
		}

		/*if ((signalLink != NULL) && (!signalLink->xmlArtifactInfoWritten)) {

			signalLink->xmlArtifactInfoWritten = true;
			peak = signalLink->height;

			text << indent << "<" << bracketTag << ">" << endLine;
			text << indent << "\t<mean>" << signalLink->mean << "</mean>" << endLine;
			text << indent << "\t<height>" << peak << "</height>" << endLine;
			text << indent << "\t<" << locationTag << ">" << signalLink->bioID << "</" << locationTag << ">" << endLine;
			text << indent << "\t<fit>" << GetCurveFit () << "</fit>" << endLine;
			label = indent + "\t<label>";
			mNoticeObjectIterator.Reset ();
			i = 0;

			while (notice = (Notice*) mNoticeObjectIterator ()) {

				if (i > 0)
					label << "&#10;";

				label += notice->GetLabel ();
				i++;
			}

			if (temp.Length () > 0) {

				if (i > 0)
					label << "&#10;";

				label += "Allele " + temp;
			}

			label << "</label>";
			text << label << endLine;
			text << indent << "</" + bracketTag << ">" << endLine;
		}*/
	}
}
Ejemplo n.º 5
0
void MgFeatureNumericFunctions::CalculateDistribution(VECTOR& values, VECTOR& distValues)
{
    STRING funcName;
    int numCats;
    double dataMin, dataMax;
    INT32 funcCode = -1;

    // Get the arguments from the FdoFunction
    STRING propertyName;
    bool supported = MgServerFeatureUtil::FindCustomFunction(m_customFunction, funcCode);

    if (supported)
    {
        switch(funcCode)
        {
            case EQUAL_CATEGORY: // Equal Category
            {
                MgServerFeatureUtil::GetArguments(m_customFunction, propertyName, numCats, dataMin, dataMax, m_type);
                GetEqualCategories(values, numCats, dataMin, dataMax, distValues);
                break;
            }
            case STDEV_CATEGORY: // StdDev Category
            {
                MgServerFeatureUtil::GetArguments(m_customFunction, propertyName, numCats, dataMin, dataMax, m_type);
                GetStandardDeviationCategories(values, numCats, dataMin, dataMax, distValues);
                break;
            }
            case QUANTILE_CATEGORY: // Quantile Category
            {
                MgServerFeatureUtil::GetArguments(m_customFunction, propertyName, numCats, dataMin, dataMax, m_type);
                GetQuantileCategories(values, numCats, dataMin, dataMax, distValues);
                break;
            }
            case JENK_CATEGORY: // Jenk Category
            {
                MgServerFeatureUtil::GetArguments(m_customFunction, propertyName, numCats, dataMin, dataMax, m_type);
                GetJenksCategories(values, numCats, dataMin, dataMax, distValues);
                break;
            }
            case MINIMUM:
            {
                GetMinimum(values,distValues);
                break;
            }
            case MAXIMUM:
            {
                GetMaximum(values,distValues);
                break;
            }
            case MEAN:
            {
                GetMeanValue(values,distValues);
                break;
            }
            case STANDARD_DEV:
            {
                GetStandardDeviation(values,distValues);
                break;
            }
            case UNIQUE:
            {
                MgUniqueFunction<double>::Execute(values, distValues);
                break;
            }
        }
    }
}
Ejemplo n.º 6
0
        // This function builds the mass function based on lane features
    	// \param lateralOffset: current lateral offset  
    	// \param intervalTime: the interval time between the two consective frames
    	//! Assign the mass from lane source 
    	//! Standard deviation reflects the extent of wave about car. It will show the fatigue.
	void GenerateLaneIndicators(const int &sampleIdx, const int &TIME_SAMPLING_WINDOW, int &muWindowSize, int &sigmaWindowSize,
                          const double &lateralOffset, std::deque<InfoCar> &lateralOffsetDeque, std::deque <InfoCar> &LANEXDeque, 
                          std::deque<InfoTLC> &TLCDeque, LaneFeature &laneFeatures, const double &intervalTime)
    	{
        	double LATMEAN=laneFeatures.LATMEAN, LANEDEV=laneFeatures.LANEDEV, LATSD=0, LANEX=0, TLC=0, TLC_min=0;
        	int TLC_2s = 0, TLC_halfs = 0;
        	double TLCF_2s = 0, TLCF_halfs = 0;
        
		//! lateralOffsetDeque

        	InfoCar infoLO;
        	infoLO.lateralOffset = lateralOffset;
        	infoLO.intervalTime  = intervalTime;
        	if(!lateralOffsetDeque.empty()) 
		{
            		infoLO.winTime = lateralOffsetDeque.back().winTime + intervalTime;
        	} else {
            		infoLO.winTime = intervalTime;
        	}
       	 	while (infoLO.winTime > TIME_SAMPLING_WINDOW && !lateralOffsetDeque.empty()) 
		{
            		infoLO.winTime -= lateralOffsetDeque.front().intervalTime;
            		lateralOffsetDeque.pop_front();
        	}
        	lateralOffsetDeque.push_back(infoLO);
        
		//! Need to reset \param muWindowSize and \param sigmaWindowSize.
  
        	GetEWMA(sampleIdx, muWindowSize, lateralOffset, LATMEAN);
        	GetEWVAR(sampleIdx, sigmaWindowSize, lateralOffset, LATMEAN, LANEDEV);
        	GetStandardDeviation(lateralOffsetDeque, LATSD);
        	std::cout << "LO: " << lateralOffset << "LATSD: " << LATSD << std::endl;

		//! Considering the sampling Time of LANEX different that of lateralOffset 
		//! Rebuild the InfoCar struct

        	InfoCar infoLANEX;
        	infoLANEX.lateralOffset = lateralOffset;
        	infoLANEX.intervalTime  = intervalTime;
        	if(!LANEXDeque.empty()) 
		{
            		infoLANEX.winTime = LANEXDeque.back().winTime + intervalTime;
        	} else {
            		infoLANEX.winTime = intervalTime;
        	}
       	 	while (infoLANEX.winTime > TIME_SAMPLING_WINDOW) 
		{
            		infoLANEX.winTime -= LANEXDeque.front().intervalTime;
            		LANEXDeque.pop_front();
        	}
        	LANEXDeque.push_back(infoLANEX);
        
        	double sumTime_LANEX = 0, sumTime = 0;
        	for(std::deque<InfoCar>::size_type i = 0; i != LANEXDeque.size(); ++i)
        	{
            		if(LANEXDeque[i].lateralOffset == 1)
            		{
                		sumTime_LANEX += LANEXDeque[i].intervalTime;
            		}
            		sumTime += LANEXDeque[i].intervalTime;
        	}
        	LANEX = sumTime_LANEX / sumTime;
        
		//! Time-to-Lane-Crossing    

        	//! Simple TLC 
        	CV_Assert((int)lateralOffsetDeque.size() > 1);
        	double lastLateralOffset = lateralOffsetDeque.at(lateralOffsetDeque.size()-2).lateralOffset;
       	 	double lateralVelocity = lateralOffset - lastLateralOffset;
        
        	double TLC_Frame = 0;
        	if (lateralVelocity < 0)//direct to left
            	TLC_Frame = std::abs((1 + lateralOffset) / lateralVelocity);
        	else if(lateralVelocity > 0)//direct to right
            	TLC_Frame = std::abs((1 - lateralOffset) / lateralVelocity);
        	else
            	TLC_Frame = 10000;//Max TLC shows a safe deviation 
        	TLC = TLC_Frame * intervalTime;//sec
        	TLC = TLC < 1000 ? TLC : 1000;
        
        	InfoTLC infoTLC;
        	infoTLC.TLC = TLC;
        	infoTLC.intervalTime = intervalTime;
        	if(!TLCDeque.empty()) 
		{
            		infoTLC.winTime = TLCDeque.back().winTime + intervalTime;
        	} else {
            		infoTLC.winTime = intervalTime;
        	}
        	while (infoTLC.winTime > TIME_SAMPLING_WINDOW) 
		{
            		infoTLC.winTime -= TLCDeque.front().intervalTime;
            		TLCDeque.pop_front();
        	}
        	TLCDeque.push_back(infoTLC);
       
        	//! Number of times that TLC below a threshold
        	for(std::deque<double>::size_type i = 0; i != TLCDeque.size(); ++i)
        	{
            		//!TLC with signal falling below 2s in a given time interval
            		if(TLCDeque[i].TLC < 2.0)
            		{
                		TLC_2s ++;
            		}
            		//!TLC with signal falling below 0.5s in a given time interval
            		if(TLCDeque[i].TLC < 0.5)
            		{
                		TLC_halfs ++;
            		}
        	}
        	//! Fraction of TLC_2s and TLC_halfs
        	TLCF_2s = (double)TLC_2s / (double)TLCDeque.size();
        	TLCF_halfs = (double)TLC_halfs / (double)TLCDeque.size();
        
        	//! Global minimum of TLC over a given time interval;
        	std::deque<InfoTLC> cmpTLCDeque = TLCDeque;
        	sort(cmpTLCDeque.begin(), cmpTLCDeque.end(), TLC_cmp);
        	TLC_min = cmpTLCDeque.back().TLC;
        	std::deque<InfoTLC>::iterator iter = cmpTLCDeque.end();
        	while (TLC_min == 0) 
		{ 
            		--iter;
            		TLC_min = iter->TLC;
        	}
        
        	//!Update the LaneFeature struct
        	laneFeatures.frame          = sampleIdx;
        	laneFeatures.lateralOffset  = lateralOffset;
        	laneFeatures.LATMEAN        = LATMEAN;  //EWMA
        	laneFeatures.LANEDEV        = LANEDEV;  //EWVAR
        	laneFeatures.LATSD          = LATSD;
        	laneFeatures.LANEX          = LANEX;
        	laneFeatures.TLC            = TLC;
        	laneFeatures.TLC_2s         = TLC_2s;
        	laneFeatures.TLC_halfs      = TLC_halfs;
        	laneFeatures.TLC_min        = TLC_min;
        	laneFeatures.TLCF_2s        = TLCF_2s;
        	laneFeatures.TLCF_halfs     = TLCF_halfs;
	}//end GenerateLaneIndicators
Ejemplo n.º 7
0
    	void GetLaneBaseline(const int &sampleIdx, 
                         const int &TIME_SAMPLING_WINDOW,
                         int &muWindowSize, int &sigmaWindowSize, 
                         const double &lateralOffset,
                         std::vector<double> &LATSD_Baseline,
                         std::deque<InfoCar> &lateralOffsetDeque, 
                         std::deque<InfoCar> &LANEXDeque, 
                         std::deque<InfoTLC> &TLCDeque,
                         LaneFeature &laneFeatures,
                         const double &intervalTime)
    	{
        	laneFeatures.frame = sampleIdx;
        	laneFeatures.lateralOffset = lateralOffset;
        
		//! lateralOffsetDeque
		InfoCar infoLO;
        	infoLO.lateralOffset = lateralOffset;
        	infoLO.intervalTime  = intervalTime;
        	if(!lateralOffsetDeque.empty()) 
		{
            		infoLO.winTime = lateralOffsetDeque.back().winTime + intervalTime;
        	} else {
            		infoLO.winTime = intervalTime;
        	}
        	while (infoLO.winTime > TIME_SAMPLING_WINDOW && !lateralOffsetDeque.empty()) 
		{
            		infoLO.winTime -= lateralOffsetDeque.front().intervalTime;
            		lateralOffsetDeque.pop_front();
        	}
        	lateralOffsetDeque.push_back(infoLO);
        
		//! Need to reset \param muWindowSize and \param sigmaWindowSize.
        	GetEWMA(sampleIdx, muWindowSize, lateralOffset , laneFeatures.LATMEAN);
        	GetEWVAR(sampleIdx, sigmaWindowSize, lateralOffset , laneFeatures.LATMEAN, laneFeatures.LANEDEV);
        
		//! Standard Deviation of LATSD for Baseline
        	GetStandardDeviation(lateralOffsetDeque, laneFeatures.LATSD);
        	LATSD_Baseline.push_back(laneFeatures.LATSD);
        	sort(LATSD_Baseline.begin(), LATSD_Baseline.end(), LATSD_cmp);
        
		//! Considering the sampling Time of LANEX different that of lateralOffset 
		//! Rebuild the InfoCar struct
        	InfoCar infoLANEX;
        	infoLANEX.lateralOffset = lateralOffset;
        	infoLANEX.intervalTime  = intervalTime;
        
        	if(!LANEXDeque.empty()) 
		{
            		infoLANEX.winTime = LANEXDeque.back().winTime + intervalTime;
        	} else {
            		infoLANEX.winTime = intervalTime;
        	}
        
        	while (infoLANEX.winTime > TIME_SAMPLING_WINDOW) 
		{
            		infoLANEX.winTime -= LANEXDeque.front().intervalTime;
            		LANEXDeque.pop_front();
        	}
        	LANEXDeque.push_back(infoLANEX);
        
		double sumTime_LANEX = 0;
		for(std::deque<InfoCar>::size_type i = 0; i != LANEXDeque.size(); ++i)
		{
		    	if(LANEXDeque[i].lateralOffset == 1)
		    	{
		        	sumTime_LANEX += LANEXDeque[i].intervalTime;
		    	}
		}
		double LANEX = sumTime_LANEX / LANEXDeque.back().winTime;
        
		if(sampleIdx > 1) 
		{
			//! Add TLC into deque. Simple TLC 

            		double TLC = 0, TLC_min = 0;
            		int TLC_2s = 0, TLC_halfs = 0;
            		double TLCF_2s = 0, TLCF_halfs = 0;
            
            		CV_Assert((int)lateralOffsetDeque.size() > 1);
            		double lastLateralOffset = lateralOffsetDeque.at(lateralOffsetDeque.size()-2).lateralOffset;
            		double lateralVelocity = lateralOffset - lastLateralOffset;
            
            		double TLC_Frame = 0;
            		if (lateralVelocity < 0)//direct to left
                	TLC_Frame = std::abs((1 + lateralOffset) / lateralVelocity);
            		else if(lateralVelocity > 0)//direct to right
                	TLC_Frame = std::abs((1 - lateralOffset) / lateralVelocity);
            		else
                	TLC_Frame = 10000;//Max TLC shows a safe deviation 
            		TLC = TLC_Frame / intervalTime;//sec
            		TLC = TLC < 1000 ? TLC : 1000;
            
            		InfoTLC infoTLC;
            		infoTLC.TLC = TLC;
            		infoTLC.intervalTime = intervalTime;
            		if(!TLCDeque.empty()) 
			{
                		infoTLC.winTime = TLCDeque.back().winTime + intervalTime;
            		} else {
                		infoTLC.winTime = intervalTime;
            		}
            		while (infoTLC.winTime > TIME_SAMPLING_WINDOW) 
			{
                		infoTLC.winTime -= TLCDeque.front().intervalTime;
                		TLCDeque.pop_front();
            		}
            		TLCDeque.push_back(infoTLC);
            
            		//! Number of times that TLC below a threshold
            		for(std::deque<double>::size_type i = 0; i != TLCDeque.size(); i++) 
			{
                		//!TLC with signal falling below 2s in a given time interval
                		if(TLCDeque[i].TLC < 2.0) 
				{
                    			TLC_2s ++;
                		}
                		//!TLC with signal falling below 0.5s in a given time interval
                		if(TLCDeque[i].TLC < 0.5) 
				{
                    			TLC_halfs ++;
                		}
            		}
            		//! Fraction of TLC_2s and TLC_halfs
            		TLCF_2s = (double)TLC_2s / (double)TLCDeque.size();
            		TLCF_halfs = (double)TLC_halfs / (double)TLCDeque.size();
                        
            		//! Global minimum of TLC over a given time interval;
            		std::deque<InfoTLC> cmpTLCDeque = TLCDeque;
            		sort(cmpTLCDeque.begin(), cmpTLCDeque.end(), TLC_cmp);
            		TLC_min = cmpTLCDeque.back().TLC;
            		std::deque<InfoTLC>::iterator iter = cmpTLCDeque.end();
            		while (TLC_min == 0) 
			{ 
                		--iter;
                		TLC_min = iter->TLC;
            		}
       
			//! Calculate the Baseline
            		//!Baseline of LATSD should be the median value.
            		laneFeatures.LATSD_Baseline = LATSD_Baseline.at(cvRound(LATSD_Baseline.size()/2.0));
            		//!Others
            		laneFeatures.LATMEAN_Baseline = laneFeatures.LATMEAN_Baseline > laneFeatures.LATMEAN ? laneFeatures.LATMEAN_Baseline : laneFeatures.LATMEAN;
            		laneFeatures.LANEDEV_Baseline = laneFeatures.LANEDEV_Baseline > laneFeatures.LANEDEV ? laneFeatures.LANEDEV_Baseline : laneFeatures.LANEDEV;
            		laneFeatures.LANEX = LANEX;
            		laneFeatures.TLC = TLC;
            		laneFeatures.TLC_2s = TLC_2s;
            		laneFeatures.TLC_halfs = TLC_halfs;
            		laneFeatures.TLC_min = TLC_min;
            		laneFeatures.TLCF_2s = TLCF_2s;
            		laneFeatures.TLCF_halfs = TLCF_halfs;
        	} else {
            		laneFeatures.LATMEAN_Baseline   = 0;
            		laneFeatures.LANEDEV_Baseline   = 0;
            		laneFeatures.LATSD_Baseline     = 0;
            		laneFeatures.LANEX              = 0;
            		laneFeatures.TLC                = 0;
            		laneFeatures.TLC_2s             = 0;
            		laneFeatures.TLC_halfs          = 0;
            		laneFeatures.TLC_min            = 0;
            		laneFeatures.TLCF_2s            = 0;
            		laneFeatures.TLCF_halfs         = 0;
        	}
    	}//end GetLaneBaseline