trigger demo
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
struct minEval{
|
||||
double value;
|
||||
int* values;
|
||||
int* values = nullptr;
|
||||
|
||||
double eval;
|
||||
long left; // how many on its left
|
||||
|
||||
+3
-2
@@ -1,11 +1,12 @@
|
||||
OPT_FLASG =
|
||||
ifneq ($(DEBUG), 1)
|
||||
ifneq ($(AQ_DEBUG), 1)
|
||||
OPT_FLAGS = -Ofast -march=native -flto -DNDEBUG
|
||||
else
|
||||
OPT_FLAGS = -g3 -D_DEBUG -fsanitize=leak -fsanitize=address
|
||||
OPT_FLAGS = -shared-libasan -g3 -D_DEBUG #-fsanitize=address
|
||||
endif
|
||||
example:
|
||||
$(CXX) -shared -fPIC example.cpp aquery_mem.cpp -fno-semantic-interposition -Ofast -march=native -flto --std=c++1z -L.. -laquery -o ../test.so
|
||||
irf:
|
||||
rm ../libirf.so ; \
|
||||
$(CXX) -shared -fPIC RF.cpp irf.cpp incrementalDecisionTree.cpp aquery_mem.cpp Evaluation.cpp -fno-semantic-interposition $(OPT_FLAGS) --std=c++1z -o ../libirf.so
|
||||
all: example
|
||||
|
||||
+18
-5
@@ -28,20 +28,33 @@ struct Session{
|
||||
void* memory_map;
|
||||
};
|
||||
|
||||
struct Context{
|
||||
struct Trigger;
|
||||
struct IntervalBasedTriggerHost;
|
||||
struct CallbackBasedTriggerHost;
|
||||
|
||||
struct Context {
|
||||
typedef int (*printf_type) (const char *format, ...);
|
||||
void* module_function_maps = 0;
|
||||
|
||||
void* module_function_maps = nullptr;
|
||||
Config* cfg;
|
||||
|
||||
int n_buffers, *sz_bufs;
|
||||
void **buffers;
|
||||
|
||||
void* alt_server;
|
||||
void* alt_server = nullptr;
|
||||
Log_level log_level = LOG_INFO;
|
||||
|
||||
Session current;
|
||||
|
||||
|
||||
const char* aquery_root_path;
|
||||
#ifdef THREADING
|
||||
void* thread_pool;
|
||||
#endif
|
||||
#ifndef __AQ_USE_THREADEDGC__
|
||||
void* gc;
|
||||
#endif
|
||||
printf_type print;
|
||||
Context();
|
||||
virtual ~Context();
|
||||
template <class ...Types>
|
||||
void log(Types... args) {
|
||||
if (log_level == LOG_INFO)
|
||||
|
||||
@@ -14,7 +14,7 @@ std::mt19937 g(rd());
|
||||
|
||||
struct minEval{
|
||||
double value;
|
||||
int* values;
|
||||
int* values = nullptr;
|
||||
|
||||
double eval;
|
||||
long left; // how many on its left
|
||||
@@ -825,7 +825,10 @@ void DecisionTree::IncrementalUpdate(double** data, long* result, long size, DT*
|
||||
for(i=low;i<low+size;i++){
|
||||
t[resultNew[i]]++;
|
||||
}
|
||||
if(cMin.values!=nullptr)free(cMin.values);
|
||||
if(cMin.values!=nullptr){
|
||||
free(cMin.values);
|
||||
cMin.values = nullptr;
|
||||
}
|
||||
current->result = std::distance(t, std::max_element(t, t+classes));
|
||||
free(index);
|
||||
free(current->dataRecord);
|
||||
@@ -989,13 +992,17 @@ void DecisionTree::Update(double** data, long* result, long size, DT* current){
|
||||
}
|
||||
if(c.eval<cMin.eval){
|
||||
cMin.eval = c.eval;
|
||||
if(cMin.values!=nullptr)free(cMin.values);
|
||||
if(cMin.values!=nullptr){
|
||||
free(cMin.values);
|
||||
cMin.values = nullptr;
|
||||
}
|
||||
cMin.values = c.values;
|
||||
cMin.value = c.value;
|
||||
cFeature = col;
|
||||
left = c.left;
|
||||
}else if(c.values!=nullptr){
|
||||
free(c.values);
|
||||
c.values = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
-13
@@ -6,7 +6,10 @@
|
||||
|
||||
#include "aquery.h"
|
||||
|
||||
#include "./server/gc.h"
|
||||
#include "../server/gc.h"
|
||||
|
||||
inline GC* GC::gc_handle = nullptr;
|
||||
inline ScratchSpace* GC::scratch_space = nullptr;
|
||||
__AQEXPORT__(void) __AQ_Init_GC__(Context* cxt) {
|
||||
GC::gc_handle = static_cast<GC*>(cxt->gc);
|
||||
GC::scratch_space = nullptr;
|
||||
@@ -16,18 +19,18 @@ DecisionTree *dt = nullptr;
|
||||
RandomForest *rf = nullptr;
|
||||
|
||||
__AQEXPORT__(bool)
|
||||
newtree(int height, long f, ColRef<int> X, double forget, long maxf, long noclasses, Evaluation e, long r, long rb)
|
||||
newtree(int ntree, long f, ColRef<int> sparse, double forget, long maxf, long nclasses, Evaluation e)
|
||||
{
|
||||
if (X.size != f)
|
||||
if (sparse.size != f)
|
||||
return false;
|
||||
int *X_cpy = (int *)malloc(f * sizeof(int));
|
||||
|
||||
memcpy(X_cpy, X.container, f);
|
||||
memcpy(X_cpy, sparse.container, f);
|
||||
|
||||
if (maxf < 0)
|
||||
maxf = f;
|
||||
dt = new DecisionTree(f, X_cpy, forget, maxf, noclasses, e);
|
||||
rf = new RandomForest(height, f, X_cpy, forget, noclasses, e);
|
||||
// dt = new DecisionTree(f, X_cpy, forget, maxf, noclasses, e);
|
||||
rf = new RandomForest(ntree, f, X_cpy, forget, nclasses, e, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,14 +56,20 @@ __AQEXPORT__(bool)
|
||||
fit_inc(vector_type<vector_type<double>> v, vector_type<long> res)
|
||||
{
|
||||
static uint32_t last_offset = 0;
|
||||
double **data = (double **)malloc(v.size * sizeof(double *));
|
||||
if(last_offset >= v.size)
|
||||
if(last_offset > v.size)
|
||||
last_offset = 0;
|
||||
for (int i = last_offset; i < v.size; ++i)
|
||||
data[i] = v.container[i].container;
|
||||
rf->fit(data, res.container, v.size);
|
||||
free(data);
|
||||
return true;
|
||||
const auto curr_size = (v.size - last_offset);
|
||||
if(curr_size > 0) {
|
||||
double **data = (double **)malloc( curr_size * sizeof(double *));
|
||||
for (uint32_t i = last_offset; i < v.size; ++i)
|
||||
data[i - last_offset] = v.container[i].container;
|
||||
rf->fit(data, res.container + last_offset, curr_size);
|
||||
|
||||
last_offset = v.size;
|
||||
free(data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user