Question
import numpy as np
from scipy.special import comb

def cumulative_comb_with_repetition(n, k):
"""
Compute the number of possible non-negative, integer solutions to
x1 + x2 + ... + xk <= n.
  
We will use this function to compute the dimension
of order k polynomial feature vector

Args:
n: integer, the number of "balls" or "stars"
k: integer, the number of "urns" or "bars"
  
Returns: the total number of combinations, integer.
"""
# your code below

# your code above
raise NotImplementedError

import numpy as np from scipy.special import comb def cumulative_comb_with_repetition(n, k): Compute the number of possible n

The question doesn't ask for the number of one combination only but the total number of all combinations
0 0
Add a comment Improve this question Transcribed image text
Answer #1

part1:

   the given inequality is x1+x2+x3+........+xk<=n

we can say that x1+x2+x3+....+xk can be n,n-1,n-2,........,3,2,1,0 according to the given inequality.

The no of non negative solutions will be (n+k-1)Ck-1 when r.h.s=n

   The no of non negative solutions will be (n+k-2)Ck-1 when r.h.s=n-1

    The no of non negative solutions will be (n+k-3)Ck-1 when r.h.s=n-2

    ..........................................................................................................

    ...........................................................................................................

   The no of non negative solutions will be (k)Ck-1 when r.h.s=1

     The no of non negative solutions will be (k-1)Ck-1 when r.h.s=0

   So total no of non negative solutions will be

=(k-1)Ck-1+ (k)Ck-1+ .................+(n+k-3)Ck-1+(n+k-2)Ck-1+(n+k-1)Ck-1

=(n+k)Ck (We know that (r)Cr+ (r+1)Cr+ .................+(n-3)Cr+(n-2)Cr+(n-1)Cr+(n)Cr=(n+1)C(r+1).....combination formula)

Now we are going to code it out in python to find (n+k)Ck

python code snippet:>

In [1] : import numpy as np from scipy.special import comb def cumulative comb with repetition (n, k): #using comb () functio

text code:>

import numpy as np
from scipy.special import comb
def cumulative_comb_with_repetition(n,k):
    #using comb() function to calculate (n+k)C(k)
    return comb(n+k,k)
#getting the no of non negative solutions for x1+x2+x3<=5
print(cumulative_comb_with_repetition(5,3))

#getting the no of non negative solutions for x1+x2+x3+x4<=6
print(cumulative_comb_with_repetition(6,4))

output:>

56.0
35.0

Hope the solution is useful.If you have any problem regarding the answer,then comment down below.

Add a comment
Know the answer?
Add Answer to:
import numpy as np from scipy.special import comb def cumulative_comb_with_repetition(n, k): """ Compute the number of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • def stochastic_gradient_descent(feature_matrix, label, learning_rate = 0.05, epoch = 1000): """ Implement gradient descent algorithm for regression....

    def stochastic_gradient_descent(feature_matrix, label, learning_rate = 0.05, epoch = 1000): """ Implement gradient descent algorithm for regression.    Args: feature_matrix - A numpy matrix describing the given data, with ones added as the first column. Each row represents a single data point.    label - The correct value of response variable, corresponding to feature_matrix.    learning_rate - the learning rate with default value 0.5    epoch - the number of iterations with default value 1000 Returns: A numpy array for the...

  • def gradient_descent(feature_matrix, label, learning_rate = 0.05, epoch = 1000): """ Implement gradient descent algorithm for regression....

    def gradient_descent(feature_matrix, label, learning_rate = 0.05, epoch = 1000): """ Implement gradient descent algorithm for regression.    Args: feature_matrix - A numpy matrix describing the given data, with ones added as the first column. Each row represents a single data point.    label - The correct value of response variable, corresponding to feature_matrix.    learning_rate - the learning rate with default value 0.5    epoch - the number of iterations with default value 1000 Returns: A numpy array for the...

  • Problem 5 (5 points) Given an integer number, n, create a n by n matrix that...

    Problem 5 (5 points) Given an integer number, n, create a n by n matrix that has values 0 to n- Use the built-in NumPy methods to solve this problem. You can solve this problem in one line In [ ]: def np1(n): # YOUR CODE HERE raise NotImplementedError) Expected output: np1(2) yields [[0,1],[2,3]] np1(3) yields ([[e, 1, 2], 3, 4, 51 Use the cell below to test your function In : np1(2)

  • PYTHON import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.linear_model import...

    PYTHON import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression from sklearn.linear_model import LogisticRegression from sklearn.model_selection import train_test_split Our goal is to create a linear regression model to estimate values of ln_price using ln_carat as the only feature. We will now prepare the feature and label arrays. "carat"   "cut" "color"   "clarity"   "depth"   "table"   "price"   "x"   "y"   "z" "1" 0.23   "Ideal" "E" "SI2" 61.5 55 326   3.95   3.98   2.43 "2" 0.21   "Premium" "E" "SI1"...

  • Undecimal to decimal&decimal to undecimal #Your code here Thank you! Binary-to-Decimal In a previous lab, we...

    Undecimal to decimal&decimal to undecimal #Your code here Thank you! Binary-to-Decimal In a previous lab, we considered converting a byte string to decimal. What about converting a binary string of arbitrary length to decimal? Given a binary string of an arbitrarily length k, bk-1....bi .box the decimal number can be computed by the formula 20 .bo +21.b, + ... + 2k-1. bx-1- In mathematics, we use the summation notation to write the above formula: k- 2.b; i=0) In a program,...

  • NEED HELP WITH PROBLEM 1 AND 2 OF THIS LAB. I NEED TO PUT IT INTO...

    NEED HELP WITH PROBLEM 1 AND 2 OF THIS LAB. I NEED TO PUT IT INTO PYTHON CODE! THANK YOU! LAB 9 - ITERATIVE METHODS FOR EIGENVALUES AND MARKOV CHAINS 1. POWER ITERATION The power method is designed to find the dominant' eigenvalue and corresponding eigen- vector for an n x n matrix A. The dominant eigenvalue is the largest in absolute value. This means if a 4 x 4 matrix has eigenvalues -4, 3, 2,-1 then the power method...

  • Python Programming (Just need the Code) Index.py #Python 3.0 import re import os import collections import...

    Python Programming (Just need the Code) Index.py #Python 3.0 import re import os import collections import time #import other modules as needed class index:    def __init__(self,path):    def buildIndex(self):        #function to read documents from collection, tokenize and build the index with tokens        # implement additional functionality to support methods 1 - 4        #use unique document integer IDs    def exact_query(self, query_terms, k):    #function for exact top K retrieval (method 1)    #Returns...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT