Reels
Loading...
Searching...
No Matches
Namespaces | Macros | Typedefs | Functions | Variables
reels.cpp File Reference
#include "reels.h"
#include "thousand_sequences.hpp"
Include dependency graph for reels.cpp:

Namespaces

namespace  reels
 The namespace including everything to simplify using Reels in a c++ application,.
 

Macros

#define MURMUR_SEED   76493
 Just a 5 digit prime. More...
 

Typedefs

typedef EventspEvents
 
typedef ClientspClients
 
typedef ClipspClips
 
typedef TargetspTargets
 
typedef TimesToTargetpIterTimes
 
typedef std::map< int, pEventsEventsServer
 
typedef std::map< int, pClientsClientsServer
 
typedef std::map< int, pClipsClipsServer
 
typedef std::map< int, pTargetsTargetsServer
 
typedef std::map< int, pIterTimesIterTimesServer
 
typedef std::map< int, pBinaryImageBinaryImageServer
 

Functions

uint64_t reels::MurmurHash64A (const void *key, int len)
 MurmurHash2, 64-bit versions, by Austin Appleby. More...
 
bool reels::image_put (pBinaryImage p_bi, void *p_data, int size)
 A function to push arbitrary raw data into a BinaryImage. More...
 
bool reels::image_get (pBinaryImage p_bi, int &c_block, int &c_ofs, void *p_data, int size)
 A function to get an arbitrary raw data block from a BinaryImage. More...
 
bool reels::compare_optimize_eval (const OptimizeEvalItem a, const OptimizeEvalItem b)
 Compare two OptimizeEvalItem structures for sorting. More...
 
bool reels::compare_score_item (const CodeScoreItem a, const CodeScoreItem b)
 Compare two CodeScoreItem structures for sorting. More...
 
bool destroy_binary_image_iterator (int image_id)
 Destroy an iterator for a binary image(returned by save_as_binary_image()). More...
 
char * image_block_as_string (uint8_t *p_in)
 Serializes a complete binary block (fixed size) as a base-64 string which is Python compatible. More...
 
char * image_block_as_string (ImageBlock &blk)
 Serializes a complete binary block (fixed size) as a base-64 string which is Python compatible. More...
 
bool string_as_image_block (ImageBlock &blk, char *p_in)
 Deserializes a base-64 string which is Python compatible as a complete binary ImageBlock (fixed size). More...
 
int new_events ()
 Create a new Events object that can be used via the Python interface. More...
 
bool destroy_events (int id)
 Destroy a Events object that was used via the Python interface. More...
 
bool events_insert_row (int id, char *p_e, char *p_d, double w)
 Process a row from a transaction file in an Events object stored by the EventsServer. More...
 
bool events_define_event (int id, char *p_e, char *p_d, double w, int code)
 Define events explicitly in an Events object stored by the EventsServer. More...
 
char * events_optimize_events (int id, int id_clips, int id_targets, int num_steps, int codes_per_step, double threshold, char *force_include, char *force_exclude, char *x_form, char *agg, double p, int depth, int as_states, double exp_decay, double lower_bound_p, bool log_lift)
 Events optimizer. More...
 
bool events_load_block (int id, char *p_block)
 Pushes raw image blocks into an initially empty Events object and finally creates it already populated with the binary image. More...
 
int events_save (int id)
 Saves an Events object as a BinaryImage. More...
 
bool parse_bin_event_pt (char *line, BinEventPt &ev)
 
char * events_describe_next_event (int id, char *prev_event)
 Describes the internal representation of an event. (Iterate through all.) More...
 
bool events_set_max_num_events (int id, int max_events)
 Sets the public property max_num_events in an Events object stored by the EventsServer. More...
 
bool events_set_store_strings (int id, bool store)
 Sets the public property store_strings in an Events object stored by the EventsServer. More...
 
int events_num_events (int id)
 Return the number of events stored in an Events object stored by the EventsServer. More...
 
int new_clients ()
 Create a new Clients object that can be used via the Python interface. More...
 
