Skip to content

Commit

Permalink
v1.15.1 Sync cppEDM. ignoreNan PredictNonlinear. Remove unicode in pl…
Browse files Browse the repository at this point in the history
…ot labels.
  • Loading branch information
SoftwareLiteracy committed Oct 27, 2023
1 parent ea00e99 commit 713d168
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 25 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: rEDM
Type: Package
Title: Empirical Dynamic Modeling ('EDM')
Version: 1.15.0
Date: 2023-10-21
Version: 1.15.1
Date: 2023-10-27
Authors@R: c( person("Joseph", "Park", role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0001-5411-1409")),
Expand Down
14 changes: 10 additions & 4 deletions R/EDM.R
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ CCM = function( pathIn = "./",
plot( libSize, ccm.df[ , V1 ],
ylim = range( ccm.df[ , V1 ], ccm.df[ , V2 ] ),
main = title, col = "blue", type = "l", lwd = 3,
xlab = 'Library Size', ylab = 'Prediction Skill (\U03C1)' )
xlab = 'Library Size',
ylab = expression( "Prediction Skill (" * rho * ")" ) )
lines( libSize, ccm.df[ , V2 ], col = "red", lwd = 3 )
abline( h = 0 )
legend( 'topright', c( V1, V2 ),
Expand Down Expand Up @@ -524,7 +525,8 @@ EmbedDimension = function ( pathIn = "./",
if ( showPlot ) {
title = paste(dataFile , "\nTp=" , Tp )
plot( df $ E, df $ rho, main = title, xlab = "Embedding Dimension",
ylab = "Prediction Skill (\U03C1)", type = "l", lwd = 3 )
ylab = expression( "Prediction Skill (" * rho * ")" ),
type = "l", lwd = 3 )
}

return ( df )
Expand Down Expand Up @@ -604,7 +606,8 @@ PredictInterval = function( pathIn = "./",
if ( showPlot ) {
title = paste( dataFile , "\nE=" , E )
plot( df $ Tp, df $ rho, main = title, xlab = "Forecast Interval",
ylab = "Prediction Skill (\U03C1)", type = "l", lwd = 3 )
ylab = expression( "Prediction Skill (" * rho * ")" ),
type = "l", lwd = 3 )
}

return( df )
Expand All @@ -631,6 +634,7 @@ PredictNonlinear = function( pathIn = "./",
embedded = FALSE,
verbose = FALSE,
validLib = vector(),
ignoreNan = TRUE,
numThreads = 4,
showPlot = TRUE,
noTime = FALSE ) {
Expand Down Expand Up @@ -686,12 +690,14 @@ PredictNonlinear = function( pathIn = "./",
embedded,
verbose,
validLib,
ignoreNan,
numThreads )

if ( showPlot ) {
title = paste(dataFile , "\nE=", E )
plot( df $ Theta, df $ rho, main=title,
xlab = "S-map Localisation", ylab = "Prediction Skill (\U03C1)",
xlab = "S-map Localisation",
ylab = expression( "Prediction Skill (" * rho * ")" ),
type = "l", lwd = 3 )
}

Expand Down
5 changes: 4 additions & 1 deletion man/PredictNonlinear.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ PredictNonlinear(pathIn = "./", dataFile = "", dataFrame = NULL,
pathOut = "./", predictFile = "", lib = "", pred = "", theta = "",
E = 1, Tp = 1, knn = 0, tau = -1, exclusionRadius = 0,
columns = "", target = "", embedded = FALSE, verbose = FALSE,
validLib = vector(), numThreads = 4, showPlot = TRUE, noTime = FALSE )
validLib = vector(), ignoreNan = TRUE, numThreads = 4,
showPlot = TRUE, noTime = FALSE )
}
\arguments{
\item{pathIn}{path to \code{dataFile}.}
Expand Down Expand Up @@ -59,6 +60,8 @@ input data used to create the library.}
rows. Any data row represented in this vector as FALSE, will not be
included in the library.}

\item{ignoreNan}{logical to internally redefine library to avoid nan.}

\item{numThreads}{number of parallel threads for computation.}

\item{showPlot}{logical to plot results.}
Expand Down
3 changes: 3 additions & 0 deletions src/PredictNL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ r::DataFrame PredictNonlinear_rcpp( std::string pathIn,
bool embedded,
bool verbose,
std::vector<bool> validLib,
bool ignoreNan,
unsigned numThreads ) {

DataFrame< double > PredictDF;
Expand All @@ -46,6 +47,7 @@ r::DataFrame PredictNonlinear_rcpp( std::string pathIn,
embedded,
verbose,
validLib,
ignoreNan,
numThreads );
}
else if ( dataFrame.size() ) {
Expand All @@ -67,6 +69,7 @@ r::DataFrame PredictNonlinear_rcpp( std::string pathIn,
embedded,
verbose,
validLib,
ignoreNan,
numThreads );
}
else {
Expand Down
1 change: 1 addition & 0 deletions src/RcppEDMCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ auto PredictNonlinearArgs = r::List::create(
r::_["embedded"] = false,
r::_["verbose"] = false,
r::_["validLib"] = std::vector<bool>(),
r::_["ignoreNan"] = true,
r::_["numThreads"] = 4 );

//-------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/RcppEDMCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ r::DataFrame PredictNonlinear_rcpp( std::string pathIn,
bool embedded,
bool verbose,
std::vector<bool> validLib,
bool ignoreNan,
unsigned numThreads );

r::DataFrame PredictInterval_rcpp( std::string pathIn,
Expand Down
2 changes: 2 additions & 0 deletions src/cppEDM/src/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ DataFrame< double > PredictNonlinear( std::string pathIn = "./data/",
bool verbose = true,
std::vector<bool> validLib =
std::vector<bool>(),
bool ignoreNan = true,
unsigned nThreads = 4 );

DataFrame< double > PredictNonlinear( DataFrame< double > & dataFrameIn,
Expand All @@ -378,5 +379,6 @@ DataFrame< double > PredictNonlinear( DataFrame< double > & dataFrameIn,
bool verbose = true,
std::vector<bool> validLib =
std::vector<bool>(),
bool ignoreNan = true,
unsigned nThreads = 4 );
#endif
12 changes: 6 additions & 6 deletions src/cppEDM/src/DataFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ class DataFrame {
//-----------------------------------------------------------------
DataFrame():
n_rows( 0 ), n_columns( 0 ), elements( 0 ),
maxRowPrint( 10 ), noTime( false ) {}
nanFound( false ), maxRowPrint( 10 ), noTime( false ) {}

//-----------------------------------------------------------------
// Load data from CSV file path/fileName, populate DataFrame
//-----------------------------------------------------------------
DataFrame( std::string path, std::string fileName, bool noTime = false ):
maxRowPrint( 10 ), noTime( noTime )
nanFound( false ), maxRowPrint( 10 ), noTime( noTime )
{
ReadData( path, fileName );
SetupDataFrame(); // Process parsedData into a DataFrame
Expand All @@ -76,16 +76,16 @@ class DataFrame {
//-----------------------------------------------------------------
DataFrame( size_t rows, size_t columns ):
n_rows( rows ), n_columns( columns ), elements( columns * rows ),
maxRowPrint( 10 ), noTime( false ) {}
nanFound( false ), maxRowPrint( 10 ), noTime( false ) {}

//-----------------------------------------------------------------
// Empty DataFrame of size (rows, columns) with column names in a
// single whitespace delimited string.
//-----------------------------------------------------------------
DataFrame( size_t rows, size_t columns, std::string colNames ):
n_rows( rows ), n_columns( columns ), elements( columns * rows ),
columnNames( std::vector<std::string>(columns) ), maxRowPrint( 10 ),
noTime( false )
columnNames( std::vector<std::string>(columns) ),
nanFound( false ), maxRowPrint( 10 ), noTime( false )
{
BuildColumnNameIndex( colNames );
}
Expand All @@ -97,7 +97,7 @@ class DataFrame {
DataFrame( size_t rows, size_t columns,
std::vector< std::string > columnNames ):
n_rows( rows ), n_columns( columns ), elements( columns * rows ),
columnNames( columnNames ), maxRowPrint( 10 ),
columnNames( columnNames ), nanFound( false ), maxRowPrint( 10 ),
noTime( false )
{
BuildColumnNameIndex();
Expand Down
15 changes: 11 additions & 4 deletions src/cppEDM/src/Eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ void SMapThread( EDM_Eval::WorkQueue &workQ,
std::string target,
bool embedded,
bool verbose,
std::vector<bool> validLib );
std::vector<bool> validLib,
bool ignoreNan );

//----------------------------------------------------------------
// EmbedDimension() : Evaluate Simplex rho vs. dimension E
Expand Down Expand Up @@ -497,6 +498,7 @@ DataFrame< double > PredictNonlinear( std::string pathIn,
bool embedded,
bool verbose,
std::vector<bool> validLib,
bool ignoreNan,
unsigned nThreads ) {

// Create DataFrame (constructor loads data)
Expand All @@ -518,6 +520,7 @@ DataFrame< double > PredictNonlinear( std::string pathIn,
embedded,
verbose,
validLib,
ignoreNan,
nThreads );
return Theta_rho;
}
Expand All @@ -542,6 +545,7 @@ DataFrame< double > PredictNonlinear( DataFrame< double > & data,
bool embedded,
bool verbose,
std::vector<bool> validLib,
bool ignoreNan,
unsigned nThreads ) {

std::vector<double> ThetaValues( { 0.01, 0.1, 0.3, 0.5, 0.75, 1,
Expand Down Expand Up @@ -600,7 +604,8 @@ DataFrame< double > PredictNonlinear( DataFrame< double > & data,
target,
embedded,
verbose,
validLib ) );
validLib,
ignoreNan ) );
}

// join threads
Expand Down Expand Up @@ -647,7 +652,8 @@ void SMapThread( EDM_Eval::WorkQueue &workQ,
std::string target,
bool embedded,
bool verbose,
std::vector<bool> validLib )
std::vector<bool> validLib,
bool ignoreNan )
{
std::size_t i =
std::atomic_fetch_add( &EDM_Eval::smap_count_i, std::size_t(1) );
Expand Down Expand Up @@ -679,7 +685,8 @@ void SMapThread( EDM_Eval::WorkQueue &workQ,
embedded,
false, // const_predict
verbose,
validLib );
validLib,
ignoreNan );

DataFrame< double > predictions = S.predictions;
DataFrame< double > coefficients = S.coefficients;
Expand Down
7 changes: 4 additions & 3 deletions src/cppEDM/src/Parameter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Parameters::Parameters(
validated ( false ),

// Instantiate Version
version( 1, 15, 0, "2023-10-21" )
version( 1, 15, 1, "2023-10-27" )
{
// Constructor code
if ( method != Method::None ) {
Expand Down Expand Up @@ -184,14 +184,15 @@ void Parameters::Validate() {
if ( randomLib ) {
if ( subSamples < 1 ) {
std::string errMsg( "Parameters::Validate(): "
"CCM samples must be > 0.\n" );
"CCM sample must be > 0.\n" );
throw std::runtime_error( errMsg );
}
}

// CCM librarySizes
if ( not libSizes_str.size() ) {
std::string errMsg( "Parameters::Validate(): CCM libSize empty.\n" );
std::string errMsg( "Parameters::Validate(): "
"CCM libSizes empty.\n" );
throw std::runtime_error( errMsg );
}

Expand Down
30 changes: 25 additions & 5 deletions src/cppEDM/src/SMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,11 @@ void SMapClass::WriteOutput () {
}
}

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Do not use LAPACK on Windog: use scikit-learn LinearRegression
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#if !defined _WIN32 || defined USING_R

//----------------------------------------------------------------
// Singular Value Decomposition : wrapper for Lapack_SVD()
//----------------------------------------------------------------
Expand All @@ -504,11 +509,11 @@ SVDValues SVD( DataFrame < double > A,

double *b = &( B[0] );

SVDValues SVD_ = Lapack_SVD( A.NRows(), // number of rows
A.NColumns(), // number of columns
a, // A
b, // b
1.E-9 ); // rcond
SVDValues SVD_ = Lapack_SVD( A.NRows(), // number of rows
A.NColumns(), // number of columns
a, // A
b, // b
1.E-9 ); // rcond

#ifdef DEBUG_ALL
std::cout << "SVD------------------------\n";
Expand Down Expand Up @@ -657,3 +662,18 @@ SVDValues Lapack_SVD( int m, // rows in matrix

return SVD_;
}
#else
//-----------------------------------------------------------------
// Singular Value Decomposition : SVD() dummy function: Replaced by
// scikit-learn LinearRegression on Windog. LAPACK is not feasible.
//-----------------------------------------------------------------
SVDValues SVD( DataFrame < double > A,
std::valarray< double > B ) {
if ( A.NRows() == B.size() ) {} // Avoid compiler unused warn
SVDValues SVD_;
return SVD_;
}
#endif
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// Do not use LAPACK on Windog: use scikit-learn LinearRegression
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
5 changes: 5 additions & 0 deletions src/cppEDM/src/SMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ using Solver = SVDValues (*) ( DataFrame < double >,
// Prototype declaration of general functions
SVDValues SVD( DataFrame < double > A, std::valarray< double > B );

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Do not use LAPACK on Windog: use scikit-learn LinearRegression
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#if !defined _WIN32 || defined USING_R
SVDValues Lapack_SVD( int m, // number of rows in matrix
int n, // number of columns in matrix
double *a, // pointer to top-left corner
double *b,
double rcond );
#endif

//----------------------------------------------------------------
// SMap class inherits from EDM class and defines
Expand Down

0 comments on commit 713d168

Please sign in to comment.