Skip to content

Commit

Permalink
Added only_lower_triangle option to TestM2M
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerkin committed Nov 22, 2019
1 parent 73fc350 commit 9137bc9
Showing 1 changed file with 201 additions and 0 deletions.
201 changes: 201 additions & 0 deletions sciunit/unit_test/test_only_lower_triangle.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from sciunit.models.examples import ConstModel\n",
"from sciunit.tests import TestM2M\n",
"from sciunit.scores import RatioScore\n",
"from sciunit.capabilities import ProducesNumber"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"class MyTestM2M(TestM2M): \n",
" required_capabilities = (ProducesNumber,)\n",
" score_type = RatioScore \n",
" \n",
" def generate_prediction(self, model): \n",
" return model.produce_number() "
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"models = [ConstModel(x, name='%s producer'%x) for x in range(1,4)]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>1 producer</th>\n",
" <th>2 producer</th>\n",
" <th>3 producer</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1 producer</th>\n",
" <td>Ratio = 1.00</td>\n",
" <td>Ratio = 2.00</td>\n",
" <td>Ratio = 3.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2 producer</th>\n",
" <td>Ratio = 0.50</td>\n",
" <td>Ratio = 1.00</td>\n",
" <td>Ratio = 1.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3 producer</th>\n",
" <td>Ratio = 0.33</td>\n",
" <td>Ratio = 0.67</td>\n",
" <td>Ratio = 1.00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 1 producer 2 producer 3 producer\n",
"1 producer Ratio = 1.00 Ratio = 2.00 Ratio = 3.00\n",
"2 producer Ratio = 0.50 Ratio = 1.00 Ratio = 1.50\n",
"3 producer Ratio = 0.33 Ratio = 0.67 Ratio = 1.00"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"test = MyTestM2M() \n",
"test.judge(models) "
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>1 producer</th>\n",
" <th>2 producer</th>\n",
" <th>3 producer</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1 producer</th>\n",
" <td>Ratio = 1.00</td>\n",
" <td>Ratio = 2.00</td>\n",
" <td>Ratio = 3.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2 producer</th>\n",
" <td>Ratio = 2.00</td>\n",
" <td>Ratio = 1.00</td>\n",
" <td>Ratio = 1.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3 producer</th>\n",
" <td>Ratio = 3.00</td>\n",
" <td>Ratio = 1.50</td>\n",
" <td>Ratio = 1.00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 1 producer 2 producer 3 producer\n",
"1 producer Ratio = 1.00 Ratio = 2.00 Ratio = 3.00\n",
"2 producer Ratio = 2.00 Ratio = 1.00 Ratio = 1.50\n",
"3 producer Ratio = 3.00 Ratio = 1.50 Ratio = 1.00"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"test.judge(models, only_lower_triangle=True)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 9137bc9

Please sign in to comment.