Commit 3e609fbf authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[MERGE]

parents 16d81ee3 859f9750
......@@ -31,6 +31,8 @@
#include <vector>
#include "../WAssert.h"
#include "../WLogger.h"
#include "../WStringUtils.h"
#include "WDendrogram.h"
WDendrogram::WDendrogram( size_t n )
......@@ -86,11 +88,8 @@ std::string WDendrogram::toTXTString() const
level[ i ] = std::max( level[ left ], level[ right ] ) + 1;
preds[ m_parents[ i ] ].insert( i );
std::set< size_t > join;
std::set_union( childsOfInnerNodes[ m_parents[ i ] ].begin(),
childsOfInnerNodes[ m_parents[ i ] ].end(),
childsOfInnerNodes[ i ].begin(),
childsOfInnerNodes[ i ].end(),
std::inserter( join, join.begin() ) );
std::set_union( childsOfInnerNodes[ m_parents[ i ] ].begin(), childsOfInnerNodes[ m_parents[ i ] ].end(),
childsOfInnerNodes[ i ].begin(), childsOfInnerNodes[ i ].end(), std::inserter( join, join.begin() ) );
childsOfInnerNodes[ m_parents[ i ] ] = join;
ss << "(" << level[i] << ", (";
size_t numElements = childsOfInnerNodes[i].size();
......@@ -106,11 +105,16 @@ std::string WDendrogram::toTXTString() const
}
numElements -= 1;
}
ss << " (" << left << ", " << right << "), " << m_heights[ i - m_heights.size() + 1 ] << ")" << std::endl;
// TODO(math): the needs to be made with a writer instead
std::ofstream file( "/home/math/pansen.txt" );
file << ss.str();
file.close();
using string_utils::operator<<;
ss << "(" << left << ", " << right << "), " << m_heights[ i - m_heights.size() - 1 ] << ")" << std::endl;
}
// TODO(math): the needs to be made with a writer instead
wlog::debug( "WDendrogram" ) << "start writing the txt file to pansen.txt";
std::ofstream file( "/home/math/pansen.txt" );
file << ss.str();
file.close();
wlog::debug( "WDendrogram" ) << "written the txt file to pansen.txt";
return ss.str();
}
......@@ -25,8 +25,9 @@
#ifndef WDENDROGRAM_H
#define WDENDROGRAM_H
#include <vector>
#include <sstream>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
......
......@@ -27,6 +27,7 @@
#include <cxxtest/TestSuite.h>
#include "../../WLogger.h"
#include "../WDendrogram.h"
/**
......@@ -36,10 +37,51 @@ class WDendrogramTest : public CxxTest::TestSuite
{
public:
/**
* When a new node is created, each member should be equal to zero.
* Check if the dendrogram correctly constructs the txt string. <dfn>($level, ($childs,...),
* ($left, $right), $similarity)\n</dfn> But for the leaves we have <dfn>(0,
* ($tractNum,))\n</dfn>.
\verbatim
.----'----. 0.32
| 8 |
0.4 .---'---. |
| 6 | .--'--. 0.6
0.8 .--'--. | | 7 |
| 5 | | | |
| | | | |
0 1 2 3 4
\endverbatim
*/
void testNewNodesHaveAlwaysZerosAssignedInitially( void )
void testStringCreation( void )
{
WDendrogram d( 5 );
d.merge( 0, 1, 0.8 ); // 5
d.merge( 5, 2, 0.4 ); // 6
d.merge( 3, 4, 0.60 ); // 7
d.merge( 6, 7, 0.32 ); // 8
std::stringstream ss;
ss << "(0, (0,))" << std::endl;
ss << "(0, (1,))" << std::endl;
ss << "(0, (2,))" << std::endl;
ss << "(0, (3,))" << std::endl;
ss << "(0, (4,))" << std::endl;
ss << "(1, (0, 1), (0, 1), 0.8)" << std::endl;
ss << "(2, (0, 1, 2), (2, 5), 0.4)" << std::endl;
ss << "(1, (3, 4), (3, 4), 0.6)" << std::endl;
ss << "(3, (0, 1, 2, 3, 4), (6, 7), 0.32)" << std::endl;
if( ss.str() != d.toTXTString() )
{
std::cout << "Expected:" << std::endl << ss.str();
std::cout << "But got:" << std::endl << d.toTXTString();
TS_FAIL( "Invalid dendrogram to string generation" );
}
}
/**
* Sets up the WLogger to properly log some thing...
*/
void setUp( void )
{
WLogger::startup();
}
};
......
......@@ -138,8 +138,7 @@ boost::shared_ptr< WMDetTractClusteringGP::MST > WMDetTractClusteringGP::compute
// initialize the first the similarities to the root node.
const WGaussProcess& root = dataSet->front(); // is the root vertex of the MST
std::vector< double > similarities( dataSet->size(), 0.0 );
similarities[0] = wlimits::MAX_DOUBLE; // root node has maximal similarity and is selected first
for( size_t i = 1; i < dataSet->size(); ++i )
for( size_t i = 0; i < dataSet->size(); ++i )
{
const WGaussProcess& p = ( *dataSet )[i];
if( root.getBB().minDistance( p.getBB() ) < root.getMaxSegmentLength() + p.getMaxSegmentLength() )
......@@ -226,7 +225,7 @@ boost::shared_ptr< WDendrogram > WMDetTractClusteringGP::computeDendrogram( boos
size_t u = cit->second.first;
size_t v = cit->second.second;
// u and v may already contain to a cluster, thus we need their cannonical elements
// u and v may already be a member of a cluster, thus we need their cannonical elements
size_t cEu = uf.find( u );
size_t cEv = uf.find( v );
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMDETTRACTCLUSTERING_TEST_H
#define WMDETTRACTCLUSTERING_TEST_H
#include <cxxtest/TestSuite.h>
#include "../WMDetTractClustering.h"
/**
* TODO(math): Document this!
*/
class WMDetTractClusteringTest : public CxxTest::TestSuite
{
public:
/**
* TODO(math): Document this!
*/
void testSomething( void )
{
}
};
#endif // WMDETTRACTCLUSTERING_TEST_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment