-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
438 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import random\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"from skcriteria import Data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<table>\n", | ||
"<thead>\n", | ||
"<tr><th style=\"text-align: center;\"> ALT./CRIT. </th><th style=\"text-align: center;\"> C0 (min) W.19 </th><th style=\"text-align: center;\"> C1 (max) W.27 </th><th style=\"text-align: center;\"> C2 (min) W.94 </th></tr>\n", | ||
"</thead>\n", | ||
"<tbody>\n", | ||
"<tr><td style=\"text-align: center;\"> A0 </td><td style=\"text-align: center;\"> 0.510896 </td><td style=\"text-align: center;\"> 0.473174 </td><td style=\"text-align: center;\"> 0.1366 </td></tr>\n", | ||
"<tr><td style=\"text-align: center;\"> A1 </td><td style=\"text-align: center;\"> 0.815747 </td><td style=\"text-align: center;\"> 0.845667 </td><td style=\"text-align: center;\"> 0.961278 </td></tr>\n", | ||
"<tr><td style=\"text-align: center;\"> A2 </td><td style=\"text-align: center;\"> 0.427846 </td><td style=\"text-align: center;\"> 0.851048 </td><td style=\"text-align: center;\"> 0.157045 </td></tr>\n", | ||
"</tbody>\n", | ||
"</table>" | ||
], | ||
"text/plain": [ | ||
" ALT./CRIT. C0 (min) W.19 C1 (max) W.27 C2 (min) W.94\n", | ||
"------------ --------------- --------------- ---------------\n", | ||
" A0 0.510896 0.473174 0.1366\n", | ||
" A1 0.815747 0.845667 0.961278\n", | ||
" A2 0.427846 0.851048 0.157045" | ||
] | ||
}, | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"mtx = np.random.rand(3, 3)\n", | ||
"criteria = np.asarray([random.choice((1, -1)) for e in range(3)])\n", | ||
"weights = np.random.randint(1, 100, 3)\n", | ||
"data = Data(mtx, criteria, weights)\n", | ||
"data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"ename": "NameError", | ||
"evalue": "global name 'data' is not defined", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", | ||
"\u001b[0;32m<ipython-input-3-66a0473f7c22>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | ||
"\u001b[0;32m/home/juan/proyectos/scikit-criteria/src/skcriteria/plot/__init__.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, plotname, *args, **kwargs)\u001b[0m\n\u001b[1;32m 86\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__call__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mplotname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"radar\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 87\u001b[0m \u001b[0mmethod\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mplotname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 88\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 89\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 90\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mto_str\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
"\u001b[0;32m/home/juan/proyectos/scikit-criteria/src/skcriteria/plot/__init__.py\u001b[0m in \u001b[0;36mradar\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 96\u001b[0m \u001b[0mmtx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmtx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcriteria\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcriteria\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 97\u001b[0m \u001b[0mweights\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mweights\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0manames\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0manames\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 98\u001b[0;31m cnames=data.cnames, *args, **kwargs)\n\u001b[0m", | ||
"\u001b[0;32m/home/juan/proyectos/scikit-criteria/src/skcriteria/plot/radar.pyc\u001b[0m in \u001b[0;36mradar_plot\u001b[0;34m(mtx, criteria, weights, anames, cnames, frame, cmap)\u001b[0m\n\u001b[1;32m 166\u001b[0m frame=\"polygon\", cmap=None):\n\u001b[1;32m 167\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 168\u001b[0;31m \u001b[0mmincrits\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqueeze\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwhere\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcriteria\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0msc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mMIN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 169\u001b[0m \u001b[0mmincrits_inverted\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1.0\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmtx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmincrits\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 170\u001b[0m \u001b[0mpdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmtx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmincrits_inverted\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
"\u001b[0;31mNameError\u001b[0m: global name 'data' is not defined" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"data.plot()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 2", | ||
"language": "python", | ||
"name": "python2" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import random | ||
|
||
import numpy as np | ||
|
||
from skcriteria import Data | ||
|
||
mtx = np.random.rand(10, 10) | ||
criteria = np.asarray([1,-1, 1, 1,1,1,1,1,1,1]) | ||
weights = np.random.randint(1, 100, 10) | ||
data = Data(mtx, criteria, weights) | ||
data.plot(mnorm="vector", wnorm="sum", cmap="jet", frame="circle") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2016-2017, Cabral, Juan; Luczywo, Nadia | ||
# All rights reserved. | ||
|
||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
|
||
# * Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
|
||
# * Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
|
||
# * Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
|
||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
# ============================================================================= | ||
# FUTURE | ||
# ============================================================================= | ||
|
||
from __future__ import unicode_literals | ||
|
||
|
||
# ============================================================================= | ||
# DOCS | ||
# ============================================================================= | ||
|
||
__doc__ = """Plotting utilities | ||
""" | ||
|
||
|
||
# ============================================================================= | ||
# IMPORTS | ||
# ============================================================================= | ||
|
||
from .. import norm | ||
|
||
from .radar import radar_plot | ||
|
||
|
||
# ============================================================================= | ||
# CLASS | ||
# ============================================================================= | ||
|
||
class PlotProxy(object): | ||
|
||
def __init__(self, data): | ||
self._data = data | ||
|
||
def __unicode__(self): | ||
return self.to_str() | ||
|
||
def __bytes__(self): | ||
encoding = sys.getdefaultencoding() | ||
return self.__unicode__().encode(encoding, 'replace') | ||
|
||
def __str__(self): | ||
"""Return a string representation for a particular Object | ||
Invoked by str(df) in both py2/py3. | ||
Yields Bytestring in Py2, Unicode String in py3. | ||
""" | ||
if six.PY3: | ||
return self.__unicode__() | ||
return self.__bytes__() | ||
|
||
def __repr__(self): | ||
return str(self) | ||
|
||
def __call__(self, plotname="radar", **kwargs): | ||
method = getattr(self, plotname) | ||
return method(**kwargs) | ||
|
||
def to_str(self): | ||
return "PlotProxy for {}".format(self._data) | ||
|
||
def preprocess(self, data, mnorm, wnorm): | ||
nmtx = norm.norm(mnorm, data.mtx, criteria=data.criteria, axis=0) | ||
nweights = ( | ||
norm.norm(wnorm, data.weights, criteria=data.criteria) | ||
if data.weights is not None else | ||
np.ones(data.criteria.shape)) | ||
return nmtx, data.criteria, nweights | ||
|
||
def plot(self, func, mnorm="none", wnorm="none", **kwargs): | ||
data = self._data | ||
nmtx, criteria, nweights = self.preprocess(data, mnorm, wnorm) | ||
kwargs.update({ | ||
"mtx": nmtx, "criteria": criteria, | ||
"weights": nweights, "anames": data.anames, | ||
"cnames": data.cnames}) | ||
return func(**kwargs) | ||
|
||
def radar(self, **kwargs): | ||
self.plot(radar_plot, **kwargs) |
Oops, something went wrong.