Last active
July 18, 2017 12:58
-
-
Save sofianehaddad/359f4e96329d7700384657f2212bff18 to your computer and use it in GitHub Desktop.
Expert mixture Point operators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Point ExpertMixture::evaluate_supervised(const Point & inP) const | |
{ | |
if (supervised_) return evaluate_supervised(inP); | |
return evaluate_non_supervised(inP); | |
} | |
Point ExpertMixture::evaluate_non_supervised(const Point & inP) const | |
{ | |
const UnsignedInteger inputDimension = getInputDimension(); | |
if (inP.getDimension() != inputDimension) throw InvalidArgumentException(HERE) << "Error: expected a point of dimension=" << inputDimension << " and got a point of dimension=" << inP.getDimension(); | |
const UnsignedInteger outputDimension = getOutputDimension(); | |
const UnsignedInteger size = experts_.getSize(); | |
UnsignedInteger bestClass = 0; | |
// Build the point z for the first class and grade it according to the classifier | |
// In a non supervised case no need to stack data | |
Point mixedPoint(inP); | |
Scalar bestGrade = classifier_.grade(mixedPoint, bestClass); | |
LOGDEBUG(OSS() << "Class index=" << 0 << ", grade=" << bestGrade); | |
for (UnsignedInteger classIndex = 1; classIndex < size; ++classIndex) | |
{ | |
// Build the point z for each other class and grade it according to the classifier | |
const Scalar grade = classifier_.grade(mixedPoint, classIndex); | |
LOGDEBUG(OSS() << "Class index=" << classIndex << ", grade=" << grade); | |
// The best class will give the output value | |
if (grade > bestGrade) | |
{ | |
bestGrade = grade; | |
bestClass = classIndex; | |
} | |
} | |
const Point bestValue(experts_[bestClass](inP)); | |
LOGDEBUG(OSS() << "Best class index=" << bestClass << ", best grade=" << bestGrade << ", best value=" << bestValue); | |
return bestValue; | |
} | |
Point ExpertMixture::evaluate_supervised(const Point & inP) const | |
{ | |
const UnsignedInteger inputDimension = getInputDimension(); | |
if (inP.getDimension() != inputDimension) throw InvalidArgumentException(HERE) << "Error: expected a point of dimension=" << inputDimension << " and got a point of dimension=" << inP.getDimension(); | |
const UnsignedInteger outputDimension = getOutputDimension(); | |
const UnsignedInteger size = experts_.getSize(); | |
UnsignedInteger bestClass = 0; | |
// Build the point z for the first class and grade it according to the classifier | |
Point mixedPoint(inP); | |
// z=(x, f(x)) | |
Point bestValue(experts_[0](inP)); | |
mixedPoint.add(bestValue); | |
Scalar bestGrade = classifier_.grade(mixedPoint, bestClass); | |
LOGDEBUG(OSS() << "Class index=" << 0 << ", grade=" << bestGrade << ", value=" << bestValue); | |
for (UnsignedInteger classIndex = 1; classIndex < size; ++classIndex) | |
{ | |
// Build the point z for each other class and grade it according to the classifier | |
const Point localValue(experts_[classIndex](inP)); | |
// z=(x, f(x)) | |
// mixedPoint is already defined so we just copy the localValue | |
std::copy(localValue.begin(), localValue.end(), mixedPoint.begin() + inputDimension); | |
const Scalar grade = classifier_.grade(mixedPoint, classIndex); | |
LOGDEBUG(OSS() << "Class index=" << classIndex << ", grade=" << grade << ", value=" << localValue); | |
// The best class will give the output value | |
if (grade > bestGrade) | |
{ | |
bestGrade = grade; | |
bestClass = classIndex; | |
bestValue = localValue; | |
} | |
} | |
LOGDEBUG(OSS() << "Best class index=" << bestClass << ", best grade=" << bestGrade << ", best value=" << bestValue); | |
return bestValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment