19 #include "vnl/vnl_random.h"
22 : m_Network( nullptr )
24 , m_TargetThreshold( 0.0 )
25 , m_TargetDensity( 1.0 )
37 if( ! CheckValidity() )
43 switch(m_ThresholdingScheme)
45 case RandomRemovalOfWeakest :
47 result = ThresholdByRandomRemoval( m_Network, m_TargetDensity );
50 case LargestLowerThanDensity :
52 result = ThresholdBelowDensity( m_Network, m_TargetDensity );
57 result = Threshold( m_Network, m_TargetThreshold );
62 MITK_ERROR <<
"Specified unknown Thresholding Scheme";
74 if( m_Network.IsNull() )
80 switch(m_ThresholdingScheme)
82 case RandomRemovalOfWeakest :
83 case LargestLowerThanDensity :
85 if( m_TargetDensity < 0.0 )
90 if( m_TargetDensity > 1.0 )
93 MITK_ERROR <<
"Target density is larger than 1.";
99 if( m_TargetThreshold < 0 )
102 MITK_ERROR <<
"Target threshold is negative.";
109 MITK_ERROR <<
"Specified unknown Thresholding Scheme";
119 result->ImportNetwort( input );
123 calculator->SetNetwork( result );
124 calculator->Update();
127 vnl_random rng( (
unsigned int) rand() );
129 bool notBelow( targetDensity < calculator->GetConnectionDensity() );
131 double minWeight( result->GetMaximumWeight() );
137 std::vector< EdgeDescriptorType > candidateVector;
138 minWeight = result->GetMaximumWeight();
145 boost::tie(iterator, end) = boost::edges( *boostGraph );
147 for ( ; iterator != end; ++iterator)
152 tempWeight = (*boostGraph)[ *iterator ].weight;
156 candidateVector.push_back( *iterator );
159 else if( tempWeight < minWeight )
161 candidateVector.clear();
162 candidateVector.push_back( *iterator );
163 minWeight = tempWeight;
169 int deleteNumber( rng.lrand32( count - 1 ) );
171 boost::remove_edge( candidateVector.at( deleteNumber ), *boostGraph );
173 calculator->SetNetwork( result );
174 calculator->Update();
175 notBelow = targetDensity < calculator->GetConnectionDensity();
185 result->ImportNetwort( input );
189 calculator->SetNetwork( result );
190 calculator->Update();
192 bool notBelow( targetDensity < calculator->GetConnectionDensity() );
194 for(
int loop( 1 ); notBelow; loop++ )
196 result = Threshold( result, loop );
197 calculator->SetNetwork( result );
198 calculator->Update();
199 notBelow = targetDensity < calculator->GetConnectionDensity();
208 result->ImportNetwort( input );
215 bool edgeHasBeenRemoved(
true );
218 while( edgeHasBeenRemoved )
220 edgeHasBeenRemoved =
false;
222 boost::tie(iterator, end) = boost::edges( *boostGraph );
224 bool endReached(
false );
225 while( !edgeHasBeenRemoved && !endReached )
227 if( iterator != end )
230 if( (*boostGraph)[ *iterator ].weight < targetThreshold )
232 edgeHasBeenRemoved =
true;
234 boost::remove_edge( *iterator, *boostGraph );
~ConnectomicsNetworkThresholder()
itk::SmartPointer< Self > Pointer
boost::graph_traits< NetworkType >::edge_iterator EdgeIteratorType
mitk::ConnectomicsNetwork::Pointer ThresholdBelowDensity(mitk::ConnectomicsNetwork::Pointer input, double targetDensity)
mitk::ConnectomicsNetwork::Pointer ThresholdByRandomRemoval(mitk::ConnectomicsNetwork::Pointer input, double targetDensity)
DataCollection - Class to facilitate loading/accessing structured data.
mitk::ConnectomicsNetwork::NetworkType NetworkType
mitk::ConnectomicsNetwork::Pointer GetThresholdedNetwork()
Apply thresholding scheme and get resulting network.
ConnectomicsNetworkThresholder()
mitk::ConnectomicsNetwork::Pointer Threshold(mitk::ConnectomicsNetwork::Pointer input, double targetThreshold)
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
A class for thresholding connectomics networks.
itk::SmartPointer< Self > Pointer