Click here to Skip to main content
13,150,946 members (39,914 online)
Click here to Skip to main content


109 bookmarked
Posted 20 Nov 2007

Kohonen's Self Organizing Maps in C++ with Application in Computer Vision Area

, 20 Nov 2007
The article demonstrates the self organizing maps clustering approach for unsupervised AI classification tasks with application examples in computer vision area for faces clustering and recognition

#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 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 {
                for (int c = 0; c < classes_number; c++)
        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.


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Chesnokov Yuriy
Russian Federation Russian Federation
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.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170924.2 | Last Updated 20 Nov 2007
Article Copyright 2007 by Chesnokov Yuriy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid