Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warm_start for SGD #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions fastFM/ffm.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,20 @@ def ffm_sgd_fit(fm, X, double[:] y):
pt_param = <cffm.ffm_param *> PyCapsule_GetPointer(param, "FFMParam")

# allocate the coefs
cdef double w_0 = 0
cdef np.ndarray[np.float64_t, ndim=1, mode='c'] w =\
np.zeros(n_features, dtype=np.float64)
cdef np.ndarray[np.float64_t, ndim=2, mode='c'] V =\
np.zeros((fm.rank, n_features), dtype=np.float64)
# allocate the coefs
cdef double w_0
cdef np.ndarray[np.float64_t, ndim=1, mode='c'] w
cdef np.ndarray[np.float64_t, ndim=2, mode='c'] V

if fm.warm_start:
w_0 = 0 if fm.ignore_w_0 else fm.w0_
w = np.zeros(n_features, dtype=np.float64) if fm.ignore_w else fm.w_
V = np.zeros((fm.rank, n_features), dtype=np.float64)\
if fm.rank == 0 else fm.V_
else:
w_0 = 0
w = np.zeros(n_features, dtype=np.float64)
V = np.zeros((fm.rank, n_features), dtype=np.float64)

cffm.ffm_sgd_fit(&w_0, <double *> w.data, <double *> V.data,
pt_X, &y[0], pt_param)
Expand All @@ -147,11 +156,20 @@ def ffm_fit_sgd_bpr(fm, X, np.ndarray[np.float64_t, ndim=2, mode='c'] pairs):
pt_param = <cffm.ffm_param *> PyCapsule_GetPointer(param, "FFMParam")

#allocate the coefs
cdef double w_0 = 0
cdef np.ndarray[np.float64_t, ndim=1, mode='c'] w =\
np.zeros(n_features, dtype=np.float64)
cdef np.ndarray[np.float64_t, ndim=2, mode='c'] V =\
np.zeros((fm.rank, n_features), dtype=np.float64)
# allocate the coefs
cdef double w_0
cdef np.ndarray[np.float64_t, ndim=1, mode='c'] w
cdef np.ndarray[np.float64_t, ndim=2, mode='c'] V

if fm.warm_start:
w_0 = 0 if fm.ignore_w_0 else fm.w0_
w = np.zeros(n_features, dtype=np.float64) if fm.ignore_w else fm.w_
V = np.zeros((fm.rank, n_features), dtype=np.float64)\
if fm.rank == 0 else fm.V_
else:
w_0 = 0
w = np.zeros(n_features, dtype=np.float64)
V = np.zeros((fm.rank, n_features), dtype=np.float64)

cffm.ffm_sgd_bpr_fit(&w_0, <double *> w.data, <double *> V.data,
pt_X, <double *> pairs.data, pairs.shape[0], pt_param)
Expand Down