In previous works, we proposed to estimate cosmological parameters with an artificial neural network (ANN) and a mixture density network (MDN). In this work, we propose an improved method called a mixture neural network (MNN) to achieve parameter estimation by combining ANN and MDN, which can overcome shortcomings of the ANN and MDN methods. Besides, we propose sampling parameters in a hyperellipsoid for the generation of the training set, which makes the parameter estimation more efficient. A high-fidelity posterior distribution can be obtained using
(
10
2
)
forward simulation samples. In addition, we develop a code named CoLFI for parameter estimation, which incorporates the advantages of MNN, ANN, and MDN, and is suitable for any parameter estimation of complicated models in a wide range of scientific fields. CoLFI provides a more efficient way for parameter estimation, especially for cases where the likelihood function is intractable or cosmological models are complex and resource-consuming. It can learn the conditional probability density p(
θ
∣
d
) using samples generated by models, and the posterior distribution p(
θ
∣
d
0) can be obtained for a given observational data
d
0. We tested the MNN using power spectra of the cosmic microwave background and Type Ia supernovae and obtained almost the same result as the Markov Chain Monte Carlo method. The numerical difference only exists at the level of
(
10
−
2
σ
)
. The method can be extended to higher-dimensional data.