bool destroy_clients (int id)
 Destroy a Clients object that was used via the Python interface. More...
 
char * clients_hash_client_id (int id, char *p_cli)
 Return the hash of a client ID as a decimal string. More...
 
bool clients_add_client_id (int id, char *p_cli)
 Add a client ID to a Clients object stored by the ClientsServer only if new. More...
 
char * clients_hash_by_index (int id, int idx)
 Return the hash of a stored client ID by index as a decimal string. More...
 
int clients_num_clients (int id)
 Return the number of clients stored in an Clients object stored by the ClientsServer. More...
 
bool clients_load_block (int id, char *p_block)
 Pushes raw image blocks into an initially empty Clients object and finally creates it already populated with the binary image. More...
 
int clients_save (int id)
 Saves an Clients object as a BinaryImage. More...
 
int new_clips (int id_clients, int id_events)
 Create a new Clips object that can be used via the Python interface. More...
 
bool destroy_clips (int id)
 Destroy a Clips object that was used via the Python interface. More...
 
bool clips_set_time_format (int id, char *fmt)
 Sets the public property time_format to simplify the python interface in a Clips object stored by the ClipsServer. More...
 
bool clips_scan_event (int id, char *p_e, char *p_d, double w, char *p_c, char *p_t)
 Process a row from a transaction file, to add the event to the client's timeline in a Clips object stored by the ClipsServer. More...
 
char * clips_hash_by_previous (int id, char *prev_hash)
 Return the hash of the client ID of a clip defined the previous value or zero for the first one as a decimal string. More...
 
bool clips_load_block (int id, char *p_block)
 Pushes raw image blocks into an initially empty Clips object and finally creates it already populated with the binary image. More...
 
int clips_save (int id)
 Saves an Clips object as a BinaryImage. More...
 
char * clips_describe_clip (int id, char *client_id)
 Describes the internal representation of a clip. More...
 
int clips_num_clips (int id)
 Return the number of clips stored in the internal ClipMap in a Clips object stored by the ClipsServer. More...
 
int clips_num_events (int id)
 Return the number of events stored in the internal ClipMap in a Clips object stored by the ClipsServer. More...
 
char * clips_test_sequence (int seq_num, bool target)
 Generates a constant sequence of codes for testing the Event Optimizer. More...
 
int new_targets (int id_clips)
 Create a new Targets object that can be used via the Python interface. More...
 
bool destroy_targets (int id)
 Destroy a Targets object that was used via the Python interface. More...
 
bool targets_set_time_format (int id, char *fmt)
 Sets the public property time_format to simplify the python interface in a Targets object stored by the TargetsServer. More...
 
bool targets_insert_target (int id, char *p_c, char *p_t)
 Utility to fill the internal TargetMap target in a Targets object stored by the TargetsServer. More...
 
bool targets_fit (int id, char *x_form, char *agg, double p, int depth, int as_states)
 Fit the prediction model in a Targets object stored by the TargetsServer. More...
 
int targets_predict_clients (int id, int id_clients)
 Predict time to target for all the clients in a given Clients object whose clips have been used to fit the model in a Targets object stored by the TargetsServer. More...
 
int targets_predict_clips (int id, int id_clips)
 Predict time to target for a set of clients whose clips are given in a ClipMap in a Targets object stored by the TargetsServer. More...
 
bool targets_load_block (int id, char *p_block)
 Pushes raw image blocks into an initially empty Targets object and finally creates it already populated with the binary image. More...
 
int targets_save (int id)
 Saves an Targets object as a BinaryImage. More...
 
int targets_num_targets (int id)
 Returns the number of target points stored in the internal target variable. More...
 
int targets_tree_node_idx (int id, int parent_idx, int code)
 Returns the index of a tree node by parent node and code. More...
 
char * targets_tree_node_children (int id, int idx)
 Lists the children of a tree node. More...
 
char * targets_describe_tree_node (int id, int idx)
 Describes the internal representation of a tree node. More...
 
char * targets_describe_tree (int id)
 Describes some statistics of a fitted tree inside a Targets object. More...
 
