コード例 #1
0
float WrfStatisticSolver::GetHittingRate(std::vector< RecordSetMap* >& bias_set_vec, 
	std::vector< float >& attrib_weight, WeightMap& grid_model_weight, int grid_size, 
	std::vector< float >& grid_alpha_map, int current_time, int his_time_length, float threshold, 
	WrfGridValueMap* test_map){

	std::vector< float > hitting_count, temp_hitting_count;
	float bias_hitting_count = 0;
	hitting_count.resize(attrib_weight.size(), 0);
	temp_hitting_count.resize(attrib_weight.size(), 0);

	//GetBiasVarMap(bias_set_vec, attrib_weight, grid_model_weight, grid_size, grid_alpha_map, current_time, his_time_length, test_map);

	int longi_grid_size = test_map->longitude_grid_number / grid_size;
	int lati_grid_size = test_map->latitude_grid_number / grid_size;

	for ( int i = 0; i < test_map->latitude_grid_number; ++i ){
		int temp_lati_index = i / grid_size;
		if ( temp_lati_index >= lati_grid_size ) continue;
		for ( int j = 0; j < test_map->longitude_grid_number; ++j ){
			int temp_longi_index = j / grid_size;
			if ( temp_longi_index >= longi_grid_size ) continue;

			int temp_grid_index = temp_lati_index * longi_grid_size + temp_longi_index;
			int grid_index = i * test_map->longitude_grid_number + j;
			
			if ( test_map->values[grid_index] > threshold ) continue;

			bias_hitting_count += 1;
			for ( int k = 0; k < bias_set_vec.size(); ++k ){
				for ( int t = current_time - his_time_length; t < current_time; ++t ){
					std::vector< std::vector< float > >* model_weight = grid_model_weight.at(t);
					float temp_time_value = Ftime(current_time - t);

					WrfDataRecordSet* record_set = bias_set_vec[k]->at(t);
					WrfDataRecord* temp_record = record_set->values[grid_index];
					WrfDataRecord* his_record = record_set->his_values[grid_index];
					if ( abs(temp_record->rain) / (abs(his_record->rain) + 0.1) < threshold ) hitting_count[WRF_RAIN] += temp_time_value;
					if ( abs(temp_record->pressure) / (abs(his_record->pressure) + 0.1) < threshold ) hitting_count[WRF_PRESSURE] += temp_time_value;
					if ( abs(temp_record->relative_humidity_850hpa) / (abs(his_record->relative_humidity_850hpa) + 0.1) < threshold ) hitting_count[WRF_RH_850HPA] += temp_time_value;
					if ( abs(temp_record->height_850hpa) / (abs(his_record->height_850hpa) + 0.1) < threshold ) hitting_count[WRF_HEIGHT_850HPA] += temp_time_value;
					if ( abs(temp_record->temperature_850hpa) / (abs(his_record->temperature_850hpa) + 0.1) < threshold ) hitting_count[WRF_TEMPERATURE_850HPA] += temp_time_value;
					if ( abs(temp_record->x_speed_850hpa) / (abs(his_record->x_speed_850hpa) + 0.1) < threshold ) hitting_count[WRF_WIND_X_850HPA] += temp_time_value;
					if ( abs(temp_record->y_speed_850hpa) / (abs(his_record->y_speed_850hpa) + 0.1) < threshold ) hitting_count[WRF_WIND_Y_850HPA] += temp_time_value;
				}
			}
		}
	}

	float time_acc = 0;
	for ( int t = current_time - his_time_length; t < current_time; ++t ) time_acc += Ftime(current_time - t);
	//float node_num = longi_grid_size * lati_grid_size * grid_size * grid_size * bias_set_vec.size() * time_acc;
	bias_hitting_count *= time_acc * bias_set_vec.size();
	for ( int i = 0; i < 7; ++i ) hitting_count[i] /= bias_hitting_count;
	float theropy = 0;
	for ( int i = 0; i < 7; ++i ) 
		if (hitting_count[i] != 0 ) theropy += -1 * hitting_count[i] * log(hitting_count[i]);

	return theropy;
}
コード例 #2
0
bool WrfStatisticSolver::GetBiasVarMap(std::vector< RecordSetMap* >& bias_set_vec,
	std::vector< float >& attrib_weight, WeightMap& grid_model_weight, int grid_size,
	std::vector< float >& grid_alpha_map, int current_time, int his_time_length, float history_weight, float current_weight, 
	WrfGridValueMap* bias_var_map){
	
	int longi_grid_size = bias_var_map->longitude_grid_number / grid_size;
	int lati_grid_size = bias_var_map->latitude_grid_number / grid_size;
	memset(bias_var_map->values.data(), 0, bias_var_map->values.size() * sizeof(float));

	for ( int i = 0; i < bias_var_map->latitude_grid_number; ++i ){
		int temp_lati_index = i / grid_size;
		if ( temp_lati_index >= lati_grid_size ) continue;
		for ( int j = 0; j < bias_var_map->longitude_grid_number; ++j ){
			int temp_longi_index = j / grid_size;
			if ( temp_longi_index >= longi_grid_size ) continue;

			int temp_grid_index = temp_lati_index * longi_grid_size + temp_longi_index;
			int grid_index = i * bias_var_map->longitude_grid_number + j;

			WrfDataRecord bias_record;
			float result_value = 0;
			for ( int k = 0; k < bias_set_vec.size(); ++k ){
				float temp_result_value = 0;
				float temp_weight = 0;
				for ( int t = current_time - his_time_length; t < current_time; ++t ){
					std::vector< std::vector< float > >* model_weight = grid_model_weight.at(t);

					WrfDataRecordSet* record_set = bias_set_vec[k]->at(t);
					WrfDataRecord* temp_record = record_set->values[grid_index];
					WrfDataRecord* his_record = record_set->his_values[grid_index];

					bias_record.rain += abs(temp_record->rain) / (abs(his_record->rain) + 0.1 + 5) * attrib_weight[WRF_RAIN];
					bias_record.pressure += abs(temp_record->pressure) / (abs(his_record->pressure) + 0.1 + 2) * attrib_weight[WRF_PRESSURE];
					bias_record.relative_humidity_850hpa += abs(temp_record->relative_humidity_850hpa) / (abs(his_record->relative_humidity_850hpa) + 0.1 + 10) * attrib_weight[WRF_RH_850HPA];
					bias_record.height_850hpa += abs(temp_record->height_850hpa) / (abs(his_record->height_850hpa) + 0.1 + 2) * attrib_weight[WRF_HEIGHT_850HPA];
					bias_record.temperature_850hpa += abs(temp_record->temperature_850hpa) / (abs(his_record->temperature_850hpa) + 0.1 + 2) * attrib_weight[WRF_TEMPERATURE_850HPA];
					bias_record.x_speed_850hpa += abs(temp_record->x_speed_850hpa) / (abs(his_record->x_speed_850hpa) + 0.1 + 10) * attrib_weight[WRF_WIND_X_850HPA];
					bias_record.y_speed_850hpa += abs(temp_record->y_speed_850hpa) / (abs(his_record->y_speed_850hpa) + 0.1 + 10) * attrib_weight[WRF_WIND_Y_850HPA];

					float temp_scale = Ftime(current_time - t);
					temp_weight += temp_scale;
					bias_record *= temp_scale;
					bias_record *= model_weight->at(temp_grid_index)[k];

					temp_result_value += bias_record.ToSum();
				}
				if ( temp_weight > 1e-5 ) temp_result_value /= temp_weight;

				WrfDataRecordSet* current_set = bias_set_vec[k]->at(current_time);
				WrfDataRecordSet* prev_set = bias_set_vec[k]->at(current_time - 1);
				WrfDataRecord* current_record = current_set->values[grid_index];
				WrfDataRecord* pre_record = prev_set->values[grid_index];
				WrfDataRecord* pre_his_record = prev_set->his_values[grid_index];
				float scale = 0;
				scale += abs(current_record->rain - pre_record->rain - pre_his_record->rain) / (abs(pre_record->rain + pre_his_record->rain) + 5 + 0.1) * attrib_weight[WRF_RAIN];
				scale += abs(current_record->pressure - pre_record->pressure - pre_his_record->pressure) / (abs(pre_record->pressure + pre_his_record->pressure) + 2 + 0.1) * attrib_weight[WRF_PRESSURE];
				scale += abs(current_record->relative_humidity_850hpa - pre_record->relative_humidity_850hpa - pre_his_record->relative_humidity_850hpa) / (abs(pre_record->relative_humidity_850hpa + pre_his_record->relative_humidity_850hpa) + 10 + 0.1) * attrib_weight[WRF_RH_850HPA];
				scale += abs(current_record->height_850hpa - pre_record->height_850hpa - pre_his_record->height_850hpa) / (abs(pre_record->height_850hpa + pre_his_record->height_850hpa) + 2 + 0.1) * attrib_weight[WRF_HEIGHT_850HPA];
				scale += abs(current_record->temperature_850hpa - pre_record->temperature_850hpa - pre_his_record->temperature_850hpa) / (abs(pre_record->temperature_850hpa + pre_his_record->temperature_850hpa) + 2 + 0.1) * attrib_weight[WRF_TEMPERATURE_850HPA];
				scale += abs(current_record->x_speed_850hpa - pre_record->x_speed_850hpa - pre_his_record->x_speed_850hpa) / (abs(pre_record->x_speed_850hpa + pre_his_record->x_speed_850hpa) + 2 + 0.1) * attrib_weight[WRF_WIND_X_850HPA];
				scale += abs(current_record->y_speed_850hpa - pre_record->y_speed_850hpa - pre_his_record->y_speed_850hpa) / (abs(pre_record->y_speed_850hpa + pre_his_record->y_speed_850hpa) + 2 + 0.1) * attrib_weight[WRF_WIND_Y_850HPA];
				result_value += temp_result_value * history_weight + scale * current_weight;
			}
			result_value /= bias_set_vec.size();
			bias_var_map->values[grid_index] = result_value;
		}
	}
	
	float max_sum = -1, min_sum = 1e20;
	SortValues(bias_var_map->values, max_sum, min_sum);
	
	for ( int i = 0; i < bias_var_map->latitude_grid_number * bias_var_map->longitude_grid_number; ++i ){
		bias_var_map->values[i] = (bias_var_map->values[i] - min_sum) / (max_sum - min_sum);
		if ( bias_var_map->values[i] > 1 ) bias_var_map->values[i] = 1;
		if ( bias_var_map->values[i] < 0 ) bias_var_map->values[i] = 0;
	}

	bias_var_map->level = 0;
	bias_var_map->weight.resize(attrib_weight.size());
	bias_var_map->weight.assign(attrib_weight.begin(), attrib_weight.end());

	return true;
}
コード例 #3
0
bool WrfStatisticSolver::GetWindVarianceMap(std::vector< RecordSetMap* >& bias_set_vec, 
	WeightMap& grid_model_weight, std::vector< float >& grid_alpha_map, int grid_size,
	int current_time, WrfGridValueMap* wind_var_map){

	std::vector< std::vector< float > >* model_weight = grid_model_weight.at(current_time - 1);

	wind_var_map->values.resize(wind_var_map->longitude_grid_number * wind_var_map->latitude_grid_number, 0);
	memset(wind_var_map->values.data(), 0, wind_var_map->values.size() * sizeof(float));

	std::vector< float > x_values, y_values;
	float his_x_values, his_y_values;
	float xmean, ymean;
	x_values.resize(bias_set_vec.size());
	y_values.resize(bias_set_vec.size());
	int longi_grid_size = wind_var_map->longitude_grid_number / grid_size;
	int lati_grid_size = wind_var_map->latitude_grid_number / grid_size;
	for ( int lati = 0; lati < wind_var_map->latitude_grid_number; ++lati){
		int temp_lati_index = lati / grid_size;
		if ( temp_lati_index >= lati_grid_size ) continue;
		for ( int longi = 0; longi < wind_var_map->longitude_grid_number; ++longi){
			int temp_longi_index = longi / grid_size;
			if ( temp_longi_index >= longi_grid_size ) continue;

			int temp_grid_index = temp_lati_index * longi_grid_size + temp_longi_index;
			int temp_index = lati * wind_var_map->longitude_grid_number + longi;
			his_x_values = 0;
			his_y_values = 0;
			for ( int k = 0; k < bias_set_vec.size(); ++k ){
				WrfDataRecordSet* data_set = bias_set_vec[k]->at(current_time - 1);
				float temp_weight = model_weight->at(temp_grid_index)[k];
				x_values[k] = data_set->values[temp_index]->x_speed_850hpa * temp_weight;
				y_values[k] = data_set->values[temp_index]->y_speed_850hpa * temp_weight;
				his_x_values += data_set->his_values[temp_index]->x_speed_850hpa * temp_weight;
				his_y_values += data_set->his_values[temp_index]->y_speed_850hpa * temp_weight;
			}
			xmean = 0;
			ymean = 0;
			for ( int k = 0; k < bias_set_vec.size(); ++k ){
				xmean += x_values[k];
				ymean += y_values[k];
			}
			xmean /= bias_set_vec.size();
			ymean /= bias_set_vec.size();
			float variancex = 0, variancey = 0;
			for ( int k = 0; k < bias_set_vec.size(); ++k ){
				variancex += pow((x_values[k] - xmean), 2);
				variancey += pow((y_values[k] - ymean), 2);
			}
			variancex *= grid_alpha_map[temp_index];
			variancex *= grid_alpha_map[temp_index];
			wind_var_map->values[temp_index] = variancex / abs(his_x_values) + variancey / abs(his_y_values);
		}
	}

	float max_variance;
	float min_variance;
	SortValues(wind_var_map->values, max_variance, min_variance);

	for ( int i = 0; i < wind_var_map->values.size(); ++i ) {
		wind_var_map->values[i] = (wind_var_map->values[i] - min_variance) / (max_variance - min_variance);
		if ( wind_var_map->values[i] > 1 ) wind_var_map->values[i] = 1;
		if ( wind_var_map->values[i] < 0 ) wind_var_map->values[i] = 0;
	}

	return true;
}