Skip to content

Commit

Permalink
v0.2.2 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikulatomas authored Jan 19, 2022
1 parent a47cc8a commit 80e9695
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 31 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Tomáš Mikula
Copyright (c) 2022 Tomáš Mikula

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ https://doi.org/10.1016/j.ijar.2021.12.001

fcapsy-experiments requires:

* Python (>= 3.6)
* fcapsy
* plotly
* pandas
Expand Down
4 changes: 2 additions & 2 deletions fcapsy_experiments/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .correlation_table import CorrelationTable
from .correlations_box_plot import correlations_boxplots

__version__ = "0.2.1"
__version__ = "0.2.2"
__author__ = "Tomáš Mikula"
__email__ = "mail@tomasmikula.cz"
__license__ = 'MIT license'
__license__ = "MIT license"
10 changes: 7 additions & 3 deletions fcapsy_experiments/_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
},
{"selector": "td", "props": [("padding", "3px")]},
{"selector": ".row_heading", "props": [("padding-right", "3px")]}
{"selector": ".row_heading", "props": [("padding-right", "3px")]},
]

css_typ = [
Expand All @@ -24,6 +24,10 @@

css_corr = [
{"selector": "td, th", "props": [("text-align", "center")]},
{"selector": "thead th", "props": [("text-align", "center !important")]},
# {"selector": "thead th", "props": [("text-align", "center !important")]},
{"selector": "tbody th", "props": [("text-align", "right")]},
]
{
"selector": "th.col_heading",
"props": [("writing-mode", "vertical-rl"), ("transform", "rotateZ(-90deg)")],
},
]
27 changes: 23 additions & 4 deletions fcapsy_experiments/correlation_table.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import typing
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go

from fuzzycorr import fuzzy_correlation_factory
from fuzzycorr.strict_orderings import lukasiewicz_strict_ordering_factory
Expand Down Expand Up @@ -41,7 +43,7 @@ def _make_triangle(self, df):
df = df.where(np.triu(np.ones(df.shape)).astype(bool))
return df.fillna("")

def to_html(self) -> str:
def to_html(self, triangle=True) -> str:
"""Generates html which represents the correlation table.
Returns:
Expand All @@ -53,15 +55,18 @@ def highlight_low_corr(x):
return None
return f"font-weight: bold;" if abs(x) < 0.2 else None

df = self._make_triangle(self.corr)
if triangle:
df = self._make_triangle(self.corr)
else:
df = self.corr

df = df.style.format(precision=2)
df.set_table_styles(css + css_corr)
df.applymap(highlight_low_corr)

return df.to_html()

def p_values_to_html(self) -> typing.Optional[str]:
def p_values_to_html(self, triangle=True) -> typing.Optional[str]:
"""Generates html of pvalues table.
Returns:
Expand All @@ -76,14 +81,28 @@ def highlight_high_p_value(x):
if self.p_values is None:
return None

df = self._make_triangle(self.p_values)
if triangle:
df = self._make_triangle(self.p_values)
else:
df = self.p_values

df = df.style.format(precision=2)
df.set_table_styles(css + css_corr)
df.applymap(highlight_high_p_value)

return df.to_html()

def to_plotly(self) -> "go.Figure":
fig = px.imshow(self.corr)
return fig

def to_plotly_html(self) -> str:
return self.to_plotly().to_html(
full_html=False,
include_plotlyjs="cdn",
include_mathjax="cdn",
)


class CorrelationTable:
def __init__(self, source: "pd.DataFrame", dataset: str = None) -> None:
Expand Down
12 changes: 6 additions & 6 deletions fcapsy_experiments/correlations_box_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def correlations_boxplots(correlations, to):
dataset = correlation.dataset
local_df = correlation.kendall.corr
local_df_p_values = correlation.kendall.p_values

local_row = local_df.drop(to, axis=1)
local_row.loc[to][local_df_p_values.drop(to, axis=1).loc[to] > 0.04] = np.NaN

Expand Down Expand Up @@ -66,8 +66,8 @@ def correlations_boxplots(correlations, to):
fig.update_traces(orientation="h")

return fig.to_html(
full_html=False,
include_plotlyjs="cdn",
include_mathjax="cdn",
default_width=739 // 2,
)
full_html=False,
include_plotlyjs="cdn",
include_mathjax="cdn",
default_width=739 // 2,
)
16 changes: 9 additions & 7 deletions fcapsy_experiments/typicality/concept_typicality.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import itertools
import typing

import pandas as pd
import plotly.graph_objects as go
Expand Down Expand Up @@ -86,20 +85,21 @@ def _init(self, concept, count, typicality_functions, extra_columns):
if args:
row = []
for name, arg in typicality["args"].items():
print(name)
row.append(function(item, concept, *arg))
else:
row.append(function(item, concept))



df.loc[item] = row

if count:
counts = (extent.bits().count("1") for extent in self._items_sets)

df[self.count_label] = [
row[1] for row in filter(lambda x: x[0] in self._concept_core, zip(self._items_domain, counts))
row[1]
for row in filter(
lambda x: x[0] in self._concept_core,
zip(self._items_domain, counts),
)
]

if extra_columns:
Expand Down Expand Up @@ -207,7 +207,9 @@ def to_plotly(self) -> "go.Figure":

return fig

def to_plotly_html(self, default_width: int=700, default_height: int=390) -> str:
def to_plotly_html(
self, default_width: int = 700, default_height: int = 390
) -> str:
"""Generates html version of plotly graph
Args:
Expand All @@ -223,4 +225,4 @@ def to_plotly_html(self, default_width: int=700, default_height: int=390) -> str
include_mathjax="cdn",
default_width=default_width,
default_height=default_height,
)
)
13 changes: 6 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import pathlib
from setuptools import setup, find_packages
from fcapsy_experiments import __version__, __author__, __email__, __license__

setup(
name="fcapsy-experiments",
version=__version__,
author=__author__,
author_email=__email__,
version="0.2.2",
author="Tomáš Mikula",
author_email="mail@tomasmikula.cz",
description="Package of experiments for fcapsy library.",
keywords="fca formal concept analysis experiments",
license=__license__,
license="MIT license",
url="https://github.com/mikulatomas/fcapsy_experiments",
packages=find_packages(),
python_requires=">=3.6",
python_requires=">=3.7",
install_requires=[
"fcapsy",
"plotly",
Expand All @@ -31,9 +30,9 @@
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
)

0 comments on commit 80e9695

Please sign in to comment.