コード例 #1
0
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
}
コード例 #2
0
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() );
    }
}
コード例 #3
0
ファイル: Caculate.cpp プロジェクト: wyrover/GDES
static void StringsToNum( const AcStringArray& strDatas, doubleVector& doubleDatas)
{
	for(int i = 0; i < strDatas.length(); i++)
	{
		double temp = _tstof(strDatas[i].kACharPtr());
		doubleDatas.push_back(temp);
	}
}
コード例 #4
0
void
Dyna3DFile::GetMaterials(intVector &matnos, stringVector &matnames, doubleVector &matdens)
{
    for(int i = 0; i < materialCards.size(); ++i)
    {
        matnos.push_back(materialCards[i].materialNumber);
        matnames.push_back(materialCards[i].materialName);
        matdens.push_back(materialCards[i].density);
    }
}
コード例 #5
0
void
avtMinMaxQuery::CreateMessage(const int nMsg, const MinMaxInfo &info1,
                              const MinMaxInfo &info2, string &msg,
                              doubleVector &vals)
{
    if (nMsg == 0)
        return;

    string var = queryAtts.GetVariables()[0];

    if (nMsg == 1)
    {
        msg =  var + " -- " + info1.GetType() + " = ";
        msg += InfoToString(info1);
        vals.push_back(info1.GetValue());
    }
    else
    {
        if (nodeCentered)
        {
            msg =  var + " -- " + info1.GetType() + " " + nodeMsg1;
            msg +=  "\n           = ";
            msg += InfoToString(info1);
            msg =  msg + "\n" + var + " -- " + info2.GetType() + " " + nodeMsg2;
            msg +=  "\n           = ";
            msg += InfoToString(info2);
            vals.push_back(info1.GetValue());
        }
        else
        {
            msg =  var + " -- " + info1.GetType() + " " + zoneMsg1;
            msg +=  "\n           = ";
            msg += InfoToString(info1);
            msg =  msg + "\n" + var + " -- " + info2.GetType() + " " + zoneMsg2;
            msg +=  "\n           = ";
            msg += InfoToString(info2);
            vals.push_back(info2.GetValue());
        }
    }
}
コード例 #6
0
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);
}
コード例 #7
0
bool 
QvisXRayImageQueryWidget::GetDoubleValues(int whichWidget, doubleVector &pt)
{
    QString temp;
  
    if (whichWidget == 0) // Background intensities
    {
        temp = backgroundIntensities->displayText().simplified();
    }
    bool okay = !temp.isEmpty();

    if(okay)
    {
        QStringList s = temp.split(" ", QString::SkipEmptyParts);
        for (int i = 0; okay && i < s.size(); ++i)
        {
            double val = s[i].toDouble(&okay);
            if (okay) pt.push_back(val);
        }
    }

    return okay;
}
コード例 #8
0
void
avtFVCOMParticleFileFormat::GetTimes(doubleVector &t)
{
  const char *mName = "avtFVCOMParticleFileObject::GetTimes: ";
  debug4 << mName << endl;
  
  int ncid;
  ncid=fileObject->GetFileHandle(); 
  if (ncid == -1)
    {
      std::string msg("Could not get file handle in avtParticleFileFormat::GetTimes");
      EXCEPTION1(ImproperUseException, msg);
    }
  
  
  char varname[NC_MAX_NAME+1];
  nc_type vartype;
  int  ndims;
  int  dims[NC_MAX_VAR_DIMS];
  int  varnatts;
  int time_id;
  int status = nc_inq_varid (ncid, "time", &time_id);
  if (status != NC_NOERR) 
    {
      fileObject-> HandleError(status);
      debug4 << "Could not find variable: time" << endl;
      return;
    }
  // Now get variable type!
  status = nc_inq_var(ncid, time_id, varname, &vartype, &ndims, 
                      dims, &varnatts);
  if (status != NC_NOERR) fileObject-> HandleError(status);
  
  std::string timeunits;
  if(fileObject->ReadStringAttribute("time", "units", timeunits))
    {
      debug4<< "timeunits: " << timeunits << endl;
    }
  else
    debug4<< "timeunits+++ could not get" << endl;
  
  double convert=1;
  if (strncmp(timeunits.c_str(), "seconds",7)==0)
    convert=convert/double(60*60*24);
  

  size_t ntimesteps;
  int ntime_id;
  status = nc_inq_dimid(ncid, "time", &ntime_id);
  if (status != NC_NOERR) fileObject-> HandleError(status);
  
  status = nc_inq_dimlen(ncid, ntime_id, &ntimesteps);
  if (status != NC_NOERR) fileObject-> HandleError(status);
  

  if (ndims==1 && vartype == NC_FLOAT)
    {
      float *tf = new float[ntimesteps+1];
      fileObject->ReadVariableInto("time",FLOATARRAY_TYPE , tf);
      
      for(int n=0; n<ntimesteps; ++n)
        {
          t.push_back(convert * double(tf[n]));
        }
      delete [] tf;
    }
  else
    {
      debug4 << mName << "Wrong dimension for variable Time" << endl;
    }
  

}
コード例 #9
0
void
DatabaseCorrelation::AddDatabase(const std::string &database, int nStates,
    const doubleVector &times, 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();
    }
}
コード例 #10
0
avtDataTree_p
avtQueryOverTimeFilter::CreateTree(const doubleVector &times,
                                   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;
    }
}