Skip to content

Commit

Permalink
fix the meta test and some confilcts
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeLing authored and vigsterkr committed Feb 22, 2018
1 parent d5a5d2b commit 9da37a2
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 27 deletions.
12 changes: 6 additions & 6 deletions examples/meta/generator/translate.py
Expand Up @@ -81,7 +81,7 @@ def getSGTypesToStore():
def getSGTypeToStoreMethodName(sgType):
""" Translates given SG* type into meta language type """
assert sgType in getSGTypesToStore()

if sgType=="RealVector":
return "real_vector"
elif sgType=="FloatVector":
Expand All @@ -90,10 +90,10 @@ def getSGTypeToStoreMethodName(sgType):
return "real_matrix"
elif sgType=="FloatMatrix":
return "float_matrix"

else:
raise RuntimeError("Given Shogun type \"%s\" cannot be translated to meta type", sgType)


def getVarsToStore(program):
""" Extracts all variables in program that should be stored """
Expand Down Expand Up @@ -489,7 +489,7 @@ def translateInit(self, init):
)

normalArgs = [
arg for arg in initialisation["ArgumentList"]
arg for arg in initialisation["ArgumentList"]
if not "KeywordArgument" in arg
]
kwargsString = self.translateKwargs(
Expand Down Expand Up @@ -560,7 +560,7 @@ def translateExpr(self, expr, returnKwargs=False):
elif key == "StringLiteral":
template = Template(self.targetDict["Expr"]["StringLiteral"])
return template.substitute(literal=expr[key])

elif key == "CharLiteral":
template = Template(self.targetDict["Expr"]["CharLiteral"])
return template.substitute(literal=expr[key])
Expand Down Expand Up @@ -651,7 +651,7 @@ def translateGlobalCall(self, globalCall, returnKwargs):
)

