Implementing training, encoding and decoding using L-BFGS algorithm