double Entropy::estimate() const { double HEsti = 0; int symbolnumber = 0; for ( const auto & pair : fin ) { int N = pair.first; symbolnumber += pair.second; if ( N > N_thr) // plug-in { double x = (double)N / (double)n; HEsti += (-x*log(x)+0.5/n) * (pair.second); } else // polynomial { HEsti += getCoeff(N) * (pair.second); } } HEsti += 1.0*getCoeff(0) * (k-symbolnumber); HEsti = (HEsti > 0)? HEsti:0; // HEsti = (HEsti < log(k))?HEsti:log(k); return HEsti/log(2); // return the estimated entropy (bits) }
static int config(struct vf_instance *vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt){ int i, j; vf->priv->pvStride= width; vf->priv->pv= av_malloc(width*height*2*sizeof(int32_t)); initPv(vf->priv, width, height); for(i=0; i<SUB_PIXELS; i++){ double d= i/(double)SUB_PIXELS; double temp[4]; double sum=0; for(j=0; j<4; j++) temp[j]= getCoeff(j - d - 1); for(j=0; j<4; j++) sum+= temp[j]; for(j=0; j<4; j++) vf->priv->coeff[i][j]= (int)floor((1<<COEFF_BITS)*temp[j]/sum + 0.5); } return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); }
void Poly::add(Poly& p) { auto i = this->terms.begin(); auto j = p.terms.begin(); while (i != this->terms.end() && j != p.terms.end()) { if (i->getPower() < j->getPower()) { i++; } else if (i->getPower() == j->getPower()) { i->setCoeff(i->getCoeff() + j->getCoeff()); i++; j++; } else { this->terms.insert(i, *j); j++; } } while (i == this->terms.end() && j != p.terms.end()) { this->terms.push_back(*j); j++; } }
void A2L::fillScalarsInfo(QVector< QSharedPointer<ECUScalar> > &scalars) const { for ( ptrdiff_t i=0; i<m_scalarsInfo.size(); i++ ) { QSharedPointer<ECUScalar> scal(new ECUScalar()); const ptrdiff_t compuMethodInd = findCompuMethod(m_scalarsInfo[i][6]); if ( m_compumethodsInfo[compuMethodInd][2] == "RAT_FUNC" ) { scal->setType(VARTYPE_SCALAR_NUM); scal->setCoefficients(getCoeff(compuMethodInd)); } else if ( m_compumethodsInfo[compuMethodInd][2] == "TAB_VERB" ) { scal->setType(VARTYPE_SCALAR_VTAB); const ptrdiff_t compuVTabInd = findCompuVTab(m_compumethodsInfo[compuMethodInd][5].split(' ').last()); scal->setVTable(getVTab(compuVTabInd)); } scal->setName(m_scalarsInfo[i][0]); scal->setShortDescription(delQuotes(m_scalarsInfo[i][1])); scal->setAddress(m_scalarsInfo[i][3].split("x").last()); scal->setNumType(m_scalarsInfo[i][4].split('_').last()); scal->setRangeSoft(m_scalarsInfo[i][5].toDouble()); scal->setMinValueSoft(m_scalarsInfo[i][7].toDouble()); scal->setMaxValueSoft(m_scalarsInfo[i][8].toDouble()); scal->setPrecision(delQuotes(m_scalarsInfo[i][9].split('.').last()).toInt()); QVector<double> v = getHardLimints(m_scalarsInfo[i][10]); scal->setMinValueHard(v[0]); scal->setMaxValueHard(v[1]); scal->setReadOnly(isReadOnly(i)); scal->setDimension("[" + delQuotes(m_compumethodsInfo[compuMethodInd][4]) + "]"); scalars.push_back(scal); } }
double Entropy::estimate_non_zero() const // Only use fingerprint f_j for j>=1. In other words, g(0)=0. { double HEsti = 0; for ( const auto & pair : fin ) { int N = pair.first; if ( N > N_thr) // plug-in { double x = (double)N / (double)n; HEsti += (-x*log(x)+0.5/n) * (pair.second); } else // polynomial { HEsti += getCoeff(N) * (pair.second); } } HEsti = (HEsti > 0)? HEsti:0; // HEsti = (HEsti < log(k))?HEsti:log(k); return HEsti/log(2); // return the estimated entropy (bits) }
string EltwiseLayer::convet2CaffeFormat() { string layerStrStart = "layer\n{\n"; string layerStrEnd = "}"; string nameStrStart = "\tname: \""; string nameStrEnd = "\"\n"; string typeStrStart = "\ttype: \""; string typeStrEnd = "\"\n"; string topStrStart = "\ttop: \""; string topStrEnd = "\"\n"; string bottomStrStart = "\tbottom: \""; string bottomStrEnd = "\"\n"; string eltwiseParamStrStart = "\teltwise_param\n\t{\n"; string eltwiseParamStrEnd = "\t}\n"; string operationStrStart = "\t\toperation: "; string operationStrEnd = "\n"; string coeffStrStart = "\t\tcoeff: "; string coeffStrEnd = "\n"; string stableProdGradStrStart = "\t\tstable_prod_grad: "; string stableProdGradStrEnd = "\n"; string phaseStrStart = "\tinclude:\n\t{\n"; string phaseStrEnd = "\t}\n"; string phaseStateStrStart = "\t\tphase: "; string phaseStateStrEnd = "\n"; string outStr = layerStrStart + nameStrStart + mName + nameStrEnd + typeStrStart + getLayerType() + typeStrEnd; for(size_t i = 0; i < mTops->size(); i++) { outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd; } for(size_t i = 0; i < mBottoms->size(); i++) { outStr = outStr + bottomStrStart + (*mBottoms)[i] + bottomStrEnd; } outStr = outStr + eltwiseParamStrStart ; if(((EltwiseParam*)mParam)->mOperation != MMALab::ELTWISEOP_SUM) { switch (((EltwiseParam*)mParam)->mOperation) { case MMALab::ELTWISEOP_PROD: outStr += operationStrStart + "PROD" + operationStrEnd; break; case MMALab::ELTWISEOP_MAX: outStr += operationStrStart + "MAX" + operationStrEnd; } } outStr += coeffStrStart + to_string(getCoeff()) + coeffStrEnd; if(((EltwiseParam*)mParam)->mStableProdGrad != true) { outStr += stableProdGradStrStart + "false" + stableProdGradStrEnd; } outStr += eltwiseParamStrEnd ; if (mPhase != Phase::BOTH) { outStr += phaseStrStart + phaseStateStrStart; if (mPhase == Phase::TRAIN) { outStr += "TRAIN"; } else if (mPhase == Phase::TEST) { outStr += "TEST"; } outStr += phaseStateStrEnd + phaseStrEnd; } outStr += layerStrEnd; return outStr; }