function [X_opt, l_opt] = isoform_estimation_mine(A, L, L1, N, N1, NN, read_len, gene)

epsilon = 1e-10;
[m,n] = size(A);

% find X_opt
L = [L L1];
L = L - read_len; %The effective exon length

N = [N N1];
A1 = zeros(m*(m-1)/2, n);
l = 1;
for i=1:m         %Calculating the splice matrix: c_{ij}c_{ik}\theta_i
    for j=i+1:m
        A1(l,:) = A(i,:).*A(j,:);
        for k=i+1:j-1
            A1(l,:) = A1(l,:).*(1-A(k,:)); %%There is no other exons between two junction exons
        end
        l = l + 1;
    end
end

A = [A; A1];
i = 1;
while i <= length(L)
    if L(i)<=0
        if N(i)~=0
            %disp(sprintf('warning: L(i)<=0 & N(i)~=0 for gene %s.', gene));
            N(i)=0;
        end
        A(i,:)=[];
        L(i)=[];
        N(i)=[];
        continue;
    end
    i = i + 1;
end

[m,n]=size(A);

A = (NN / 1e6 * (L / 1e3)' * ones(1, n)) .* A; %RPKM,Reads per kilo per million
% sum(N)*1e9/NN/(L*A)
%N*A./(L*A)
%A = (NN / 1e3 * (L / 1e1)' * ones(1, n)) .* A; %RPKM,Reads per kilo per million
%tstart=cputime;
%[X_opt, l_opt]= solve_likelihood(A, N);     %Here N is the number of reads, corresponding to x in the paper
%cputime-tstart
%tstart=cputime;
[X_opt,l_opt]  = alspgrad_2(A,N,1e-3,1e3);
l_opt = -l_opt;
%t = cputime-tstart
%t

