Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Make the ping interval customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcslws committed Jan 29, 2019
1 parent 2daa976 commit 36b556d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 66 deletions.
10 changes: 6 additions & 4 deletions src/nupic/bindings/experimental.i
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,22 @@ using namespace nupic;

%pythoncode %{
def computeGridUniquenessHypercube(domainToPlaneByModule, latticeBasisByModule,
phaseResolution, ignoredCenterDiameter):
phaseResolution, ignoredCenterDiameter,
pingInterval=10.0):
domainToPlaneByModule = numpy.asarray(domainToPlaneByModule, dtype="float64")
latticeBasisByModule = numpy.asarray(latticeBasisByModule, dtype="float64")

return _computeGridUniquenessHypercube(
domainToPlaneByModule, latticeBasisByModule, phaseResolution,
ignoredCenterDiameter)
ignoredCenterDiameter, pingInterval)
%}

%inline {
PyObject* _computeGridUniquenessHypercube(PyObject* py_domainToPlaneByModule,
PyObject* py_latticeBasisByModule,
Real64 phaseResolution,
Real64 ignoredCenterDiameter)
Real64 ignoredCenterDiameter,
Real64 pingInterval)
{
PyArrayObject* pyArr_domainToPlaneByModule =
(PyArrayObject*)py_domainToPlaneByModule;
Expand Down Expand Up @@ -200,7 +202,7 @@ using namespace nupic;
std::pair<Real64,std::vector<Real64>> result =
nupic::experimental::grid_uniqueness::computeGridUniquenessHypercube(
domainToPlaneByModule, latticeBasisByModule, phaseResolution,
ignoredCenterDiameter);
ignoredCenterDiameter, pingInterval);

