Skip to content

Commit

Permalink
[PrematureStopping] Style fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
geektoni authored and vigsterkr committed Jul 12, 2017
1 parent 917be87 commit 0b9aeaa
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/shogun/classifier/svm/LibLinear.cpp
Expand Up @@ -78,7 +78,7 @@ CLibLinear::~CLibLinear()

bool CLibLinear::train_machine(CFeatures* data)
{

ASSERT(m_labels)
ASSERT(m_labels->get_label_type() == LT_BINARY)

Expand Down
1 change: 0 additions & 1 deletion src/shogun/classifier/svm/MPDSVM.cpp
Expand Up @@ -79,7 +79,6 @@ bool CMPDSVM::train_machine(CFeatures* data)

bool primalcool;
bool dualcool;


//if (nustop)
//etas[1] = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/classifier/svm/NewtonSVM.cpp
Expand Up @@ -51,7 +51,7 @@ CNewtonSVM::~CNewtonSVM()

bool CNewtonSVM::train_machine(CFeatures* data)
{

ASSERT(m_labels)
ASSERT(m_labels->get_label_type() == LT_BINARY)

Expand Down
2 changes: 0 additions & 2 deletions src/shogun/classifier/svm/OnlineSVMSGD.cpp
Expand Up @@ -100,8 +100,6 @@ bool COnlineSVMSGD::train(CFeatures* data)
if (features->is_seekable())
features->reset_stream();



ELossType loss_type = loss->get_loss_type();
bool is_log_loss = false;
if ((loss_type == L_LOGLOSS) || (loss_type == L_LOGLOSSMARGIN))
Expand Down
1 change: 0 additions & 1 deletion src/shogun/classifier/svm/SGDQN.cpp
Expand Up @@ -137,7 +137,6 @@ bool CSGDQN::train(CFeatures* data)
calibrate();

SG_INFO("Training on %d vectors\n", num_vec)


ELossType loss_type = loss->get_loss_type();
bool is_log_loss = false;
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/classifier/svm/SVMLight.cpp
Expand Up @@ -646,7 +646,7 @@ int32_t CSVMLight::optimize_to_convergence(int32_t* docs, int32_t* label, int32_
#ifdef CYGWIN
for (;((iteration<100 || (!mkl_converged && callback) ) || (retrain && (!terminate))); iteration++){
#else

for (;((!CSignal::cancel_computations()) && ((iteration<3 || (!mkl_converged && callback) ) || (retrain && (!terminate)))); iteration++){
#endif

Expand Down
1 change: 0 additions & 1 deletion src/shogun/classifier/svm/SVMSGD.cpp
Expand Up @@ -109,7 +109,6 @@ bool CSVMSGD::train_machine(CFeatures* data)
calibrate();

SG_INFO("Training on %d vectors\n", num_vec)


ELossType loss_type = loss->get_loss_type();
bool is_log_loss = false;
Expand Down
1 change: 0 additions & 1 deletion src/shogun/classifier/vw/VowpalWabbit.cpp
Expand Up @@ -163,7 +163,6 @@ bool CVowpalWabbit::train_machine(CFeatures* feat)
"loss", "last", "counter", "weight", "label", "predict", "features");
}


features->start_parser();
while (!(CSignal::cancel_computations()) && (env->passes_complete < env->num_passes))
{
Expand Down
4 changes: 0 additions & 4 deletions src/shogun/features/DotFeatures.cpp
Expand Up @@ -63,8 +63,6 @@ void CDotFeatures::dense_dot_range(float64_t* output, int32_t start, int32_t sto
int32_t num_vectors=stop-start;
ASSERT(num_vectors>0)



int32_t num_threads;
int32_t step;
auto pb = progress(range(num_vectors), *this->io);
Expand Down Expand Up @@ -114,8 +112,6 @@ void CDotFeatures::dense_dot_range_subset(int32_t* sub_index, int32_t num, float
ASSERT(sub_index)
ASSERT(output)



auto pb = progress(range(num), *this->io);
int32_t num_threads;
int32_t step;
Expand Down
4 changes: 0 additions & 4 deletions src/shogun/features/hashed/HashedWDFeaturesTransposed.cpp
Expand Up @@ -222,8 +222,6 @@ void CHashedWDFeaturesTransposed::dense_dot_range(float64_t* output, int32_t sta
#endif
ASSERT(num_threads>0)



if (dim != w_dim)
SG_ERROR("Dimensions don't match, vec_len=%d, w_dim=%d\n", dim, w_dim)

Expand Down Expand Up @@ -315,8 +313,6 @@ void CHashedWDFeaturesTransposed::dense_dot_range_subset(int32_t* sub_index, int
#endif
ASSERT(num_threads>0)



if (dim != w_dim)
SG_ERROR("Dimensions don't match, vec_len=%d, w_dim=%d\n", dim, w_dim)

Expand Down
Expand Up @@ -1252,7 +1252,7 @@ void CWeightedDegreePositionStringKernel::compute_batch(

if (num_threads < 2)
{

auto pb = progress(range(num_feat), *this->io);
for (int32_t j=0; j<num_feat && !CSignal::cancel_computations(); j++)
{
Expand Down Expand Up @@ -1281,7 +1281,6 @@ void CWeightedDegreePositionStringKernel::compute_batch(
else
{


auto pb = progress(range(num_feat), *this->io);
for (int32_t j=0; j<num_feat && !CSignal::cancel_computations(); j++)
{
Expand Down
4 changes: 2 additions & 2 deletions src/shogun/kernel/string/WeightedDegreeStringKernel.cpp
Expand Up @@ -884,7 +884,7 @@ void CWeightedDegreeStringKernel::compute_batch(

if (num_threads < 2)
{

for (int32_t j=0; j<num_feat && !CSignal::cancel_computations(); j++)
{
init_optimization(num_suppvec, IDX, alphas, j);
Expand All @@ -909,7 +909,7 @@ void CWeightedDegreeStringKernel::compute_batch(
#ifdef HAVE_PTHREAD
else
{

for (int32_t j=0; j<num_feat && !CSignal::cancel_computations(); j++)
{
init_optimization(num_suppvec, IDX, alphas, j);
Expand Down
51 changes: 24 additions & 27 deletions src/shogun/lib/Signal.cpp
Expand Up @@ -12,29 +12,27 @@

#include <stdlib.h>

#include <shogun/io/SGIO.h>
#include <shogun/lib/Signal.h>
#include <shogun/base/init.h>
#include <rxcpp/rx-includes.hpp>
#include <rxcpp/rx.hpp>
#include <shogun/base/init.h>
#include <shogun/io/SGIO.h>
#include <shogun/lib/Signal.h>

using namespace shogun;
using namespace rxcpp;

int CSignal::signals[NUMTRAPPEDSIGS]={SIGINT, SIGURG};
struct sigaction CSignal::oldsigaction[NUMTRAPPEDSIGS];

rxcpp::connectable_observable<int> CSignal::m_sigint_observable = rxcpp::observable<>::create<int>(
[](rxcpp::subscriber<int> s){
s.on_completed();
}
).publish();
rxcpp::connectable_observable<int> CSignal::m_sigint_observable =
rxcpp::observable<>::create<int>([](rxcpp::subscriber<int> s) {
s.on_completed();
}).publish();

rxcpp::connectable_observable<int> CSignal::m_sigurg_observable = rxcpp::observable<>::create<int>(
[](rxcpp::subscriber<int> s){
s.on_next(1);
}
).publish();
rxcpp::connectable_observable<int> CSignal::m_sigurg_observable =
rxcpp::observable<>::create<int>([](rxcpp::subscriber<int> s) {
s.on_next(1);
}).publish();

CSignal::CSignal()
: CSGObject()
Expand All @@ -43,8 +41,7 @@ CSignal::CSignal()
m_active = true;
}

CSignal::CSignal(bool active)
: CSGObject()
CSignal::CSignal(bool active) : CSGObject()
{
// Set if the signal handler is active or not
m_active = active;
Expand All @@ -68,22 +65,22 @@ void CSignal::handler(int signal)
{
if (signal == SIGINT)
{
//SG_SPRINT("\nImmediately return to prompt / Prematurely finish computations / Do nothing (I/P/D)? ")
//char answer=fgetc(stdin);
// SG_SPRINT("\nImmediately return to prompt / Prematurely finish
// computations / Do nothing (I/P/D)? ")
// char answer=fgetc(stdin);
/*switch (answer){
case 'I':
m_sigint_observable.connect();
break;
case 'P':
m_sigurg_observable.connect();
break;
default:
SG_SPRINT("Continuing...\n")
break;
case 'I':
m_sigint_observable.connect();
break;
case 'P':
m_sigurg_observable.connect();
break;
default:
SG_SPRINT("Continuing...\n")
break;
}*/
SG_SPRINT("Killing the application...\n");
m_sigint_observable.connect();

}
else if (signal == SIGURG)
m_sigurg_observable.connect();
Expand Down
4 changes: 1 addition & 3 deletions src/shogun/lib/Signal.h
Expand Up @@ -11,8 +11,8 @@
#ifndef __SIGNAL__H_
#define __SIGNAL__H_

#include <shogun/lib/config.h>
#include <rxcpp/rx-includes.hpp>
#include <shogun/lib/config.h>

#if defined(__MINGW64__) || defined(_MSC_VER)
typedef unsigned long sigset_t;
Expand Down Expand Up @@ -74,7 +74,6 @@ namespace shogun
class CSignal : public CSGObject
{
public:

CSignal();
CSignal(bool active);
virtual ~CSignal();
Expand Down Expand Up @@ -110,7 +109,6 @@ class CSignal : public CSGObject
virtual const char* get_name() const { return "Signal"; }

private:

/** signals; handling external lib */
static int signals[NUMTRAPPEDSIGS];

Expand Down
4 changes: 0 additions & 4 deletions src/shogun/machine/KernelMachine.cpp
Expand Up @@ -298,8 +298,6 @@ SGVector<float64_t> CKernelMachine::apply_get_outputs(CFeatures* data)
{
SG_DEBUG("computing output on %d test examples\n", num_vectors)



if (io->get_show_progress())
io->enable_progress();
else
Expand Down Expand Up @@ -495,8 +493,6 @@ SGVector<float64_t> CKernelMachine::apply_locked_get_output(
int32_t num_inds=indices.vlen;
SGVector<float64_t> output(num_inds);



if (io->get_show_progress())
io->enable_progress();
else
Expand Down
3 changes: 0 additions & 3 deletions src/shogun/multiclass/KNN.cpp
Expand Up @@ -181,7 +181,6 @@ CMulticlassLabels* CKNN::apply_multiclass(CFeatures* data)
SGVector<int32_t> train_lab(m_k);

SG_INFO("%d test examples\n", num_lab)


//histogram of classes and returned output
SGVector<float64_t> classes(m_num_classes);
Expand All @@ -207,7 +206,6 @@ CMulticlassLabels* CKNN::classify_NN()
SGVector<float64_t> distances(m_train_labels.vlen);

SG_INFO("%d test examples\n", num_lab)


distance->precompute_lhs();

Expand Down Expand Up @@ -262,7 +260,6 @@ SGMatrix<int32_t> CKNN::classify_for_multiple_k()
SGVector<int32_t> classes(m_num_classes);

SG_INFO("%d test examples\n", num_lab)


init_solver(m_knn_solver);

Expand Down
2 changes: 0 additions & 2 deletions src/shogun/multiclass/LaRank.cpp
Expand Up @@ -619,8 +619,6 @@ bool CLaRank::train_machine(CFeatures* data)
ASSERT(m_labels && m_labels->get_num_labels())
ASSERT(m_labels->get_label_type() == LT_MULTICLASS)



if (data)
{
if (data->get_num_vectors() != m_labels->get_num_labels())
Expand Down
2 changes: 0 additions & 2 deletions src/shogun/multiclass/MulticlassLibLinear.cpp
Expand Up @@ -121,8 +121,6 @@ bool CMulticlassLibLinear::train_machine(CFeatures* data)
for (int32_t i=0; i<num_vectors; i++)
C[i] = m_C;



Solver_MCSVM_CS solver(&mc_problem,num_classes,C,w0.matrix,m_epsilon,
m_max_iter,m_max_train_time,m_train_state);
solver.solve();
Expand Down
1 change: 0 additions & 1 deletion src/shogun/optimization/liblinear/tron.cpp
Expand Up @@ -104,7 +104,6 @@ void CTron::tron(float64_t *w, float64_t max_train_time)

iter = 1;


CTime start_time;
auto pb = progress(range(10));

Expand Down
1 change: 0 additions & 1 deletion src/shogun/regression/svr/LibLinearRegression.cpp
Expand Up @@ -58,7 +58,6 @@ CLibLinearRegression::~CLibLinearRegression()

bool CLibLinearRegression::train_machine(CFeatures* data)
{


if (data)
set_features((CDotFeatures*)data);
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/transfer/multitask/LibLinearMTL.cpp
Expand Up @@ -72,7 +72,7 @@ CLibLinearMTL::~CLibLinearMTL()

bool CLibLinearMTL::train_machine(CFeatures* data)
{

ASSERT(m_labels)

if (data)
Expand Down
23 changes: 11 additions & 12 deletions tests/unit/lib/Signal_unittest.cc
@@ -1,21 +1,20 @@
#include <gtest/gtest.h>
#include <shogun/lib/Signal.h>
#include <rxcpp/rx.hpp>
#include <shogun/lib/Signal.h>

#include <csignal>

using namespace shogun;
using namespace rxcpp;


TEST(Signal, SIGINT_test) {
TEST(Signal, SIGINT_test)
{

CSignal tmp;
int on_next_v=0;
int on_complete_v=0;
int on_next_v = 0;
int on_complete_v = 0;
auto sub = rxcpp::make_subscriber<int>(
[&on_next_v](int v) {on_next_v=1;}, [&]() {on_complete_v=1;}
);
[&on_next_v](int v) { on_next_v = 1; }, [&]() { on_complete_v = 1; });

tmp.get_SIGINT_observable().subscribe(sub);

Expand All @@ -25,14 +24,14 @@ TEST(Signal, SIGINT_test) {
EXPECT_TRUE(on_complete_v == 1);
}

TEST(Signal, SIGURG_test) {
TEST(Signal, SIGURG_test)
{

CSignal tmp;
int on_next_v=0;
int on_complete_v=0;
int on_next_v = 0;
int on_complete_v = 0;
auto sub = rxcpp::make_subscriber<int>(
[&](int v) {on_next_v++;}, [&]() {on_complete_v++;}
);
[&](int v) { on_next_v++; }, [&]() { on_complete_v++; });

tmp.get_SIGURG_observable().subscribe(sub);

Expand Down

0 comments on commit 0b9aeaa

Please sign in to comment.