double ConsistencySubsetEvaluator::evaluateSubset(const std::vector<int>& columns, TgsProgress*) { BinHashFunctor::_columns = columns; const DataFrame& df = _dataFrame; // hash<bin key, hash<class enumeration, instance count> > typedef HashMap< std::vector<int>, // bin key InconsistentInstancesMap, // map of class enumerations to instance count BinHashFunctor> // fancy hash function and comparison that only looks at 'columns' BinMap; BinMap binMap; for (unsigned int i = 0; i < _bins.size(); i++) { //BinMap::iterator it = binMap.find(_bins[i]); InconsistentInstancesMap& eim = binMap[_bins[i]]; int classEnum = _enumMap[df.getTrainingLabel(i)]; if (eim.size() == 0) { eim.resize(_enumMap.size(), 0); } eim[classEnum]++; } int inconsistencyCount = 0; for (BinMap::const_iterator it = binMap.begin(); it != binMap.end(); it++) { inconsistencyCount += _calculateInconsistentCount(it->second); } double inconsistencyRate = (double)inconsistencyCount / (double)_bins.size(); return -inconsistencyRate; }
void BandPass::_buildData(const BinMap& map, float scale, float /*offset*/) { int mapId = map.hash(); _dataSets.insert(mapId, QVector<float>(map.numberBins()) ); for( unsigned int i=0; i < map.numberBins(); ++i ) { _dataSets[mapId][i] = scale * _evaluate(map.binAssignmentNumber(i)); } _zeroChannelsMap(map); }
// set the dataset for a specified map to zero for all killed bands void BandPass::_zeroChannelsMap(const BinMap& map) { foreach( const Range<float>& r, _killed.subranges() ) { int min = map.binIndex(r.min()); int max = map.binIndex(r.max()); if( max < min ) { int tmp; tmp = max; max = min; min = tmp; }; int mapId=map.hash(); if(_dataSets[mapId].size() < max ) _dataSets[mapId].resize(max + 1); do { _dataSets[mapId][min] = 0.0; } while( ++min <= max ); } }
inline void addValue(double v) { BinMap::iterator bm_itr; for (bm_itr=bins.begin(); bm_itr != bins.end(); bm_itr++) { const BinRange& range = bm_itr->first; if (range.first < v && v <= range.second) { bm_itr->second++; total++; break; } } }
void resetBins(const BinRangeList& brl) { bins.clear(); total=0; for (BinRangeList::const_iterator i=brl.begin(); i != brl.end(); i++) bins[*i] = 0; }
inline void dump(std::ostream& s) const { BinMap::const_iterator bmi; for (bmi = bins.begin(); bmi != bins.end(); bmi++) { const BinRange& br = bmi->first; s << std::right << std::setw(3) << br.first << "-" << std::left << std::setw(3) << br.second << ": " << std::right << bmi->second << std::endl; } s << std::right << std::setw(3) << bins.begin()->first.first << "-" << std::left << std::setw(3) << bins.rbegin()->first.second << ": " << std::right << total << std::endl; };
void BandPass::reBin(const BinMap& map) { _currentMap = map; int mapId = map.hash(); _currentMapId = mapId; if( ! _dataSets.contains(mapId) ) { double scale = map.width()/_primaryMap.width(); // scale the RMS and median _rms[mapId]= _rms[_primaryMapId] * std::sqrt( 1.0/scale ); _median[mapId] = _median[_primaryMapId] * scale; _mean[mapId] = _mean[_primaryMapId] * scale; // scale and set the intensities _buildData(_currentMap, scale, 0.0); //for( unsigned int i=0; i < map.numberBins(); ++i ) { // _dataSets[mapId][i] = scale * _evaluate(map.binAssignmentNumber(i)); //} //_zeroChannelsMap(map); } }
FlatGridSorter::BinMap FlatGridSorter::GetRow(UInt_t row) { BinMap ret; // Find the data that pertains to the row UInt_t bin = row*fXaxis.GetNbins(); BinMap::value_type p = std::make_pair(bin, BinData()); BinMap::iterator it = std::lower_bound(fBins.begin(), fBins.end(), p); if (it!=fBins.end()) { while (it->first < (row+1)*fXaxis.GetNbins()) { UInt_t bin = it->first%fXaxis.GetNbins(); ret.insert(std::make_pair(bin,it->second)); } } return ret; }
void BinParticles(const SurfacePod& binningSurface, const GpuParticleList& particles, int numBinColumns, int numBinRows, size_t maxParticlesPerBin, Matrix4 mvp) { typedef std::list<GpuParticle> Bin; typedef std::map<int, Bin> BinMap; BinMap binMap; for (GpuParticleList::const_iterator pParticle = particles.begin(); pParticle != particles.end(); ++pParticle) { Point3 center(pParticle->Px, pParticle->Py, pParticle->Pz); float r = pParticle->Radius; // Build the AABB for this particle: Vector3 i(r, 0, 0), j(0, r, 0), k(0, 0, r); Point3 corners[8] = { center + i + j + k, center + i + j - k, center - i + j - k, center - i + j + k, center + i - j + k, center + i - j - k, center - i - j - k, center - i - j + k, }; int minX = 1000; int maxX = -1000; int minY = 1000; int maxY = -1000; // Find the screen-space 2D AABB of the post-transformed 3D AABB: for (int cornerIndex = 0; cornerIndex < sizeof(corners) / sizeof(corners[0]); ++cornerIndex) { Vector4 ndcCenter = mvp * corners[cornerIndex]; float centerX = 0.5f * (1 + ndcCenter[0] / ndcCenter[3]); float centerY = 0.5f * (1 + ndcCenter[1] / ndcCenter[3]); int i = int(centerX * numBinColumns); int j = int(centerY * numBinRows); minX = std::min(minX, i); minY = std::min(minY, j); maxX = std::max(maxX, i); maxY = std::max(maxY, j); } //minX = 0; maxX = NumBinColumns - 1; //minY = 0; maxY = NumBinRows - 1; // Fill every bin that intersects with the 2D AABB: std::set<int> cornerBins; for (int i = minX; i <= maxX; i++) { for (int j = minY; j <= maxY; j++) { if (i >= 0 && i < numBinColumns && j >= 0 && j < numBinRows) { int binIndex = GetBin(j, i); if (cornerBins.find(binIndex) == cornerBins.end()) { cornerBins.insert(binIndex); if (binMap[binIndex].size() < maxParticlesPerBin) binMap[binIndex].push_back(*pParticle); } } } } } glBindBuffer(GL_PIXEL_UNPACK_BUFFER, binningSurface.Pbo); float* mappedSurface = (float*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY); float* pRow = mappedSurface; for (int row = 0; row < numBinRows; ++row) { float* pCol = pRow; for (int col = 0; col < numBinColumns; ++col) { float* pDestParticle = pCol; BinMap::const_iterator pBin = binMap.find(GetBin(row, col)); if (pBin != binMap.end()) { Bin::const_iterator pSrcParticle = pBin->second.begin(); for (; pSrcParticle != pBin->second.end(); ++pSrcParticle) { *pDestParticle++ = pSrcParticle->Px; *pDestParticle++ = pSrcParticle->Py; *pDestParticle++ = pSrcParticle->Pz; *pDestParticle++ = pSrcParticle->Radius; } } *pDestParticle++ = 0; *pDestParticle++ = 0; *pDestParticle++ = 0; *pDestParticle++ = 0; #define DEBUG_BINS 0 #if DEBUG_BINS while (pDestParticle < pCol + 4 * (MaxParticlesPerBin + 1)) { *pDestParticle++ = float(row) / NumBinRows; *pDestParticle++ = float(col) / NumBinColumns; *pDestParticle++ = 0.25f; *pDestParticle++ = 1; } #endif pCol += 4 * (maxParticlesPerBin + 1); } pRow += 4 * numBinColumns * (maxParticlesPerBin + 1); } glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); glBindTexture(GL_TEXTURE_2D, binningSurface.ColorTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, binningSurface.Width, binningSurface.Height, 0, GL_RGBA, GL_FLOAT, 0); glBindTexture(GL_TEXTURE_2D, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); }