Skip to content

Commit

Permalink
v1.14.0 Sync cppEDM. In generative mode limit library to original data.
Browse files Browse the repository at this point in the history
  • Loading branch information
SoftwareLiteracy committed Jan 8, 2023
1 parent 7acc779 commit 725ddfa
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 19 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.13.1
Date: 2022-07-01
Version: 1.14.0
Date: 2023-01-07
Authors@R: c( person("Joseph", "Park", role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0001-5411-1409")),
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### rEDM NEWS

2022-07-01 version 1.13.1 <[email protected]>
2023-01-07 version 1.14.0 <[email protected]>

---

Expand All @@ -11,6 +11,9 @@

---

##### Version 1.14
- cppEDM core added `generateLibrary` parameter to `Simplex()` and `SMap()`. If `TRUE` the state-space library has newly generated points added. Not available due to Rcpp 20 parameter limit.

##### Version 1.13
- Adds `embedded` and multivariate embedding to `CCM()`.
- Parameters `pathOut`, `predictFile` are removed from `CCM` to accomodate the Rcpp 20 parameter limit.
Expand Down
2 changes: 2 additions & 0 deletions src/RcppEDMCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ auto SimplexArgs = r::List::create(
r::_["verbose"] = false,
r::_["validLib"] = std::vector<bool>(),
r::_["generateSteps"] = 0,
//r::_["generateLibrary"] = false, // Rcpp 20 arg limit
r::_["parameterList"] = false );

auto SMapArgs = r::List::create(
Expand All @@ -81,6 +82,7 @@ auto SMapArgs = r::List::create(
r::_["verbose"] = false,
r::_["validLib"] = std::vector<bool>(),
r::_["generateSteps"] = 0,
//r::_["generateLibrary"] = false, // Rcpp 20 arg limit
r::_["parameterList"] = false );

auto MultiviewArgs = r::List::create(
Expand Down
10 changes: 7 additions & 3 deletions src/SMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ r::List SMap_rcpp( std::string pathIn,
bool verbose,
std::vector<bool> validLib,
int generateSteps,
//bool generateLibrary, // Rcpp has 20 arg limit
bool parameterList ) {

SMapValues SM;

std::string pathOut("./"); // Rcpp has 20 arg limit
std::string predictFile(""); // Rcpp has 20 arg limit
std::string jacobians(""); // Rcpp has 20 arg limit
std::string pathOut("./"); // Rcpp has 20 arg limit
std::string predictFile(""); // Rcpp has 20 arg limit
std::string jacobians(""); // Rcpp has 20 arg limit
bool generateLibrary = false; // Rcpp has 20 arg limit

if ( dataFile.size() ) {
// dataFile specified, dispatch overloaded SMap, ignore dataFrame
Expand All @@ -57,6 +59,7 @@ r::List SMap_rcpp( std::string pathIn,
verbose,
validLib,
generateSteps,
generateLibrary,
parameterList );
}
else if ( dataFrame.size() ) {
Expand All @@ -82,6 +85,7 @@ r::List SMap_rcpp( std::string pathIn,
verbose,
validLib,
generateSteps,
generateLibrary,
parameterList );
}
else {
Expand Down
5 changes: 5 additions & 0 deletions src/Simplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ r::List Simplex_rcpp( std::string pathIn,
bool verbose,
std::vector<bool> validLib,
int generateSteps,
//bool generateLibrary, // Rcpp has 20 arg limit
bool parameterList ) {

SimplexValues S;

bool generateLibrary = false; // Rcpp has 20 arg limit

if ( dataFile.size() ) {
// dataFile specified, dispatch overloaded Simplex, ignore dataFrame
S = Simplex( pathIn,
Expand All @@ -47,6 +50,7 @@ r::List Simplex_rcpp( std::string pathIn,
verbose,
validLib,
generateSteps,
generateLibrary,
parameterList );
}
else if ( dataFrame.size() ) {
Expand All @@ -69,6 +73,7 @@ r::List Simplex_rcpp( std::string pathIn,
verbose,
validLib,
generateSteps,
generateLibrary,
parameterList );
}
else {
Expand Down
24 changes: 19 additions & 5 deletions src/cppEDM/src/API.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ SimplexValues Simplex( std::string pathIn,
bool verbose,
std::vector<bool> validLib,
int generateSteps,
bool generateLibrary,
bool parameterList )
{
// DataFrame constructor loads data
Expand All @@ -220,6 +221,7 @@ SimplexValues Simplex( std::string pathIn,
verbose,
validLib,
generateSteps,
generateLibrary,
parameterList );

return S;
Expand All @@ -245,6 +247,7 @@ SimplexValues Simplex( DataFrame< double > & DF,
bool verbose,
std::vector<bool> validLib,
int generateSteps,
bool generateLibrary,
bool parameterList )
{
// Instantiate Parameters
Expand All @@ -254,7 +257,8 @@ SimplexValues Simplex( DataFrame< double > & DF,
exclusionRadius,
columns, target, embedded,
const_predict, verbose, validLib,
generateSteps, parameterList );
generateSteps, generateLibrary,
parameterList );

// Instantiate EDM::SimplexClass object
SimplexClass SimplexModel = SimplexClass( DF, std::ref( parameters ) );
Expand Down Expand Up @@ -298,6 +302,7 @@ SMapValues SMap( std::string pathIn,
bool verbose,
std::vector<bool> validLib,
int generateSteps,
bool generateLibrary,
bool parameterList )
{
// DataFrame constructor loads data
Expand All @@ -309,7 +314,8 @@ SMapValues SMap( std::string pathIn,
exclusionRadius,
columns, target, smapFile, derivatives,
embedded, const_predict, verbose, validLib,
generateSteps, parameterList );
generateSteps, generateLibrary,
parameterList );
return SMapOutput;
}

Expand Down Expand Up @@ -337,6 +343,7 @@ SMapValues SMap( DataFrame< double > & DF,
bool verbose,
std::vector<bool> validLib,
int generateSteps,
bool generateLibrary,
bool parameterList )
{
// Call overload 4) with default SVD function
Expand All @@ -346,7 +353,8 @@ SMapValues SMap( DataFrame< double > & DF,
columns, target, smapFile, derivatives,
& SVD, // LAPACK SVD default
embedded, const_predict, verbose, validLib,
generateSteps, parameterList );
generateSteps, generateLibrary,
parameterList );

return SMapOutput;
}
Expand Down Expand Up @@ -377,6 +385,7 @@ SMapValues SMap( std::string pathIn,
bool verbose,
std::vector<bool> validLib,
int generateSteps,
bool generateLibrary,
bool parameterList )
{
// DataFrame constructor loads data
Expand All @@ -388,7 +397,8 @@ SMapValues SMap( std::string pathIn,
exclusionRadius,
columns, target, smapFile, derivatives,
solver, embedded, const_predict, verbose,
validLib, generateSteps, parameterList );
validLib, generateSteps, generateLibrary,
parameterList );
return SMapOutput;
}

Expand Down Expand Up @@ -417,6 +427,7 @@ SMapValues SMap( DataFrame< double > & DF,
bool verbose,
std::vector<bool> validLib,
int generateSteps,
bool generateLibrary,
bool parameterList )
{
if ( derivatives.size() ) {} // -Wunused-parameter
Expand All @@ -427,7 +438,8 @@ SMapValues SMap( DataFrame< double > & DF,
exclusionRadius,
columns, target, embedded,
const_predict, verbose, validLib,
generateSteps, parameterList, smapFile );
generateSteps, generateLibrary,
parameterList, smapFile );

// Handle nan
// If nan are found in library or prediction rows of columns or target,
Expand Down Expand Up @@ -592,6 +604,7 @@ CCMValues CCM( DataFrame< double > & DF,
verbose, //
std::vector<bool>(), // validLib
0, // generateSteps
false, // generateLibrary
parameterList, //
"", // SmapFile
"", // blockFile
Expand Down Expand Up @@ -704,6 +717,7 @@ MultiviewValues Multiview( DataFrame< double > & DF,
verbose, //
std::vector<bool>(), // validLib
0, // generateSteps
false, // generateLibrary
parameterList,//
"", // SmapFile
"", // blockFile
Expand Down
6 changes: 6 additions & 0 deletions src/cppEDM/src/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ SimplexValues Simplex( std::string pathIn = "./data/",
bool verbose = true,
std::vector<bool> validLib = std::vector<bool>(),
int generateSteps = 0,
bool generateLibrary = false,
bool parameterList = false );

SimplexValues Simplex( DataFrame< double > & dataFrameIn,
Expand All @@ -76,6 +77,7 @@ SimplexValues Simplex( DataFrame< double > & dataFrameIn,
bool verbose = true,
std::vector<bool> validLib = std::vector<bool>(),
int generateSteps = 0,
bool generateLibrary = false,
bool parameterList = false );

// SMap is a special case since it can be called with a function pointer
Expand Down Expand Up @@ -103,6 +105,7 @@ SMapValues SMap( std::string pathIn = "./data/",
bool verbose = true,
std::vector<bool> validLib = std::vector<bool>(),
int generateSteps = 0,
bool generateLibrary = false,
bool parameterList = false );

// 2) DataFrame with default SVD (LAPACK) assigned in Smap.cc 2)
Expand All @@ -126,6 +129,7 @@ SMapValues SMap( DataFrame< double > &dataFrameIn,
bool verbose = true,
std::vector<bool> validLib = std::vector<bool>(),
int generateSteps = 0,
bool generateLibrary = false,
bool parameterList = false );

// 3) Data path/file with external solver object, init to default SVD
Expand Down Expand Up @@ -153,6 +157,7 @@ SMapValues SMap( std::string pathIn = "./data/",
bool verbose = true,
std::vector<bool> validLib = std::vector<bool>(),
int generateSteps = 0,
bool generateLibrary = false,
bool parameterList = false );


Expand Down Expand Up @@ -180,6 +185,7 @@ SMapValues SMap( DataFrame< double > &dataFrameIn,
bool verbose = true,
std::vector<bool> validLib = std::vector<bool>(),
int generateSteps = 0,
bool generateLibrary = false,
bool parameterList = false );

CCMValues CCM( std::string pathIn = "./data/",
Expand Down
8 changes: 7 additions & 1 deletion src/cppEDM/src/Parameter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Parameters::Parameters(
std::vector<bool> validLib,

int generateSteps,
bool generateLibrary,
bool parameterList,

std::string SmapOutputFile,
Expand Down Expand Up @@ -76,6 +77,7 @@ Parameters::Parameters(
validLib ( validLib ),

generateSteps ( generateSteps ),
generateLibrary ( generateLibrary ),
parameterList ( parameterList ),

SmapOutputFile ( SmapOutputFile ),
Expand All @@ -96,7 +98,7 @@ Parameters::Parameters(
validated ( false ),

// Instantiate Version
version( 1, 13, 1, "2022-07-01" )
version( 1, 14, 0, "2023-01-07" )
{
// Constructor code
if ( method != Method::None ) {
Expand Down Expand Up @@ -819,6 +821,10 @@ void Parameters::FillMap() {
Map[ "generateSteps" ] = ss.str();
ss.str( std::string() );

ss << generateLibrary;
Map[ "generateLibrary" ] = ss.str();
ss.str( std::string() );

ss << parameterList;
Map[ "parameterList" ] = ss.str();
ss.str( std::string() );
Expand Down
12 changes: 7 additions & 5 deletions src/cppEDM/src/Parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,23 @@ class Parameters {
int E; // dimension
int Tp; // prediction interval
int knn; // k nearest neighbors
int tau; // block embedding delay
double theta; // S Map localization
int tau; // embedding delay
double theta; // S-Map localization
int exclusionRadius; // temporal rows to ignore in predict

std::string columns_str;
std::string target_str;
std::string columns_str; // multi argument parameters
std::string target_str; // argument parameter(s)
std::vector< std::string > columnNames; // state-space column name(s)
std::vector< std::string > targetNames; // target column name(s)

bool embedded; // true if data is already embedded/block
bool embedded; // true if data is already embedded
bool const_predict; // true to compute non "predictor" stats
bool verbose;

std::vector<bool> validLib; // maps row to valid library flag

int generateSteps; // Number of timesteps to feedback generate
bool generateLibrary; // Increment library with generated data

bool parameterList; // Add parameter list to output

Expand Down Expand Up @@ -102,6 +103,7 @@ class Parameters {
std::vector<bool> validLib = std::vector<bool>(),

int generateSteps = 0,
bool generateLibrary = false,
bool parameterList = false,

std::string SmapOutputFile = "",
Expand Down
14 changes: 13 additions & 1 deletion src/cppEDM/src/SMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ void SMapClass::Generate( Solver solver ) {
std::cout << " data.Time() end: " << data.Time().back() << std::endl;
#endif

// Replace SMap object data with one containing only lib rows
// -- The data becomes a data library from which predictions are generated
// NOTE : JP Presume library starts at index 0 : Should be lib parameter
std::vector<size_t> dataLibRows;
for ( size_t i = 0; i <= parameters.library.back(); i++ ) {
dataLibRows.push_back( i );
}
DataFrame<double> dataLib = data.DataFrameFromRowIndex( dataLibRows );
this->data = dataLib; // JP is this a leak?

// Override prediction to have max( 2,Tp ) points at end of data.
// We need Tp points if Tp > 1 to prevent nan gaps in prediction.
// prediction & library are zero-offset in Parameters::Validate()
Expand Down Expand Up @@ -282,7 +292,9 @@ void SMapClass::Generate( Solver solver ) {
generatedTime.push_back( newTime );

// 3) Increment library by adding another row index ------------
parameters.library.push_back( parameters.library.back() + 1 );
if ( parameters.generateLibrary ) {
parameters.library.push_back( parameters.library.back() + 1 );
}

// 4) Increment prediction indices -----------------------------
for ( auto pi = parameters.prediction.begin();
Expand Down
Loading

0 comments on commit 725ddfa

Please sign in to comment.