How to use column_strategy method in pandera

Best Python code snippet using pandera_python

week1.py

Source:week1.py Github

copy

Full Screen

1# @author: František Dostál2import numpy as np3# COLUMN = minimizing4# ROW = maximizing5def evaluate(matrix_r, matrix_c, row_strategy, column_strategy):6 return row_strategy @ matrix_r @ column_strategy, row_strategy @ matrix_c @ column_strategy7def evaluate_zero_sum(matrix, row_strategy, column_strategy):8 return row_strategy @ matrix @ column_strategy9#algorithms for zero sum games10#opponents best response, not equilibrial response11def best_response_calc_row(matrix, row_strategy):12 return np.argmin((row_strategy @ matrix))13#opponents best response to given strategy, not equilibrial response14def best_response_calc_column(matrix, column_strategy):15 return np.argmin(-( matrix @ column_strategy))16def best_response_value_column(matrix, column_strategy):17 #column value against best responding opponent18 return np.min(-matrix @ column_strategy)19def best_response_value_row(matrix, row_strategy):20 #row value against best responding opponent21 return np.min(row_strategy @ matrix)22def strongly_dominated_row(matrix):23 for index in range(matrix.shape[0]):24 c = np.delete(matrix, index, 0)25 if np.any(np.all(c > matrix[index], axis=1)):26 return index27 return None28def strongly_dominated_column(matrix):29 for index in range(matrix.shape[1]):30 c = np.delete(matrix, index, 1)31 if np.any(np.all((c.transpose() < matrix[:, index]).transpose(), axis=0)):32 return index33 return None34def strongly_dominated_rows(matrix):35 #generator version36 M = matrix.copy()37 for index in range(M.shape[0]):38 c = np.delete(M, index, 0)39 if np.any(np.all(c > M[index], axis=1)):40 yield index41def strongly_dominated_columns(matrix):42 #generator version43 M = matrix.copy()44 for index in range(M.shape[1]):45 c = np.delete(M, index, 1)46 if np.any(np.all((c.transpose() < M[:, index]).transpose(), axis=0)):47 yield index48def pruning_dominated(matrix):49 M=matrix.copy()50 dominated_row = strongly_dominated_row(matrix)51 dominated_column = strongly_dominated_column(matrix)52 while dominated_column is not None or dominated_row is not None:53 if dominated_row is not None: M = np.delete(M, dominated_row, 0)54 if dominated_column is not None: M = np.delete(M, dominated_column, 1)55 dominated_row = strongly_dominated_row(M)56 dominated_column = strongly_dominated_column(M)...

Full Screen

Full Screen

test_week1.py

Source:test_week1.py Github

copy

Full Screen

1import libs.week1 as week12import numpy as np3import pytest4def test_week1():5 matrix = np.array([[0, 1, -1], [-1, 0, 1], [1, -1, 0]])6 row_strategy = np.array([[0.1, 0.2, 0.7]])7 column_strategy = np.array([[0.3, 0.2, 0.5]]).transpose()8 row_value = week1.evaluate(matrix=matrix, row_strategy=row_strategy, column_strategy=column_strategy)9 assert row_value == pytest.approx(0.08)10 br_value_row = week1.best_response_value_row(matrix=matrix, row_strategy=row_strategy)11 br_value_column = week1.best_response_value_column(matrix=matrix, column_strategy=column_strategy)12 assert br_value_row == pytest.approx(-0.6)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful