Skip to content

Commit

Permalink
Merge pull request #71 from satzbeleg/dev
Browse files Browse the repository at this point in the history
Bug fixed
  • Loading branch information
ulf1 authored Jul 2, 2021
2 parents a8b22a5 + 59059d3 commit 5a21137
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The package `bwsample` addresses three areas:
The `bwsample` [git repo](http://github.com/satzbeleg/bwsample) is available as [PyPi package](https://pypi.org/project/bwsample)

```sh
pip install bwsample>=0.6.5
pip install bwsample>=0.6.7
```

## Overview
Expand Down
2 changes: 1 addition & 1 deletion bwsample/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.6.6'
__version__ = '0.6.7'

from .sampling import sample
from .counting import count
Expand Down
2 changes: 2 additions & 0 deletions bwsample/ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ def maximize_hoaglinapprox(cnt: scipy.sparse.csr_matrix,
P.data = np.maximum(0.0, np.minimum(1.0, P.data))
# only if Nij>Nji
P = P.multiply(cnt > cnt.T)
# Q = 1-P
P.data = 1. - P.data

# sum rows in DoK matrix
metrics = np.array(P.sum(axis=1).flatten())[0]
Expand Down
117 changes: 105 additions & 12 deletions docs/rank.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,114 @@
"name": "stdout",
"output_type": "stream",
"text": [
" Positions: [0 5 3 1 2 4]\n",
"Ordered IDs: ['A' 'F' 'D' 'B' 'C' 'E']\n",
" Scores: [1. 0.8 0.6 0.3 0.3 0. ]\n"
" Positions: [5 3 1 2 0 4]\n",
"Ordered IDs: ['F' 'D' 'B' 'C' 'A' 'E']\n",
" Scores: [1. 0.8 0.4 0.4 0.2 0. ]\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"../bwsample/ranking.py:72: UserWarning: Use 'approx' because it's faster.\n",
" warnings.warn(\"Use 'approx' because it's faster.\", UserWarning)\n"
]
}
],
"source": [
"positions, sortedids, metrics, scores, info = bws.rank(\n",
" dok, method='approx', avg='exist', adjust='quantile')\n",
" dok, method='pvalue', avg='exist', adjust='quantile')\n",
"\n",
"print(f\" Positions: {positions}\") \n",
"print(f\"Ordered IDs: {sortedids}\") \n",
"print(f\" Scores: {scores}\") "
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "7094d503-a956-45a4-9bf8-65d8dae4b070",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0. , 0. , 0. , 0.398, 0.993, 0. ],\n",
" [0.892, 0. , 0. , 0. , 0.954, 0. ],\n",
" [0.892, 0. , 0. , 0. , 0.954, 0. ],\n",
" [0. , 0.892, 0.892, 0. , 0.999, 0. ],\n",
" [0. , 0. , 0. , 0. , 0. , 0. ],\n",
" [0.999, 0.954, 0.954, 0.993, 1. , 0. ]])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"info['P'].todense().round(3)"
]
},
{
"cell_type": "markdown",
"id": "9fdbe524-f05a-4a2d-bcd1-b06b1c071c47",
"metadata": {},
"source": [
"# Hoaglin Approximation"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "da48ee5c-cef2-42bc-865f-581ab47d2a1a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Positions: [5 3 1 2 0 4]\n",
"Ordered IDs: ['F' 'D' 'B' 'C' 'A' 'E']\n",
" Scores: [1. 0.8 0.4 0.4 0.2 0. ]\n"
]
}
],
"source": [
"positions, sortedids, metrics, scores, info = bws.rank(\n",
" dok, method='hoaglin', avg='exist', adjust='quantile')\n",
"\n",
"print(f\" Positions: {positions}\") \n",
"print(f\"Ordered IDs: {sortedids}\") \n",
"print(f\" Scores: {scores}\") "
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "7d68d4bc-7172-440c-95fb-6aebcb317666",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0. , 0. , 0. , 0.848, 0.971, 0. ],\n",
" [0.933, 0. , 0. , 0. , 0.951, 0. ],\n",
" [0.933, 0. , 0. , 0. , 0.951, 0. ],\n",
" [0. , 0.933, 0.933, 0. , 0.981, 0. ],\n",
" [0. , 0. , 0. , 0. , 0. , 0. ],\n",
" [0.981, 0.951, 0.951, 0.971, 0.992, 0. ]])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"info['P'].todense().round(3)"
]
},
{
"cell_type": "markdown",
"id": "ordered-worth",
Expand All @@ -131,7 +224,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 9,
"id": "several-safety",
"metadata": {},
"outputs": [
Expand All @@ -156,7 +249,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 10,
"id": "handy-regard",
"metadata": {},
"outputs": [
Expand All @@ -183,7 +276,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 11,
"id": "convenient-hurricane",
"metadata": {},
"outputs": [
Expand All @@ -208,7 +301,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 12,
"id": "gross-fiction",
"metadata": {},
"outputs": [
Expand All @@ -234,7 +327,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 13,
"id": "desirable-company",
"metadata": {},
"outputs": [
Expand All @@ -259,7 +352,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 14,
"id": "available-spiritual",
"metadata": {},
"outputs": [
Expand All @@ -277,7 +370,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 15,
"id": "healthy-faculty",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -317,7 +410,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
"version": "3.7.9"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 5a21137

Please sign in to comment.