int size_result_iterator (int iter_id)
 Return the number of unread items in an iterator returned by predict(). More...
 
double next_result_iterator (int iter_id)
 Return the first unread item in an iterator returned by predict(). More...
 
void destroy_result_iterator (int iter_id)
 Destroy an iterator returned by predict(). More...
 
int size_binary_image_iterator (int image_id)
 Return the number of unread binary images blocks in an iterator returned by a save_as_binary_image() call. More...
 
char * next_binary_image_iterator (int image_id)
 Return the first unread binary images block in an iterator returned by a save_as_binary_image() call. More...
 

Variables

Logger reels::REELS_logger = {}
 Used to output stats of Events::get_top_codes added by the Python API in events_optimize_events() More...
 
int events_num = 0
 
int clients_num = 0
 
int clips_num = 0
 
int targets_num = 0
 
int it_times_num = 0
 
EventsServer events = {}
 
ClientsServer clients = {}
 
ClipsServer clips = {}
 
TargetsServer targets = {}
 
IterTimesServer it_times = {}
 
BinaryImageServer image = {}
 
char answer_buffer [8192]
 
char answer_block [8208]
 
char b64chars [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
 
uint8_t b64inverse [256] = {0}
 

Macro Definition Documentation

◆ MURMUR_SEED

#define MURMUR_SEED   76493

Just a 5 digit prime.

Typedef Documentation

◆ BinaryImageServer

typedef std::map<int, pBinaryImage> BinaryImageServer

◆ ClientsServer

typedef std::map<int, pClients> ClientsServer

◆ ClipsServer

typedef std::map<int, pClips> ClipsServer

◆ EventsServer

typedef std::map<int, pEvents> EventsServer

◆ IterTimesServer

typedef std::map<int, pIterTimes> IterTimesServer

◆ pClients

typedef Clients* pClients

◆ pClips

typedef Clips* pClips

◆ pEvents

typedef Events* pEvents

◆ pIterTimes

◆ pTargets

typedef Targets* pTargets

◆ TargetsServer

typedef std::map<int, pTargets> TargetsServer

Function Documentation

◆ clients_add_client_id()

bool clients_add_client_id ( int  id,
char *  p_cli 
)

Add a client ID to a Clients object stored by the ClientsServer only if new.

Parameters
idThe id returned by a previous new_clients() call.
p_cliThe "client". A string representing "the actor".
Returns
True on success. False on id not found or p_cli is empty or already a client.

◆ clients_hash_by_index()

char * clients_hash_by_index ( int  id,
int  idx 
)

Return the hash of a stored client ID by index as a decimal string.

Parameters
idThe id returned by a previous new_clients() call.
idxThe index of the client in the container (In range 0..size() - 1).
Returns
The hash of the selected client id as a decimal string.

◆ clients_hash_client_id()

char * clients_hash_client_id ( int  id,
char *  p_cli 
)

Return the hash of a client ID as a decimal string.

Parameters
idThe id returned by a previous new_clients() call.
p_cliThe "client". A string representing "the actor".
Returns
The hash of the selected client if as a decimal string.

◆ clients_load_block()

bool clients_load_block ( int  id,
char *  p_block 
)

Pushes raw image blocks into an initially empty Clients object and finally creates it already populated with the binary image.

Parameters
idThe id returned by a previous new_clients() call. The object must be empty (never called).
p_blockIf non-empty, a block in the right order making a binary image obtained for a previous clients_save() call. If empty, an order to .load() the Clients object and destroyed the previously stored blocks.
Returns
True on success.

◆ clients_num_clients()

int clients_num_clients ( int  id)

Return the number of clients stored in an Clients object stored by the ClientsServer.

Parameters
idThe id returned by a previous new_clients() call.
Returns
The size of the internal ClientIDSet() or a negative error code on failure.

◆ clients_save()

int clients_save ( int  id)

Saves an Clients object as a BinaryImage.

Parameters
idThe id returned by a previous new_clients() call.
Returns
0 on error, or a binary_image_id > 0 which is the same as id and must be destroyed using destroy_binary_image_iterator()

◆ clips_describe_clip()

char * clips_describe_clip ( int  id,
char *  client_id 
)

Describes the internal representation of a clip.

Parameters
idThe id returned by a previous new_clips() call.
client_idThe hash identifying a client or the client id.
Returns
On success, it will return a tab separated list of codes corresponding to the clip.

◆ clips_hash_by_previous()

char * clips_hash_by_previous ( int  id,
char *  prev_hash 
)

Return the hash of the client ID of a clip defined the previous value or zero for the first one as a decimal string.

Parameters
idThe id returned by a previous new_clients() call.
prev_hashThe previous hash returned by this function to use as an iterator.
Returns
The hash of the selected client id as a hexadecimal string.

◆ clips_load_block()

bool clips_load_block ( int  id,
char *  p_block 
)

Pushes raw image blocks into an initially empty Clips object and finally creates it already populated with the binary image.

Parameters
idThe id returned by a previous new_clips() call. The object must be empty (never called).
p_blockIf non-empty, a block in the right order making a binary image obtained for a previous clips_save() call. If empty, an order to .load() the Clips object and destroyed the previously stored blocks.
Returns
True on success.

◆ clips_num_clips()

int clips_num_clips ( int  id)

Return the number of clips stored in the internal ClipMap in a Clips object stored by the ClipsServer.

Parameters
idThe id returned by a previous new_clips() call.
Returns
The number clips in the internal ClipMap.

◆ clips_num_events()

int clips_num_events ( int  id)

Return the number of events stored in the internal ClipMap in a Clips object stored by the ClipsServer.

Parameters
idThe id returned by a previous new_clips() call.
Returns
The total count of events aggregating all the clips in the internal ClipMap or -1 on error.

◆ clips_save()

int clips_save ( int  id)

Saves an Clips object as a BinaryImage.

Parameters
idThe id returned by a previous new_clips() call.
Returns
0 on error, or a binary_image_id > 0 which is the same as id and must be destroyed using destroy_binary_image_iterator()

◆ clips_scan_event()

bool clips_scan_event ( int  id,
char *  p_e,
char *  p_d,
double  w,
char *  p_c,
char *  p_t 
)

Process a row from a transaction file, to add the event to the client's timeline in a Clips object stored by the ClipsServer.

Parameters
idThe id returned by a previous new_clips() call.
p_eThe "emitter". A C/Python string representing "owner of event".
p_dThe "description". A C/Python string representing "the event".
wThe "weight". A double representing a weight of the event.
p_cThe "client". A C/Python string representing "the actor".
p_tThe "time". A timestamp of the event as a C/Python string. (The format is given via set_time_format().)
Returns
True on insertion. False usually just means, the event is not in events or the client is not in clients. Occasionally, it may be a time parsing error or id not found.

◆ clips_set_time_format()

bool clips_set_time_format ( int  id,
char *  fmt 
)

Sets the public property time_format to simplify the python interface in a Clips object stored by the ClipsServer.

Parameters
idThe id returned by a previous new_clips() call.
fmtThe time format in standard calendar time format http://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html
Returns
True on valid id.

◆ clips_test_sequence()

char * clips_test_sequence ( int  seq_num,
bool  target 
)

Generates a constant sequence of codes for testing the Event Optimizer.

This returns one of the 500 non target sequences or one of the 500 target sequences.

Parameters
seq_numThe sequence id (in range 0.499).
targetTrue for one of the target sequences, false for non target.
Returns
A sequence of integer codes as a comma separated string. Empty if seq_num is out of range.

◆ destroy_binary_image_iterator()

bool destroy_binary_image_iterator ( int  image_id)

Destroy an iterator for a binary image(returned by save_as_binary_image()).

Parameters
image_idThe image_id returned by a previous save_as_binary_image() call.
Returns
True on success.

◆ destroy_clients()

bool destroy_clients ( int  id)

Destroy a Clients object that was used via the Python interface.

Parameters
idThe id returned by a previous new_clients() call.
Returns
True on success.

◆ destroy_clips()

bool destroy_clips ( int  id)

Destroy a Clips object that was used via the Python interface.

Parameters
idThe id returned by a previous new_clips() call.
Returns
True on success.

◆ destroy_events()

bool destroy_events ( int  id)

Destroy a Events object that was used via the Python interface.

Parameters
idThe id returned by a previous new_events() call.
Returns
True on success.

◆ destroy_result_iterator()

void destroy_result_iterator ( int  iter_id)

Destroy an iterator returned by predict().

Parameters
iter_idThe iter_id returned by a previous predict() call.

◆ destroy_targets()

bool destroy_targets ( int  id)

Destroy a Targets object that was used via the Python interface.

Parameters
idThe id returned by a previous new_targets() call.
Returns
True on success.

◆ events_define_event()

bool events_define_event ( int  id,
char *  p_e,
char *  p_d,
double  w,
int  code 
)

Define events explicitly in an Events object stored by the EventsServer.

Parameters
idThe id returned by a previous new_events() call.
p_eThe "emitter". A C/Python string representing "owner of event".
p_dThe "description". A C/Python string representing "the event".
wThe "weight". A double representing a weight of the event.
codeA unique code number identifying the event.
Returns
True on success.

◆ events_describe_next_event()

char * events_describe_next_event ( int  id,
char *  prev_event 
)

Describes the internal representation of an event. (Iterate through all.)

Parameters
idThe id returned by a previous new_events() call.
prev_eventThe previous description, either complete or the (emitter, description, weight) triple alone, or empty for the first.
Returns
On success, it will return either tab separated emitter, description, weight, code (if store_strings is true) or the same with hashes corresponding to strings instead of strings if false.

◆ events_insert_row()

bool events_insert_row ( int  id,
char *  p_e,
char *  p_d,
double  w 
)

Process a row from a transaction file in an Events object stored by the EventsServer.

Parameters
idThe id returned by a previous new_events() call.
p_eThe "emitter". A C/Python string representing "owner of event".
p_dThe "description". A C/Python string representing "the event".
wThe "weight". A double representing a weight of the event.
Returns
True on success.

◆ events_load_block()

bool events_load_block ( int  id,
char *  p_block 
)

Pushes raw image blocks into an initially empty Events object and finally creates it already populated with the binary image.

Parameters
idThe id returned by a previous new_events() call. The object must be empty (never called).
p_blockIf non-empty, a block in the right order making a binary image obtained for a previous events_save() call. If empty, an order to .load() the Events object and destroyed the previously stored blocks.
Returns
True on success.

◆ events_num_events()

int events_num_events ( int  id)

Return the number of events stored in an Events object stored by the EventsServer.

Parameters
idThe id returned by a previous new_events() call.
Returns
The size of the internal EventMap() or a negative error code on failure.

◆ events_optimize_events()

char * events_optimize_events ( int  id,
int  id_clips,
int  id_targets,
int  num_steps,
int  codes_per_step,
double  threshold,
char *  force_include,
char *  force_exclude,
char *  x_form,
char *  agg,
double  p,
int  depth,
int  as_states,
double  exp_decay,
double  lower_bound_p,
bool  log_lift 
)

Events optimizer.

Optimizes the events to maximize prediction signal. (F1 score over same number of positives.) It converts code values many-to-one trying to group event codes into categories that represent similar events.

Before starting, a non-optimized Events object must be populated with an initial set of codes we want to reduce by assigning new many-to-one codes to them.

The algorithm initially removes all codes not found in the clips object. This completely removes them.

The algorithm builds a list of most promising (not already used) codes at the beginning of each step by full tree search. From that list, each code is tried downwards as {noise, new_code, last_code} for score improvement above threshold up to codes_per_step steps. And assigned a new code accordingly. The codes assigned become part of the internal EventCodeMap and in the next step they will replace their old values.

When the algorithm finishes, the internal EventCodeMap is used to rename the object codes and the whole process is reported.

Parameters
idThe id returned by a previous new_events() call. The object must be empty (never called).
id_clipsThe id of a clips object with the same codes and clips for a set of clients whose prediction we optimize.
id_targetsThe id of a Targets object whose internal TargetMap defines the targets. (Internally a new Targets object will be used to make the predictions we want to optimize.)
num_stepsThe number of steps to iterate. The method will stop early if no codes are found at a step.
codes_per_stepThe number of codes to be tried from the top of the priority list at each step.
thresholdA minimum threshold, below which a score change is not considered improvement.
force_includeAn optional pointer to a set of codes that must be included before starting.
force_excludeAn optional pointer to a set of codes that will excluded and set to the base code.
x_formThe x_form argument to fit the internal Targets object prediction model.
aggThe agg argument to fit the internal Targets object prediction model.
pThe p argument to fit the internal Targets object prediction model.
depthThe depth argument to fit the internal Targets object prediction model.
as_statesThe as_states argument to fit the internal Targets object prediction model.
exp_decayExponential Decay Factor applied to the internal score in terms of depth. That score selects what codes enter the model. The decay is applied to the average tree depth. 0 is no decay, default value = 0.00693 decays to 0.5 in 100 steps.
lower_bound_pAnother p for lower bound, but applied to the scoring process rather than the model.
log_liftA boolean to set if lift (= LB(included)/LB(after inclusion)) is log() transformed or not.
Returns
A lf separated report string that contains either "ERROR" or "success" as the first line.

◆ events_save()

int events_save ( int  id)

Saves an Events object as a BinaryImage.

Parameters
idThe id returned by a previous new_events() call.
Returns
0 on error, or a binary_image_id > 0 which is the same as id and must be destroyed using destroy_binary_image_iterator()

◆ events_set_max_num_events()

bool events_set_max_num_events ( int  id,
int  max_events 
)

Sets the public property max_num_events in an Events object stored by the EventsServer.

Parameters
idThe id returned by a previous new_events() call.
max_eventsThe value to apply to max_num_events.
Returns
True on success.

◆ events_set_store_strings()

bool events_set_store_strings ( int  id,
bool  store 
)

Sets the public property store_strings in an Events object stored by the EventsServer.

Parameters
idThe id returned by a previous new_events() call.
storeTrue for storing the string contents.
Returns
True on success.

◆ image_block_as_string() [1/2]

char * image_block_as_string ( ImageBlock blk)

Serializes a complete binary block (fixed size) as a base-64 string which is Python compatible.

Parameters
blkAn ImageBlock passed by reference.
Returns
The address of a fixed buffer big enough to hold the output.

◆ image_block_as_string() [2/2]

char * image_block_as_string ( uint8_t *  p_in)

Serializes a complete binary block (fixed size) as a base-64 string which is Python compatible.

Parameters
p_inThe address of the ImageBlock as a generic unsigned pointer.
Returns
The address of a fixed buffer big enough to hold the output.

◆ new_clients()

int new_clients ( )

Create a new Clients object that can be used via the Python interface.

Returns
A unique ID that can be passed as the id parameter for any method in the Python interface.

To free the resources allocated by this ID, the (python) caller must call destroy_clients() with the id and never use the same id after that.

◆ new_clips()

int new_clips ( int  id_clients,
int  id_events 
)

Create a new Clips object that can be used via the Python interface.

Parameters
id_clientsThe id returned by a previous new_clients() call passed to the constructor.
id_eventsThe id returned by a previous new_events() call passed to the constructor.
Returns
A unique ID that can be passed as the id parameter for any method in the Python interface or -1 on error.

To free the resources allocated by this ID, the (python) caller must call destroy_clips() with the id and never use the same id after that.

◆ new_events()

int new_events ( )

Create a new Events object that can be used via the Python interface.

Returns
A unique ID that can be passed as the id parameter for any method in the Python interface.

To free the resources allocated by this ID, the (python) caller must call destroy_events() with the id and never use the same id after that.

◆ new_targets()

int new_targets ( int  id_clips)

Create a new Targets object that can be used via the Python interface.

Parameters
id_clipsThe id returned by a previous new_clips() call passed to the constructor.
Returns
A unique ID that can be passed as the id parameter for any method in the Python interface or -1 on error.

To free the resources allocated by this ID, the (python) caller must call destroy_targets() with the id and never use the same id after that.

◆ next_binary_image_iterator()

char * next_binary_image_iterator ( int  image_id)

Return the first unread binary images block in an iterator returned by a save_as_binary_image() call.

Parameters
image_idThe image_id returned by a previous save_as_binary_image() call.
Returns
The the binary image block serialized as base64 or an empty string on failure.

◆ next_result_iterator()

double next_result_iterator ( int  iter_id)

Return the first unread item in an iterator returned by predict().

Parameters
iter_idThe iter_id returned by a previous predict() call.
Returns
The str_id of an insert()-ed set that matches the query.

◆ parse_bin_event_pt()

bool parse_bin_event_pt ( char *  line,
BinEventPt ev 
)

◆ size_binary_image_iterator()

int size_binary_image_iterator ( int  image_id)

Return the number of unread binary images blocks in an iterator returned by a save_as_binary_image() call.

Parameters
image_idThe image_id returned by a previous save_as_binary_image() call.
Returns
The number of unread blocks in the iterator.

◆ size_result_iterator()

int size_result_iterator ( int  iter_id)

Return the number of unread items in an iterator returned by predict().

Parameters
iter_idThe iter_id returned by a previous predict() call.
Returns
The number of unread items in the iterator.

◆ string_as_image_block()

bool string_as_image_block ( ImageBlock blk,
char *  p_in 
)

Deserializes a base-64 string which is Python compatible as a complete binary ImageBlock (fixed size).

Parameters
blkAn ImageBlock passed by reference.
p_inThe address of the ImageBlock as a generic unsigned pointer.
Returns
The address of a fixed buffer big enough to hold the output.

◆ targets_describe_tree()

char * targets_describe_tree ( int  id)

Describes some statistics of a fitted tree inside a Targets object.

Parameters
idThe id returned by a previous new_targets() call.
Returns
On success, it will return a descriptive text with node count numbers for different node content.

◆ targets_describe_tree_node()

char * targets_describe_tree_node ( int  id,
int  idx 
)

Describes the internal representation of a tree node.

Parameters
idThe id returned by a previous new_targets() call.
idxThe index of the node in the tree, typically navigated using targets_tree_node_idx().
Returns
On success, it will return a tab separated list n_seen, n_target, sum_time_d, num_codes.

◆ targets_fit()

bool targets_fit ( int  id,
char *  x_form,
char *  agg,
double  p,
int  depth,
int  as_states 
)

Fit the prediction model in a Targets object stored by the TargetsServer.

Parameters
idThe id returned by a previous new_targets() call.
x_formA possible transformation of the times. (Currently "log" or "linear".)
aggThe mechanism used for the aggregation. (Currently "minimax", "mean" or "longest".)
pThe width of the confidence interval for the binomial proportion used to calculate the lower bound. (E.g., p = 0.5 will estimate a lower bound of a symmetric CI with coverage of 0.5.)
depthThe maximum depth of the tree (maximum sequence length learned).
as_statesTreat events as states by removing repeated ones from the ClipMap keeping the time of the first instance only. When used, the ClipMap passed to the constructor by reference will be converted to states as a side effect.

Fit can only be called once in the life of a Targets object and predict() cannot be called before fit().

Returns
True on success. Error if already fitted, wrong arguments or the id is not found.

◆ targets_insert_target()

bool targets_insert_target ( int  id,
char *  p_c,
char *  p_t 
)

Utility to fill the internal TargetMap target in a Targets object stored by the TargetsServer.

The TargetMap can be initialized and given to the constructor, or an empty TargetMap can be given to the constructor ans initialized by this method. From the python interface only the latter is available.

Parameters
idThe id returned by a previous new_targets() call.
p_cThe "client". A C/Python string representing "the actor".
p_tThe "time". A timestamp of the event as a C/Python string. (The format is given via set_time_format().)
Returns
True on new clients. False if the client is already in the TargetMap or the time is in the wrong format. Also false if the id is not found.

◆ targets_load_block()

bool targets_load_block ( int  id,
char *  p_block 
)

Pushes raw image blocks into an initially empty Targets object and finally creates it already populated with the binary image.

Parameters
idThe id returned by a previous new_targets() call. The object must be empty (never called).
p_blockIf non-empty, a block in the right order making a binary image obtained for a previous targets_save() call. If empty, an order to .load() the Targets object and destroyed the previously stored blocks.
Returns
True on success.

◆ targets_num_targets()

int targets_num_targets ( int  id)

Returns the number of target points stored in the internal target variable.

Parameters
idThe id returned by a previous new_targets() call.
Returns
-1 on error (wrong id) or the size.

◆ targets_predict_clients()

int targets_predict_clients ( int  id,
int  id_clients 
)

Predict time to target for all the clients in a given Clients object whose clips have been used to fit the model in a Targets object stored by the TargetsServer.

predict() cannot be called before fit() and can be called any number of times in all overloaded forms after that.

\param id         The id returned by a previous new_targets() call.
\param id_clients The id returned by a previous new_clients() call passed to the constructor.

\return  The index of an iterator (valid for size_result_iterator(), next_result_iterator() and destroy_result_iterator() calls)
with the times of the predictions in seconds or -1 on error such as id not found.

◆ targets_predict_clips()

int targets_predict_clips ( int  id,
int  id_clips 
)

Predict time to target for a set of clients whose clips are given in a ClipMap in a Targets object stored by the TargetsServer.

predict() cannot be called before fit() and can be called any number of times in all overloaded forms after that.

Parameters
idThe id returned by a previous new_targets() call.
id_clipsThe id returned by a previous new_clips() call passed to the constructor.
Returns
The index of an iterator (valid for size_result_iterator(), next_result_iterator() and destroy_result_iterator() calls) with the times of the predictions in seconds or -1 on error such as id not found.

◆ targets_save()

int targets_save ( int  id)

Saves an Targets object as a BinaryImage.

Parameters
idThe id returned by a previous new_targets() call.
Returns
0 on error, or a binary_image_id > 0 which is the same as id and must be destroyed using destroy_binary_image_iterator()

◆ targets_set_time_format()

bool targets_set_time_format ( int  id,
char *  fmt 
)

Sets the public property time_format to simplify the python interface in a Targets object stored by the TargetsServer.

Parameters
idThe id returned by a previous new_targets() call.
fmtThe time format in standard calendar time format http://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html
Returns
True on valid id.

◆ targets_tree_node_children()

char * targets_tree_node_children ( int  id,
int  idx 
)

Lists the children of a tree node.

Parameters
idThe id returned by a previous new_targets() call.
idxThe index of the node in the tree, typically navigated using targets_tree_node_idx().
Returns
On success, it will return a tab separated list of integer codes.

◆ targets_tree_node_idx()

int targets_tree_node_idx ( int  id,
int  parent_idx,
int  code 
)

Returns the index of a tree node by parent node and code.

Parameters
idThe id returned by a previous new_targets() call.
parent_idxThe index of the parent node which is either 0 for root or returned from a previous targets_tree_node_idx() call.
codeThe code that leads in the tree from the parent node to the child node.
Returns
On success, i.e, if both the parent index exists and contains the code, it will return the index of the child (-1 otherwise).

Variable Documentation

◆ answer_block

char answer_block[8208]

◆ answer_buffer

char answer_buffer[8192]

◆ b64chars

char b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

◆ b64inverse

uint8_t b64inverse[256] = {0}

◆ clients

ClientsServer clients = {}

◆ clients_num

int clients_num = 0

◆ clips

ClipsServer clips = {}

◆ clips_num

int clips_num = 0

◆ events

EventsServer events = {}

◆ events_num

int events_num = 0

◆ image

BinaryImageServer image = {}

◆ it_times

IterTimesServer it_times = {}

◆ it_times_num

int it_times_num = 0

◆ targets

TargetsServer targets = {}

◆ targets_num

int targets_num = 0