Dataset::Dataset(string str): root(str){ path full_path = system_complete(root); directory_iterator end_itr; size_t label = 0; if(is_directory(full_path)){ try{ for (directory_iterator itr( full_path ); itr != end_itr;++itr ){ if(is_directory(itr->path())){ string root, descriptor, catname; root = (string) itr->path().string().c_str(); catname = (string) itr->path().filename().c_str(); vector<DataPoint> dps = getDataPoints(itr->path(), label, catname); Category newcat(catname, root, label, dps); category_names[label] = catname; if(newcat.size() > 10){ addCategory(newcat); label++; } } } } catch(...){ } } }
std::vector<DataPoint> Analysis_Impl::getDataPoints( const std::vector< boost::optional<Measure> >& measures) const { DataPointVector result; std::vector<QVariant> variableValues = problem().getVariableValues(measures); if (variableValues.size() == measures.size()) { // problem was able to match all measures result = getDataPoints(variableValues); } return result; }
std::vector<DataPoint> Analysis_Impl::getDataPoints( const std::vector< boost::optional<DiscretePerturbation> >& perturbations) const { DataPointVector result; std::vector<QVariant> variableValues = problem().getVariableValues(perturbations); if (variableValues.size() == perturbations.size()) { // problem was able to match all perturbations result = getDataPoints(variableValues); } return result; }
boost::optional<DataPoint> Analysis_Impl::getDataPoint( const std::vector<Measure>& measures) const { OptionalDataPoint result; std::vector<QVariant> variableValues = problem().getVariableValues(measures); if (variableValues.size() == measures.size()) { // problem was able to match all measures DataPointVector intermediate = getDataPoints(variableValues); OS_ASSERT(intermediate.size() < 2u); if (intermediate.size() == 1u) { result = intermediate[0]; } } return result; }
boost::optional<DataPoint> Analysis_Impl::getDataPoint( const std::vector<DiscretePerturbation>& perturbations) const { OptionalDataPoint result; std::vector<QVariant> variableValues = problem().getVariableValues(perturbations); if (variableValues.size() == perturbations.size()) { // problem was able to match all perturbations DataPointVector intermediate = getDataPoints(variableValues); BOOST_ASSERT(intermediate.size() < 2u); if (intermediate.size() == 1u) { result = intermediate[0]; } } return result; }
/******************************************************************** * Function Name: writeOutputGradient * Example: writeOutputGradient( &outputGradient, shift ) * Purpose: writes an output gradient for a compound gradient axis * Input * Formal: outputGradient - pointer to a output gradient * shift * Private: none * Public: none * Output * Return: none * Formal: none * Private: none * Public: none * Notes: none *********************************************************************/ double writeOutputGradientDBStr(SGL_GRADIENT_T *aOutputGradient, double aStartTime, double aDuration, char *aGradParams ) { char *gradParams; char _tempname[MAX_STR]; int _error; int _startIdx, _endIdx; double *_vec; long _nPts; _vec = getDataPoints( aOutputGradient ); _nPts = getNumPoints( aOutputGradient ); _startIdx = (long)ROUND(aStartTime/GRADIENT_RES); _endIdx = (long)ROUND((aStartTime + aDuration)/GRADIENT_RES); if( _startIdx >= 0 && _endIdx <= _nPts ) { _vec += _startIdx; _nPts = _endIdx - _startIdx; } gradParams = NULL; appendFormattedString( &gradParams, "%g %ld", getAmplitude(aOutputGradient), _nPts); if( aGradParams != NULL ) { appendFormattedString( &gradParams, " %s", aGradParams ); } if( !gradShapeWritten( getName(aOutputGradient), gradParams, _tempname ) ) { setName( aOutputGradient, _tempname ); _error = writeToDisk( _vec, _nPts, _vec[0], getResolution(aOutputGradient), 1, getName(aOutputGradient) ); } else { setName( aOutputGradient, _tempname ); } return _nPts*GRADIENT_RES; }
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; }
vector<vector<double > > spectralDecomposition(CSCMat mat, int nev, double diffuse_t) { /* Compute Eigenvectors and Eigenvalues of lower Laplacian matrix */ int n = mat.pCol.size() -1; // dimension (number of rows or cols od similiar matrix) int nconv; // number of "converged" eigenvalues. int nnz = mat.val.size(); double* eigVal = new double[n]; // Eigenvalues. double* eigVec = new double[n*nev]; // Eigenvectors stored sequentially. char uplo = 'L'; #ifdef DEBUG printf("Spectral decomposition started \n"); unsigned int start_time = time(NULL); #endif nconv = AREig(eigVal, eigVec, n, nnz, &mat.val[0], &mat.iRow[0], &mat.pCol[0], uplo, nev, "SM", 0, 0.0, 1000000); #ifdef DEBUG unsigned int end_time = time(NULL); printf("Spectral decomposition finished in %u s\n", end_time-start_time); #endif Solution(nconv, n, nnz, &mat.val[0], &mat.iRow[0], &mat.pCol[0], uplo, eigVal, eigVec); vector<vector<double > > dataPoints = getDataPoints(eigVec,nev,n); // unnormalized data point for clustering eigenvectors in columns //vector<vector<double > > dataPointsTrans = getDataPointsTrans(eigVec,nev,n); diffuse(dataPoints, eigVal, diffuse_t); //print2DVecArray(dataPoints); //vecSave2DArray("eigvec.txt", dataPoints); vecNormalize(dataPoints); //vecSave2DArray("eigvecnorm.txt", dataPoints); return dataPoints; }
/******************************************************************** * Function Name: gradListDutyCycle * Example: dutyCycle( (void *)&readGrad, (void *)&phaseGrad, (void *)&sliceGrad, * scaleRead, scalePhase, scaleSlice, theta, psi, phi, gMax, * &msCurrents ) * Purpose: initializes duty cycle calculations * Input * Formal: none * Private: none * Public: none * Output * Return: none * Formal: msCurrents * Private: none * Public: none * Notes: none *********************************************************************/ void dutyCycleOfGradListWithEulerMatrix( struct SGL_GRAD_NODE_T* gradList, double startTime, double duration, SGL_EULER_MATRIX_T *rot, double gmax, SGL_MEAN_SQUARE_CURRENTS_T *msCurrents ) { double _startTime, _endTime, _duration; struct SGL_GRAD_NODE_T* _current = gradList; double _relStart; int i; double _x, _y, _z; int _startIdx, _endIdx; GENERIC_GRADIENT_T _s, _r, _p; _startTime = getStartTimeOfList( gradList ); _endTime = getEndTimeOfList( gradList ); _duration = _endTime - _startTime; if( startTime < _startTime ) { abort_message("dutyCycleOfGradListWithEulerMatrix: bad start time!"); } if( (duration > 0)&& ((startTime + duration) > _endTime )) { abort_message("dutyCycleOfGradListWithEulerMatrix: bad end time!"); } if( startTime == 0.0 ) { startTime = _startTime; } if( duration == 0.0 ) { duration = _endTime - startTime; } initOutputGradient( &_r, "READ", _duration, GRADIENT_RES ); initOutputGradient( &_p, "PHASE", _duration, GRADIENT_RES ); initOutputGradient( &_s, "SLICE", _duration, GRADIENT_RES ); while( _current != NULL ) { _relStart = _current->startTime - _startTime; switch( _current->logicalAxis ) { case READ: copyToOutputGradient( &_r, getDataPoints( _current->grad ) , getNumPoints( _current->grad ), _relStart, _current->invert ); break; case PHASE: copyToOutputGradient( &_p, getDataPoints( _current->grad ) , getNumPoints( _current->grad ), _relStart, _current->invert ); break; case SLICE: copyToOutputGradient( &_s, getDataPoints( _current->grad ) , getNumPoints( _current->grad ), _relStart, _current->invert ); default: break; } _current = _current->next; } _startIdx = startTime/ GRADIENT_RES; _endIdx = (startTime + duration)/GRADIENT_RES; for(i=_startIdx; i< _endIdx; i++ ) { eulerRotate( _r.dataPoints[i], _p.dataPoints[i], _s.dataPoints[i], rot, &_x, &_y, &_z ); msCurrents->x += meanSquareCurrent( _x, gmax, coilLimits.current, GRADIENT_RES ); msCurrents->y += meanSquareCurrent( _y, gmax, coilLimits.current, GRADIENT_RES ); msCurrents->z += meanSquareCurrent( _z, gmax, coilLimits.current, GRADIENT_RES ); } }
/******************************************************************** * Function Name: dutyCycle * Example: dutyCycle( (void *)&readGrad, (void *)&phaseGrad, (void *)&sliceGrad, * scaleRead, scalePhase, scaleSlice, theta, psi, phi, gMax, * &msCurrents ) * Purpose: initializes duty cycle calculations * Input * Formal: none * Private: none * Public: none * Output * Return: none * Formal: msCurrents * Private: none * Public: none * Notes: none *********************************************************************/ void dutyCycleWithEulerMatrix( SGL_GRADIENT_T *readGrad, SGL_GRADIENT_T *phaseGrad, SGL_GRADIENT_T *sliceGrad, double scaleR, double scaleP, double scaleS, SGL_EULER_MATRIX_T *rot, double gmax, SGL_MEAN_SQUARE_CURRENTS_T *msCurrents ) { long _numPoints; int _i; double *_pointsR = NULL; double *_pointsP = NULL; double *_pointsS = NULL; double _x, _y, _z; ERROR_NUM_T _error; _numPoints = 0; if(( readGrad == NULL ) && ( phaseGrad == NULL ) && (sliceGrad == NULL )) { _error = ERR_GRAD_PULSES; displayError( _error, __FILE__, __FUNCTION__, __LINE__ ); } if( readGrad != NULL ) { _numPoints = getNumPoints( readGrad ); _pointsR = getDataPoints( readGrad ); } if( phaseGrad != NULL ) { if( _numPoints == 0) { _numPoints = getNumPoints( phaseGrad ); } else if( _numPoints != getNumPoints( phaseGrad )) { _error = ERR_GRAD_DURATION; displayError( _error, __FILE__, __FUNCTION__, __LINE__ ); } _pointsP = getDataPoints( phaseGrad ); } if( sliceGrad != NULL ) { if( _numPoints == 0) { _numPoints = getNumPoints( sliceGrad ); } else if( _numPoints != getNumPoints( sliceGrad )) { _error = ERR_GRAD_DURATION; displayError( _error, __FILE__, __FUNCTION__, __LINE__ ); } _pointsS = getDataPoints( sliceGrad ); } for( _i=0; _i< _numPoints; _i++ ) { eulerRotate( ( readGrad == NULL ? 0.0: _pointsR[_i]*scaleR ), ( phaseGrad == NULL ? 0.0: _pointsP[_i]*scaleP ), ( sliceGrad == NULL ? 0.0: _pointsS[_i]*scaleS ), rot, &_x, &_y, &_z ); msCurrents->x += meanSquareCurrent( _x, gmax, coilLimits.current, GRADIENT_RES ); msCurrents->y += meanSquareCurrent( _y, gmax, coilLimits.current, GRADIENT_RES ); msCurrents->z += meanSquareCurrent( _z, gmax, coilLimits.current, GRADIENT_RES ); } }