summaryrefslogtreecommitdiff
path: root/ot/gpu/cudamat/cudamat/learn.py
blob: 741ca13084bcf6cac9e58ad9f955689d7f0b88aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os

import ctypes as ct
import numpy as np

from cudamat import load_library, generate_exception

_cudalearn = load_library('libcudalearn')

_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)