boonnano 1
C++ library giving usage access to the Boon Logic Nano technology
 
Loading...
Searching...
No Matches
base-example.cpp
#include "boonnano.h"
#include "boonconfig.h"
#include "clusterstats.h"
#include "autotune.h"
#include <fstream>
#include <sstream>
// Full pipeline for nano core usage
int main() {
CBoonNano Nano;
// Set up configuration (boonconfig.h)
// init parameters
int SWS = 1;
int NUM_FEATURES = 15;
float MinVal = -400.0;
float MaxVal = 1100.0;
int Weight = 1;
float PV = 0.05;
// set parameters in config object
NCP.SetParameters(NF_FLOAT, PV, SWS);
NCP.AddFeature(MinVal, MaxVal, Weight, "column", NUM_FEATURES);
// set config
Nano.Setup(NCP);
// EXAMPLE OUTPUT
std::cout << NCP.GetStatusString() << std::endl;
// CNanoConfigParameters
// Numeric Type: Float PV: 0.050000 SWS: 1
// Feature 0:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 1:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 2:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 3:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 4:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 5:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 6:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 7:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 8:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 9:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 10:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 11:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 12:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 13:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 14:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Error Message:
// Clustering (boonnano.h)
// Load data
std::string line;
std::ifstream myFile("./docs/examples/Planets.csv");
int length = 14400; // hardcoded for the specific file
float *Data = new float[NUM_FEATURES * length];
float val;
int i = 0;
while (std::getline(myFile, line)) {
std::stringstream ss(line);
while (ss >> val) {
Data[i] = val;
i++;
if (ss.peek() == ',')
ss.ignore();
}
}
myFile.close();
// Cluster
int *ClusterResults = new int[length];
Nano.ClusterData(Data, length, ClusterResults);
// EXAMPLE OUTPUT
std::cout << Nano.GetStatusString() << std::endl;
// CBoonNano
// CNanoConfigParameters
// Numeric Type: Float PV: 0.050000 SWS: 1
// Feature 0:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 1:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 2:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 3:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 4:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 5:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 6:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 7:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 8:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 9:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 10:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 11:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 12:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 13:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Feature 14:
// Label: column MinVal: -400.000000 MaxVal: 1100.000000 Weight: 1
// Error Message:
// IsNanoBackend: true
// BackendManager is Non-nullptr
// CNanoBackendManager
// SGXManager is nullptr
// BackendInUse 0: true
// NumKernels: 1 InitComplete: true
// Error Message:
// NanoBackend 0
// NanoBackend is Non-nullptr
// nano_sw_backend Ptr = 5502959616
// InitComplete: true PatternLength: 15 NumOfPatternsClustered: 14400 Learning is ON
// Error Message:
// Cluster 0:
// Size: 0 Created at Inference: 0 RI: 1000 FI: 0 DI: 0 PI: 1000 NN: 0 PCA: (0, 0, 0) RCA: ()
// Cluster 1:
// Size: 1200 Created at Inference: 1 RI: 0 FI: 1042 DI: 409 PI: 0 NN: 0 PCA: (83, 689, 116) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 2:
// Size: 417 Created at Inference: 1201 RI: 149 FI: 886 DI: 363 PI: 320 NN: 0 PCA: (135, 734, 203) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 3:
// Size: 783 Created at Inference: 1225 RI: 60 FI: 979 DI: 380 PI: 176 NN: 0 PCA: (135, 704, 199) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 4:
// Size: 1200 Created at Inference: 2401 RI: 0 FI: 1042 DI: 407 PI: 0 NN: 0 PCA: (0, 1000, 8) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 5:
// Size: 1200 Created at Inference: 3601 RI: 0 FI: 1042 DI: 398 PI: 0 NN: 0 PCA: (78, 724, 124) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 6:
// Size: 948 Created at Inference: 4801 RI: 33 FI: 1007 DI: 313 PI: 144 NN: 0 PCA: (697, 40, 249) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 7:
// Size: 252 Created at Inference: 5328 RI: 220 FI: 812 DI: 304 PI: 422 NN: 0 PCA: (710, 60, 253) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 8:
// Size: 1200 Created at Inference: 6001 RI: 0 FI: 1042 DI: 299 PI: 0 NN: 0 PCA: (684, 151, 298) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 9:
// Size: 1200 Created at Inference: 7201 RI: 0 FI: 1042 DI: 317 PI: 0 NN: 0 PCA: (1000, 0, 223) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 10:
// Size: 1200 Created at Inference: 8401 RI: 0 FI: 1042 DI: 299 PI: 0 NN: 0 PCA: (702, 42, 265) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 11:
// Size: 1200 Created at Inference: 9601 RI: 0 FI: 1042 DI: 302 PI: 0 NN: 0 PCA: (258, 99, 606) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 12:
// Size: 1200 Created at Inference: 10801 RI: 0 FI: 1042 DI: 323 PI: 0 NN: 0 PCA: (251, 21, 718) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 13:
// Size: 1200 Created at Inference: 12001 RI: 0 FI: 1042 DI: 347 PI: 0 NN: 0 PCA: (223, 8, 1000) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 14:
// Size: 645 Created at Inference: 13201 RI: 87 FI: 951 DI: 309 PI: 213 NN: 0 PCA: (281, 31, 662) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Cluster 15:
// Size: 555 Created at Inference: 13633 RI: 108 FI: 928 DI: 303 PI: 257 NN: 0 PCA: (321, 1, 649) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Error Message:
// Clean up
Nano.Reset();
delete[] ClusterResults;
delete[] Data;
return 0;
}
const uint16_t NF_FLOAT
Numeric code for float data type.
Definition boonconfig.h:74
bool Setup(CNanoConfigParameters &NanoConfig)
Set configuration parameters for model clustering.
std::string GetStatusString(int CurrentIndent=0, int AdditionalIndent=4)
Print string of object variables.
int ClusterData(float *Pattern, CClusterStats *AdvancedAnalytics=nullptr)
Cluster float pattern.
void Reset(bool BackendReset=true)
Clear object variables.
Main class of processing data.
Definition boonnano.h:110
std::string GetStatusString(int CurrentIndent=0, int AdditionalIndent=4) const
Print string of object.
bool AddFeature(float MinVal, float MaxVal, uint16_t Weight, const char *Label=nullptr, uint16_t NumInstances=1)
Add feature values to overall config.
bool SetParameters(uint16_t NumericFormat, float PercentVariation, uint16_t StreamingWindowSize)
Initialize base config values.
Main object for configuration.
Definition boonconfig.h:86