Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I would like to know if my code is correct for the following question and pls edit the part where its giving an error Question

I would like to know if my code is correct for the following question and pls edit the part where its giving an error
Question : Discrete Optimization: Consider each of the three levels for each of the five attributes
and enumerate all the possibilities in lexical order with Price as the leftmost attribute
changing slowest and taking levels sequentially $30, $10, $5, then Time Insulated as
the left-second-most attribute changing second-slowest and taking values sequentially
0.5 hrs,1 hr,3 hrs and so on. You will have 243 product candidates. (The lexical order
produces indices as shown in mugs-products-lexical-order.csv. Please make sure
you list your products in that exact same order. The lexical order of products is
obtained by looping as shown in mugs-products-lexical-order-loop.R, which has
close similarity in python. Again, using the compensatory rule, compute and report
the following four columns of numbers for each candidate: the share, the cost, the
margin and the expected profit per person (all under the current competition
incumbents). The table that you submit needs to have all 243 rows. Hint to check your
answer: product candidate 230 has a negative expected profit per customer of between
-1.75 and -1.85, and product candidate 106 has an expected profit per customer of
between 0.7 and 0.8.
Code :
import numpy as np
# Define the incumbents' attributes
incumbent_attributes =[
('$30','3 hrs','20 oz', 'Clean Easy', 'Leak resistant', 'Brand A'),
('$10','1 hrs','20 oz', 'Clean Fair', 'Spill resistant', 'Brand B'),
('$30','1 hrs','20 oz', 'Clean Easy', 'Leak resistant', 'Brand C')
]
# Define the scaling constant
c =0.0139
# Define the attribute levels
attribute_levels =[
['$30','$10','$5'],
['0.5 hrs','1 hrs','3 hrs'],
['12 oz','20 oz','32 oz'],
['Difficult (7 min)', 'Fair (5 min)', 'Easy (2 min)'],
['Slosh resistant', 'Spill resistant', 'Leak resistant'],
['Brand A', 'Brand B', 'Brand C']
]
# Initialize the part-worth utility matrix
part_worth_utilities = np.zeros((5,3))
# Function to compute utility
def compute_utility(candidate, incumbent):
diff = sum(c *(candidate[a]== incumbent[a]) for a in range(5))- sum(c *(candidate[a]!= incumbent[a]) for a in range(5))
return 1/(1+ np.exp(-diff))
# Generate candidate attributes and compute utilities
for i, price in enumerate(attribute_levels[0]):
for j, time in enumerate(attribute_levels[1]):
for k, capacity in enumerate(attribute_levels[2]):
for l, cleanability in enumerate(attribute_levels[3]):
for m, containment in enumerate(attribute_levels[4]):
for n, brand in enumerate(attribute_levels[5]):
# Generate candidate attributes
candidate_attributes =[price, time, capacity, cleanability, containment, brand]
# Compute utilities for each attribute
utilities =[compute_utility(candidate_attributes, incumbent) for incumbent in incumbent_attributes]
# Average utility for the candidate product
avg_utility = np.mean(utilities)
# Update part-worth utilities matrix
for a in range(5):
part_worth_utilities[a, n]+= avg_utility
# Normalize the part-worth utilities by the number of combinations
num_combinations = len(attribute_levels[0])* len(attribute_levels[1])* len(attribute_levels[2])* len(attribute_levels[3])* len(attribute_levels[4])
part_worth_utilities /= num_combinations
print(part_worth_utilities)
cleanability_mapping ={
'Difficult': 'Difficult (7 min)',
'Fair': 'Fair (5 min)',
'Easy': 'Easy (2 min)'
}
# Import the dataset
df = pd.read_csv('mugs-products-lexical-order.csv')
# Define the levels for each attribute
price_levels =['$30','$10','$5']
time_insulated_levels =['0.5 hrs','1 hr','3 hrs']
# Modified calculate_metrics function using the previously defined utility and cost calculation logic
def calculate_metrics(price, time_insulated, capacity, cleanability, containment, brand):
candidate =[price, time_insulated, capacity, cleanability, containment, brand]
utilities =[compute_utility(candidate, incumbent) for incumbent in incumbent_attributes]
share = exp(np.mean(utilities))/(1+ sum(exp(u) for u in utilities))
cost = costs['time_insulated'][time_insulated]+ costs['capacity'][capacity]+ costs['cleanability'][cleanability]+ costs['containment'][containment]
margin = float(price[1:])- cost
expected_profit_per_person = share * margin
return share, cost, margin, expected_profit_per_person
# Loop through the dataset
for index, row in df.iterrows():
# Access data for each attribute
price = row[' $30'].strip()
time_insulated = row['0.5 hrs'].strip()
capacity = row['12 oz'].strip(

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago