Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-099

L-BFGS Memory Shift

Problem

Shift an L-BFGS correction history by appending a new pair.

Append s_new and y_new to the histories, then keep only the m most recent pairs. Return [s_list_new, y_list_new] as two lists of vectors.

Hint

Keep the newest pairs at the end and drop from the front.

Test cases

case 1
in: [[[1,0],[0,1]],[[2,0],[0,2]],[1,1],[3,3],2]
expected: [[[0,1],[1,1]],[[0,2],[3,3]]]
case 2
in: [[],[],[1],[2],3]
expected: [[[1]],[[2]]]
case 3
in: [[[1]],[[2]],[3],[4],1]
expected: [[[3]],[[4]]]
case 4
in: [[[1]],[[2]],[3],[4],0]
expected: [[],[]]
Starter codePython
def lbfgs_memory_shift(s_list, y_list, s_new, y_new, m):
    # Returns [s_list_new, y_list_new]
    # Your code here
    pass

4 test cases · run your code against them in the editor