脑js用于连续时间预测

时间:2018-04-13 19:27:34

标签: node.js machine-learning

有没有人试图用brainjs实现连续时间预测模型? 我有一个发生事件的日期,我想找到下一个发生事件的时间。

由于

1 个答案:

答案 0 :(得分:1)

https://github.com/BrainJS/brain.js#for-training-with-rnntimestep-lstmtimestep-and-grutimestep

#include "cpprest/uri.h"
#include "cpprest/producerconsumerstream.h"
#include "cpprest/http_listener.h"

using namespace std;
using namespace web;
using namespace http;
using namespace utility;
using namespace concurrency;
using namespace http::experimental::listener;

struct MyServer
{
  MyServer(string_t url);
  pplx::task<void> open()  { return mListener.open(); };
  pplx::task<void> close() { return mListener.close(); };

private:

  void handleGet(http_request iRequest);
  http_listener mListener;
};

MyServer::MyServer(utility::string_t url) : mListener(url)
{
  mListener.support(methods::GET, bind(&MyServer::handleGet, this, placeholders::_1));
}

void MyServer::handleGet(http_request iRequest)
{
  ucout << iRequest.to_string() << endl;

  http_response wResponse;

  // Setting headers
  wResponse.set_status_code(status_codes::OK);
  wResponse.headers().add(header_names::access_control_allow_origin, U("*"));
  wResponse.headers().add(header_names::content_type, U("text/event-stream"));

  // Preparing buffer
  streams::producer_consumer_buffer<char> wBuffer;
  streams::basic_istream<uint8_t> wStream(wBuffer);
  wResponse.set_body(wStream);

  auto wReplyTask = iRequest.reply(wResponse);

  wBuffer.putn_nocopy("data: a\n",10).wait();
  wBuffer.putn_nocopy("data: b\n\n",12).wait();
  wBuffer.sync().wait();  // seems equivalent to 'flush'

  this_thread::sleep_for(chrono::milliseconds(2000));

  wBuffer.putn_nocopy("data: c\n", 10).wait();
  wBuffer.putn_nocopy("data: d\n\n", 12).wait();
  wBuffer.sync().wait();
  // wBuffer.close(std::ios_base::out).wait();    // closes the connection
  wReplyTask.wait();      // blocking!
}

unique_ptr<MyServer> gHttp;

void onInit(const string_t iAddress)
{
  uri_builder wUri(iAddress);
  auto wAddress = wUri.to_uri().to_string();
  gHttp = unique_ptr<MyServer>(new MyServer(wAddress));

  gHttp->open().wait();
  ucout << string_t(U("Listening for requests at: ")) << wAddress << endl;

}

void onShutdown()
{
  gHttp->close().wait();
}


void main(int argc, wchar_t* argv[])
{

  onInit(U("http://*:32123"));

  cout << "Wait until connection occurs..." << endl;
  getchar();

  onShutdown();
}