LinA

Generate code from formulas

                
                def rename_this_function(X,b,l,m,y):
    """
    Generated with LinA from input:
        sum[i]((y[i]-m-sum[j](X[i,j]*b[j]))^2)+l*sum[j](b[j])
        vector(1)'*(y-m*vector(1)-X*diag(b)*vector(1)).^2+vector(1)'*b*l
    Matrices:
        X
    Vectors:
        l,m,y
    Scalars:
        b
    Matching matrix and vector dimensions:
        X.shape[1] == b.shape[0]
        X.shape[0] == y.shape[0]
    """
    return np.sum((y-m-X.dot(b))**2)+l*np.sum(b)
              
                
                using namespace Eigen;
typedef Matrix​<​double,Dynamic,1​> RowVector;
typedef Matrix​<​double,1,Dynamic​> RowCoVector;
typedef Matrix​<​double,Dynamic,Dynamic,RowMajor​> RowMatrix;

/**
 * Generated with LinA from input:
 *     sum[i]((y[i]-m-sum[j](X[i,j]*b[j]))^2)+l*sum[j](b[j])
 *     vector(1)'*(y-m*vector(1)-X*diag(b)*vector(1)).^2+vector(1)'*b*l
 * Matrices:
 *     X
 * RowVectors:
 *     l,m,y
 * Scalars:
 *     b
 * Matching matrix and vector dimensions:
 *     X.cols() == b.rows()
 *     X.rows() == m.rows() == y.rows()
 * @return double
 */
double rename_this_function(const RowMatrix& X,const double& b,const RowVector& l,const RowVector& m,const RowVector& y){
    return (pow(((y.array()-m).matrix()-X*b).array(),2)).matrix().sum()+l*b.sum();
}

              

Examples

sum[i](0.5*x[i]*A[i,i]*x[i]) 0.5*x'*A*x sum[i](x[i]*log(x[i]/y[i])) x'*log(x./y) sum[i](sum[j]((x[i]*A[i,j]))) sum(A'*x) sum[i]((y[i]-b-sum[j](X[i,j]*m[j]))^2)+c*sum[j](m[j]) sum((y-vector(b)-X*m).^2)+c*sum(m) sum[i](log(exp(-y[i]*sum[j](X[i,j]*w[j]))+1)) sum(log(exp(-y.*(D*x))+vector(1))) sum[j](sum[i](A[i,j]*x[j]-y[j])^2)^0.5 sum((A*x-y).^2)^0.5 sum[i](log(1+exp(x[i]))) sum(log(vector(1)+exp(x)))