|
#include "stdafx.h"
#include "node.h"
///////////////////////////////////node constructor/destructor///////////////////////////////////////////
Node::Node(const float *weights, int weights_number,
const float *coords, int coords_number, int class_) : m_weights_number(weights_number), m_class(class_), m_precision(0.0f)
{
m_weights = (float *)malloc(m_weights_number * sizeof(float));
for (int i = 0; i < weights_number; i++)
m_weights[i] = weights[i];
m_coords = (float *)malloc(coords_number * sizeof(float));
for (int i = 0; i < coords_number; i++)
m_coords[i] = coords[i];
}
Node::~Node()
{
free(m_weights);
free(m_coords);
}
///////////////////////////////////node constructor/destructor///////////////////////////////////////////
/////////////////////////////votes calculation/////////////////////////////////////////////
void Node::clear_votes(int classes_number)
{
if (m_votes.size() && classes_number == (int)m_votes.size()) {
for (int c = 0; c < classes_number; c++)
m_votes[c] = 0;
} else {
m_votes.clear();
for (int c = 0; c < classes_number; c++)
m_votes.push_back(0);
}
m_class = 0;
m_precision = 0.0f;
}
bool Node::evaluate_class(const int *classes, int classes_number) //classes 1,2,3 or 2,4,5 or 5,2,1 ... not in ascending order
{
if (classes_number) {
m_precision = 0.0f;
//get max votes number and assign a class to that node
int maxvotes = m_votes[0];
m_class = classes[0];
for (int c = 1; c < classes_number; c++) {
if (maxvotes < m_votes[c]) {
maxvotes = m_votes[c];
m_class = classes[c];
}
}
//calculate node presicion = maxvotes/(cls1votes+cls2votes+ ... )
if (maxvotes) {
for (int c = 0; c < classes_number; c++)
m_precision += m_votes[c];
m_precision = ((float)maxvotes / m_precision);
} else
m_class = 0;
return true;
} else
return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Highly skilled Engineer with 14 years of experience in academia, R&D and commercial product development supporting full software life-cycle from idea to implementation and further support. During my academic career I was able to succeed in MIT Computers in Cardiology 2006 international challenge, as a R&D and SW engineer gain CodeProject MVP, find algorithmic solutions to quickly resolve tough customer problems to pass product requirements in tight deadlines. My key areas of expertise involve Object-Oriented
Analysis and Design OOAD, OOP, machine learning, natural language processing, face recognition, computer vision and image processing, wavelet analysis, digital signal processing in cardiology.