Exemple #1
0
    def request(self, a, b, p):
        """(p, a, b) -> a

        Parameters
        ----------
        a: tuple[numpy.array]
        b: numpy.array
        p: tuple[numpy.array]

        Returns
        -------
        tuple[numpy.array]
        """
        i = self.implement(a, p)

        a = a[0]
        p00, p01, p10, b00, b01, q0, q1, b1 = p

        beta = [
            sigmoid_derivative(p00 * a[0] + p10 * a[1] + b00),
            sigmoid_derivative(p01 * a[0] + b01)
        ]

        gamma = sigmoid_derivative(q0 *
                                   sigmoid(p00 * a[0] + p10 * a[1] + b00) +
                                   q1 * sigmoid(p01 * a[0] + b01) + b1)

        return numpy.array([
            a[0] - (i - b) * gamma * (q0 * beta[0] * p00 + q1 * beta[1] * p10),
            a[1] - (i - b) * gamma * (q0 * beta[0] * p01)
        ]).reshape(2),
Exemple #2
0
    def implement(self, a, p):
        """(p, a) -> b

        Parameters
        ----------
        a : tuple[numpy.array]
        p : tuple[numpy.array]

        Returns
        -------
        numpy.array
        """
        a = a[0]
        w00, w01, w10, b0, b1 = p

        return numpy.array(
            [sigmoid(w00 * a[0] + w10 * a[1] + b0),
             sigmoid(w01 * a[0] + b1)]).reshape(2)
Exemple #3
0
    def implement(self, a, p):
        """(p, a) -> b

        Parameters
        ----------
        a : tuple[numpy.array]
        p : tuple[numpy.array]

        Returns
        -------
        numpy.array
        """
        a = a[0]
        p00, p01, p10, b00, b01, q0, q1, b1 = p

        return numpy.array([
            sigmoid(q0 * sigmoid(p00 * a[0] + p10 * a[1] + b00) +
                    q1 * sigmoid(p01 * a[0] + b01) + b1)
        ]).reshape(1)
Exemple #4
0
    def update(self, a, b, p):
        """(p, a, b) -> p

        Parameters
        ----------
        a : tuple[numpy.array]
        b : numpy.array
        p : tuple[numpy.array]

        Returns
        -------
        tuple[numpy.array]
        """
        i = self.implement(a, p)

        a = a[0]
        p00, p01, p10, b00, b01, q0, q1, b1 = p

        beta = [p00 * a[0] + p10 * a[1] + b00, p01 * a[0] + b01]

        beta_sigma_derivative = [
            sigmoid_derivative(beta[0]),
            sigmoid_derivative(beta[1])
        ]
        beta_sigma = [sigmoid(beta[0]), sigmoid_derivative(beta[1])]

        gamma = sigmoid_derivative(q0 *
                                   sigmoid(p00 * a[0] + p10 * a[1] + b00) +
                                   q1 * sigmoid(p01 * a[0] + b01) + b1)

        return (p00 - self.eps *
                (i - b) * gamma * q0 * beta_sigma_derivative[0] * a[0],
                p01 - self.eps *
                (i - b) * gamma * q0 * beta_sigma_derivative[0] * a[1],
                p10 - self.eps *
                (i - b) * gamma * q1 * beta_sigma_derivative[1] * a[0], b00 -
                self.eps * (i - b) * gamma * q0 * beta_sigma_derivative[0],
                b01 - self.eps *
                (i - b) * gamma * q1 * beta_sigma_derivative[1],
                q0 - self.eps * (i - b) * gamma * beta_sigma[0],
                q1 - self.eps * (i - b) * gamma * beta_sigma[1],
                b1 - self.eps * (i - b) * gamma)
Exemple #5
0
 def f(src):
     return sigmoid(src[0] * 2 + src[1] + 1) * 3 + sigmoid(src[0] * -1 + 2) + 3