double avtModelFitFilter::calculateDistance(doubleVector mins, int distanceType) { double distance = 0; if(!distanceType) {/* Euclidean Distance ////////////////////////ED*/ for(size_t j = 0; j < mins.size(); j++) //ED distance += pow(mins[j], 2); //ED return sqrt(distance); //ED*/ } if(distanceType == 1) {/* Manhattan Distance /////////////////////////MD*/ for(size_t j = 0; j < mins.size(); j++) //MD distance += fabs(mins[j]); //MD return distance; //MD*/ } if(distanceType == 2) {/* Chebyshev Distance /////////////////////////CD*/ double max = mins[0]; //CD for(size_t j = 1; j < mins.size(); j++) //CD if(mins[j] > max) //CD max = mins[j]; //CD return max; //CD*/ } return distance; /// TODO: check fix for return of non-void warning }
void pnlRandNormal(doubleVector* vls, doubleVector &mean, doubleVector &sigma ) { int myid = PAR_OMP_NUM_CURR_THREAD; int nEl = mean.size(); vls->resize(nEl); if( nEl > 1 ) { doubleVector normVls(nEl); pnlRandNormal(nEl,&normVls.front(), 0, 1); CxMat matNormVls = cxMat( nEl, 1, CX_64FC1, &normVls.front() ); CxMat matMean = cxMat( nEl, 1, CX_64FC1, &mean.front() ); CxMat matCov = cxMat( nEl, nEl, CX_64FC1, &sigma.front() ); doubleVector evecData( nEl*nEl ); CxMat evecMat = cxMat( nEl, nEl, CX_64FC1, &evecData.front() ); doubleVector evalData( nEl*nEl ); CxMat evalMat = cxMat( nEl, nEl, CX_64FC1, &evalData.front() ); cxSVD( &matCov, &evalMat, &evecMat, NULL, CX_SVD_MODIFY_A ); int i; for( i = 0; i < nEl; i++) { evalData[i*(nEl+1)] = sqrt( evalData[i*(nEl+1)] ); } CxMat *prodMat1 = cxCreateMat( nEl, nEl, CX_64FC1 ); cxMatMul( &evecMat, &evalMat, prodMat1 ); CxMat matResultVls = cxMat( nEl, 1, CX_64FC1, &(vls->front()) ); cxMatMulAdd( prodMat1, &matNormVls, &matMean, &matResultVls ); cxReleaseMat( &prodMat1 ); } else { //vsRngGaussian( VSL_METHOD_SGAUSSIAN_BOXMULLER2, g_RNG[myid].m_vslStream, 1, // &(vls->front()), mean.front(), sigma.front() ); vls->front() = pnlRandNormal( mean.front(), sigma.front() ); } }
void QvisWindowBase::StringToDoubleList(const char *str, doubleVector &dv, int max) { size_t length, offset = 0; // Clear the vector. dv.clear(); // Get out if the input string is nothing. if(str == NULL || ((length = strlen(str)) == 0)) { return; } do { // Skip any preceding spaces, stop at end of string too. for(; str[offset] == ' ' || str[offset] == '\0'; ++offset); if(offset < length) { char buf[30]; sscanf(str + offset, "%s", buf); offset += strlen(buf); // Only add if the token was something. if(strlen(buf) > 0) { double dtemp = (double)atof(buf); if(dv.size() < (size_t)max) dv.push_back(dtemp); else offset = length * 2; } } } while(offset < length); }
void DatabaseCorrelation::AddDatabase(const std::string &database, int nStates, const doubleVector ×, const intVector &cycles) { // If the database is already in the correlation, maybe we should // remove it and then add it again in case the length changed like // when we add time states to a file. if(UsesDatabase(database)) return; // // Add the times and cycles for the new database to the correlation so // we can access them later and perhaps use them to correlate. // for(int i = 0; i < nStates; ++i) { double t = ((i < times.size()) ? times[i] : 0.); databaseTimes.push_back(t); int c = ((i < cycles.size()) ? cycles[i] : 0); databaseCycles.push_back(c); } if(method == IndexForIndexCorrelation) { if(numStates >= nStates) { // // The number of states in the correlation is larger than // the number of states in the database so we can append // the database's states to the end of the indices and // repeat the last frames. // for(int i = 0; i < numStates; ++i) { int state = (i < nStates) ? i : (nStates - 1); indices.push_back(state); } } else { // // The number of states for the current database is larger // than the number of states in the correlation. The correlation // must be lengthened. // indices.clear(); for(size_t i = 0; i < databaseNames.size(); ++i) { for(int j = 0; j < nStates; ++j) { int state = (j < databaseNStates[i]) ? j : (databaseNStates[i]-1); indices.push_back(state); } } // Add the new database to the correlation. for(int i = 0; i < nStates; ++i) indices.push_back(i); numStates = nStates; } databaseNames.push_back(database); databaseNStates.push_back(nStates); } else if(method == StretchedIndexCorrelation) { databaseNames.push_back(database); databaseNStates.push_back(nStates); indices.clear(); int maxStates = (numStates > nStates) ? numStates : nStates; for(size_t i = 0; i < databaseNames.size(); ++i) { for(int j = 0; j < maxStates; ++j) { float t = float(j) / float(maxStates - 1); int state = int(t * (databaseNStates[i] - 1) + 0.5); indices.push_back(state); } } numStates = maxStates; } else if(method == UserDefinedCorrelation) { if(numStates > nStates) { // // The database being added has fewer states so we need to // repeat the last states. // // We'll have to pass in the user-defined indices and append them to the indices vector } else { } } else if(method == TimeCorrelation) { databaseNames.push_back(database); databaseNStates.push_back(nStates); // Align time for all databases on the same time axis so we can count the // number of times and make that be the new number of states. std::map<double, intVector> timeAlignmentMap; int index = 0; for(size_t i = 0; i < databaseNames.size(); ++i) for(int j = 0; j < databaseNStates[i]; ++j, ++index) timeAlignmentMap[databaseTimes[index]].push_back(i); // // Set the condensed times vector // condensedTimes.clear(); for(std::map<double,intVector>::const_iterator p = timeAlignmentMap.begin(); p != timeAlignmentMap.end(); ++p) { condensedTimes.push_back(p->first); } // Now there is a map that has for each time in all of the databases // a list of the databases that contain that time. indices.clear(); for(size_t i = 0; i < databaseNames.size(); ++i) { int state = 0; std::map<double, intVector>::const_iterator pos = timeAlignmentMap.begin(); for(; pos != timeAlignmentMap.end(); ++pos) { // Look to see if the current database is in the list of databases // for the current time. If so, we need to increment the state after // we use it. intVector::const_iterator dbIndex = std::find(pos->second.begin(), pos->second.end(), i); indices.push_back(state); if(dbIndex != pos->second.end() && state < databaseNStates[i] - 1) ++state; } } numStates = timeAlignmentMap.size(); } else if(method == CycleCorrelation) { databaseNames.push_back(database); databaseNStates.push_back(nStates); // Align cycle for all databases on the same time axis so we can count the // number of cycles and make that be the new number of states. std::map<int, intVector> cycleAlignmentMap; int index = 0; for(size_t i = 0; i < databaseNames.size(); ++i) for(int j = 0; j < databaseNStates[i]; ++j, ++index) cycleAlignmentMap[databaseCycles[index]].push_back(i); // // Set the condensed cycles vector // condensedCycles.clear(); for(std::map<int,intVector>::const_iterator p = cycleAlignmentMap.begin(); p != cycleAlignmentMap.end(); ++p) { condensedCycles.push_back(p->first); } // Now there is a map that has for each time in all of the databases // a list of the databases that contain that time. indices.clear(); for(size_t i = 0; i < databaseNames.size(); ++i) { int state = 0; std::map<int, intVector>::const_iterator pos = cycleAlignmentMap.begin(); for(; pos != cycleAlignmentMap.end(); ++pos) { // Look to see if the current database is in the list of databases // for the current time. If so, we need to increment the state after // we use it. intVector::const_iterator dbIndex = std::find(pos->second.begin(), pos->second.end(), i); indices.push_back(state); if(dbIndex != pos->second.end() && state < databaseNStates[i] - 1) ++state; } } numStates = cycleAlignmentMap.size(); } }
avtDataTree_p avtQueryOverTimeFilter::CreateTree(const doubleVector ×, const doubleVector &res, stringVector &vars, const bool doMultiCurvePlot) { int nPts = 0; bool singleCurve = true; if (useTimeForXAxis && nResultsToStore == 1) { // Single curve with time for x axis. NORMAL case. // Most queries currently use this option. nPts = (times.size() <= res.size() ? times.size() : res.size()); } else if (!useTimeForXAxis && nResultsToStore == 2) { // Single curve, res[odd] = x, res[even] = y. nPts = res.size() / 2; } else if (useTimeForXAxis && nResultsToStore > 1) { singleCurve = false; } else if (!useTimeForXAxis && nResultsToStore > 2) { // multiple curves, res[odd] = x, res[even] = y. } if (singleCurve) { vtkRectilinearGrid *rgrid = vtkVisItUtility::Create1DRGrid(nPts); if (nPts == 0) { avtDataTree_p tree = new avtDataTree(rgrid, 0); rgrid->Delete(); return tree; } vtkDataArray *xc = rgrid->GetXCoordinates(); vtkDoubleArray *sc = vtkDoubleArray::New(); sc->SetNumberOfComponents(1); sc->SetNumberOfTuples(nPts); rgrid->GetPointData()->SetScalars(sc); rgrid->SetDimensions(nPts, 1 , 1); sc->Delete(); for (int i = 0; i < nPts; i++) { if (useTimeForXAxis) { xc->SetTuple1(i, times[i]); sc->SetTuple1(i, res[i]); } else { xc->SetTuple1(i, res[i*2]); sc->SetTuple1(i, res[i*2+1]); } } avtDataTree_p tree = new avtDataTree(rgrid, 0); rgrid->Delete(); return tree; } else if(doMultiCurvePlot) { // Setup for a MultiCurve plot nPts = times.size(); vtkRectilinearGrid *rgrid = vtkVisItUtility::CreateEmptyRGrid(nPts, nResultsToStore, 1, VTK_FLOAT); if (nPts == 0) { avtDataTree_p tree = new avtDataTree(rgrid, 0); rgrid->Delete(); return tree; } if (res.size() != nPts*nResultsToStore) { debug1 << "Mismatch in QOT times/results sizes: " << endl; debug1 << " times size: " << times.size() << endl; debug1 << " nResultsToStore: " << nResultsToStore << endl; debug1 << " results size: " << res.size() << endl; avtDataTree_p tree = new avtDataTree(rgrid, 0); rgrid->Delete(); return tree; } vtkDataArray *xc = rgrid->GetXCoordinates(); vtkDataArray *yc = rgrid->GetYCoordinates(); vtkDoubleArray *sc = vtkDoubleArray::New(); sc->SetNumberOfComponents(1); sc->SetNumberOfTuples(nPts*nResultsToStore); rgrid->GetPointData()->SetScalars(sc); sc->Delete(); for (int i = 0; i < nPts; i++) { xc->SetTuple1(i, times[i]); } for (int i = 0; i < nResultsToStore; i++) { yc->SetTuple1(i, i); for (int j = 0; j < nPts; j++) sc->SetTuple1(i*nPts+j, res[i + nResultsToStore*j]); } avtDataTree_p tree = new avtDataTree(rgrid, 0); rgrid->Delete(); return tree; } else { // Setup for a Curve plot with multiple curves. nPts = times.size(); if (nPts == 0) { vtkRectilinearGrid *rgrid = vtkVisItUtility::Create1DRGrid(nPts, VTK_FLOAT); avtDataTree_p tree = new avtDataTree(rgrid, 0); rgrid->Delete(); return tree; } if (res.size() != nPts*nResultsToStore) { vtkRectilinearGrid *rgrid = vtkVisItUtility::Create1DRGrid(nPts, VTK_FLOAT); debug1 << "Mismatch in QOT times/results sizes: " << endl; debug1 << " times size: " << times.size() << endl; debug1 << " nResultsToStore: " << nResultsToStore << endl; debug1 << " results size: " << res.size() << endl; avtDataTree_p tree = new avtDataTree(rgrid, 0); rgrid->Delete(); return tree; } if (vars.size() != nResultsToStore) { vtkRectilinearGrid *rgrid = vtkVisItUtility::Create1DRGrid(nPts, VTK_FLOAT); debug1 << "Mismatch in QOT vars/nresults sizes: " << endl; debug1 << " vars size: " << times.size() << endl; debug1 << " nResultsToStore: " << nResultsToStore << endl; avtDataTree_p tree = new avtDataTree(rgrid, 0); rgrid->Delete(); return tree; } int nVars = vars.size(); vtkDataSet **grids = new vtkDataSet *[nVars]; for (int i = 0; i< nVars; ++i) { grids[i] = vtkVisItUtility::Create1DRGrid(nPts, VTK_FLOAT); vtkDataArray *xc = ((vtkRectilinearGrid*)grids[i])->GetXCoordinates(); vtkDoubleArray *sc = vtkDoubleArray::New(); sc->SetNumberOfComponents(1); sc->SetNumberOfTuples(nPts); sc->SetName(vars[i].c_str()); grids[i]->GetPointData()->SetScalars(sc); sc->Delete(); for (int j = 0; j < nPts; ++j) { xc->SetTuple1(j, times[j]); sc->SetTuple1(j, res[i + nResultsToStore*j]); } } avtDataTree_p tree = new avtDataTree(nVars, grids, -1, vars); for (int i = 0; i< nVars; ++i) grids[i]->Delete(); delete [] grids; return tree; } }