Skip to content

Commit

Permalink
Merge branch 'feature/function_separation' into develop
Browse files Browse the repository at this point in the history
* feature/function_separation:
  bug fixes
  cmakelists update
  typo fix
  bug fix
  • Loading branch information
Zheng SHAO committed Dec 11, 2015
2 parents 008bbe2 + b2f9325 commit 25566fd
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 25 deletions.
5 changes: 2 additions & 3 deletions GLP/Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set_target_properties(gspan_pls_static PROPERTIES LINK_FLAGS "-static")
ENDIF()

install_targets(/bin gspan)
install_targets(/bin gspan_static)
install_targets(/bin gspan_pls_static)
install(TARGETS gspan gspan_static gspan_pls_static
RUNTIME DESTINATION bin)

add_subdirectory(gspls)
8 changes: 3 additions & 5 deletions GLP/Examples/gspls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set_target_properties(gspls-classify-static PROPERTIES LINK_FLAGS "-static")
ENDIF()

install_programs(/bin gspls)
install_targets(/bin gspls-train)
install_targets(/bin gspls-train-static)
install_targets(/bin gspls-classify)
install_targets(/bin gspls-classify-static)
install(PROGRAMS gspls DESTINATION bin)
install(TARGETS gspls-train gspls-train-static gspls-classify gspls-classify-static
RUNTIME DESTINATION bin)
6 changes: 2 additions & 4 deletions GLP/Examples/gspls/gspls-train-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ string usage()
"gspls-train is a part of GLP v1.0\n\n"
" Usage: gspls-train [options] [gsp file]\n\n"
" Options: \n"
" [--reg | --cla] regression or classification mode\n"
" [--reg | --cla] regression or classification mode, default: regression\n"
" [-m] min frequency of common graphs, default: 2\n"
" [-L] max graph size for gspan mining, default: 10\n"
" [-n] max iterator number, default: 100\n"
Expand Down Expand Up @@ -77,12 +77,10 @@ int main(int argc, char* argv[])
train->gspanResult = train->gspan(selectedCol);

// spls
cout << "Train" << endl;
MatrixXd features = get<MatrixXd>(train->gspanResult[SLGraphMiningResultTypeX]);
train->splsResult = train->spls(features);

// overfit detection
cout << "Validation" << endl;
vector<Rule> rules = get< vector<Rule> >(train->gspanResult[SLGraphMiningResultTypeRules]);

if (train->isOverfit(rules)){
Expand All @@ -97,7 +95,7 @@ int main(int argc, char* argv[])
train->timeEnd();

// write result to file
size_t best = i - param->resultHist.length;
size_t best = i == param->n ? i : i - param->resultHist.length;
train->saveResults(best);

return 0;
Expand Down
28 changes: 19 additions & 9 deletions GLP/Examples/gspls/gspls-train.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ time_duration SLGsplsTrain::timeDuration()
return time_duration(_timeEnd - _timeStart);
}

void SLGsplsTrain::setFileSuffix(string suffix)
void SLGsplsTrain::setFilePrefix(string prefix)
{
_fileSuffix = suffix;
_filePrefix = prefix;
}

SLGsplsTrain* SLGsplsTrain::initWithParam(TrainParameters& param)
Expand Down Expand Up @@ -217,11 +217,14 @@ SLGsplsTrain* SLGsplsTrain::initWithParam(TrainParameters& param)
// load train gsp file
if (param.respFile != NULL)
EigenExt::loadMatrixFromFile(train->_trainRespMat, train->_param.respFile);

else
train->_trainRespMat = get<MatrixXd>(train->_gspls->getInnerValues(SLGraphMiningInnerValueY)[SLGraphMiningInnerValueY]);

// calculate valid data length
if (param.validLength < 0){
param.validLength = floor(train->_trainRespMat.rows() * VALID_RATIO);
}

