Path: blob/master/src/FMNM/cost_utils.py
1700 views
#!/usr/bin/env python31# -*- coding: utf-8 -*-2"""3Created on Mon Jun 10 09:56:25 201945@author: cantaro866"""78import numpy as np91011def no_opt(x, y, cost_b, cost_s):12cost = np.zeros((len(x), len(y)))1314for i in range(len(y)):15if y[i] <= 0:16cost[:, i] = (1 + cost_b) * y[i] * np.exp(x)17else:18cost[:, i] = (1 - cost_s) * y[i] * np.exp(x)1920return cost212223def writer(x, y, cost_b, cost_s, K):24cost = np.zeros((len(x), len(y)))2526for i in range(len(x)):27for j in range(len(y)):28if y[j] < 0 and (1 + cost_b) * np.exp(x[i]) <= K:29cost[i][j] = (1 + cost_b) * y[j] * np.exp(x[i])3031elif y[j] >= 0 and (1 + cost_b) * np.exp(x[i]) <= K:32cost[i][j] = (1 - cost_s) * y[j] * np.exp(x[i])3334elif y[j] - 1 >= 0 and (1 + cost_b) * np.exp(x[i]) > K:35cost[i][j] = ((1 - cost_s) * (y[j] - 1) * np.exp(x[i])) + K3637elif y[j] - 1 < 0 and (1 + cost_b) * np.exp(x[i]) > K:38cost[i][j] = ((1 + cost_b) * (y[j] - 1) * np.exp(x[i])) + K3940return cost414243def buyer(x, y, cost_b, cost_s, K):44cost = np.zeros((len(x), len(y)))4546for i in range(len(x)):47for j in range(len(y)):48if y[j] < 0 and (1 + cost_b) * np.exp(x[i]) <= K:49cost[i][j] = (1 + cost_b) * y[j] * np.exp(x[i])5051elif y[j] >= 0 and (1 + cost_b) * np.exp(x[i]) <= K:52cost[i][j] = (1 - cost_s) * y[j] * np.exp(x[i])5354elif y[j] + 1 >= 0 and (1 + cost_b) * np.exp(x[i]) > K:55cost[i][j] = ((1 - cost_s) * (y[j] + 1) * np.exp(x[i])) - K5657elif y[j] + 1 < 0 and (1 + cost_b) * np.exp(x[i]) > K:58cost[i][j] = ((1 + cost_b) * (y[j] + 1) * np.exp(x[i])) - K5960return cost616263