Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
KUMAZAKI Hiroki committed Mar 19, 2015
1 parent 39a3fb2 commit cb1aee4
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions jubatus/core/driver/recommender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ void recommender::unpack(msgpack::object o) {
wm_.get_model()->unpack(o.via.array.ptr[1]);
}

void recommender::import_model(common::byte_buffer& from) const {

}
common::byte_buffer recommender::export_model() const {
}

} // namespace driver
} // namespace core
} // namespace jubatus
3 changes: 3 additions & 0 deletions jubatus/core/driver/recommender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class recommender : public driver_base {
fv_converter::datum decode_row(const std::string& id);
std::vector<std::string> get_all_rows();

void import_model(common::byte_buffer& from) const;
common::byte_buffer export_model() const;

private:
jubatus::util::lang::shared_ptr<fv_converter::datum_to_fv_converter>
converter_;
Expand Down
11 changes: 11 additions & 0 deletions jubatus/core/unlearner/lru_unlearner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "../fv_converter/key_matcher.hpp"
#include "../fv_converter/key_matcher_factory.hpp"
#include "../common/exception.hpp"
#include "../common/unordered_set.hpp"

using jubatus::util::data::unordered_set;
using jubatus::core::fv_converter::key_matcher_factory;
Expand Down Expand Up @@ -126,6 +127,16 @@ bool lru_unlearner::exists_in_memory(const std::string& id) const {
return entry_map_.count(id) > 0 || sticky_ids_.count(id) > 0;
}

void lru_unlearner::import_model(msgpack::object o) {
this->clear();
msgpack::type::make_define(lru_).msgpack_unpack(o);
for (lru::iterator it = lru_.begin();
it != lru_.end();
++it) {
entry_map_[*it] = it;
}
}

// private

void lru_unlearner::rebuild_entry_map() {
Expand Down
7 changes: 6 additions & 1 deletion jubatus/core/unlearner/lru_unlearner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "jubatus/util/data/optional.h"
#include "jubatus/util/lang/shared_ptr.h"
#include "unlearner_base.hpp"
#include "../common/porting_model.hpp"
#include "../common/unordered_map.hpp"

namespace jubatus {
namespace core {
Expand Down Expand Up @@ -54,7 +56,6 @@ class lru_unlearner : public unlearner_base {
void clear() {
lru_.clear();
entry_map_.clear();
sticky_ids_.clear();
}

explicit lru_unlearner(const config& conf);
Expand All @@ -64,6 +65,10 @@ class lru_unlearner : public unlearner_base {
bool remove(const std::string& id);
bool exists_in_memory(const std::string& id) const;

JUBATUS_EXPORT_MODEL(lru_);
// CAUTION!: JUBATUS_IMPORT_MODEL should be hand-written
void import_model(msgpack::object o);

private:
typedef std::list<std::string> lru;
typedef jubatus::util::data::unordered_map<std::string, lru::iterator>
Expand Down
5 changes: 5 additions & 0 deletions jubatus/core/unlearner/random_unlearner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

#include <string>
#include <vector>
#include "msgpack.hpp"
#include "jubatus/util/data/optional.h"
#include "jubatus/util/data/serialization.h"
#include "jubatus/util/data/unordered_map.h"
#include "jubatus/util/math/random.h"
#include "unlearner_base.hpp"
#include "../common/porting_model.hpp"
#include "../common/unordered_set.hpp"

namespace jubatus {
namespace core {
Expand Down Expand Up @@ -58,6 +61,8 @@ class random_unlearner : public unlearner_base {
bool remove(const std::string& id);
bool exists_in_memory(const std::string& id) const;

JUBATUS_PORTING_MODEL(id_set_, ids_, max_size_);

private:
/**
* Map of ID and its position in ids_.
Expand Down
7 changes: 7 additions & 0 deletions jubatus/core/unlearner/unlearner_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <string>
#include "jubatus/util/lang/function.h"
#include "jubatus/core/framework/packer.hpp"

namespace jubatus {
namespace core {
Expand Down Expand Up @@ -72,6 +73,12 @@ class unlearner_base {
// touched and not unlearned since then, it returns true.
virtual bool exists_in_memory(const std::string& id) const = 0;

// Export the innner model as msgpack format
virtual void export_model(framework::jubatus_packer& pk) const = 0;

// Overwrite the innner model from serialised data
virtual void import_model(msgpack::object o) = 0;

protected:
void unlearn(const std::string& id) const {
callback_(id);
Expand Down

0 comments on commit cb1aee4

Please sign in to comment.