Пример #1
0
void Sensor::Sensing(SensingInfo* info) {
	uint32_t currentTime = millis();
	if ( (currentTime - lastTime) > 2000 ) {
		
		if (count >= MAX_COUNT) {
			StaticJsonBuffer<SENSORDATA_JSON_SIZE>* jsonBuffer = new StaticJsonBuffer<SENSORDATA_JSON_SIZE>; 
			JsonObject& root = jsonBuffer->createObject();
			
			root[FPSTR(TEMPERATURE_KEY)] = prevTemp = nomalization(temperature);
			root[FPSTR(HUMIDITY_KEY)] = prevHumid = nomalization(humidity);
			
			String SensingData = "";
			
			root.printTo(SensingData);
			info->deserialize(SensingData);

			delete jsonBuffer;
			
			requireUpdate = true;
			count = 0;
		}

		checkHumData(count);
		checkTemData(count);
		count++;

		lastTime = currentTime;
	}
}
Пример #2
0
void Adaboost(TrainData *data,int T){
    InitWi(data);
    double temptheta=0.0,theta1=0.0;
    double error,beta;
    int p=0;                            //p=0 <=> '<' p=0 <=> '>'
    double min;
//////////////left is positive & right is nagitive//////////////
    for(int i=0;i<T;i++){
        //get theta first
        p=0;
        min=DBL_MAX;//////Be careful
        nomalization(data);
        for(int j=0;j<Data_Size_G;j++){
            InitStatus(data);
            temptheta=data[j].property;
            for(int k=0;k<Data_Size_G;k++){
                if((data[k].property<=temptheta)&&(data[k].label==0))
                    data[k].status=MISS;
                if((data[k].property>temptheta)&&(data[k].label))
                    data[k].status=MISS;
            }
            error=getError(data);
            if(error<=min&&error<0.5){
                theta1=temptheta;
                min=error;
            
            }
        }
        
//////////////right is positive & left is nagitive//////////////
        temptheta=0.0;
        double theta2=0.0;
        for(int j=0;j<Data_Size_G;j++){
            InitStatus(data);
            temptheta=data[j].property;
            for(int k=0;k<Data_Size_G;k++){
                if((data[k].property>=temptheta)&&(data[k].label==0))
                    data[k].status=MISS;
                if((data[k].property<temptheta)&&(data[k].label))
                    data[k].status=MISS;
            }
            error=getError(data);
            if(error<=min){
                theta2=temptheta;
                min=error;
                p=1;
                
            }
        }
//////////////////////////////////////////////////////////////////////////
        InitStatus(data);
        double theta=p?theta2:theta1;
        if(p)
            for(int k=0;k<Data_Size_G;k++){
                if((data[k].property>=theta)&&(data[k].label==0))
                    data[k].status=MISS;
                if((data[k].property<theta)&&(data[k].label))
                    data[k].status=MISS;
            }
        else
            for(int k=0;k<Data_Size_G;k++){
                if((data[k].property<=theta)&&(data[k].label==0))
                    data[k].status=MISS;
                if((data[k].property>theta)&&(data[k].label))
                    data[k].status=MISS;
            }
        
        
        
        error=getError(data);
        beta=getBeta(error);
        updataWi(data, beta);
        
        if(p)
            printf("|>=|   |Threshold:%9lf|error:%9lf |Alpha:%9lf|\n",theta,error,getAlpha(beta));
        else
            printf("|<=|   |Threshold:%9lf|error:%9lf |Alpha:%9lf|\n",theta,error,getAlpha(beta));
        
      
    }

}