//============================================================================== static void read_range(const String& input, BoolVector& range, uint_t min_value, uint_t max_value) { boost::cmatch what; boost::regex exp("(\\d{1,})-(\\d{1,})"); StringVector list; boost::split(list, input, boost::is_any_of(",")); foreach(const String& item, list) { uint_t n = 0; uint_t r1, r2; if (string_to_number(item, n)) r1 = r2 = n; else { if (!boost::regex_match(item.c_str(), what, exp)) throw std::runtime_error("read_range: incorrect input"); string_to_number(what[1].str(), r1); string_to_number(what[2].str(), r2); if (r1 > r2) std::swap(r1, r2); } if (r2 > max_value || r1 < min_value) throw std::runtime_error("read_range: value is out of range"); if (range.size() <= r2) range.resize(r2 + 1, false); for (; r1 <= r2; r1++) range[r1] = true; }
bool CalvinCELDataAdapter::IsOutlier(int index) { BoolVector v; if (calvinCel.GetOutliers(index, 1, v)) return v.at(0); else return false; }
bool CalvinCELDataAdapter::IsMasked(int index) { BoolVector v; if (calvinCel.GetMasked(index, 1, v)) return v.at(0); else return false; }
bool CalvinCELDataAdapter::IsOutlier(int x, int y) { BoolVector v; int32_t index = XYToIndex(x, y); if (calvinCel.GetOutliers(index, 1, v)) return v.at(0); else return false; }
std::vector<bool> OSArgument::domainAsBool() const { if (!hasDomain()) { LOG_AND_THROW("No domain set for OSArgument '" << name() << "'."); } BoolVector result; for (const QVariant& value : m_domain) { if ("true" == value.toString()) { result.push_back(true); } result.push_back(false); } return result; }
bool BoolTable:: GenerateMaximalTrueBVList( List< BoolVector > &result ) { BoolVector *newBV = NULL; BoolVector *oldBV = NULL; for( int i = 0; i < numCols; i++ ) { newBV = new BoolVector( ); newBV->Init( numRows ); for( int row = 0; row < numRows; row++ ) { newBV->SetValue( row, table[i][row] ); } result.Rewind( ); bool addBV = true; bool isSubset = false; while( result.Next( oldBV ) ) { newBV->IsTrueSubsetOf( *oldBV, isSubset ); if( isSubset ) { addBV = false; break; } oldBV->IsTrueSubsetOf( *newBV, isSubset ); if( isSubset ) { result.DeleteCurrent( ); } } if( addBV ) { result.Append( newBV ); } else { delete newBV; } } return true; }
void removeInvalidMeans( const Vector3fVector& means, const BoolVector& valid, Vector3fVector& means_f) { unsigned int size = valid.size(); for(unsigned int i = 0; i < size; ++i) { if (valid[i]) { const Vector3f& mean = means[i]; means_f.push_back(mean); } } }
void removeInvalidDistributions( const Vector3fVector& means, const Matrix3fVector& covariances, const BoolVector& valid, Vector3fVector& means_f, Matrix3fVector& covariances_f) { unsigned int size = valid.size(); for(unsigned int i = 0; i < size; ++i) { if (valid[i]) { const Vector3f& mean = means[i]; const Matrix3f& cov = covariances[i]; means_f.push_back(mean); covariances_f.push_back(cov); } } }
void ADFun<Base>::for_hes_sparsity( const BoolVector& select_domain , const BoolVector& select_range , bool internal_bool , sparse_rc<SizeVector>& pattern_out ) { size_t n = Domain(); size_t m = Range(); // CPPAD_ASSERT_KNOWN( size_t( select_domain.size() ) == n, "for_hes_sparsity: size of select_domain is not equal to " "number of independent variables" ); CPPAD_ASSERT_KNOWN( size_t( select_range.size() ) == m, "for_hes_sparsity: size of select_range is not equal to " "number of dependent variables" ); // do not need transpose or depenency bool transpose = false; bool dependency = false; // sparse_rc<SizeVector> pattern_tmp; if( internal_bool ) { // forward Jacobian sparsity pattern for independent variables local::sparse_pack internal_for_jac; internal_for_jac.resize(num_var_tape_, n + 1 ); for(size_t j = 0; j < n; j++) if( select_domain[j] ) { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < n + 1 ); internal_for_jac.add_element( ind_taddr_[j] , ind_taddr_[j] ); } // forward Jacobian sparsity for all variables on tape local::ForJacSweep( dependency, n, num_var_tape_, &play_, internal_for_jac ); // reverse Jacobian sparsity pattern for select_range local::sparse_pack internal_rev_jac; internal_rev_jac.resize(num_var_tape_, 1); for(size_t i = 0; i < m; i++) if( select_range[i] ) { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); internal_rev_jac.add_element( dep_taddr_[i] , 0 ); } // reverse Jacobian sparsity for all variables on tape local::RevJacSweep( dependency, n, num_var_tape_, &play_, internal_rev_jac ); // internal vector of sets that will hold Hessian local::sparse_pack internal_for_hes; internal_for_hes.resize(n + 1, n + 1); // // compute forward Hessian sparsity pattern local::ForHesSweep( n, num_var_tape_, &play_, internal_for_jac, internal_rev_jac, internal_for_hes ); // // put the result in pattern_tmp get_internal_sparsity( transpose, ind_taddr_, internal_for_hes, pattern_tmp ); } else { // forward Jacobian sparsity pattern for independent variables // (corresponds to D) local::sparse_list internal_for_jac; internal_for_jac.resize(num_var_tape_, n + 1 ); for(size_t j = 0; j < n; j++) if( select_domain[j] ) { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < n + 1 ); internal_for_jac.add_element( ind_taddr_[j] , ind_taddr_[j] ); } // forward Jacobian sparsity for all variables on tape local::ForJacSweep( dependency, n, num_var_tape_, &play_, internal_for_jac ); // reverse Jacobian sparsity pattern for select_range // (corresponds to s) local::sparse_list internal_rev_jac; internal_rev_jac.resize(num_var_tape_, 1); for(size_t i = 0; i < m; i++) if( select_range[i] ) { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); internal_rev_jac.add_element( dep_taddr_[i] , 0 ); } // reverse Jacobian sparsity for all variables on tape local::RevJacSweep( dependency, n, num_var_tape_, &play_, internal_rev_jac ); // internal vector of sets that will hold Hessian local::sparse_list internal_for_hes; internal_for_hes.resize(n + 1, n + 1); // // compute forward Hessian sparsity pattern local::ForHesSweep( n, num_var_tape_, &play_, internal_for_jac, internal_rev_jac, internal_for_hes ); // // put the result in pattern_tmp get_internal_sparsity( transpose, ind_taddr_, internal_for_hes, pattern_tmp ); } // subtract 1 from all column values CPPAD_ASSERT_UNKNOWN( pattern_tmp.nr() == n ); CPPAD_ASSERT_UNKNOWN( pattern_tmp.nc() == n + 1 ); const SizeVector& row( pattern_tmp.row() ); const SizeVector& col( pattern_tmp.col() ); size_t nr = n; size_t nc = n; size_t nnz = pattern_tmp.nnz(); pattern_out.resize(nr, nc, nnz); for(size_t k = 0; k < nnz; k++) { CPPAD_ASSERT_UNKNOWN( 0 < col[k] ); pattern_out.set(k, row[k], col[k] - 1); } return; }
bool BoolTable:: GenerateMinimalFalseBVList( List< BoolVector > &result ) { List< BoolVector > *baseBVList = new List< BoolVector >( ); List< BoolVector > *oldBVList = new List< BoolVector >( ); List< BoolVector > *newBVList = new List< BoolVector >( ); BoolVector *bv = NULL; BoolValue bval = FALSE_VALUE; GenerateMaximalTrueBVList( *baseBVList ); if( baseBVList->IsEmpty( ) ) { delete baseBVList; delete oldBVList; delete newBVList; return true; } // NEGATE baseBVList->Rewind( ); while( baseBVList->Next( bv ) ) { for( int i = 0; i < numRows; i++ ) { bv->GetValue( i, bval ); if( bval == TRUE_VALUE ) { bv->SetValue( i, FALSE_VALUE ); } else { bv->SetValue( i, TRUE_VALUE ); } } } // DISTRIB & COMBINE BoolVector *baseBV = NULL; BoolVector *newBV = NULL; BoolVector *oldBV = NULL; baseBVList->Rewind( ); while( baseBVList->Next( baseBV ) ) { for( int i = 0; i < numRows; i++ ) { baseBV->GetValue( i, bval ); if( bval == TRUE_VALUE ) { if( oldBVList->IsEmpty( ) ) { newBV = new BoolVector( ); newBV->Init( numRows ); for( int j = 0; j < numRows; j++ ) { if( i == j ) { newBV->SetValue( j, TRUE_VALUE ); } else { newBV->SetValue( j, FALSE_VALUE ); } } newBVList->Append( newBV ); } else { oldBVList->Rewind( ); while( oldBVList->Next( oldBV ) ) { newBV = new BoolVector( ); newBV->Init( oldBV ); newBV->SetValue( i, TRUE_VALUE ); newBVList->Append( newBV ); } } } } oldBVList->Rewind( ); while( oldBVList->Next( oldBV ) ) { delete oldBV; } delete oldBVList; oldBVList = newBVList; newBVList = new List< BoolVector >( ); } // PRUNE oldBVList->Rewind( ); while( oldBVList->Next( newBV ) ) { result.Rewind( ); bool addBV = true; bool isSubset = false; while( result.Next( oldBV ) ) { oldBV->IsTrueSubsetOf( *newBV, isSubset ); if( isSubset ) { addBV = false; break; } newBV->IsTrueSubsetOf( *oldBV, isSubset ); if( isSubset ) { result.DeleteCurrent( ); } } if( addBV ) { result.Append( newBV ); } else delete newBV; } baseBVList->Rewind( ); while( baseBVList->Next( oldBV ) ) { delete oldBV; } delete baseBVList; delete newBVList; delete oldBVList; return true; }