forked from mtresearcher/CPMT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SGD.h
53 lines (41 loc) · 980 Bytes
/
SGD.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* EM.h
*
* Created on: Apr 28, 2015
* Author: prmathur
*/
#pragma once
#ifndef SGD_H_
#define SGD_H_
#include <iostream>
#include <vector>
#include <string>
#include "cpmStore.h"
class SGD {
struct SoftmaxOutput{
std::vector<double> P;
std::vector<double> N;
double possim;
double negsim;
};
float m_lr;
int m_negative;
size_t m_maxIter;
unsigned int m_topics;
bool printModels;
void Step();
double HierarchicalSoftmax(Code* w, std::vector<Context*>& c, std::vector<double>& res, bool neg=false);
SoftmaxOutput CalculateObjective(Code* w);
void InitializeParams();
void normalize();
// Actual model is Q where the parameters are stored,
// P is for storing expected counts, later useless.
// p, q store partial values
boost::unordered_map<Code*, boost::unordered_map<unsigned short int, double> > Q;
public:
SGD(unsigned int, unsigned int, bool, float, int);
~SGD();
void Train();
void PrintModel(char*);
};
#endif /* SGD_H_ */