summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2011-07-27 00:03:35 +0200
committerPatrick Simianer <p@simianer.de>2011-09-23 19:13:57 +0200
commit4a1d2e56744cc97c11ef8220623bd7c5467d6c02 (patch)
treebeb2ce8b03cc18ae52b9cf7e4e28ee394096dc24 /utils
parent6057a8ea61eebd4b698b78814b05f3de1c96944f (diff)
hacking in weights setting, getting
Diffstat (limited to 'utils')
-rw-r--r--utils/fdict.h4
-rw-r--r--utils/weights.cc18
-rw-r--r--utils/weights.h4
3 files changed, 26 insertions, 0 deletions
diff --git a/utils/fdict.h b/utils/fdict.h
index f9673023..70315a38 100644
--- a/utils/fdict.h
+++ b/utils/fdict.h
@@ -11,6 +11,10 @@ struct FD {
static void Freeze() {
frozen_ = true;
}
+ static void UnFreeze() {
+ frozen_ = false;
+ }
+
static inline int NumFeats() {
return dict_.max() + 1;
}
diff --git a/utils/weights.cc b/utils/weights.cc
index b994a2fe..6b7e58ed 100644
--- a/utils/weights.cc
+++ b/utils/weights.cc
@@ -88,3 +88,21 @@ void Weights::InitFromVector(const SparseVector<double>& w) {
for (int i = 1; i < FD::NumFeats(); ++i)
wv_[i] = w.value(i);
}
+
+void Weights::SetWeight(SparseVector<double>* v, const string fname, const double w) {
+ WordID fid = FD::Convert(fname);
+ cout << "fid " << fid << endl;
+ SetWeight(v, fid, w);
+}
+
+void Weights::SetWeight(SparseVector<double>* v, const WordID fid, const double w) {
+ wv_.resize(FD::NumFeats(), 0.0);
+ wv_[fid] = w;
+ //v->set_value(fid, w);
+}
+
+void Weights::sz()
+{
+ cout << "wv_.size() " << wv_.size() << endl;
+}
+
diff --git a/utils/weights.h b/utils/weights.h
index cc20283c..86701add 100644
--- a/utils/weights.h
+++ b/utils/weights.h
@@ -15,6 +15,10 @@ class Weights {
void InitSparseVector(SparseVector<double>* w) const;
void InitFromVector(const std::vector<double>& w);
void InitFromVector(const SparseVector<double>& w);
+ void SetWeight(SparseVector<double>* v, const std::string f, const double w);
+ void SetWeight(SparseVector<double>* v, const WordID fid, const double w);
+ std::vector<double>* getw() { return &wv_; }; // probably a hack
+ void sz();
private:
std::vector<double> wv_;
};