Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dendrogram #150

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
32 changes: 32 additions & 0 deletions src/Scheduler/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,38 @@ MatrixXf Scheduler::getJobResult(const job_id_t job_id) {
}
}


modelResult Scheduler::getClusteringResult(const int job_id) {
if (ValidJobId(job_id)) {
Job_t* job = getJob(job_id);
if (AdaMultiLasso* model = dynamic_cast<AdaMultiLasso*>(job->model)) {
return model->getClusteringResult();
} else if (Gflasso* model = dynamic_cast<Gflasso*>(job->model)) {
return model->getClusteringResult();
} else if (LinearRegression* model = dynamic_cast<LinearRegression*>(job->model)) {
return model->getClusteringResult();
} else if (MultiPopLasso* model = dynamic_cast<MultiPopLasso*>(job->model)) {
return model->getClusteringResult();
} else if (SparseLMM* model = dynamic_cast<SparseLMM*>(job->model)) {
return model->getClusteringResult();
} else if (TreeLasso* model = dynamic_cast<TreeLasso*>(job->model)) {
return model->getClusteringResult();
} else if (LinearMixedModel* model = dynamic_cast<LinearMixedModel*>(job->model)) {
return model->getClusteringResult();
} else if (FisherTest* model = dynamic_cast<FisherTest*>(job->model)) {
return model->getClusteringResult();
} else if (Chi2Test* model = dynamic_cast<Chi2Test*>(job->model)) {
return model->getClusteringResult();
} else if (WaldTest* model = dynamic_cast<WaldTest*>(job->model)) {
return model->getClusteringResult();
} else {
return model->getClusteringResult();
}
} else {
return modelResult();
}
}

////////////////////////////////////////////////////////
// Private Functions
////////////////////////////////////////////////////////
Expand Down
69 changes: 37 additions & 32 deletions src/Scheduler/Scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifdef BAZEL
#include "Algorithms/Algorithm.hpp"
#include "Algorithms/AlgorithmOptions.hpp"
#include "Models/Model.hpp"
#include "Models/ModelOptions.hpp"
#include "Scheduler/Job.hpp"
#include "gtest/gtest_prod.h"
Expand All @@ -26,6 +27,7 @@
#include "../Algorithms/AlgorithmOptions.hpp"
#include "Job.hpp"
#include "../Models/ModelOptions.hpp"
#include "../Models/Model.hpp"
#endif


