void TMultiClassifier::predictionAndDistribution(const TExample &ex, PValueList &classValues, PDistributionList &classDists) { if (computesProbabilities) { classDists = classDistribution(ex); PValueList classValues = new TValueList(); TValue value; PVariable classVar; for (int i = 0; i < classVars->size(); i++) { classVar = classVars->at(i); value = classVar->varType == TValue::FLOATVAR ? TValue(classDists->at(i)->average()) : classDists->at(i)->highestProbValue(ex); classValues->push_back(value); } } else { classValues = operator()(ex); PDistributionList classDist = new TDistributionList(); PDistribution dist; PVariable classVar; for (int i = 0; i < classVars->size(); i++) { classVar = classVars->at(i); dist = TDistribution::create(classVar); dist->add(classValues->at(i)); classDist->push_back(dist); } } }
void dump_dense() { dense_index_type index(m_fd); for (size_t i = 0; i < index.size(); ++i) { if (index.get(i) != TValue()) { std::cout << i << " " << index.get(i) << "\n"; } } }
void ForEach(TF && f) const { if (IsEmpty()) return; coding::CompressedBitVectorEnumerator::ForEach(*m_cbv, [&f](uint64_t const bitPosition) { f(TValue(bitPosition)); }); }
void Deserialize(TSource & src, SingleValueSerializer<TValue> const & serializer) { m_values.clear(); while (src.Size() > 0) { m_values.push_back(TValue()); serializer.DeserializeFromSource(src, m_values.back()); } }
pair<TValue &, bool> Get(TKey const & key) { auto r = m_map.insert(make_pair(key, TValue())); ++m_accesses; if (r.second) ++m_misses; return pair<TValue &, bool>(r.first->second, r.second); }
TValue TCostWrapperClassifier::operator ()(PDiscDistribution risks) { float ccost = numeric_limits<float>::max(); int wins=0, bestPrediction; const_ITERATE(TDiscDistribution, ri, risks.getReference()) if ( (*ri<ccost) && ((wins=1)==1) || (*ri==ccost) && globalRandom->randbool(++wins)) { bestPrediction=ri-risks->begin(); ccost=*ri; } return wins ? TValue(bestPrediction) : classVar->DK(); }
void TClassifier::predictionAndDistribution(const TExample &ex, TValue &val, PDistribution &classDist) { if (computesProbabilities) { classDist = classDistribution(ex); val = classVar->varType==TValue::FLOATVAR ? TValue(classDist->average()) : classDist->highestProbValue(ex); } else { val = operator()(ex); classDist = TDistribution::create(classVar); classDist->add(val); } }
DeserializationResult deserializeSigned(const char* buffer, TValue& value) const { char* end = NULL; long long tmp = strtoll(buffer, &end, 0); DeserializationResult result = Deserialization_UNKNOWN; if (end == buffer) { result = Deserialization_NOT_A_NUMBER; } else if (LLONG_MIN == tmp && ERANGE == errno) { result = Deserialization_UNDERFLOW; } else if (LLONG_MAX == tmp && ERANGE == errno) { result = Deserialization_OVERFLOW; } else if (!isEmptyOrWhitespace(end)) { result = Deserialization_NOT_A_NUMBER; } #if defined(_WIN32) // VS2015 generates this sign mismatch warning when TValue is unsigned, and // unsigned values are not process here. #pragma warning(suppress:4018) #endif else if (tmp < std::numeric_limits<TValue>::min()) { result = Deserialization_UNDERFLOW; } #if defined(_WIN32) // VS2015 generates this sign mismatch warning when TValue is unsigned, and // unsigned values are not process here. #pragma warning(suppress:4018) #endif else if (tmp > std::numeric_limits<TValue>::max()) { result = Deserialization_OVERFLOW; } else { value = TValue(tmp); result = Deserialization_SUCCESS; } return result; }
PValueList TMultiClassifier::operator ()(const TExample &exam) { if (!computesProbabilities) raiseError("invalid setting of 'computesProbabilities'"); PValueList classValues = new TValueList(); TValue value; PVariable classVar; PDistributionList classDists = classDistribution(exam); for (int i = 0; i < classVars->size(); i++) { classVar = classVars->at(i); value = classVar->varType == TValue::FLOATVAR ? TValue(classDists->at(i)->average()) : classDists->at(i)->highestProbValue(exam); classValues->push_back(value); } return classValues; }
bool search_sparse(TKey key) { typedef typename sparse_index_type::element_type element_type; sparse_index_type index(m_fd); element_type elem {key, TValue()}; auto positions = std::equal_range(index.begin(), index.end(), elem, [](const element_type& lhs, const element_type& rhs) { return lhs.key < rhs.key; }); if (positions.first == positions.second) { std::cout << key << " not found" << std::endl; return false; } for (auto& it = positions.first; it != positions.second; ++it) { std::cout << it->key << " " << it->value << "\n"; } return true; }
DeserializationResult deserializeFloatingPoint(const char* buffer, TValue& value) const { char* end = NULL; long double tmp = strtold(buffer, &end); DeserializationResult result = Deserialization_UNKNOWN; if (0 == tmp && end == buffer) { result = Deserialization_NOT_A_NUMBER; } else if (0 == tmp && ERANGE == errno) { result = Deserialization_UNDERFLOW; } else if ((-HUGE_VALL == tmp || HUGE_VALL == tmp) && ERANGE == errno) { result = Deserialization_OVERFLOW; } else if (!isEmptyOrWhitespace(end)) { result = Deserialization_NOT_A_NUMBER; } #if defined(_WIN32) // VS2015 generates this warning (as an error) with unsigned integral types, // even though this method does not process integral types. #pragma warning(suppress:4146) #endif else if (tmp < -std::numeric_limits<TValue>::max()) { result = Deserialization_OVERFLOW; } else if (tmp > std::numeric_limits<TValue>::max()) { result = Deserialization_OVERFLOW; } else { value = TValue(tmp); result = Deserialization_SUCCESS; } return result; }
void CMyTime::SetAllString(CString Value,BOOL blnSimple) { CString strYear,strMonth,strDay,strHour,strMin,strSec; if(blnSimple==FALSE) { strYear=Value.Mid(0,4); strMonth=Value.Mid(4,2); strDay=Value.Mid(6,2); if(Value.GetLength()>8) { strHour=Value.Mid(8,2); strMin=Value.Mid(10,2); strSec=Value.Mid(12,2); } else { strHour="0"; strMin="0"; strSec="0"; } } else { strYear=Value.Mid(0,4); strMonth=Value.Mid(5,2); strDay=Value.Mid(8,2); if(Value.GetLength()>10) { strHour=Value.Mid(11,2); strMin=Value.Mid(14,2); strSec=Value.Mid(17,2); } else { strHour="0"; strMin="0"; strSec="0"; } } CTime TValue(atoi(strYear),atoi(strMonth),atoi(strDay),atoi(strHour),atoi(strMin),atoi(strSec)); ValueTime=TValue; }
void TExampleForMissing::resetExample() { checkProperty(dataDescription); DCs.clear(); DKs.clear(); float averageWeight=1; TVarList::const_iterator vi(domain->attributes->begin()), vie(domain->attributes->end()); TExample::iterator ei(begin()), bei(ei); vector<float>::const_iterator ai(dataDescription->averages.begin()), aei(dataDescription->averages.end()); for(; vi!=vie; ei++, vi++) { if ((*ei).isSpecial()) { if ((*vi)->varType==TValue::FLOATVAR) *ei=TValue(*ai); else if (dataDescription->missingWeight && (*ei).isDK()) { DKs.push_back(ei-bei); averageWeight/=float((*vi)->noOfValues()); } else DCs.push_back(ei-bei); (*vi)->firstValue(*ei); } if (ai!=aei) ai++; } if (dataDescription->missingWeight) { float weight = dataDescription->originalWeight ? getMeta(dataDescription->originalWeight).floatV : 1; if (dataDescription->domainDistributions) { TDomainDistributions::const_iterator di(dataDescription->domainDistributions->begin()); ITERATE(vector<int>, ci, DKs) { // DKs contain only discrete variables, so it is safe to cast const TDiscDistribution &dist = CAST_TO_DISCDISTRIBUTION(*(di+*ci)); if (dist.abs) weight *= dist.front() / dist.abs; } }
bool convertFromPythonExisting(PyObject *lst, TExample &example) { PDomain dom=example.domain; if (PyOrExample_Check(lst)) { const TExample &orex = PyExample_AS_ExampleReference(lst); if (orex.domain != dom) dom->convert(example, orex); else example = orex; return true; } if (!PyList_Check(lst)) { PyErr_Format(PyExc_TypeError, "invalid argument type (expected list, got '%s)", lst ? lst->ob_type->tp_name : "None"); return false; } int const nvars = dom->variables->size() + dom->classVars->size(); if (Py_ssize_t(nvars) != PyList_Size(lst)) { PyErr_Format(PyExc_IndexError, "invalid list size (got %i, expected %i items)", PyList_Size(lst), nvars); return false; } Py_ssize_t pos = 0; TExample::iterator ei(example.begin()); TVarList::iterator vi(dom->variables->begin()); TVarList::const_iterator const ve(dom->variables->end()); TVarList::const_iterator const ce(dom->classVars->end()); while(vi != ce && vi != ve) { PyObject *li=PyList_GetItem(lst, pos++); if (!li) PYERROR(PyExc_SystemError, "can't read the list", false); if (PyOrValue_Check(li)) if (PyValue_AS_Variable(li) ? (PyValue_AS_Variable(li) != *vi) : (PyValue_AS_Value(li).varType=!(*vi)->varType) ) { PyErr_Format(PyExc_TypeError, "wrong value type for attribute no. %i (%s)", pos, (*vi)->get_name().c_str()); return false; } else *(ei++)=PyValue_AS_Value(li); else { if (li == Py_None) { *(ei++) = (*vi)->DK(); } else if (PyString_Check(li)) (*vi)->str2val(string(PyString_AsString(li)), *(ei++)); else if ((*vi)->varType==TValue::INTVAR) { if (PyInt_Check(li)) *(ei++)=TValue(int(PyInt_AsLong(li))); else { PyErr_Format(PyExc_TypeError, "attribute no. %i (%s) is ordinal, string value expected", pos, (*vi)->get_name().c_str()); return false; } } else if ((*vi)->varType==TValue::FLOATVAR) { float f; if (PyNumber_ToFloat(li, f)) *(ei++) = TValue(f); else { PyErr_Format(PyExc_TypeError, "attribute no. %i (%s) is continuous, float value expected", pos, (*vi)->get_name().c_str()); return false; } } else ei++; } if (++vi == ve) { vi = dom->classVars->begin(); } } return true; }
static uint8_t calculateDatatype() { return InfoPacket<TValue>(0, TValue(), 0).datatype(); }
LineWriter(unsigned int id, const boost::filesystem::path filePath = "", bool truncate = true) : LogicNode(id), m_truncate(truncate) { ADD_ISOCK(File, filePath); ADD_ISOCK(Value, TValue()); }
CEnumDataType::TValue& CEnumDataType::AddValue(const string& valueName, TEnumValueType value) { m_Values.push_back(TValue(valueName, value)); return m_Values.back(); }
CTreePair(const TId& aid, const TValue& avalue = TValue()) : id(aid), value(avalue) {}
void CLocalHookSetBase::SetHook(THookData* key, THook* hook) { THooks::iterator it = x_Find(key); _ASSERT(!x_Found(it, key)); m_Hooks.insert(it, TValue(key, CRef<CObject>(hook))); }
TValue& SetMatrix( int q, int s, double score, ECode code ) { return SetMatrix( q, s ) = TValue( score, code ); }
TValue TClassifier::operator ()(const TExample &exam) { if (!computesProbabilities) raiseError("invalid setting of 'computesProbabilities'"); return classVar->varType==TValue::FLOATVAR ? TValue(classDistribution(exam)->average()) : classDistribution(exam)->highestProbValue(exam); }