// setup response data
train->_validRespMat = train->_trainRespMat.bottomRows(param.validLength);
train->_trainRespMat = train->_trainRespMat.topRows(train->_trainRespMat.rows() - param.validLength);
Expand All @@ -246,15 +249,15 @@ SLGsplsTrain* SLGsplsTrain::initWithParam(TrainParameters& param)
// graph changed, rebuild dfs tree;
trainGspan.rebuildDFSTree();

// outout file suffix
string suffix = (format("gspls_m%d_L%d_n%d_k%d_t%d_") %
// outout file prefix
string prefix = (format("gspls_m%d_L%d_n%d_k%d_t%d_") %
param.minsup %
param.maxpat %
param.n %
param.topk %
param.resultHist.length
).str();
train->setFileSuffix(suffix);
train->setFilePrefix(prefix);
return train;
}

Expand All @@ -267,6 +270,8 @@ SLGraphMiningResult SLGsplsTrain::gspan(MatrixXd& selectedColumn)

SLModelResult SLGsplsTrain::spls(MatrixXd& feature)
{
cout << "Train" << endl;

SLModelResult result = _gspls->train(feature, _trainRespMat, _param.mode->getResultType());

long rows = feature.rows();
Expand All @@ -288,6 +293,11 @@ bool SLGsplsTrain::isOverfit(vector<Rule> rules)
{
_param.resultHist.push_front(make_pair(gspanResult, splsResult));

// do not detect overfit if validation data was not been set
if (_param.validLength == 0) return false;

cout << "Validation" << endl;

MatrixXd result(_validTransaction.size(), rules.size());
_validGspan->buildDarts(rules);
for (size_t i = 0; i < _validTransaction.size(); ++i) {
Expand Down Expand Up @@ -321,10 +331,10 @@ void SLGsplsTrain::saveResults(size_t index)
resultPair = _param.resultHist.back();

// best index
cout << "Best: n = " << index << endl;
cout << "Best: n = " << best << endl;

// beta
ofstream outBeta((_fileSuffix+"Beta.txt").c_str(), ios::out);
ofstream outBeta((_filePrefix+"Beta.txt").c_str(), ios::out);
outBeta.precision(12);
outBeta.flags(ios::left);
outBeta << resultPair.second[SLModelResultTypeBeta] << endl;
Expand All @@ -333,7 +343,7 @@ void SLGsplsTrain::saveResults(size_t index)
// dfs
cout << "DFS" << endl;
vector<Rule> DFSes = get< vector<Rule> >(resultPair.first[SLGraphMiningResultTypeRules]);
ofstream outDFS((_fileSuffix+"DFS.txt").c_str(), ios::out);
ofstream outDFS((_filePrefix+"DFS.txt").c_str(), ios::out);
for ( size_t i = 0; i < DFSes.size(); ++i )
{
cout << DFSes[i].dfs << endl;
Expand Down
4 changes: 2 additions & 2 deletions GLP/Examples/gspls/gspls-train.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class SLGsplsTrain
bool _isOverfit;

ptime _timeStart, _timeEnd;
string _fileSuffix;
string _filePrefix;

SLGlpProduct<SLSparsePls, SLGspan>* _gspls;

Expand All @@ -154,7 +154,7 @@ class SLGsplsTrain
void timeEnd();
time_duration timeDuration();

void setFileSuffix(string);
void setFilePrefix(string);

MatrixXd& getTrainMat();
MatrixXd& getTrainRespMat();
Expand Down
4 changes: 3 additions & 1 deletion GLP/Library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ add_library(glp_static STATIC ${SOURCES})
set_target_properties(glp_static PROPERTIES OUTPUT_NAME "glp")
set_target_properties(glp_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)

install_targets(/lib glp glp_static)
install(TARGETS glp glp_static
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION include
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Eigen 3.1.2 or higher.
Boost 1.4.2 or higher.

# Installation
make
make
make install

# License
Expand Down

0 comments on commit 25566fd

Please sign in to comment.