boonnano 1
C++ library giving usage access to the Boon Logic Nano technology
 
Loading...
Searching...
No Matches
results.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() {
// Configure
CBoonNano Nano;
int SWS = 1;
int NUM_FEATURES = 15;
float MinVal = -10.0;
float MaxVal = 10.0;
int Weight = 1;
float PV = 0.05;
NCP.SetParameters(NF_FLOAT, PV, SWS);
for (uint16_t i = 0; i < NUM_FEATURES; i++) {
NCP.AddFeature(MinVal, MaxVal, Weight, "column-");
}
Nano.Setup(NCP);
// Autotune
CAutotuneNanoConfig ANC(&Nano);
ANC.LoadNanoConfig(NCP);
AP.ConfigureDefault(NUM_FEATURES * SWS, 1500);
// 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();
// Autotune
ANC.Autotune((uint8_t*)Data, NUM_FEATURES * length * sizeof(float));
NCP.CopyFrom(ANC.GetNanoConfig());
Nano.Setup(NCP);
// RESULT: Autotuning elbow output
// PV: 0.010 Cluster Count: 1500
// PV: 0.011 Cluster Count: 1500
// PV: 0.012 Cluster Count: 1500
// PV: 0.013 Cluster Count: 1500
// PV: 0.014 Cluster Count: 1500
// PV: 0.015 Cluster Count: 1500
// PV: 0.016 Cluster Count: 1500
// PV: 0.017 Cluster Count: 1500
// PV: 0.018 Cluster Count: 1500
// PV: 0.019 Cluster Count: 1500
// PV: 0.020 Cluster Count: 1500
// PV: 0.021 Cluster Count: 1500
// PV: 0.022 Cluster Count: 1500
// PV: 0.023 Cluster Count: 1500
// PV: 0.024 Cluster Count: 1500
// PV: 0.025 Cluster Count: 1500
// PV: 0.026 Cluster Count: 1500
// PV: 0.027 Cluster Count: 1500
// PV: 0.028 Cluster Count: 1500
// PV: 0.029 Cluster Count: 1500
// PV: 0.030 Cluster Count: 1500
// PV: 0.031 Cluster Count: 1500
// PV: 0.032 Cluster Count: 1500
// PV: 0.033 Cluster Count: 1500
// PV: 0.034 Cluster Count: 1432
// PV: 0.035 Cluster Count: 1189
// PV: 0.036 Cluster Count: 957
// PV: 0.037 Cluster Count: 808
// PV: 0.038 Cluster Count: 654
// PV: 0.039 Cluster Count: 535
// PV: 0.040 Cluster Count: 453
// PV: 0.041 Cluster Count: 376
// PV: 0.042 Cluster Count: 303
// PV: 0.043 Cluster Count: 267
// PV: 0.044 Cluster Count: 221
// PV: 0.045 Cluster Count: 192
// PV: 0.046 Cluster Count: 171
// PV: 0.047 Cluster Count: 152
// PV: 0.048 Cluster Count: 125
// PV: 0.049 Cluster Count: 122
// PV: 0.050 Cluster Count: 99
// PV: 0.051 Cluster Count: 86
// PV: 0.052 Cluster Count: 74
// PV: 0.053 Cluster Count: 67
// PV: 0.054 Cluster Count: 60
// PV: 0.055 Cluster Count: 53
// PV: 0.056 Cluster Count: 48
// PV: 0.057 Cluster Count: 44
// PV: 0.058 Cluster Count: 40
// PV: 0.059 Cluster Count: 35
// PV: 0.060 Cluster Count: 33
// PV: 0.061 Cluster Count: 29
// PV: 0.062 Cluster Count: 29
// PV: 0.063 Cluster Count: 29
// PV: 0.064 Cluster Count: 30
// PV: 0.065 Cluster Count: 27
// PV: 0.066 Cluster Count: 25
// PV: 0.067 Cluster Count: 25
// PV: 0.068 Cluster Count: 24
// PV: 0.069 Cluster Count: 23
// PV: 0.070 Cluster Count: 23
// PV: 0.071 Cluster Count: 21
// PV: 0.072 Cluster Count: 21
// PV: 0.073 Cluster Count: 19
// PV: 0.074 Cluster Count: 17
// PV: 0.075 Cluster Count: 15
// PV: 0.076 Cluster Count: 14
// PV: 0.077 Cluster Count: 14
// PV: 0.078 Cluster Count: 14
// PV: 0.079 Cluster Count: 14
// PV: 0.080 Cluster Count: 14
// PV: 0.081 Cluster Count: 14
// PV: 0.082 Cluster Count: 14
// PV: 0.083 Cluster Count: 14
// PV: 0.084 Cluster Count: 14
// PV: 0.085 Cluster Count: 14
// PV: 0.086 Cluster Count: 14
// PV: 0.087 Cluster Count: 14
// PV: 0.088 Cluster Count: 14
// PV: 0.089 Cluster Count: 14
// PV: 0.090 Cluster Count: 13
// PV: 0.091 Cluster Count: 13
// PV: 0.092 Cluster Count: 13
// PV: 0.093 Cluster Count: 13
// PV: 0.094 Cluster Count: 13
// PV: 0.095 Cluster Count: 13
// PV: 0.096 Cluster Count: 13
// PV: 0.097 Cluster Count: 13
// PV: 0.098 Cluster Count: 13
// PV: 0.099 Cluster Count: 13
// PV: 0.100 Cluster Count: 13
// PV: 0.101 Cluster Count: 13
// PV: 0.102 Cluster Count: 13
// PV: 0.103 Cluster Count: 13
// PV: 0.104 Cluster Count: 13
// PV: 0.105 Cluster Count: 13
// PV: 0.106 Cluster Count: 13
// PV: 0.107 Cluster Count: 13
// PV: 0.108 Cluster Count: 13
// PV: 0.109 Cluster Count: 13
// PV: 0.110 Cluster Count: 13
// PV: 0.111 Cluster Count: 13
// PV: 0.112 Cluster Count: 13
// PV: 0.113 Cluster Count: 13
// PV: 0.114 Cluster Count: 13
// PV: 0.115 Cluster Count: 13
// PV: 0.116 Cluster Count: 13
// PV: 0.117 Cluster Count: 13
// PV: 0.118 Cluster Count: 13
// PV: 0.119 Cluster Count: 13
// PV: 0.120 Cluster Count: 13
// PV: 0.121 Cluster Count: 13
// PV: 0.122 Cluster Count: 13
// PV: 0.123 Cluster Count: 13
// PV: 0.124 Cluster Count: 13
// PV: 0.125 Cluster Count: 13
// PV: 0.126 Cluster Count: 13
// PV: 0.127 Cluster Count: 13
// PV: 0.128 Cluster Count: 13
// PV: 0.129 Cluster Count: 13
// PV: 0.130 Cluster Count: 13
// PV: 0.131 Cluster Count: 13
// PV: 0.132 Cluster Count: 13
// PV: 0.133 Cluster Count: 13
// PV: 0.134 Cluster Count: 13
// PV: 0.135 Cluster Count: 13
// PV: 0.136 Cluster Count: 13
// PV: 0.137 Cluster Count: 13
// PV: 0.138 Cluster Count: 13
// PV: 0.139 Cluster Count: 13
// PV: 0.140 Cluster Count: 13
// PV: 0.141 Cluster Count: 13
// PV: 0.142 Cluster Count: 13
// PV: 0.143 Cluster Count: 13
// PV: 0.144 Cluster Count: 13
// PV: 0.145 Cluster Count: 13
// PV: 0.146 Cluster Count: 13
// PV: 0.147 Cluster Count: 13
// PV: 0.148 Cluster Count: 12
// PV: 0.149 Cluster Count: 12
// PV: 0.150 Cluster Count: 12
// PV: 0.151 Cluster Count: 12
// PV: 0.152 Cluster Count: 12
// PV: 0.153 Cluster Count: 12
// PV: 0.154 Cluster Count: 12
// PV: 0.155 Cluster Count: 12
// PV: 0.156 Cluster Count: 12
// PV: 0.157 Cluster Count: 12
// PV: 0.158 Cluster Count: 12
// PV: 0.159 Cluster Count: 12
// PV: 0.160 Cluster Count: 12
// PV: 0.161 Cluster Count: 12
// PV: 0.162 Cluster Count: 12
// PV: 0.163 Cluster Count: 12
// PV: 0.164 Cluster Count: 12
// PV: 0.165 Cluster Count: 12
// PV: 0.166 Cluster Count: 12
// PV: 0.167 Cluster Count: 12
// PV: 0.168 Cluster Count: 12
// PV: 0.169 Cluster Count: 12
// PV: 0.170 Cluster Count: 12
// PV: 0.171 Cluster Count: 12
// PV: 0.172 Cluster Count: 11
// PV: 0.173 Cluster Count: 11
// PV: 0.174 Cluster Count: 11
// PV: 0.175 Cluster Count: 11
// PV: 0.176 Cluster Count: 11
// PV: 0.177 Cluster Count: 11
// PV: 0.178 Cluster Count: 11
// PV: 0.179 Cluster Count: 10
// PV: 0.180 Cluster Count: 10
// PV: 0.181 Cluster Count: 10
// PV: 0.182 Cluster Count: 9
// PV: 0.183 Cluster Count: 9
// PV: 0.184 Cluster Count: 9
// PV: 0.185 Cluster Count: 9
// PV: 0.186 Cluster Count: 9
// PV: 0.187 Cluster Count: 9
// PV: 0.188 Cluster Count: 9
// PV: 0.189 Cluster Count: 9
// PV: 0.190 Cluster Count: 9
// PV: 0.191 Cluster Count: 9
// PV: 0.192 Cluster Count: 9
// PV: 0.193 Cluster Count: 9
// PV: 0.194 Cluster Count: 9
// PV: 0.195 Cluster Count: 9
// PV: 0.196 Cluster Count: 9
// PV: 0.197 Cluster Count: 9
// PV: 0.198 Cluster Count: 9
// PV: 0.199 Cluster Count: 9
// PV: 0.200 Cluster Count: 9
// Clustering
int *ClusterResults = new int[length];
Nano.ClusterData(Data, length, ClusterResults);
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;
}
// Size: 0 Created at Inference: 0 RI: 4294967295 FI: 4294967295 DI: 4294967295 PI: 4294967295 NN: 0 PCA: (4294967295, 4294967295, 4294967295) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000)
// Ghost ID: -1 Size: 1 Created at Inference: 14404 RI: 1000 FI: 1000 DI: 1000 PI: 1000 NN: 1 PCA: (0, 0, 0) RCA: (0.024911, 0.065469, 0.295894, 0.159119, 0.117647, 0.159951, 0.049555, 0.242718, 0.043695, 0.003846, 0.101863, 0.041184, 0.058673, 0.150183, 0.299113)
// Size: 0 Created at Inference: 0 RI: 4294967295 FI: 4294967295 DI: 4294967295 PI: 4294967295 NN: 0 PCA: (4294967295, 4294967295, 4294967295) RCA: (0.000000, 0.085290, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.914710, 0.000000, 0.000000, 0.000000)
// Size: 0 Created at Inference: 0 RI: 4294967295 FI: 4294967295 DI: 4294967295 PI: 4294967295 NN: 0 PCA: (4294967295, 4294967295, 4294967295) RCA: (0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)
// Ghost ID: -2 Size: 1 Created at Inference: 14405 RI: 1000 FI: 1000 DI: 1000 PI: 1000 NN: 1 PCA: (0, 0, 0) RCA: (0.099644, 0.427471, 0.061594, 0.221542, 0.012032, 0.001221, 0.049555, 0.287621, 0.043695, 0.025641, 0.047205, 0.102960, 0.059949, 0.234432, 0.253485)
// RESULT: root cause
float *rc = new float[NUM_FEATURES * SWS];
Nano.GetRootCause(-1, rc); // Get root cause for ghost cluster -1 (positive IDs are in the model and root cause will all be 0)
std::string RootCauseString = "RootCause: ";
for(int i = 0; i < NUM_FEATURES * SWS; i++) {
RootCauseString += std::to_string(rc[i]);
if (i != NUM_FEATURES * SWS - 1) {
RootCauseString += ",";
}
}
std::cout << RootCauseString << std::endl;
// RootCause: 0.024911,0.065469,0.295894,0.159119,0.117647,0.159951,0.049555,0.242718,0.043695,0.003846,0.101863,0.041184,0.058673,0.150183,0.299113
// Clean up
Nano.Reset();
delete[] AdvancedAnalyticsBuffer;
delete[] ClusterResults;
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.
void DisplayAutotuningElbow()
Generates print string of autotuning elbow.
Main autotuning functionality.
Definition autotune.h:85
void ConfigureDefault(uint16_t PatternLength, uint16_t MaxClusters)
Auto-set object variables to all be true.
Object for autotuning specific parameters.
Definition autotune.h:23
bool Setup(CNanoConfigParameters &NanoConfig)
Set configuration parameters for model clustering.
bool GetRootCause(int ID, float *RootCause)
Get root cause array from cluster.
void SetLearningMode(bool LearningOn)
Enable/disable new cluster creation.
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
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