Package com.numb3r3.common.opt

Source Code of com.numb3r3.common.opt.Tanh

package com.numb3r3.common.opt;

import org.jblas.DoubleMatrix;
import org.jblas.MatrixFunctions;

public class Tanh extends DifferentiableMatrixFunction {

    /**
     * Return the plain tanh, available from the library
     */
    @Override
    public DoubleMatrix valueAt(DoubleMatrix M) {
        return MatrixFunctions.tanh(M);
    }

    /**
     * @param M input double matrix
     * @return tanh_prime = (1-M.^2);
     */
    @Override
    public DoubleMatrix derivativeAt(DoubleMatrix M) {
        DoubleMatrix Squared = M.mul(M);
        return (Squared.muli(-1)).addi(1);
    }

}
TOP

Related Classes of com.numb3r3.common.opt.Tanh

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.