boonnano 1
C++ library giving usage access to the Boon Logic Nano technology
 
Loading...
Searching...
No Matches
full-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 = -10.0;
float MaxVal = 10.0;
int Weight = 1;
float PV = 0.05;
// set parameters in config object
NCP.SetParameters(NF_FLOAT, PV, SWS);
for (uint16_t i = 0; i < NUM_FEATURES; i++) {
NCP.AddFeature(MinVal, MaxVal, Weight, "column-");
}
// 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: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 1:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 2:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 3:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 4:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 5:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 6:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 7:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 8:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 9:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 10:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 11:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 12:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 13:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Feature 14:
// Label: column- MinVal: -10.000000 MaxVal: 10.000000 Weight: 1
// Error Message:
// Autotune (autotune.h)
// set up autotuning config
CAutotuneNanoConfig ANC(&Nano); // init with boonnano object
ANC.LoadNanoConfig(NCP); // Get config values from boon config object; for information like numeric type
// init parameters
AP.m_AutotunePV = true;
AP.m_AutotuneRange = true;
AP.m_AutotuneByFeature = false;
AP.m_MaxClusters = 1500;
// set autotuning config
// EXAMPLE OUTPUT
std::cout << AP.GetStatusString() << std::endl;
// CAutotuningParameters
// AutotunePV: true AutotuneRange: true AutotuneByFeature: false MaxClusters: 1500
// Autotune over ALL features
// Load autotuning 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();
// Main autotune step
ANC.Autotune((uint8_t*)Data, NUM_FEATURES * length * sizeof(float)); // runs the synchronous autotuning function
// Configure the nano object using the newly autotuned config
NCP.CopyFrom(ANC.GetNanoConfig());
Nano.Setup(NCP);
// EXAMPLE OUTPUT
std::cout << NCP.GetStatusString() << std::endl;
// CNanoConfigParameters
// Numeric Type: Float PV: 0.061000 SWS: 1
// Feature 0:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 1:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 2:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 3:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 4:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 5:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 6:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 7:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 8:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 9:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 10:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 11:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 12:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 13:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 14:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Error Message:
// Clustering (boonnano.h)
// Set backend statuses
Nano.SetLearningMode(true); // required to be true to create new clusters
Nano.SetNanoClippingDetection(false); // normal clipping of pattern range for clusters
// 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.061000 SWS: 1
// Feature 0:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 1:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 2:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 3:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 4:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 5:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 6:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 7:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 8:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 9:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 10:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 11:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 12:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 13:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 Weight: 1
// Feature 14:
// Label: column- MinVal: -457.800262 MaxVal: 1211.813721 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 = 5234524160
// 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: 1011 DI: 435 PI: 0 NN: 0 PCA: (71, 669, 103) 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: 1200 Created at Inference: 1201 RI: 0 FI: 1011 DI: 394 PI: 0 NN: 0 PCA: (132, 732, 200) 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: 1200 Created at Inference: 2401 RI: 0 FI: 1011 DI: 429 PI: 0 NN: 0 PCA: (0, 1000, 7) 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: 3601 RI: 0 FI: 1011 DI: 426 PI: 0 NN: 0 PCA: (67, 710, 108) 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: 4801 RI: 0 FI: 1011 DI: 342 PI: 0 NN: 0 PCA: (702, 46, 248) 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: 1200 Created at Inference: 6001 RI: 0 FI: 1011 DI: 326 PI: 0 NN: 0 PCA: (679, 147, 294) 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: 1200 Created at Inference: 7201 RI: 0 FI: 1011 DI: 335 PI: 0 NN: 0 PCA: (1000, 0, 218) 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: 8401 RI: 0 FI: 1011 DI: 330 PI: 0 NN: 0 PCA: (696, 46, 262) 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: 9601 RI: 0 FI: 1011 DI: 343 PI: 0 NN: 0 PCA: (259, 95, 611) 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: 10801 RI: 0 FI: 1011 DI: 345 PI: 0 NN: 0 PCA: (248, 20, 723) 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: 12001 RI: 0 FI: 1011 DI: 364 PI: 0 NN: 0 PCA: (218, 7, 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 12:
// Size: 1200 Created at Inference: 13201 RI: 0 FI: 1011 DI: 341 PI: 0 NN: 0 PCA: (277, 32, 668) 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:
// Extra Results (clusterstats.h)
Nano.SetLearningMode(false); // no new clusters can be created. patterns that dont fit in the model will create ghost clusters
// Load extra data
std::ifstream myFile2("./docs/examples/Meteors.csv");
length = 5;
float *ExtraData = new float[NUM_FEATURES * length];
i = 0;
while (std::getline(myFile2, line)) {
std::stringstream ss(line);
while (ss >> val) {
ExtraData[i] = val;
i++;
if (ss.peek() == ',')
ss.ignore();
}
}
myFile2.close();
CClusterStats *AdvancedAnalyticsBuffer = new CClusterStats[length];
Nano.ClusterData(ExtraData, length, ClusterResults, AdvancedAnalyticsBuffer);
// EXAMPLE OUTPUT
for (int i = 0; i < length; i++) {
std::cout << AdvancedAnalyticsBuffer[i].GetStatusString() << std::endl;
}
// Ghost ID: -1 Size: 1 Created at Inference: 14401 RI: 1000 FI: 1000 DI: 1000 PI: 1000 NN: 1 PCA: (0, 0, 0) RCA: (0.027284, 0.110398, 0.055556, 0.037944, 0.022727, 0.019536, 0.094028, 0.197816, 0.158552, 0.034615, 0.057143, 0.041184, 0.007653, 0.128205, 0.016477)
// Ghost ID: -2 Size: 1 Created at Inference: 14402 RI: 1000 FI: 1000 DI: 1000 PI: 1000 NN: 1 PCA: (0, 0, 0) RCA: (0.022539, 0.030809, 0.170290, 0.122399, 0.093583, 0.115995, 0.019060, 0.150485, 0.024969, 0.007692, 0.055901, 0.037323, 0.042092, 0.061050, 0.126743)
// Ghost ID: -1 Size: 2 Created at Inference: 14401 RI: 1000 FI: 1000 DI: 1000 PI: 1000 NN: 1 PCA: (0, 0, 0) RCA: (0.027284, 0.110398, 0.055556, 0.037944, 0.022727, 0.019536, 0.094028, 0.197816, 0.158552, 0.034615, 0.057143, 0.041184, 0.007653, 0.128205, 0.016477)
// Ghost ID: -3 Size: 1 Created at Inference: 14404 RI: 1000 FI: 1000 DI: 1000 PI: 1000 NN: 1 PCA: (0, 0, 0) RCA: (0.090154, 0.084724, 0.000000, 0.078335, 0.076203, 0.014652, 0.133418, 0.154126, 0.093633, 0.151282, 0.026087, 0.006435, 0.049745, 0.074481, 0.032953)
// Ghost ID: -4 Size: 1 Created at Inference: 14405 RI: 1000 FI: 1000 DI: 1000 PI: 1000 NN: 1 PCA: (0, 0, 0) RCA: (0.102017, 0.156611, 0.032609, 0.154223, 0.012032, 0.001221, 0.017789, 0.165049, 0.057428, 0.012821, 0.024845, 0.086229, 0.042092, 0.103785, 0.102662)
// Clean up
Nano.Reset();
delete[] ClusterResults;
delete[] AdvancedAnalyticsBuffer;
delete[] Data;
return 0;
}
const uint16_t NF_FLOAT
Numeric code for float data type.
Definition boonconfig.h:74
bool Autotune(uint8_t *PatternBuffer, uint64_t PatternBufferLengthInBytes)
Main autotune function.
CNanoConfigParameters & GetNanoConfig()
Get autotuned nano config.
bool LoadAutotuningConfig(CAutotuningParameters &AP)
Setup autotuning config.
bool LoadNanoConfig(CNanoConfigParameters &NCP)
Setup config for autotuning.
Main autotuning functionality.
Definition autotune.h:85
std::string GetStatusString(int CurrentIndent=0, int AdditionalIndent=4)
Generate print string of object.
Object for autotuning specific parameters.
Definition autotune.h:23
uint16_t m_MaxClusters
only allow this many clusters for each PV that is tested
Definition autotune.h:67
bool m_AutotuneRange
true means tune the range of the features, false uses the range that has been configured
Definition autotune.h:64
bool m_AutotuneByFeature
true means each feature has its range tuned separately, false uses a min and max found over all the f...
Definition autotune.h:65
bool m_AutotunePV
true means tune the percent variation, false uses the percent variation that its been set to
Definition autotune.h:63
bool Setup(CNanoConfigParameters &NanoConfig)
Set configuration parameters for model clustering.
void SetLearningMode(bool LearningOn)
Enable/disable new cluster creation.
std::string GetStatusString(int CurrentIndent=0, int AdditionalIndent=4)
Print string of object variables.
void SetNanoClippingDetection(bool ClippingOn)
Turn on/off value out of bounds anomalies.
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
Generate print string for object values.
Cluster specific statistics.
Definition clusterstats.h:17
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.
void CopyFrom(const CNanoConfigParameters &Other)
Copy parameters from given object.
Main object for configuration.
Definition boonconfig.h:86