forked from cudamat/cudamat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearn.py
More file actions
25 lines (20 loc) · 702 Bytes
/
learn.py
File metadata and controls
25 lines (20 loc) · 702 Bytes
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
import os
import pdb
import platform
import warnings
import ctypes as ct
import numpy as np
from cudamat import generate_exception
if platform.system() == 'Windows':
_cudalearn = ct.cdll.LoadLibrary('libcudalearn.dll')
else:
_cudalearn = ct.cdll.LoadLibrary(os.path.join(os.path.dirname(__file__) or os.path.curdir, 'libcudalearn.so'))
_cudalearn.mult_by_sigmoid_deriv.restype = ct.c_int
def mult_by_sigmoid_deriv(target, acts):
"""
target = target * acts * (1 - acts)
Useful for doing backprop in neural networks with logistic units.
"""
err_code = _cudalearn.mult_by_sigmoid_deriv(target.p_mat, acts.p_mat)
if err_code:
raise generate_exception(err_code)