Skip to content

Commit 49d514a

Browse files
v1.15.4 Move SMap NaN warning to verbose. Improve ComputeError NaN handling.
1 parent 6cf46f3 commit 49d514a

File tree

3 files changed

+28
-36
lines changed

3 files changed

+28
-36
lines changed

src/API.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -458,23 +458,21 @@ SMapValues SMap( DataFrame< double > & DF,
458458
}
459459
DF.FindNan( nanColsCheck ); // If nan, set DF.nanFound, DF.nanRows
460460

461-
if ( DF.NanFound() ) {
461+
if ( parameters.verbose and DF.NanFound() ) {
462462
// Issue warning
463463
std::stringstream msg;
464464
msg << "WARNING: SMap() " << DF.NanRows().size()
465465
<< " nan rows detected in columns or target. "
466466
<< "Original number of rows " << DF.NRows() << ".\n";
467467
std::cout << msg.str();
468468

469-
if ( parameters.verbose ) {
470-
msg.str( std::string() ); // clear msg
471-
msg << "WARNING: SMap() nan rows: ";
472-
std::vector< size_t >::iterator ni;
473-
for ( ni = DF.NanRows().begin(); ni != DF.NanRows().end(); ++ni ) {
474-
msg << *ni + 1 << " ";
475-
} msg << "\n";
476-
std::cout << msg.str();
477-
}
469+
msg.str( std::string() ); // clear msg
470+
msg << "WARNING: SMap() nan rows: ";
471+
std::vector< size_t >::iterator ni;
472+
for ( ni = DF.NanRows().begin(); ni != DF.NanRows().end(); ++ni ) {
473+
msg << *ni + 1 << " ";
474+
} msg << "\n";
475+
std::cout << msg.str();
478476
}
479477

480478
//-----------------------------------------------------------------

src/Common.cc

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ VectorError ComputeError( std::valarray< double > obsIn,
113113
// We need to find the appropriate slice parameters
114114

115115
// To try and be efficient, we first scan for nans, if none: stats
116-
// If there are nans, then assess the overlapping subset and slice
116+
// If there are nans, copy from the overlapping values
117117
bool nanObs = false;
118118
bool nanPred = false;
119119

@@ -130,57 +130,51 @@ VectorError ComputeError( std::valarray< double > obsIn,
130130
pred = std::valarray< double >( predIn );
131131
}
132132
else {
133-
// Handle nans...
133+
// Handle nans
134134
// Build concurrent vector of bool pairs : isnan on obsIn, predIn
135135
std::vector< std::pair< bool, bool > > nanIndexPairs( Nin );
136136
for ( size_t i = 0; i < Nin; i++ ) {
137137
nanIndexPairs[ i ] = std::make_pair( std::isnan( obsIn[i] ),
138138
std::isnan( predIn[i] ) );
139139
}
140-
// Find overlapping subset indices
140+
// Find overlapping subset indices or use set::intersection
141141
// Condense pairs into one boolean value in nonNanOverlap
142+
size_t Nout = 0;
142143
std::vector< bool > nonNanOverlap( Nin );
143144
for ( size_t i = 0; i < Nin; i++ ) {
144145
if ( not nanIndexPairs[ i ].first and
145146
not nanIndexPairs[ i ].second ) {
146147
nonNanOverlap[ i ] = true; // Both are not nan, valid index
148+
Nout++;
147149
}
148150
else {
149151
nonNanOverlap[ i ] = false;
150152
}
151153
}
152-
// Get the slice parameters
153-
auto firstValid = std::find( nonNanOverlap.begin(),
154-
nonNanOverlap.end(), true );
155-
auto lastValid = std::find( nonNanOverlap.rbegin(),
156-
nonNanOverlap.rend(), true );
157-
size_t firstValidIndex = std::distance( nonNanOverlap.begin(),
158-
firstValid );
159-
size_t lastValidIndex = std::distance( nonNanOverlap.rbegin(),
160-
lastValid );
161-
162-
lastValidIndex = Nin - lastValidIndex; // reverse iterator used...
163-
164-
int Nout = (int) lastValidIndex - (int) firstValidIndex;
165-
166-
if ( Nout < 0 ) {
154+
155+
if ( Nout < 6 ) {
167156
std::stringstream msg;
168-
msg << "WARNING: ComputeError(): nan predictions found"
169-
<< " error not computed." << std::endl;
157+
msg << "WARNING: ComputeError(): nan found. Not enough data"
158+
<< " to compute error." << std::endl;
170159
std::cout << msg.str();
171160

172-
Nout = 0;
173161
obs = std::valarray< double >( 0., 1 ); // vector [0.] N = 1
174162
pred = std::valarray< double >( 0., 1 ); // vector [0.] N = 1
175163
}
176164
else {
177165
// Allocate the output arrays and fill with slices
178166
obs = std::valarray< double >( Nout );
179167
pred = std::valarray< double >( Nout );
180-
181-
std::slice nonNan = std::slice( firstValidIndex, Nout, 1 );
182-
obs [ std::slice( 0, Nout, 1 ) ] = obsIn [ nonNan ];
183-
pred[ std::slice( 0, Nout, 1 ) ] = predIn[ nonNan ];
168+
169+
// Copy valid values into obs & pred
170+
size_t n = 0;
171+
for ( size_t i = 0; i < nonNanOverlap.size(); i++ ) {
172+
if ( nonNanOverlap[ i ] ) {
173+
obs [ n ] = obsIn [ i ];
174+
pred[ n ] = predIn[ i ];
175+
n++;
176+
}
177+
}
184178
}
185179
}
186180

src/Parameter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Parameters::Parameters(
102102
validated ( false ),
103103

104104
// Instantiate Version
105-
version( 1, 15, 3, "2023-11-31" )
105+
version( 1, 15, 4, "2024-04-05" )
106106
{
107107
// Constructor code
108108
if ( method != Method::None ) {

0 commit comments

Comments
 (0)