// 重決定係数を求める double multiple_determination(double *inputX1, double *inputX2, double *inputY, int input_size){ double *spr[2], r1Y, r2Y, sb1, sb2; standaraized_partial_regression(inputX1, inputX2, inputY, input_size, spr); r1Y = coefficient(inputX1, inputY, input_size); r2Y = coefficient(inputX2, inputY, input_size); sb1 = *spr[0]; sb2 = *spr[1]; return r1Y * sb1 + r2Y * sb2; }
bool MsqPlane::intersect( const MsqPlane& plane, MsqLine& result ) const { const double dot = normal() % plane.normal(); const double det = dot*dot - 1.0; if (fabs(det) < DBL_EPSILON) // parallel return false; const double s1 = (coefficient() - dot*plane.coefficient()) / det; const double s2 = (plane.coefficient() - dot*coefficient()) / det; result = MsqLine( s1*normal() + s2*plane.normal(), normal() * plane.normal() ); return true; }
void F4Res::loadRow(Row& r) { // std::cout << "loadRow: "; // monoid().showAlpha(r.mLeadTerm); // std::cout << std::endl; int skew_sign; // will be set to 1, unless ring().isSkewCommutative() is true, then it can be -1,0,1. // however, if it is 0, then "val" below will also be -1. FieldElement one; resGausser().set_one(one); long comp = monoid().get_component(r.mLeadTerm); auto& thiselement = mFrame.level(mThisLevel-1)[comp]; //std::cout << " comp=" << comp << " mDegree=" << thiselement.mDegree << " mThisDegree=" << mThisDegree << std::endl; if (thiselement.mDegree == mThisDegree) { // We only need to add in the current monomial //fprintf(stdout, "USING degree 0 monomial\n"); ComponentIndex val = processMonomialProduct(r.mLeadTerm, thiselement.mMonom, skew_sign); if (val < 0) fprintf(stderr, "ERROR: expected monomial to live\n"); r.mComponents.push_back(val); if (skew_sign > 0) r.mCoeffs.push_back(one); else { // Only happens if we are in a skew commuting ring. FieldElement c; ring().resGausser().negate(one, c); r.mCoeffs.push_back(c); } return; } auto& p = thiselement.mSyzygy; auto end = poly_iter(mRing, p, 1); auto i = poly_iter(mRing, p); for ( ; i != end; ++i) { ComponentIndex val = processMonomialProduct(r.mLeadTerm, i.monomial(), skew_sign); //std::cout << " monom: " << val << " skewsign=" << skew_sign << " mColumns.size=" << mColumns.size() << std::endl; if (val < 0) continue; r.mComponents.push_back(val); if (skew_sign > 0) r.mCoeffs.push_back(i.coefficient()); else { // Only happens if we are in a skew commuting ring. FieldElement c; ring().resGausser().negate(i.coefficient(), c); r.mCoeffs.push_back(c); } } }
Real RadiativeHeatFluxBCBase::computeQpResidual() { Real T4 = MathUtils::pow(_u[_qp], 4); Real T4inf = MathUtils::pow(_tinf.value(_t, _q_point[_qp]), 4); return _test[_i][_qp] * _sigma_stefan_boltzmann * coefficient() * (T4 - T4inf); }
bool MsqPlane::intersect( const MsqLine& line, double& result ) const { const double dot = line.direction() % normal(); if (fabs(dot) < DBL_EPSILON) return false; result = -(normal() % line.point() + coefficient()) / dot; return true; }
MutableMatrix* ResF4toM2Interface::to_M2_MutableMatrix( const Ring* K, SchreyerFrame& C, int lev, int degree) { // Now we loop through the elements of degree 'degree' at level 'lev' auto& thislevel = C.level(lev); int n = 0; for (auto p=thislevel.begin(); p != thislevel.end(); ++p) { if (p->mDegree == degree) n++; } auto& prevlevel = C.level(lev-1); int* newcomps = new int[prevlevel.size()]; int nextcomp = 0; for (int i=0; i<prevlevel.size(); i++) if (prevlevel[i].mDegree == degree) newcomps[i] = nextcomp++; else newcomps[i] = -1; // create the mutable matrix MutableMatrix* result = MutableMatrix::zero_matrix(K, nextcomp, n, true); // Now loop through the elements at thislevel, // and for each, loop through the terms of mSyzygy. // if the component x satisfies newcomps[x] >= 0, then place // this coeff into the mutable matrix. int col = 0; for (auto p=thislevel.begin(); p != thislevel.end(); ++p) { if (p->mDegree != degree) continue; auto& f = p->mSyzygy; auto end = poly_iter(C.ring(), f, 1); auto i = poly_iter(C.ring(), f); for ( ; i != end; ++i) { long comp = C.monoid().get_component(i.monomial()); if (newcomps[comp] >= 0) { ring_elem a; a = K->from_long(C.ring().resGausser().coeff_to_int(i.coefficient())); result->set_entry(newcomps[comp], col, a); } } ++col; } delete [] newcomps; return result; }
void linear_expression::change_subject(const variable& old_subj, const variable& new_subj) { assert(!new_subj.is_nil()); assert(!near_zero(coefficient(new_subj))); if (old_subj.is(new_subj)) return; terms_[old_subj] = new_subject(new_subj); }
inline void display_poly(FILE* fil, const ResPolyRing& R, const poly& f) { auto end = poly_iter(R, f, 1); // end for (auto it = poly_iter(R, f); it != end; ++it) { FieldElement c = R.resGausser().coeff_to_int(it.coefficient()); packed_monomial mon = it.monomial(); if (c != 1) fprintf(fil, "%d", c); R.monoid().showAlpha(mon); } }
int convertValue(char *conValue){ int b=findBase(conValue); int c=strlen(conValue); int k=0; int i; for(i=c-1; i>=0; i--) { k+=coefficient(conValue, i)*coefadd(b, c-i-1); } // printf("K Value: %d\n", k); return k; }
// 重回帰方程式を求める void multiple_regression(double *inputX1, double *inputX2, double *inputY, int input_size, double *output[3]){ double a, b1, b2, co1Y, co2Y, co12, av1, av2, avY, s1, s2, sY; co1Y = coefficient(inputX1, inputY, input_size); co2Y = coefficient(inputX2, inputY, input_size); co12 = coefficient(inputX1, inputX2, input_size); av1 = average(inputX1, input_size); av2 = average(inputX2, input_size); avY = average(inputY, input_size); s1 = standard_deviation(inputX1, input_size); s2 = standard_deviation(inputX2, input_size); sY = standard_deviation(inputY, input_size); b1 = ((co1Y - co2Y * co12) * sY) / ((1 - pow(co12, 2)) * s1); b2 = ((co2Y - co1Y * co12) * sY) / ((1 - pow(co12, 2)) * s2); a = avY - b1 * av1 - b2 * av2; output[0] = &a; output[1] = &b1; output[2] = &b2; }
std::pair<exprt,exprt> ranking_synthesis_qbf_bitwiset::ite_template() { exprt function; replace_mapt pre_replace_map; unsigned state_size = get_state_size(); unsigned bits=log((double)state_size)/log(2.0) + 1; symbol_exprt const_sym(CONSTANT_COEFFICIENT_ID, unsignedbv_typet(bits)); const_coefficient=coefficient(const_sym); unsigned cnt=0; for(bodyt::variable_mapt::const_iterator it=body.variable_map.begin(); it!=body.variable_map.end(); it++) { if(used_variables.find(it->first)==used_variables.end()) continue; exprt postsym=symbol_exprt(it->first, ns.lookup(it->first).type); exprt presym=symbol_exprt(it->second, ns.lookup(it->second).type); pre_replace_map[postsym] = presym; // save the corresponding pre-var exprt var=postsym; adjust_type(var.type()); unsigned vwidth = safe_width(var, ns); for(unsigned i=0; i<vwidth; i++) { exprt t(ID_extractbit, bool_typet()); t.copy_to_operands(var); t.copy_to_operands(from_integer(i, typet(ID_natural))); if(it==body.variable_map.begin() && i==0) function = t; else { function = if_exprt(equal_exprt(const_coefficient, from_integer(cnt, const_coefficient.type())), t, function); } cnt++; } } exprt pre_function=function; replace_expr(pre_replace_map, pre_function); return std::pair<exprt,exprt>(pre_function, function); }
int main( int argc, char *argv[]){ po::variables_map vm; process_args( argc, argv, vm); //setup some variables std::string full_complex_name = vm[ "input-file"].as< std::string>(); std::string complex_name( full_complex_name); std::string binary_name( argv[ 0]); std::string base_name( full_complex_name); std::string output_name; size_t found = complex_name.rfind( '/'); if ( found != std::string::npos){ complex_name.replace( 0, found+1, ""); } found = full_complex_name.rfind('.'); if ( found != std::string::npos){ base_name.replace(found,full_complex_name.length(), ""); output_name = base_name + ".phat"; } std::ofstream out(output_name.c_str()); Complex complex; // Read the cell_set in ctl::read_complex( full_complex_name, complex); Complex_filtration complex_filtration( complex); typedef ctl::Filtration_boundary< Complex_filtration> Filtration_boundary; typedef Filtration_boundary::Term Filtration_term; typedef ctl::Chain< Filtration_term> Chain; std::cout << "Writing PHAT ASCII file To: " << output_name << std::endl; Filtration_boundary bd( complex_filtration); for (Complex_filtration_iterator sigma = complex_filtration.begin(); sigma != complex_filtration.end(); ++sigma){ Chain cascade_boundary; cascade_boundary.reserve( bd.length( sigma)); for( auto i = bd.begin( sigma); i != bd.end( sigma); ++i){ cascade_boundary.emplace( i->cell(), i->coefficient()); } cascade_boundary.sort(); out << (*sigma)->first.dimension(); for( auto term : cascade_boundary){ out << " " << term.cell(); } out << std::endl; } return 0; }
int GenericGFPoly::evaluateAt(int a) const { if (a == 0) { // Just return the x^0 coefficient return coefficient(0); } if (a == 1) { // Just the sum of the coefficients int result = 0; for (int coef : _coefficients) { result = _field->addOrSubtract(result, coef); } return result; } int result = _coefficients[0]; for (size_t i = 1; i < _coefficients.size(); ++i) { result = _field->addOrSubtract(_field->multiply(a, result), _coefficients[i]); } return result; }
/** * @return evaluation of this polynomial at a given point */ int ModulusPoly::evaluateAt(int a) const { if (a == 0) { // Just return the x^0 coefficient return coefficient(0); } size_t size = _coefficients.size(); if (a == 1) { // Just the sum of the coefficients int result = 0; for (int coefficient : _coefficients) { result = _field->add(result, coefficient); } return result; } int result = _coefficients[0]; for (size_t i = 1; i < size; i++) { result = _field->add(_field->multiply(a, result), _coefficients[i]); } return result; }
exprt ranking_synthesis_satt::instantiate(void) { find_largest_constant(body.body_relation); binary_relation_exprt toplevel_and("and"); toplevel_and.lhs() = body.body_relation; // that's R(x,x') exprt function; replace_mapt pre_replace_map; bool first=true; for(bodyt::variable_mapt::const_iterator it=body.variable_map.begin(); it!=body.variable_map.end(); it++) { if(used_variables.find(it->first)==used_variables.end()) continue; exprt var=symbol_exprt(it->first, ns.lookup(it->first).type); pre_replace_map[var] = // save the corresponding pre-var symbol_exprt(it->second, ns.lookup(it->second).type); adjust_type(var.type()); const typet type=var.type(); exprt coef=coefficient(var); unsigned width=safe_width(var, ns); assert(width!=0); exprt term("*", typet("")); term.copy_to_operands(coef, var); if(first) { function=term; first=false; } else { // cast_up(function, term); exprt t("+", typet("")); t.move_to_operands(function, term); function = t; } } if(first) // non of the interesting variables was used - bail out! { debug("Completely non-deterministic template; " "this loop does not terminate."); return false_exprt(); } // if(!largest_constant.is_zero()) // { // // add the largest constant // symbol_exprt lc_sym("termination::LC", largest_constant.type()); // exprt lc=largest_constant; // exprt lcc=coefficient(lc_sym); //// cast_up(lc, lcc); // exprt m("*", typet("")); // m.move_to_operands(lcc, lc); // //// cast_up(function, m); // exprt t("+", typet("")); // t.move_to_operands(function, m); // function = t; // } // add a constant term symbol_exprt const_sym("termination::constant", signedbv_typet(2)); exprt cc=coefficient(const_sym); // cast_up(function, cc); exprt t2("+", typet("")); t2.move_to_operands(function, cc); function=t2; contextt context; ansi_c_parse_treet pt; rankfunction_typecheckt typecheck(pt, context, ns, *message_handler); try { typecheck.typecheck_expr(function); } catch (...) { throw "TC ERROR"; } exprt pre_function = function; replace_expr(pre_replace_map, pre_function); // save the relation for later rank_relation = binary_relation_exprt(function, "<", pre_function); // base_type(rank_relation, ns); toplevel_and.rhs()=not_exprt(rank_relation); return toplevel_and; }
std::pair<exprt,exprt> ranking_synthesis_qbf_bitwiset::affine_template( const irep_idt &termOp, const irep_idt &coefOp) { exprt function; replace_mapt pre_replace_map; for(bodyt::variable_mapt::const_iterator it=body.variable_map.begin(); it!=body.variable_map.end(); it++) { if(used_variables.find(it->first)==used_variables.end()) continue; exprt postsym=symbol_exprt(it->first, ns.lookup(it->first).type); exprt presym=symbol_exprt(it->second, ns.lookup(it->second).type); pre_replace_map[postsym] = presym; // save the corresponding pre-var exprt var=postsym; adjust_type(var.type()); exprt co = coefficient(var); irep_idt bitop = (coefOp==ID_and) ? ID_bitand : (coefOp==ID_or) ? ID_bitor : (coefOp==ID_notequal) ? ID_bitxor : ""; exprt varblock(bitop, var.type()); varblock.copy_to_operands(var, co); exprt bchain = bitwise_chain(termOp, varblock); if(it==body.variable_map.begin()) // first one function=bchain; else { if(termOp==ID_notequal) { exprt t(ID_equal, bool_typet()); t.move_to_operands(function); t.move_to_operands(bchain); function=not_exprt(t); } else { exprt t(termOp, bool_typet()); t.move_to_operands(function); t.move_to_operands(bchain); function=t; } } } // ... and a constant coefficient symbol_exprt const_sym(CONSTANT_COEFFICIENT_ID, bool_typet()); const_coefficient=coefficient(const_sym); if(termOp==ID_notequal) { exprt t(ID_equal, bool_typet()); t.move_to_operands(function); t.copy_to_operands(const_coefficient); function = not_exprt(t); } else { exprt t(termOp, bool_typet()); t.move_to_operands(function); t.copy_to_operands(const_coefficient); function = t; } exprt pre_function=function; replace_expr(pre_replace_map, pre_function); return std::pair<exprt,exprt>(pre_function, function); }
Real PikaHomogenizedKernel::computeQpResidual() { return coefficient(_qp) * HomogenizationHeatConduction::computeQpResidual(); }
int SchreyerFrame::rank(int slanted_degree, int lev) { // As above, get the size of the matrix, and 'newcols' // Now we loop through the elements of degree 'slanted_degree + lev' at level 'lev' if (not (lev > 0 and lev <= maxLevel()) and not (slanted_degree >= mLoSlantedDegree and slanted_degree < mHiSlantedDegree)) { std::cerr << "ERROR: called rank(" << slanted_degree << "," << lev << ")" << std::endl; return 0; } assert(lev > 0 and lev <= maxLevel()); assert(slanted_degree >= mLoSlantedDegree and slanted_degree < mHiSlantedDegree); int degree = slanted_degree + lev; auto& thislevel = level(lev); int ncols = 0; for (auto p=thislevel.begin(); p != thislevel.end(); ++p) { if (p->mDegree == degree) ncols++; } auto& prevlevel = level(lev-1); int* newcomps = new int[prevlevel.size()]; int nrows = 0; for (int i=0; i<prevlevel.size(); i++) if (prevlevel[i].mDegree == degree) newcomps[i] = nrows++; else newcomps[i] = -1; // Create the ARing // Create a DMat // M2::ARingZZpFlint R(gausser().get_ring()->characteristic()); // DMat<M2::ARingZZpFlint> M(R, nrows, ncols); #if 0 // TODO: Change this M2::ARingZZpFFPACK R(gausser().get_ring()->characteristic()); DMat<M2::ARingZZpFFPACK> M(R, nrows, ncols); #endif // Fill in DMat // loop through the elements at thislevel, // and for each, loop through the terms of mSyzygy. // if the component x satisfies newcomps[x] >= 0, then place // this coeff into the mutable matrix. int col = 0; long nnonzeros = 0; for (auto p=thislevel.begin(); p != thislevel.end(); ++p) { if (p->mDegree != degree) continue; auto& f = p->mSyzygy; auto end = poly_iter(ring(), f, 1); auto i = poly_iter(ring(), f); for ( ; i != end; ++i) { long comp = monoid().get_component(i.monomial()); if (newcomps[comp] >= 0) { #if 0 // TODO: change this line: M.entry(newcomps[comp], col) = gausser().coeff_to_int(i.coefficient()); #endif nnonzeros++; } } ++col; } double frac_nonzero = (nrows*ncols); frac_nonzero = nnonzeros / frac_nonzero; // buffer o; // displayMat(o, M); // std::cout << o.str() << std::endl; // call rank // auto a = DMatLinAlg<M2::ARingZZpFlint>(M); #if 0 // TODO: change this line auto a = DMatLinAlg<M2::ARingZZpFFPACK>(M); long numrows = M.numRows(); long numcols = M.numColumns(); #endif long numrows = 0; long numcols = 0; clock_t begin_time0 = clock(); int rk = 0; // TODO: static_cast<int>(a.rank()); clock_t end_time0 = clock(); double nsecs0 = (double)(end_time0 - begin_time0)/CLOCKS_PER_SEC; if (M2_gbTrace >= 2) { std::cout << "rank (" << slanted_degree << "," << lev << ") = " << rk << " time " << nsecs0 << " size= " << numrows << " x " << numcols << " nonzero " << nnonzeros << std::endl; } return rk; }
double ResF4toM2Interface::setDegreeZeroMap(SchreyerFrame& C, DMat<RingType>& result, int slanted_degree, int lev) // 'result' should be previously initialized, but will be resized. // return value: -1 means (slanted_degree, lev) is out of range, and the zero matrix was returned. // otherwise: the fraction of non-zero elements is returned. { // As above, get the size of the matrix, and 'newcols' // Now we loop through the elements of degree 'slanted_degree + lev' at level 'lev' const RingType& R = result.ring(); if (not (lev > 0 and lev <= C.maxLevel())) { result.resize(0,0); return -1; } assert(lev > 0 and lev <= C.maxLevel()); int degree = slanted_degree + lev; auto& thislevel = C.level(lev); int ncols = 0; for (auto p=thislevel.begin(); p != thislevel.end(); ++p) { if (p->mDegree == degree) ncols++; } auto& prevlevel = C.level(lev-1); int* newcomps = new int[prevlevel.size()]; int nrows = 0; for (int i=0; i<prevlevel.size(); i++) if (prevlevel[i].mDegree == degree) newcomps[i] = nrows++; else newcomps[i] = -1; result.resize(nrows, ncols); int col = 0; long nnonzeros = 0; for (auto p=thislevel.begin(); p != thislevel.end(); ++p) { if (p->mDegree != degree) continue; auto& f = p->mSyzygy; auto end = poly_iter(C.ring(), f, 1); auto i = poly_iter(C.ring(), f); for ( ; i != end; ++i) { long comp = C.monoid().get_component(i.monomial()); if (newcomps[comp] >= 0) { R.set_from_long(result.entry(newcomps[comp], col), C.gausser().coeff_to_int(i.coefficient())); nnonzeros++; } } ++col; } double frac_nonzero = (nrows*ncols); frac_nonzero = static_cast<double>(nnonzeros) / frac_nonzero; delete[] newcomps; return frac_nonzero; }
Real RadiativeHeatFluxBCBase::computeQpJacobian() { Real T3 = MathUtils::pow(_u[_qp], 3); return 4 * _sigma_stefan_boltzmann * _test[_i][_qp] * coefficient() * T3 * _phi[_j][_qp]; }