Expand Down Expand Up @@ -69,9 +71,13 @@ class Scheduler {
Job_t* getJob(const job_id_t);

MatrixXf getJobResult(const job_id_t);
// Returns the result matrix of a given job ID.

modelResult getClusteringResult(const int);
// Returns the bi-clustered result (for dendrogram) for a given job ID.

// TODO: How to know if the user owns the algorithm?
bool deleteJob(const job_id_t);
// TODO: How to know if the user owns the algorithm?

static Scheduler* Instance();
// This class follows the singleton pattern.
Expand Down Expand Up @@ -108,37 +114,36 @@ class Scheduler {
bool deleteAlgorithm(const algorithm_id_t);
bool deleteModel(const model_id_t);


#ifdef BAZEL
FRIEND_TEST(SchedulerTest, newAlgorithm);
FRIEND_TEST(SchedulerTest, newModel);
FRIEND_TEST(SchedulerTest, getNewAlgorithmId);
FRIEND_TEST(SchedulerTest, getNewModelId);
FRIEND_TEST(SchedulerTest, getNewJobId);
FRIEND_TEST(SchedulerTest, ValidAlgorithmId);
FRIEND_TEST(SchedulerTest, ValidModelId);
FRIEND_TEST(SchedulerTest, ValidJobId);
FRIEND_TEST(SchedulerTest, AlgorithmIdUsed);
FRIEND_TEST(SchedulerTest, ModelIdUsed);
FRIEND_TEST(SchedulerTest, JobIdUsed);
#endif

static Scheduler* s_instance; // Singleton
const unsigned int kMaxThreads = 5;

const algorithm_id_t kMaxAlgorithmId = 100;
algorithm_id_t next_algorithm_id;

const model_id_t kMaxModelId = 100;
model_id_t next_model_id;

const job_id_t kMaxJobId = 100;
job_id_t next_job_id;

unordered_map<algorithm_id_t, unique_ptr<Algorithm>> algorithms_map;
unordered_map<model_id_t, unique_ptr<Model>> models_map;
unordered_map<job_id_t, unique_ptr<Job_t>> jobs_map;
// Maps to track all jobs (running, waiting, and completed). indexed by job_id.
#ifdef BAZEL
FRIEND_TEST(SchedulerTest, newAlgorithm);
FRIEND_TEST(SchedulerTest, newModel);
FRIEND_TEST(SchedulerTest, getNewAlgorithmId);
FRIEND_TEST(SchedulerTest, getNewModelId);
FRIEND_TEST(SchedulerTest, getNewJobId);
FRIEND_TEST(SchedulerTest, ValidAlgorithmId);
FRIEND_TEST(SchedulerTest, ValidModelId);
FRIEND_TEST(SchedulerTest, ValidJobId);
FRIEND_TEST(SchedulerTest, AlgorithmIdUsed);
FRIEND_TEST(SchedulerTest, ModelIdUsed);
FRIEND_TEST(SchedulerTest, JobIdUsed);
#endif

static Scheduler* s_instance; // Singleton
const unsigned int kMaxThreads = 5;

const algorithm_id_t kMaxAlgorithmId = 100;
algorithm_id_t next_algorithm_id;

const model_id_t kMaxModelId = 100;
model_id_t next_model_id;

const job_id_t kMaxJobId = 100;
job_id_t next_job_id;

unordered_map<algorithm_id_t, unique_ptr<Algorithm>> algorithms_map;
unordered_map<model_id_t, unique_ptr<Model>> models_map;
unordered_map<job_id_t, unique_ptr<Job_t>> jobs_map;
// Maps to track all jobs (running, waiting, and completed). indexed by job_id.
};

void trainAlgorithmThread(uv_work_t* req);
Expand Down
26 changes: 26 additions & 0 deletions src/Scheduler/node/Scheduler_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "../../Algorithms/Algorithm.hpp"
#include "../../Algorithms/AlgorithmOptions.hpp"
#include "../../Algorithms/HypoTestPlaceHolder.h"
#include "../../Models/Model.hpp"
#include "../../Models/ModelOptions.hpp"
#include "../Job.hpp"
#include "../Scheduler.hpp"
Expand Down Expand Up @@ -169,6 +170,31 @@ void getJobResult(const v8::FunctionCallbackInfo<v8::Value>& args) {
}


// Returns the bi-clustered result for the given jobNum.
// Synchronous.
// Arguments: int job_id
// Returns empty matrix on error.
void getClusteringResult(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
try {
if (!ArgsHaveJobID(args, 0)) {
args.GetReturnValue().Set(Boolean::New(isolate, false));
return;
}
int job_id = (int)Local<Number>::Cast(args[0])->Value();
const modelResult& result = Scheduler::Instance()->getClusteringResult(job_id);
Local<v8::Array> obj = v8::Array::New(isolate);
obj->Set(0, v8::String::NewFromUtf8(isolate, JsonCoder::getInstance().encodeMatrix(result.beta).c_str()));
obj->Set(1, v8::String::NewFromUtf8(isolate, result.rowStr.c_str()));
obj->Set(2, v8::String::NewFromUtf8(isolate, result.colStr.c_str()));
args.GetReturnValue().Set(obj);
} catch (const exception& e) {
isolate->ThrowException(Exception::Error(
String::NewFromUtf8(isolate, e.what())));
}
}


// Cancels a potentially running Algorithm.
// Synchronous.
// Arguments: job_id_t job_id
Expand Down
22 changes: 14 additions & 8 deletions src/Scheduler/node/Scheduler_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,39 @@ using namespace v8;
// Visible from Node
/////////////////////////////////////////////////////

void setX(const v8::FunctionCallbackInfo<v8::Value>& args);
void setX(const v8::FunctionCallbackInfo<v8::Value>&);
// Arguments: job_num, JSON Matrix

void setY(const v8::FunctionCallbackInfo<v8::Value>& args);
void setY(const v8::FunctionCallbackInfo<v8::Value>&);
// Arguments: job_num, JSON Matrix

void setModelAttributeMatrix(const v8::FunctionCallbackInfo<v8::Value>& args);
void setModelAttributeMatrix(const v8::FunctionCallbackInfo<v8::Value>&);
// Arguments: job_num, attribute name, JSON Matrix

void newJob(const v8::FunctionCallbackInfo<v8::Value>& args);
void newJob(const v8::FunctionCallbackInfo<v8::Value>&);
// Arguments: JSON to be converted to JobOptions_t

void startJob(const v8::FunctionCallbackInfo<v8::Value>& args);
void startJob(const v8::FunctionCallbackInfo<v8::Value>&);
// trains the algorithm associated
// Arguments: function callback, job_id_t job_id
// returns True for success, false for failure.

void checkJob(const v8::FunctionCallbackInfo<v8::Value>&args);
void checkJob(const v8::FunctionCallbackInfo<v8::Value>&);
// Returns a status code for the given jobNum
// Arguments: job_id_t job_id
// Returns -1 on error.

void getJobResult(const v8::FunctionCallbackInfo<v8::Value>&args);
void getJobResult(const v8::FunctionCallbackInfo<v8::Value>&);
// Returns a Matrix of results for the given jobNum
// Arguments: job_id_t job_id
// Returns empty matrix on error.

void cancelJob(const v8::FunctionCallbackInfo<v8::Value>& args);
void getClusteringResult(const v8::FunctionCallbackInfo<v8::Value>&);
// Returns the bi-clustered result for the given jobNum.
// Arguments: int job_id
// Returns empty matrix on error.

void cancelJob(const v8::FunctionCallbackInfo<v8::Value>&);
// cancels the algorithm associated with the given jobNum
// Arguments: job_id_t job_id
// Returns True for success, false on failure.
Expand Down Expand Up @@ -99,6 +104,7 @@ void Init(Handle<Object> exports, Handle<Object> module) {
NODE_SET_METHOD(exports, "checkJob", checkJob);
NODE_SET_METHOD(exports, "cancelJob", cancelJob);
NODE_SET_METHOD(exports, "getJobResult", getJobResult);
NODE_SET_METHOD(exports, "getClusteringResult", getClusteringResult);
NODE_SET_METHOD(exports, "deleteJob", deleteJob);
}

Expand Down
3 changes: 2 additions & 1 deletion src/frontend/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ gulp.task('watch', function () {
var b = browserify({
entries: ['src/index.js'],
cache: {}, packageCache: {},
plugin: [watchify]
plugin: [watchify],
debug: true
})

b.on('update', makeBundle)
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function runAnalysis (data) {
id: json.jobId,
name: data.jobName,
projectId: data.project,
resultsPath: json.resultsPath
resultsPaths: json.resultsPaths
}
dispatch(addActivity(activity))
}).catch(err => console.log('Error: ', err))
Expand Down Expand Up @@ -217,7 +217,7 @@ export function addActivity (activity) {
id: activity.id,
name: activity.name,
projectId: activity.projectId,
resultsPath: activity.resultsPath
resultsPaths: activity.resultsPaths
}
}

Expand Down Expand Up @@ -265,7 +265,7 @@ export function receiveUpdateActivity (activity, response) {
name: activity.name,
progress: response.progress,
projectId: activity.projectId,
resultsPath: activity.resultsPath
resultsPaths: activity.resultsPaths
}
}

Expand Down Expand Up @@ -300,7 +300,7 @@ function requestAnalysisResults(activity) {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
projectId: activity.projectId,
resultsPath: activity.resultsPath
resultsPaths: activity.resultsPaths
})
}

Expand Down
Loading