dynamic-programming

jit – "Failed in nopython mode pipeline" error, despite not using nopython in numba

jit – "Failed in nopython mode pipeline" error, despite not using nopython in numba Question: I am using value function iteration to solve a complex dynamic programming problem with many states. I want to use numba/jit to speed up my code (and eventually parallelize the for loops). When I use the @jit decorator in my …

Total answers: 1

Function to dynamically extract values from multiple nested dictionary in Python

Function to dynamically extract values from multiple nested dictionary in Python Question: The problem statement is to write a function which will take a input dictionary object and return a list of all the values, even in case of multi-level nested dictionaries inside the input dictionary object. Example of such a nested dictionary below: { …

Total answers: 3

Runtime of dynamic programming versus it's naive recursive counterpart

Runtime of dynamic programming versus it's naive recursive counterpart Question: The problem follows: You are playing a game where you start with n sticks in a pile (where n is a positive integer), and each turn you can take away exactly 1, 7, or 9 sticks from the pile (if there are fewer than 9 …

Total answers: 1

Python Dynamic Programming Problem – ( 2 dimension recursion stuck in infinite loop )

Python Dynamic Programming Problem – ( 2 dimension recursion stuck in infinite loop ) Question: In the book "A Practical Guide to Quantitative Finance Interview", there is a question called Dynamic Card Game, 5.3 Dynamic Programming) The solution according to the book is basically the following: E[f(b,r)] = max(b−r,(b/(b+r))∗E[f(b−1,r)]+(r/(b+r))∗E[f(b,r−1)]) with the following boundary conditions. f(0,r)=0, …

Total answers: 3

LeetCode Climbing Stairs

LeetCode Climbing Stairs Question: I tried to separate the climbing scenarios into scenarios of how many 2 steps can be taken and to solve the question according to the sum of the combinations of the moments where 2 steps can be taken in these scenarios. import math class Solution: def climbStairs(self, n: int) -> int: …

Total answers: 1

Python lambda function in a list gives unexpected result

Python lambda function in a list gives unexpected result Question: So I’m trying to make a list where a lambda functions are the elements of the list. The lambda function calls another function which I pass an argument to. The problem is that lambda function only ‘saves’ the last value for all other items in …

Total answers: 3

Knapsack with SPECIFIC AMOUNT of items from different groups

Knapsack with SPECIFIC AMOUNT of items from different groups Question: So this is a variation of the Knapsack Problem I came with the other day. It is like a 0-1 Knapsack Problem where there are multiple groups and each item belongs to only one group. The goal is to maximize the profits subject to the …

Total answers: 1

4D Matrix operation in Python – conversion from MATLAB

4D Matrix operation in Python – conversion from MATLAB Question: I’m trying to translate this MATLAB code to Python: MATLAB: V_c = delta* max(V_L, repmat(V_A_c,[N_p 1]) – NM ) where these are 4D arrays: V_c is the continuation value for in different states, (should have shape 81, 75, 15, 31) V_L is the initial value, …

Total answers: 2