// create data points and add to analysis BOOST_FOREACH(const std::vector<QVariant>& value,variableValues) { DataPoint dataPoint = analysis.problem().createDataPoint(value).get(); dataPoint.addTag("DOE"); bool added = analysis.addDataPoint(dataPoint); if (added) { ++result; ++totPoints; if (mxSim && (totPoints == mxSim.get())) { break; } } }
vector< DataPoint > DataPoint::get_datapoints(const Matrix& o) { vector< DataPoint > ans; DataPoint tmp; for (int i = 0; i < o.row(); i++) { tmp.clear(); for (int j = 0; j < o.column(); j++) { tmp.push_back(o[i][j]); } ans.push_back(tmp); } return ans; }
//Use accept/reject method to create data int Foam::GenerateData( int DataAmount ) { //if( newDataSet->GetDataNumber() < DataAmount ) newDataSet->ReserveDataSpace( DataAmount ); for( int dataIndex = 0; dataIndex < DataAmount; ++dataIndex ) { //Generate the discrete observables, and select the correct Foam generator to use int combinationIndex = 0; int incrementValue = 1; DataPoint * temporaryDataPoint = new DataPoint(allNames); for( int discreteIndex = int(discreteNames.size() - 1); discreteIndex >= 0; --discreteIndex ) { //Create the discrete observable Observable * temporaryObservable = generationBoundary->GetConstraint( *discreteNames_ref[unsigned(discreteIndex)] )->CreateObservable(rootRandom); double currentValue = temporaryObservable->GetValue(); temporaryDataPoint->SetObservable( *discreteNames_ref2[unsigned(discreteIndex)], temporaryObservable ); delete temporaryObservable; //Calculate the index for (unsigned int valueIndex = 0; valueIndex < discreteValues[unsigned(discreteIndex)].size(); ++valueIndex ) { if ( fabs( discreteValues[unsigned(discreteIndex)][valueIndex] - currentValue ) < DOUBLE_TOLERANCE ) { combinationIndex += ( incrementValue * int(valueIndex) ); incrementValue *= int(discreteValues[unsigned(discreteIndex)].size()); break; } } } //Use the index calculated to select a Foam generator and generate an event with it Double_t* generatedEvent = new Double_t[ continuousNames.size() ]; foamGenerators[unsigned(combinationIndex)]->MakeEvent(); foamGenerators[unsigned(combinationIndex)]->GetMCvect(generatedEvent); //Store the continuous observables for (unsigned int continuousIndex = 0; continuousIndex < continuousNames.size(); ++continuousIndex ) { string unit = generationBoundary->GetConstraint( *continuousNames_ref[continuousIndex] )->GetUnit(); double newValue = minima[continuousIndex] + ( ranges[continuousIndex] * generatedEvent[continuousIndex] ); temporaryDataPoint->SetObservable( *continuousNames_ref2[continuousIndex], newValue, unit ); //cout << continuousNames[continuousIndex] << "\t" << newValue << "\t" << 0.0 << "\t" << unit << endl; } delete[] generatedEvent; // Store the event temporaryDataPoint->SetDiscreteIndex(dataIndex); newDataSet->AddDataPoint(temporaryDataPoint); } //cout << "Destroying Generator(s)" << endl; //this->RemoveGenerator(); return DataAmount; }
void MosqConnect::on_connect(int rc) { printf("Connected with code %d.\n", rc); if(rc == 0){ // Only attempt to subscribe on a successful connect. for(int i=0; i<list->size(); i++) { DataPoint dp = list->at(i); qDebug() << "subscribe" << dp.getMosqTopic(); subscribe(NULL, dp.getMosqTopic().toAscii()); } } }
TEST_F(AnalysisFixture, DataPoint_JSONSerialization_PostRun_Roundtrip) { // Create analysis Analysis analysis = analysis1(PostRun); // Retrieve "simulated" data point ASSERT_FALSE(analysis.dataPoints().empty()); DataPoint dataPoint = analysis.dataPoints()[0]; // Serialize data point std::string json = dataPoint.toJSON(); EXPECT_FALSE(json.empty()); // Deserialize and check results AnalysisJSONLoadResult loadResult = loadJSON(json); ASSERT_TRUE(loadResult.analysisObject); ASSERT_TRUE(loadResult.analysisObject->optionalCast<DataPoint>()); DataPoint copy = loadResult.analysisObject->cast<DataPoint>(); EXPECT_EQ(json,copy.toJSON()); // Save data point openstudio::path p = toPath("AnalysisFixtureData/data_point_post_run.json"); EXPECT_TRUE(dataPoint.saveJSON(p,true)); // Load and check results loadResult = loadJSON(json); ASSERT_TRUE(loadResult.analysisObject); ASSERT_TRUE(loadResult.analysisObject->optionalCast<DataPoint>()); copy = loadResult.analysisObject->cast<DataPoint>(); EXPECT_EQ(json,copy.toJSON()); if (copy.toJSON() != json) { p = toPath("AnalysisFixtureData/data_point_post_run_roundtripped.json"); copy.saveJSON(p,true); } }
float Profile::getTemp(float time) { DataPoint previous; DataPoint next; float temp = 0.0; for(int i = 0; i < dataPoints.size() - 1; i++) { if(time == dataPoints[i].getTime()) { temp = dataPoints[i].getTemp(); break; } if(time > dataPoints[i].getTime() && time < dataPoints[i+1].getTime()) { previous = dataPoints[i]; next = dataPoints[i+1]; float dt = time - previous.getTime(); float slope = (next.getTemp() - previous.getTemp()) / (next.getTime() - previous.getTime()); temp = previous.getTemp() + (dt * slope); break; } } return temp; }
void update(bbtag, const DataPoint& p) { time_t t = p.unwrap<time_t > (); int next = 0; if (t % 20 < 10) { next = 1; } if (next != last) { dp.wrap(next); myKS1.update(dp); dp.wrap(1 - next); myKS2.update(dp); } last = next; }
vector<DataPoint*> RapidFitIntegrator::getGSLIntegrationPoints( unsigned int number, vector<double> maxima, vector<double> minima, DataPoint* templateDataPoint, vector<string> doIntegrate, PhaseSpaceBoundary* thisBound ) { pthread_mutex_lock( &GSL_DATAPOINT_GET_THREADLOCK ); bool pointsGood = true; if( !_global_doEval_points.empty() ) { if( _global_doEval_points[0] != NULL ) { vector<string> allConsts = thisBound->GetDiscreteNames(); for( unsigned int i=0; i< allConsts.size(); ++i ) { double haveVal = _global_doEval_points[0]->GetObservable( allConsts[i] )->GetValue(); double wantVal = templateDataPoint->GetObservable( allConsts[i] )->GetValue(); if( haveVal != wantVal ) { pointsGood = false; break; } } } } if( ( number != _global_doEval_points.size() ) || (( ( _global_range_minima != minima ) || ( _global_range_maxima != maxima ) ) || !pointsGood ) ) { clearGSLIntegrationPoints(); _global_doEval_points = initGSLDataPoints( number, maxima, minima, templateDataPoint, doIntegrate ); _global_range_minima = minima; _global_range_maxima = maxima; _global_observable_names = doIntegrate; } vector<string> allObs = _global_doEval_points[0]->GetAllNames(); for( unsigned int i=0; i< _global_doEval_points.size(); ++i ) { DataPoint* thisPoint = _global_doEval_points[i]; for( unsigned int j=0; j< allObs.size(); ++j ) { Observable* thisObs = thisPoint->GetObservable( j ); thisObs->SetBinNumber( -1 ); thisObs->SetBkgBinNumber( -1 ); } thisPoint->ClearPerEventData(); } pthread_mutex_unlock( &GSL_DATAPOINT_GET_THREADLOCK ); return _global_doEval_points; }
/* 函数:设置数据点的领域点列表 说明:设置数据点的领域点列表 参数: 返回值: true; */ void ClusterAnalysis::SetArrivalPoints(DataPoint& dp) { for(unsigned long i=0; i<dataNum; i++) //对每个数据点执行 { double distance =GetDistance(dadaSets[i], dp); //获取与特定点之间的距离 if(distance <= radius && i!=dp.GetDpId()) //若距离小于半径,并且特定点的id与dp的id不同执行 dp.GetArrivalPoints().push_back(i); //将特定点id压力dp的领域列表中 } if(dp.GetArrivalPoints().size() >= minPTs) //若dp领域内数据点数据量> minPTs执行 { dp.SetKey(true); //将dp核心对象标志位设为true return; //返回 } dp.SetKey(false); //若非核心对象,则将dp核心对象标志位设为false }
/** Performs the classic OPTICS algorithm. * @param db All data points that are to be considered by the algorithm. Changes their values. * @param eps The epsilon representing the radius of the epsilon-neighborhood. * @param min_pts The minimum number of points to be found within an epsilon-neigborhood. * @return Return the OPTICS ordered list of Data points with reachability-distances set. */ DataVector optics( DataVector& db, const real eps, const unsigned int min_pts) { assert( eps >= 0 && "eps must not be negative"); assert( min_pts > 0 && "min_pts must be greater than 0"); DataVector ret; for( auto p_it = db.begin(); p_it != db.end(); ++p_it) { DataPoint* p = *p_it; if( p->is_processed()) continue; expand_cluster_order( db, p, eps, min_pts, ret); } return ret; }
Blackboard::Blackboard() { // default contructors init everything needed to empty //create the internal knowledge items kiSet[BB_SETTINGS]; kiSet[BB_ALL_TAGS]; //populate the tags knowlege item DataPoint dp; dp.wrap(BB_SETTINGS); kiSet[BB_ALL_TAGS].update(dp); dp.wrap(BB_ALL_TAGS); kiSet[BB_ALL_TAGS].update(dp); }
void DataTable::recordGridPoint(const DataPoint &sample) { for (unsigned int i = 0; i < getNumVariables(); i++) { grid.at(i).insert(sample.getX().at(i)); } }
// //随机选取第k个输入样本及对应的期望输出 // void AnnNetwork::sampleExpect(std::vector<DataPoint*> inputs,int k) { double _mExpect; DataPoint* dpPoint = inputs[k]; if (inputs[k] != NULL) { double _mSum = 0; for (int i = 0; i < dpPoint->size(); i++) _mSum += dpPoint->GetDimension()[i]; _mExpect = (double)_mSum / dpPoint->size(); } delete dpPoint; this->expect_[inputs[k]] = _mExpect; }
TEST_F(AnalysisFixture, DataPoint_Selected) { // Create analysis Analysis analysis = analysis1(PreRun); // See how many to queue unsigned totalToRun = analysis.dataPointsToQueue().size(); ASSERT_LT(0u,totalToRun); // Turn one off ASSERT_FALSE(analysis.dataPoints().empty()); EXPECT_EQ(totalToRun,analysis.dataPoints().size()); DataPoint dataPoint = analysis.dataPoints()[0]; dataPoint.setSelected(false); EXPECT_FALSE(dataPoint.selected()); // Make sure shows up in "ToQueue" EXPECT_EQ(totalToRun - 1u,analysis.dataPointsToQueue().size()); }
/** * Reads and normalizes CALIPSO Level 1 data from the HDFs. * * @warning Care should be taken to ensure that this is run only on CALIPSO * Level 1 data as the pointer arithmetic and memcpy() usage could present * the risk of segmentation fault on other data sources. */ bool CalipsoL1DataSource::read() { hdf4object* data = new hdf4object(new string(filename().toAscii().data())); string* tab = new string("Total_Attenuated_Backscatter_532"); float** tab_array = data->setToArray<float>(new string("Total_Attenuated_Backscatter_532") ); string* lon = new string("Longitude"); float** tmplons = data->setToArray<float>(lon); float* lons = tmplons[0]; string* lat = new string("Latitude"); float** tmplats = data->setToArray<float>(lat); float* lats = tmplats[0]; int* dims = data->getSetDimensions(tab); delete tab; delete lon; delete lat; //f*****g data is upside down for(int i = 0; i < dims[0]; i++) { float* dp_ary = new float[dataProperties().height]; float* column = tab_array[i]; column += 80; //crop array bounds to [298] - [698] for(int j = 0; j < 200; j++) { dp_ary[(2*j)+1] = dp_ary[2*j] = column[j]; } float* dp_ary2 = dp_ary + 400; column += 200; //crop array bounds to [8] - [298] memcpy(dp_ary2, column, 290*sizeof(float)); DataPoint* dp = new DataPoint; dp->setLon(lons[i]); dp->setLat(lats[i]); dp->setData(dp_ary); data_ary << dp; } data->freeArray<float>(tab_array); data->freeArray<float>(tmplons); data->freeArray<float>(tmplats); return true; }
void MosqConnect::on_message(const struct mosquitto_message *message) { /* struct mosquitto_message{ int mid; char *topic; void *payload; int payloadlen; int qos; bool retain; }; */ //Move from "void* with payloadlen" to a QString. char* messData = (char*)malloc(sizeof(char)*(message->payloadlen+1)); memcpy(messData, message->payload, message->payloadlen); messData[message->payloadlen] = '\0'; //printf("Message %s - %s.\n", message->topic, messData); QString mess = QString(messData); free(messData); QString topic = QString(message->topic); //qDebug() << "\nNew message:" << (QDateTime::currentDateTime()).toString("hh:mm:ss") << topic << mess; /// @todo create topic2url function for(int i=0; i<list->size(); i++) { DataPoint dp = list->at(i); if(topic == dp.getMosqTopic()) { qDebug() << "Mess from" << dp.getName() << mess << topic; if(!Mosq2QuickSurf::send(&dp, mess)) { qDebug() << "Error, FAILED to send mess to webserver:" << dp.getName() << mess << topic; } } } }
boost::optional<DataPoint> Analysis_Impl::getDataPointByUUID(const DataPoint& dataPoint) const { OptionalDataPoint result; BOOST_FOREACH(const DataPoint& myDataPoint,dataPoints()) { if (dataPoint.uuidEqual(myDataPoint)) { result = myDataPoint; break; } } return result; }
bool Analysis_Impl::addDataPoint(const DataPoint& dataPoint) { if (m_dataPointsAreInvalid) { LOG(Info,"Current data points are invalid. Call removeAllDataPoints before adding new ones."); return false; } if (!(dataPoint.problem().uuid() == problem().uuid())) { LOG(Error,"Cannot add given DataPoint to Analysis '" << name() << "', because it is not associated with Problem '" << problem().name() << "'."); return false; } DataPointVector existingDataPoints = getDataPoints(dataPoint.variableValues()); if (existingDataPoints.size() > 0) { BOOST_ASSERT(existingDataPoints.size() == 1); // dataPoint must be fully specified to be valid LOG(Info,"DataPoint not added to Analysis '" << name() << "', because it already exists."); return false; } m_dataPoints.push_back(dataPoint); connectChild(m_dataPoints.back(),true); onChange(AnalysisObject_Impl::Benign); return true; }
/** Updates the seeds priority queue with new neighbors or neighbors that now have a better * reachability distance than before. * @param N_eps All points in the the epsilon-neighborhood of the center_object, including p itself. * @param center_object The point on which to start the update process. * @param c_dist The core distance of the given center_object. * @param[out] o_seeds The seeds priority queue (aka set with special comparator function) that will be modified. */ void update_seeds( const DataVector& N_eps, const DataPoint* center_object, const real c_dist, DataSet& o_seeds) { assert( c_dist != OPTICS::UNDEFINED && "the core distance must be set <> UNDEFINED when entering update_seeds"); for( DataVector::const_iterator it=N_eps.begin(); it!=N_eps.end(); ++it) { DataPoint* o = *it; if( o->is_processed()) continue; const real new_r_dist = std::max( c_dist, squared_distance( center_object, o)); // *** new_r_dist != UNDEFINED *** if( o->reachability_distance() == OPTICS::UNDEFINED) { // *** o not in seeds *** o->reachability_distance( new_r_dist); o_seeds.insert( o); } else if( new_r_dist < o->reachability_distance()) { // *** o already in seeds & can be improved *** o_seeds.erase( o); o->reachability_distance( new_r_dist); o_seeds.insert( o); } } }
TEST_F(AnalysisDriverFixture,SimpleProject_NonPATToPATProject) { { // create project with one discrete variable SimpleProject project = getCleanSimpleProject("SimpleProject_NonPATToPATProject"); openstudio::path measuresDir = resourcesPath() / toPath("/utilities/BCL/Measures"); openstudio::path dir = measuresDir / toPath("SetWindowToWallRatioByFacade"); BCLMeasure measure = BCLMeasure::load(dir).get(); RubyMeasure rmeasure(measure); project.analysis().problem().push(MeasureGroup("My Variable",MeasureVector(1u,rmeasure))); DataPoint baseline = project.baselineDataPoint(); EXPECT_EQ(1u,baseline.variableValues().size()); EXPECT_TRUE(project.analysis().isDirty()); EXPECT_EQ(1u,project.analysis().dataPoints().size()); project.save(); } { SimpleProject project = getPATProject("SimpleProject_NonPATToPATProject"); DataPoint baseline = project.baselineDataPoint(); EXPECT_EQ(2u,baseline.variableValues().size()); EXPECT_FALSE(project.analysis().isDirty()); // openPATProject calls save in this case EXPECT_EQ(1u,project.analysis().dataPoints().size()); project.save(); } { SimpleProject project = getPATProject("SimpleProject_NonPATToPATProject"); DataPoint baseline = project.baselineDataPoint(); EXPECT_EQ(2u,baseline.variableValues().size()); EXPECT_FALSE(project.analysis().isDirty()); // nothing to change in this case EXPECT_EQ(1u,project.analysis().dataPoints().size()); } }
double BayesNet::query( const DataPoint& dpt ) const { for( int dvi = 0; dvi < dpt.getNumValues(); ++dvi ) // Can classify only nominal values mlAssert( dpt.getValueType(dvi) == AT_Enum ); int attrc = dpt.getNumValues() - 1; Node* qnode = getNode(attrc); DataPoint qdpt = dpt; std::vector<double> vlogp = std::vector<double>( qnode->getNumValues(), 0 ); // Compute probability for every possible value double sump = 0; double maxlogp = -DBL_MAX; int maxv = 0; for( int vi = 0; vi < qnode->getNumValues(); ++vi ) { qdpt.setEnumValue( attrc, vi ); vlogp[vi] = queryLog(qdpt); sump += exp( vlogp[vi] ); if( vlogp[vi] > maxlogp ) { maxlogp = vlogp[vi]; maxv = vi; } } // Compute scaled probability of this instance sump -= exp( vlogp[maxv] ); double logp = vlogp[ dpt.getEnumValue(attrc) ] - maxlogp - log( 1 + sump/exp( vlogp[maxv] ) ); double prob = exp(logp); return prob; }
int main(int argc, char** argv) { /* in order to test the CS, we need to have the BB in a known state. To do this we will first make a KS and make some data. */ if (myKS.connectKS()) { log("connected\n"); } else { log("Could not connect, BB did not allow me to register for tag %d\n", tag); return 1; } p.resize(6); p[0] = 'M'; p[1] = 'c'; p[2] = 'G'; p[3] = 'e'; p[4] = 'r'; p[5] = 'p'; if (myKS.update(p)) { log("updated with ack\n"); } else { log("update failed\n"); } myKS.disconnectKS(); ///////////////////////////////////////////////// // setup complete ///////////////////////////////////////////////// const char *result = all_tests(); if (result != 0) { printf("%s\n", result); } else { printf("ALL TESTS PASSED\n"); } printf("Tests run: %d\n", tests_run); myCS.disconnectCS(); return 0; }
double BayesNet::queryLog( const DataPoint& dpt ) const { for( int dvi = 0; dvi < dpt.getNumValues(); ++dvi ) // Can classify only nominal values mlAssert( dpt.getValueType(dvi) == AT_Enum ); double logp = 0; for( std::map<int, Node*>::const_iterator ni = mNodes.begin(); ni != mNodes.end(); ++ni ) { int cai = ni->first; Node* cnode = ni->second; int row_i = cnode->getCPTRowIndex(dpt); double prob = cnode->getParam( row_i, dpt.getEnumValue(cai) ); prob = IS_ZERO(prob) ? 0 : log(prob); logp += prob; } return logp; }
bool ClusterAnalysis::Init(InData indata[],int num, double radius, int minPTs) { this->radius = radius; //设置半径 this->minPTs = minPTs; //设置领域最小数据个数 this->dimNum = DIME_NUM; //设置数据维度 int j=0; int k=0; int i=0; //数据个数统计 while (i<num ) //从文件中读取POI信息,将POI信息写入POI列表中 { DataPoint tempDP; //临时数据点对象 double tempDimData[DIME_NUM]; //临时数据点维度信息 tempDimData[j++]=indata[k].x; tempDimData[j]=indata[k].y; j=0; tempDP.SetDimension(tempDimData); //将维度信息存入数据点对象内 //char date[20]=""; //char time[20]=""; ////double type; //无用信息 //ifs >> date; //ifs >> time; //无用信息读入 tempDP.SetDpId(i); //将数据点对象ID设置为i tempDP.SetVisited(false); //数据点对象isVisited设置为false tempDP.SetClusterId(-1); //设置默认簇ID为-1 dadaSets.push_back(tempDP); //将对象压入数据集合容器 i++; //计数+1 } dataNum =i; //设置数据对象集合大小为i for(unsigned long i=0; i<dataNum;i++) { SetArrivalPoints(dadaSets[i]); //计算数据点领域内对象 } return true; //返回 }
/** Expands the cluster order while adding new neighbor points to the order. * Because OPTICS can take a while on big data sets or when working with high dimensions, * a callback function informs you when a new point is inserted into the OPTICS ordering. * @param db All data points that are to be considered by the algorithm. Changes their values. * @param p The point to be examined. * @param eps The epsilon representing the radius of the epsilon-neighborhood. * @param min_pts The minimum number of points to be found within an epsilon-neigborhood. * @param[out] o_ordered_vector The ordered vector of data points. Elements will be added to this vector. * @param point_processed_callback Callback function that is called when one point is * added to the ordered output list. It takes the pointer to the data point as an argument. */ void expand_cluster_order( DataVector& db, DataPoint* p, const real eps, const unsigned int min_pts, DataVector& o_ordered_vector, std::function<void(const DataPoint* p)> point_processed_callback) { assert( eps >= 0 && "eps must not be negative"); assert( min_pts > 0 && "min_pts must be greater than 0"); DataVector N_eps = get_neighbors( p, eps, db); p->reachability_distance( OPTICS::UNDEFINED); const real core_dist_p = squared_core_distance( p, min_pts, N_eps); p->processed( true); o_ordered_vector.push_back( p); point_processed_callback( p); if( core_dist_p == OPTICS::UNDEFINED) return; DataSet seeds; update_seeds( N_eps, p, core_dist_p, seeds); while( !seeds.empty()) { DataPoint* q = *seeds.begin(); seeds.erase( seeds.begin()); // remove first element from seeds DataVector N_q = get_neighbors( q, eps, db); const real core_dist_q = squared_core_distance( q, min_pts, N_q); q->processed( true); o_ordered_vector.push_back( q); point_processed_callback( p); if( core_dist_q != OPTICS::UNDEFINED) { // *** q is a core-object *** update_seeds( N_q, q, core_dist_q, seeds); } } }
//addDataPoint //INPUT: DataPoint object //MODIFIES: this->data<DataPoint> void Table::addDataPoint(DataPoint data) { int j; int i=0; if(this->data.size()>0) { //Insert Element in order by X-Value while(i<this->data.size() && data.getElement(0)>this->data[i].getElement(0) ) i++; if(i<this->data.size()) { if(data.getElement(0)==this->data[i].getElement(0)) { //Replace if X-Value exists for(j=1;j<data.numElements();j++) { this->data[i].setElement(j,data.getElement(j)); } } else { //Shift tail back by 1 this->data.push_back(this->data[this->data.size()-1]); for(j=this->data.size()-2;j>i;j--) { this->data[j+1]=this->data[j]; } this->data[i]=data; } } else this->data.push_back(data); } else this->data.push_back(data); }
int BayesNet::Node::getCPTRowIndex( const DataPoint& dpt ) const { int ri = 0; int c = 1; // Compute row index in CPT given values of relevant attributes // (i.e. those in input nodes) for( int ni = 0; ni < getNumInNodes(); ++ni ) { Node* node = getInNode(ni); ri += ( dpt.getEnumValue( node->getAttribIndex() ) * c ); c *= node->getNumValues(); } return ri; }
bool Analysis_Impl::removeDataPoint(const DataPoint &dataPoint) { OptionalDataPoint exactDataPoint = getDataPointByUUID(dataPoint); if (exactDataPoint) { DataPointVector::iterator it = std::find(m_dataPoints.begin(),m_dataPoints.end(),*exactDataPoint); OS_ASSERT(it != m_dataPoints.end()); disconnectChild(*it); m_dataPoints.erase(it); // TODO: It may be that the algorithm should be reset, or at least marked not-complete. if (m_dataPoints.empty()) { m_resultsAreInvalid = false; m_dataPointsAreInvalid = false; } onChange(AnalysisObject_Impl::Benign); emit removedDataPoint(dataPoint.uuid()); return true; } return false; }
int main() { ifstream bindata("data.bin", ios::binary); assure(bindata, "data.bin"); // Create comparison file to verify data.txt: ofstream verify("data2.txt"); assure(verify, "data2.txt"); DataPoint d; while(bindata.read((char*)&d, sizeof d)) d.print(verify); bindata.clear(); // Reset state to "good" // Left-align everything: cout.setf(ios::left, ios::adjustfield); // Fixed precision of 4 decimal places: cout.setf(ios::fixed, ios::floatfield); cout.precision(4); int recnum = 0; while(true) { bindata.seekg(recnum* sizeof d, ios::beg); cout << "record " << recnum << endl; if(bindata.read((char*)&d, sizeof d)) { cout << asctime(&(d.getTime())); cout << setw(11) << "Latitude" << setw(11) << "Longitude" << setw(10) << "Depth" << setw(12) << "Temperature" << endl; // Put a line after the description: cout << setfill('-') << setw(43) << '-' << setfill(' ') << endl; cout << setw(11) << d.getLatitude() << setw(11) << d.getLongitude() << setw(10) << d.getDepth() << setw(12) << d.getTemperature() << endl; } else { cout << "invalid record number" << endl; exit(0); } recnum++; } } ///:~
//Actually perform the numerical integration double RapidFitIntegrator::DoNumericalIntegral( const DataPoint * NewDataPoint, PhaseSpaceBoundary * NewBoundary, const vector<string> DontIntegrateThese, ComponentRef* componentIndex, const bool IntegrateDataPoint ) { //Make lists of observables to integrate and not to integrate vector<string> doIntegrate, dontIntegrate; StatisticsFunctions::DoDontIntegrateLists( functionToWrap, NewBoundary, &DontIntegrateThese, doIntegrate, dontIntegrate ); dontIntegrate = StringProcessing::CombineUniques( dontIntegrate, DontIntegrateThese ); dontIntegrate = this->DontNumericallyIntegrateList( NewDataPoint, dontIntegrate ); vector<string> CANNOT_INTEGRATE_LIST = NewBoundary->GetDiscreteNames(); dontIntegrate = StringProcessing::CombineUniques( dontIntegrate, CANNOT_INTEGRATE_LIST ); vector<string> safeDoIntegrate; for( unsigned int i=0; i< doIntegrate.size(); ++i ) { if( StringProcessing::VectorContains( &dontIntegrate, &(doIntegrate[i]) ) == -1 ) { safeDoIntegrate.push_back( doIntegrate[i] ); } } doIntegrate = safeDoIntegrate; vector<DataPoint*> DiscreteIntegrals; vector<string> required = functionToWrap->GetPrototypeDataPoint(); bool isFixed=true; for( unsigned int i=0; i< required.size(); ++i ) { isFixed = isFixed && NewBoundary->GetConstraint( required[i] )->IsDiscrete(); } if( isFixed ) { if( NewDataPoint != NULL ) { DataPoint* thisDataPoint = new DataPoint( *NewDataPoint ); thisDataPoint->SetPhaseSpaceBoundary( NewBoundary ); double returnVal = functionToWrap->Evaluate( thisDataPoint ); delete thisDataPoint; return returnVal; } else { DiscreteIntegrals = NewBoundary->GetDiscreteCombinations(); double returnVal=0.; for( unsigned int i=0; i< DiscreteIntegrals.size(); ++i ) { returnVal+=functionToWrap->Evaluate( DiscreteIntegrals[i] ); } while( !DiscreteIntegrals.empty() ) { if( DiscreteIntegrals.back() != NULL ) delete DiscreteIntegrals.back(); DiscreteIntegrals.pop_back(); } return returnVal; } } if( IntegrateDataPoint ) { DiscreteIntegrals.push_back( new DataPoint(*NewDataPoint) ); DiscreteIntegrals.back()->SetPhaseSpaceBoundary( NewBoundary ); } else { DiscreteIntegrals = NewBoundary->GetDiscreteCombinations(); } double output_val = 0.; //If there are no observables left to integrate over, just evaluate the function if( doIntegrate.empty() || doIntegrate.size() == 0 ) { for( vector<DataPoint*>::iterator dataPoint_i = DiscreteIntegrals.begin(); dataPoint_i != DiscreteIntegrals.end(); ++dataPoint_i ) { try{ output_val += functionToWrap->Integral( *dataPoint_i, NewBoundary ); } catch(...) { cerr << "Analytical Integral Fell over!" << endl; return -9999.; } } } else { for( vector<DataPoint*>::iterator dataPoint_i = DiscreteIntegrals.begin(); dataPoint_i != DiscreteIntegrals.end(); ++dataPoint_i ) { double numericalIntegral = 0.; //Chose the one dimensional or multi-dimensional method if( doIntegrate.size() == 1 ) { if( debug != NULL ) { if( debug->DebugThisClass( "RapidFitIntegrator" ) ) { cout << "RapidFitIntegrator: One Dimensional Integral" << endl; } } pthread_mutex_lock( &one_dim_lock ); numericalIntegral += this->OneDimentionIntegral( functionToWrap, oneDimensionIntegrator, *dataPoint_i, NewBoundary, componentIndex, doIntegrate, dontIntegrate, debug ); //cout << "ret: " << numericalIntegral << endl; pthread_mutex_unlock( &one_dim_lock ); } else { if( debug != NULL ) { if( debug->DebugThisClass( "RapidFitIntegrator" ) ) { cout << "RapidFitIntegrator: Multi Dimensional Integral" << endl; } } if( !pseudoRandomIntegration ) { pthread_mutex_lock( &multi_dim_lock ); numericalIntegral += this->MultiDimentionIntegral( functionToWrap, multiDimensionIntegrator, *dataPoint_i, NewBoundary, componentIndex, doIntegrate, dontIntegrate, debug ); pthread_mutex_unlock( &multi_dim_lock ); } else { if( debug != NULL ) { if( debug->DebugThisClass( "RapidFitIntegrator" ) ) { cout << "RapidFitIntegrator: Using GSL PseudoRandomNumber :D" << endl; } } //numericalIntegral += this->PseudoRandomNumberIntegral( functionToWrap, *dataPoint_i, NewBoundary, componentIndex, doIntegrate, dontIntegrate, GSLFixedPoints ); numericalIntegral += this->PseudoRandomNumberIntegralThreaded( functionToWrap, *dataPoint_i, NewBoundary, componentIndex, doIntegrate, dontIntegrate, num_threads, GSLFixedPoints, debug ); if( debug != NULL ) { if( debug->DebugThisClass( "RapidFitIntegrator" ) ) { cout << "RapidFitIntegrator: Finished: " << numericalIntegral << endl; } } if( numericalIntegral <= -99999. ) { pthread_mutex_lock( &check_settings_lock ); cout << "Calculated a -ve Integral: " << numericalIntegral << ". Did you Compile with the GSL options Enabled with gsl available?" << endl; //cout << endl; exit(-2356); cout << "Reverting to non-GSL integration" << endl; if( doIntegrate.size() == 1 ) { pthread_mutex_lock( &one_dim_lock ); numericalIntegral = this->OneDimentionIntegral( functionToWrap, oneDimensionIntegrator, *dataPoint_i, NewBoundary, componentIndex, doIntegrate, dontIntegrate, debug ); pthread_mutex_unlock( &one_dim_lock ); } else { pthread_mutex_lock( &multi_dim_lock ); numericalIntegral = this->MultiDimentionIntegral( functionToWrap, multiDimensionIntegrator, *dataPoint_i, NewBoundary, componentIndex, doIntegrate, dontIntegrate, debug ); pthread_mutex_unlock( &multi_dim_lock ); } this->SetUseGSLIntegrator( false ); pthread_mutex_unlock( &check_settings_lock ); } } } if( !haveTestedIntegral && !functionToWrap->GetNumericalNormalisation() ) { double testIntegral = functionToWrap->Integral( *dataPoint_i, NewBoundary ); cout << "Integration Test: numerical : analytical " << setw(7) << numericalIntegral << " : " << testIntegral; string description = NewBoundary->DiscreteDescription( *dataPoint_i ); description = description.substr(0, description.size()-2); cout << " " << description << " " << functionToWrap->GetLabel() << endl; } output_val += numericalIntegral; } //cout << "output: " << output_val << endl; } while( !DiscreteIntegrals.empty() ) { if( DiscreteIntegrals.back() != NULL ) delete DiscreteIntegrals.back(); DiscreteIntegrals.pop_back(); } //cout << "ret2: " << output_val << endl; return output_val; }