normalArgs = [
arg for arg in argsList["ArgumentList"]
arg for arg in argsList["ArgumentList"]
if not "KeywordArgument" in arg
]
kwargsString = self.translateKwargs(
Expand Down
2 changes: 1 addition & 1 deletion examples/meta/src/clustering/gaussian_mixture_models.sg
@@ -1,6 +1,6 @@
CSVFile f_feats_train("../../data/classifier_4class_2d_linear_features_train.dat")

Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features_train(f_feats_train)
Expand Down
2 changes: 1 addition & 1 deletion examples/meta/src/clustering/kmeans.sg
@@ -1,5 +1,5 @@
CSVFile f_feats_train("../../data/classifier_binary_2d_linear_features_train.dat")
Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features_train(f_feats_train)
Expand Down
@@ -1,6 +1,6 @@
CSVFile f_feats("../../data/ica_2_sources.dat")

Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features(f_feats)
Expand Down
@@ -1,6 +1,6 @@
CSVFile f_feats("../../data/ica_2_sources.dat")

Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features(f_feats)
Expand Down
@@ -1,6 +1,6 @@
CSVFile f_feats("../../data/ica_2_sources.dat")

Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features(f_feats)
Expand Down
@@ -1,6 +1,6 @@
CSVFile f_feats("../../data/ica_2_sources.dat")

Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features(f_feats)
Expand Down
@@ -1,6 +1,6 @@
CSVFile f_feats("../../data/ica_2_sources.dat")

Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features(f_feats)
Expand Down
2 changes: 1 addition & 1 deletion examples/meta/src/gaussian_process/classifier.sg
Expand Up @@ -2,7 +2,7 @@ CSVFile f_feats_train("../../data/classifier_4class_2d_linear_features_train.dat
CSVFile f_feats_test("../../data/classifier_4class_2d_linear_features_test.dat")
CSVFile f_labels_train("../../data/classifier_4class_2d_linear_labels_train.dat")
CSVFile f_labels_test("../../data/classifier_4class_2d_linear_labels_test.dat")
Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features_train(f_feats_train)
Expand Down
4 changes: 3 additions & 1 deletion examples/meta/src/meta_api/calls.sg
@@ -1,9 +1,11 @@
# static call
Math:init_random(1)
# Math:init_random(1)

# global function call
get_global_io()

set_global_seed(1)

# member function call
GaussianKernel k()
k.set_width(1)
2 changes: 1 addition & 1 deletion examples/meta/src/multiclass/cartree.sg
Expand Up @@ -2,7 +2,7 @@ CSVFile f_feats_train("../../data/classifier_4class_2d_linear_features_train.dat
CSVFile f_feats_test("../../data/classifier_4class_2d_linear_features_test.dat")
CSVFile f_labels_train("../../data/classifier_4class_2d_linear_labels_train.dat")
CSVFile f_labels_test("../../data/classifier_4class_2d_linear_labels_test.dat")
Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features_train(f_feats_train)
Expand Down
2 changes: 1 addition & 1 deletion examples/meta/src/multiclass/ecoc_random.sg
@@ -1,4 +1,4 @@
Math:init_random(1)
set_global_seed(1)

CSVFile f_feats_train("../../data/classifier_4class_2d_linear_features_train.dat")
CSVFile f_feats_test("../../data/classifier_4class_2d_linear_features_test.dat")
Expand Down
2 changes: 1 addition & 1 deletion examples/meta/src/multiclass/random_forest.sg
Expand Up @@ -2,7 +2,7 @@ CSVFile f_feats_train("../../data/classifier_4class_2d_linear_features_train.dat
CSVFile f_feats_test("../../data/classifier_4class_2d_linear_features_test.dat")
CSVFile f_labels_train("../../data/classifier_4class_2d_linear_labels_train.dat")
CSVFile f_labels_test("../../data/classifier_4class_2d_linear_labels_test.dat")
Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features_train(f_feats_train)
Expand Down
Expand Up @@ -3,7 +3,7 @@ CSVFile f_feats_test("../../data/classifier_binary_2d_nonlinear_features_test.da
CSVFile f_labels_train("../../data/classifier_binary_2d_nonlinear_labels_train.dat")
CSVFile f_labels_test("../../data/classifier_binary_2d_nonlinear_labels_test.dat")

Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features_train(f_feats_train)
Expand Down
Expand Up @@ -3,7 +3,7 @@ CSVFile f_feats_test("../../data/regression_1d_sinc_features_test_with_9d_noise.
CSVFile f_labels_train("../../data/regression_1d_sinc_labels_train.dat")
CSVFile f_labels_test("../../data/regression_1d_sinc_labels_test.dat")

Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features_train(f_feats_train)
Expand Down
2 changes: 1 addition & 1 deletion examples/meta/src/regression/random_forest_regression.sg
Expand Up @@ -2,7 +2,7 @@ CSVFile f_feats_train("../../data/regression_1d_linear_features_train.dat")
CSVFile f_feats_test("../../data/regression_1d_linear_features_test.dat")
CSVFile f_labels_train("../../data/regression_1d_linear_labels_train.dat")
CSVFile f_labels_test("../../data/regression_1d_linear_labels_test.dat")
Math:init_random(1)
set_global_seed(1)

#![create_features]
RealFeatures features_train(f_feats_train)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/environments/RegressionTestEnvironment.h
Expand Up @@ -54,7 +54,7 @@ class RegressionTestEnvironment : public ::testing::Environment
public:
virtual void SetUp()
{
sg_rand->set_seed(57);
set_global_seed(57);

SGMatrix<float64_t> feat_train_data =
CDataGenerator::generate_gaussians(n_train, 1, n_dim);
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/lib/DynamicArray_unittest.cc
Expand Up @@ -62,9 +62,10 @@ TYPED_TEST(CDynamicArrayFixture, set_array)
this->wrapper_array->reset_array();
EXPECT_EQ(this->wrapper_array->get_num_elements(), 0);
TypeParam* array = SG_MALLOC(TypeParam, 5);
auto prng = std::unique_ptr<CRandom>(new CRandom());
for (int32_t i = 0; i < 5; i++)
{
array[i] = (TypeParam)CMath::random(1, 10);
array[i] = (TypeParam)prng->random(1, 10);
}
this->wrapper_array->set_array(array, 5);

Expand All @@ -79,9 +80,10 @@ TYPED_TEST(CDynamicArrayFixture, set_array)
TYPED_TEST(CDynamicArrayFixture, const_set_array)
{
TypeParam* array = SG_MALLOC(TypeParam, 5);
auto prng = std::unique_ptr<CRandom>(new CRandom());
for (int32_t i = 0; i < 5; i++)
{
array[i] = (TypeParam)CMath::random(1, 10);
array[i] = (TypeParam)prng->random(1, 10);
}
const TypeParam* const_array = array;
this->wrapper_array->reset_array();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/statistical_testing/KernelSelection_unittest.cc
Expand Up @@ -320,7 +320,7 @@ TEST(KernelSelectionMaxCrossValidation, quadratic_time_single_kernel_dense)
mmd->set_train_test_mode(false);

auto selected_kernel=static_cast<CGaussianKernel*>(mmd->get_kernel());
EXPECT_NEAR(selected_kernel->get_width(), 0.03125, 1E-10);
EXPECT_NEAR(selected_kernel->get_width(), 0.125, 1E-10);
}

TEST(KernelSelectionMaxCrossValidation, linear_time_single_kernel_dense)
Expand Down
Expand Up @@ -62,6 +62,7 @@ TEST(CrossValidationMMD, biased_full)
const float64_t difference=0.5;
const float64_t alpha=0.05;
const auto stype=ST_BIASED_FULL;
set_global_seed(12345);

auto gen_p=some<CMeanShiftDataGenerator>(0, dim, 0);
auto gen_q=some<CMeanShiftDataGenerator>(difference, dim, 0);
Expand Down Expand Up @@ -92,7 +93,6 @@ TEST(CrossValidationMMD, biased_full)
cv.m_num_runs=num_runs;
cv.m_rejections=SGMatrix<float64_t>(num_runs*num_folds, num_kernels);

set_global_seed(12345);
cv(kernel_mgr);
kernel_mgr.unset_precomputed_distance();

Expand All @@ -106,7 +106,6 @@ TEST(CrossValidationMMD, biased_full)
permutation_mmd.m_stype=stype;
permutation_mmd.m_num_null_samples=num_null_samples;

set_global_seed(12345);
for (auto k=0; k<num_kernels; ++k)
{
CKernel* kernel=kernel_mgr.kernel_at(k);
Expand Down

0 comments on commit 9da37a2

Please sign in to comment.