PyObject* pyResult = PyTuple_New(2);
PyTuple_SetItem(pyResult, 0, PyFloat_FromDouble(result.first));
Expand Down
134 changes: 73 additions & 61 deletions src/nupic/experimental/GridUniqueness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,8 @@ nupic::experimental::grid_uniqueness::computeGridUniquenessHypercube(
const vector<vector<vector<double>>>& domainToPlaneByModule,
const vector<vector<vector<double>>>& latticeBasisByModule,
double readoutResolution,
double ignoredCenterDiameter)
double ignoredCenterDiameter,
double pingInterval)
{
typedef std::chrono::steady_clock Clock;

Expand Down Expand Up @@ -1614,94 +1615,105 @@ nupic::experimental::grid_uniqueness::computeGridUniquenessHypercube(
}

const auto tStart = Clock::now();
auto tNextPrint = tStart + std::chrono::seconds(10);
auto tNextPrint = tStart + std::chrono::duration<double>(pingInterval);

bool printedInitialStatement = false;

while (!state.finished)
{
if (state.finishedCondition.wait_until(
lock, tNextPrint) == std::cv_status::timeout)
if (pingInterval <= 0)
{
if (!printedInitialStatement)
state.finishedCondition.wait(lock);
}
else
{
if (state.finishedCondition.wait_until(
lock, tNextPrint) == std::cv_status::timeout)
{
if (!printedInitialStatement)
{
std::ostringstream oss;
oss << "[";

for (size_t iModule = 0;
iModule < domainToPlaneByModule.size();
iModule++)
{
std::ostringstream oss;
oss << "[";
oss << vecs(domainToPlaneByModule[iModule][0]) << ",";
oss << vecs(domainToPlaneByModule[iModule][1]);
oss << "],";

for (size_t iModule = 0;
iModule < domainToPlaneByModule.size();
iModule++)
{
oss << "[";
oss << vecs(domainToPlaneByModule[iModule][0]) << ",";
oss << vecs(domainToPlaneByModule[iModule][1]);
oss << "],";
}
oss << "]" << std::endl;
NTA_INFO << "domainToPlaneByModule:" << std::endl << oss.str();
}
oss << "]" << std::endl;
NTA_INFO << "domainToPlaneByModule:" << std::endl << oss.str();
}

{
std::ostringstream oss;
oss << "[";
for (size_t iModule = 0;
iModule < latticeBasisByModule.size();
iModule++)
{
std::ostringstream oss;
oss << "[";
oss << vecs(latticeBasisByModule[iModule][0]) << ",";
oss << vecs(latticeBasisByModule[iModule][1]);
oss << "],";
for (size_t iModule = 0;
iModule < latticeBasisByModule.size();
iModule++)
{
oss << "[";
oss << vecs(latticeBasisByModule[iModule][0]) << ",";
oss << vecs(latticeBasisByModule[iModule][1]);
oss << "],";
}
oss << "]" << std::endl;

NTA_INFO << "latticeBasisByModule:" << std::endl << oss.str();
}
oss << "]" << std::endl;

NTA_INFO << "latticeBasisByModule:" << std::endl << oss.str();
}
NTA_INFO << "readout resolution: " << readoutResolution;

NTA_INFO << "readout resolution: " << readoutResolution;

printedInitialStatement = true;
}
printedInitialStatement = true;
}

NTA_INFO << "";
NTA_INFO << domainToPlaneByModule.size() << " modules, " << numDims
<< " dimensions, "
<< std::chrono::duration_cast<std::chrono::seconds>(
Clock::now() - tStart).count() << " seconds elapsed";
NTA_INFO << "";
NTA_INFO << domainToPlaneByModule.size() << " modules, " << numDims
<< " dimensions, "
<< std::chrono::duration_cast<std::chrono::seconds>(
Clock::now() - tStart).count() << " seconds elapsed";

if (state.foundPointBaselineRadius < std::numeric_limits<double>::max())
{
NTA_INFO << "**Hypercube side length upper bound: "
<< state.foundPointBaselineRadius << "**";
NTA_INFO << "**Grid code zero found at: "
<< vecs(state.pointWithGridCodeZero) << "**";
}
if (state.foundPointBaselineRadius <
std::numeric_limits<double>::max())
{
NTA_INFO << "**Hypercube side length upper bound: "
<< state.foundPointBaselineRadius << "**";
NTA_INFO << "**Grid code zero found at: "
<< vecs(state.pointWithGridCodeZero) << "**";
}

tNextPrint = Clock::now() + std::chrono::seconds(10);
tNextPrint = (Clock::now() +
std::chrono::duration<double>(pingInterval));

for (size_t iThread = 0; iThread < state.threadBaselineRadius.size();
iThread++)
{
if (state.threadRunning[iThread])
for (size_t iThread = 0; iThread < state.threadBaselineRadius.size();
iThread++)
{
if (state.threadShouldContinue[iThread])
if (state.threadRunning[iThread])
{
NTA_INFO << " Thread " << iThread
<< " assuming hypercube side length lower bound "
<< state.threadBaselineRadius[iThread] << ", querying x0 "
<< vecs(state.threadQueryX0[iThread]) << " and dims "
<< vecs(state.threadQueryDims[iThread]);
if (state.threadShouldContinue[iThread])
{
NTA_INFO << " Thread " << iThread
<< " assuming hypercube side length lower bound "
<< state.threadBaselineRadius[iThread]
<< ", querying x0 "
<< vecs(state.threadQueryX0[iThread]) << " and dims "
<< vecs(state.threadQueryDims[iThread]);
}
else
{
NTA_INFO << " Thread " << iThread
<< " has been ordered to stop.";
}
}
else
{
NTA_INFO << " Thread " << iThread << " has been ordered to stop.";
NTA_INFO << " Thread " << iThread << " is finished.";
}
}
else
{
NTA_INFO << " Thread " << iThread << " is finished.";
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/nupic/experimental/GridUniqueness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ namespace nupic {
* because it contains the *actual* grid code zero. Set this to be
* sufficiently large to get away from this actual zero.
*
* @param pingInterval
* How often, in seconds, the function should print its current status.
* If <= 0, no printing will occur.
*
* @return
* - The diameter of the hypercube that contains no collisions.
* - A point just outside this hypercube that collides with the origin.
Expand All @@ -129,7 +133,8 @@ namespace nupic {
const std::vector<std::vector<std::vector<Real64>>>& domainToPlaneByModule,
const std::vector<std::vector<std::vector<Real64>>>& latticeBasisByModule,
Real64 readoutResolution,
Real64 ignoredCenterDiameter);
Real64 ignoredCenterDiameter,
Real64 pingInterval=10.0);

/**
* Compute the sidelength of the smallest hypercube that encloses the
Expand Down

0 comments on commit 36b556d

Please sign in to comment.