lmccalman / stateline-cpp

C++ worker interface to Stateline

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

stateline-cpp

Library for building C++ Stateline workers.

Usage

For every Stateline worker, launch a corresponding stateline-agent with a different socket.

Example

The following code gives a minimal example of building a stateline worker in C++ with a custom likelihood function gaussianNLL:

// Compile command:
// g++ -isystem ${STATELINE_INSTALL_DIR}/include -L${STATELINE_INSTALL_DIR}/lib
//   -std=c++11 -o myworker myworker.cpp -lstatelineclient -lzmq -lpthread

#include <thread>
#include <chrono>

#include <stateline/worker.hpp>

double gaussianNLL(stateline::JobType type, const std::vector<double>& x)
{
  double squaredNorm = 0.0;
  for (auto i : x)
  {
    squaredNorm += i*i;
  }
  return 0.5*squaredNorm;
}

int main(int argc, char* argv[])
{
  if (argc != 2)
    return 1;
    
  stateline::runWorker(argv[1], gaussianNLL);
}

About

C++ worker interface to Stateline

License:Other


Languages

Language:C++ 57.5%Language:CMake 21.7%Language:Python 20.8%