Permalink
Browse files

Merge branch 'release/0.2.0'

  • Loading branch information...
kuenishi committed Feb 17, 2012
2 parents 3646d09 + 1e4b7f7 commit 6dcaaa12269b103949af045815d05c5a85c5d51f
Showing 332 changed files with 12,095 additions and 2,772 deletions.
File renamed without changes.
File renamed without changes.
@@ -23,7 +23,7 @@
#include <cmath>
#include <iostream>
#include <stdint.h>
-#include "../../common/type.hpp"
+#include "../common/type.hpp"
#include "../storage/storage_base.hpp"
#include "classifier_type.hpp"
@@ -40,6 +40,9 @@ TYPED_TEST_CASE_P(classifier_test);
TYPED_TEST_P(classifier_test, trivial) {
local_storage s;
TypeParam p(&s);
+ ASSERT_NE(p.name(), "");
+ p.set_C(1.0);
+ ASSERT_EQ(p.C(), 1.0);
sfv_t fv;
fv.push_back(make_pair(string("f1"), 1.0));
p.train(fv, string("label1"));
@@ -50,6 +53,21 @@ TYPED_TEST_P(classifier_test, trivial) {
ASSERT_EQ(2u, scores.size());
}
+TYPED_TEST_P(classifier_test, sfv_err) {
+ local_storage s;
+ TypeParam p(&s);
+ sfv_t fv;
+ fv.push_back(make_pair(string("f1"), 0.0));
+ p.train(fv, string("label1"));
+ fv.push_back(make_pair(string("f2"), 1.0));
+ p.train(fv, string("label2"));
+ classify_result scores;
+ p.classify_with_scores(fv, scores);
+ ASSERT_EQ(1u, scores.size());
+// <FIXME>why not
+// ASSERT_EQ(2u, scores.size());
+}
+
sfv_t convert(vector<double>& v) {
sfv_t fv;
for (size_t i = 0; i < v.size(); ++i) {
@@ -100,7 +118,7 @@ TYPED_TEST_P(classifier_test, random3) {
}
REGISTER_TYPED_TEST_CASE_P(classifier_test,
- trivial, random, random3);
+ trivial, sfv_err, random, random3);
typedef testing::Types<perceptron, PA, PA1, PA2, CW, AROW, NHERD> classifier_types;
@@ -24,36 +24,22 @@
#include <string>
#include <iostream>
#include <algorithm>
-
-static const double PI = 6 * std::asin(0.5);
-
-float rand_float() {
- return rand() / float(RAND_MAX);
-
-}
-
-float rand_normal() {
- float alpha = rand_float();
- float beta = rand_float();
- return std::sqrt(-2 * std::log(alpha)) * std::sin(2 * PI * beta);
-}
-
-float rand_normal(float mu, float sigma) {
- return mu + rand_normal() * sigma;
-}
+#include <pficommon/math/random.h>
void make_random(float mu, float sigma, size_t dim,
std::vector<double>& v) {
+ pfi::math::random::mtrand rand(0);
for (size_t i = 0; i < dim; i++) {
- float value = rand_normal(mu, sigma);
+ float value = rand.next_gaussian(mu, sigma);
v.push_back(value);
}
}
void make_random(const std::vector<float>& mus, float sigma, size_t dim,
std::vector<double>& v) {
+ pfi::math::random::mtrand rand(0);
for (size_t i = 0; i < dim; i++) {
- float value = rand_normal(mus[i % mus.size()], sigma);
+ float value = rand.next_gaussian(mus[i % mus.size()], sigma);
v.push_back(value);
}
}
File renamed without changes.
File renamed without changes.
@@ -26,6 +26,7 @@ namespace jubatus{
NHERD::NHERD (storage::storage_base* storage) : classifier_base(storage) {
classifier_base::use_covars_ = true;
+ set_C(0.1f);
}
void NHERD::train(const sfv_t& sfv, const string& label){
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -15,8 +15,8 @@ def build(bld):
nherd.cpp
classifier_factory.cpp
''',
- target = 'jubaclassifier',
- name = 'jubaclassifier',
+ target = 'jubatus_classifier',
+ name = 'jubatus_classifier',
includes = '.',
use = 'PFICOMMON')
@@ -28,4 +28,4 @@ def build(bld):
],
target = "classifier_test",
includes = '.',
- use = 'jubaclassifier jubastorage')
+ use = 'jubatus_classifier jubastorage')
View
@@ -1,73 +0,0 @@
-// Jubatus: Online machine learning framework for distributed environment
-// Copyright (C) 2011 Preferred Infrastracture and Nippon Telegraph and Telephone Corporation.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-#include "../server/classifier_rpc.hpp"
-#include "../jubakeeper/rpc.hpp"
-#include "accessor.hpp"
-
-#include <pficommon/network/mprpc.h>
-#include <pficommon/data/string/utility.h>
-#include <pficommon/lang/cast.h>
-
-#include <vector>
-#include <exception>
-#include <iostream>
-#include <string>
-#include <cstdlib>
-#include <ctime>
-
-using namespace std;
-
-namespace jubatus {
-namespace client {
-
-void parse_hostnames(const string& hosts, vector<connection_info>& out)
-{
- out.clear();
- string tmp(hosts);
-
- vector<string> hs = pfi::data::string::split(hosts, string(","));
- for (size_t i = 0; i < hs.size(); ++i) {
- vector<string> ps = pfi::data::string::split(hs[i], string(":"));
- out.push_back(make_pair(ps[0], pfi::lang::lexical_cast<int>(ps[1])));
- }
-}
-
-
-accessor::accessor(const string& hosts, double timeout)
- : timeout_(timeout) {
- parse_hostnames(hosts, servers_);
- if (servers_.empty())
- throw runtime_error("no servers to connect.");
-};
-
-accessor::~accessor()
-{
-}
-
-void accessor::find_one(connection_info &ret)
-{
- ret = servers_[rng_(servers_.size())];
-}
-
-void accessor::find_two(const string& key, vector<connection_info>& out){
- out = servers_;
-}
-
-}
-}
-
View
@@ -1,108 +0,0 @@
-// Jubatus: Online machine learning framework for distributed environment
-// Copyright (C) 2011 Preferred Infrastracture and Nippon Telegraph and Telephone Corporation.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-#pragma once
-
-#include <string>
-#include <map>
-
-#include <pficommon/math/random.h>
-
-#include "../jubakeeper/rpc.hpp"
-
-namespace jubatus {
-namespace client {
-
-void parse_hostnames(const std::string& hosts,
- std::vector<connection_info>& out);
-
-class accessor {
-public:
- accessor(const std::string &hosts, double timeout);
- ~accessor();
-
- void find_one(connection_info &);
- void find_two(const std::string&, std::vector<connection_info>& );
-
- const std::vector<connection_info> &servers() const {
- return servers_;
- }
-
- template <typename R, typename F>
- R merge_all(F func) {
- R ret;
- for (size_t i = 0; i < servers_.size(); ++i) {
- result<R> s = func(servers_[i]);
- if (!s.success) {
- throw std::runtime_error(s.error);
- } else {
- ret.insert(s.retval.begin(), s.retval.end());
- }
- }
- return ret;
- }
-
- template <typename F>
- void for_all(F func) {
- for (size_t i = 0; i < servers_.size(); ++i) {
- result<int> r = func(servers_[i]);
- if (!r.success) {
- throw std::runtime_error(r.error);
- }
- }
- }
-
- template <typename R, typename C, typename F>
- R for_one(F func, double timeout) {
- connection_info con;
- find_one(con);
- //C client(con.first, con.second, timeout);
- //result<R> res = func(&client);
- result<R> res = func(con);
- if (!res.success) {
- throw std::runtime_error(res.error);
- } else {
- return res.retval;
- }
- }
-
-private:
- void get_servers();
-
- double timeout_;
- std::vector<connection_info> servers_;
-
- pfi::math::random::mtrand rng_;
-};
-
-template <typename T>
-inline T return_or_throw(const result<T>& res) {
- if (!res.success) {
- throw std::runtime_error(res.error);
- } else {
- return res.retval;
- }
-}
-
-inline void check_throw(const result<int>& res) {
- if (!res.success) {
- throw std::runtime_error(res.error);
- }
-}
-
-}
-}
Oops, something went wrong.

0 comments on commit 6dcaaa1

Please sign in to comment.