Skip to content

Commit

Permalink
Merge pull request #3 from ZanMervic/develop
Browse files Browse the repository at this point in the history
Fixes to widget documentation, Install TensorFlow button
  • Loading branch information
markotoplak authored Dec 6, 2023
2 parents 8ae2f38 + 1ca751e commit 0c673da
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 141 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ coverage.xml


# Sphinx documentation
docs/_build/
doc/_build/

# Jupyter Notebook
.ipynb_checkpoints
Expand Down
File renamed without changes
File renamed without changes
1 change: 0 additions & 1 deletion orangecontrib/fairness/modeling/adversarial.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class AdversarialDebiasingModel(Model):
def __init__(self, model):
super().__init__()
self._model = model
self.params = vars()

def predict(self, data):
"""Function used to predict on new data"""
Expand Down
32 changes: 16 additions & 16 deletions orangecontrib/fairness/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
BACKGROUND = "#FFE559"

# Location of widget help files.
# WIDGET_HELP_PATH = (
# # Development documentation
# # You need to build help pages manually using
# # make htmlhelp
# # inside doc folder
# ("{DEVELOP_ROOT}/doc/_build/html/index.html", None),
WIDGET_HELP_PATH = (
# Development documentation
# You need to build help pages manually using
# make htmlhelp
# inside doc folder
("{DEVELOP_ROOT}/doc/_build/html/index.html", None),

# # Documentation included in wheel
# # Correct DATA_FILES entry is needed in setup.py and documentation has to be built
# # before the wheel is created.
# ("{}/help/orange3-fairness/index.html".format(sysconfig.get_path("data")), None),
# Documentation included in wheel
# Correct DATA_FILES entry is needed in setup.py and documentation has to be built
# before the wheel is created.
("{}/help/orange3-fairness/index.html".format(sysconfig.get_path("data")), None),

# # Online documentation url, used when the local documentation is not available.
# # Url should point to a page with a section Widgets. This section should
# # includes links to documentation pages of each widget. Matching is
# # performed by comparing link caption to widget name.
# ("http://orange3-fairness.readthedocs.io/en/latest/", "")
# )
# Online documentation url, used when the local documentation is not available.
# Url should point to a page with a section Widgets. This section should
# includes links to documentation pages of each widget. Matching is
# performed by comparing link caption to widget name.
("http://orange3-fairness.readthedocs.io/en/latest/", "")
)
18 changes: 15 additions & 3 deletions orangecontrib/fairness/widgets/owadversarialdebiasing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from Orange.widgets.utils.concurrent import TaskState, ConcurrentWidgetMixin
from Orange.base import Model
from Orange.widgets.widget import Msg
from orangecanvas.application.addons import AddonManagerDialog

from AnyQt.QtWidgets import QFormLayout, QLabel, QVBoxLayout
from AnyQt.QtWidgets import QFormLayout, QLabel, QVBoxLayout, QPushButton
from AnyQt.QtCore import Qt

from orangecontrib.fairness.modeling.adversarial import AdversarialDebiasingLearner
Expand Down Expand Up @@ -208,16 +209,27 @@ def no_tensorflow_layout(self):
layout = QVBoxLayout()
label = QLabel(
'The Adversarial Debiasing widget requires TensorFlow, which is not installed.\n'
'Install it via Options->Add-ons by clicking "Add more...", typing "tensorflow", and hitting "Add".\n'
'Note: TensorFlow installation may render Orange3 unusable, requiring a reinstallation.'
'You can install it by clicking the "Install TensorFlow" button below, selecting \n'
'the checkbox next to the "tensorflow" text and clicking the "Ok" button.\n'
'After that, you will need to restart Orange.'
)
label.setWordWrap(True)
layout.addWidget(label)
button = QPushButton("Install TensorFlow")
button.clicked.connect(self.instaall_tensorflow)
layout.addWidget(button)

box = gui.widgetBox(self.controlArea, True, orientation=layout)

self.Error.add_message("no_tensorflow", TENSORFLOW_NOT_INSTALLED)
self.Error.no_tensorflow()

def instaall_tensorflow(self):
"""
Installs tensorflow using the AddonManagerDialog
"""
manager = AddonManagerDialog(self)
manager.runQueryAndAddResults(["tensorflow"])

def add_main_layout(self):
if is_tensorflow_installed():
Expand Down
119 changes: 1 addition & 118 deletions orangecontrib/fairness/widgets/tests/test_owadversarialdebiasing.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,122 +124,5 @@ def test_callback_with_learner(self):
self.assertTrue(0 <= self.last_received_progress <= 100)




if __name__ == "__main__":
unittest.main()











# def test_cross_validation(self):
# """Check if the widget works with cross validation"""
# self.widget.number_of_epochs = 10
# self.widget.debias = False

# test_data = Table(self.data_path_adult)

# learner = self.widget.create_learner()

# cv = CrossValidation(k=5, random_state=42, store_data=True)
# results = cv(test_data, [learner])

# self.assertIsNotNone(results)
# print("Cross validation results:")
# print_metrics(results)

# def test_train_test_split(self):
# """Check if the widget works with a normal train-test split"""
# self.widget.number_of_epochs = 10
# self.widget.debias = False

# test_data = Table(self.data_path_adult)

# learner = self.widget.create_learner()

# test_on_training = TestOnTrainingData(store_data=True)
# results = test_on_training(test_data, [learner])

# self.assertIsNotNone(results)
# print("Train test split results:")
# print_metrics(results)


# def test_compatibility_with_test_and_score(self):
# """Check that the widget works with the predictions widget"""
# self.test_and_score = self.create_widget(OWTestAndScore)

# self.widget.number_of_epochs = 10
# self.widget.debias = False

# data_sample = Table("orangedemo/tests/datasets/adult_sample.pkl")
# data_remaining = Table("orangedemo/tests/datasets/adult_remaining.pkl")
# self.send_signal(self.widget.Inputs.data, data_sample)

# self.wait_until_finished(self.widget, timeout=2000000)

# learner = self.get_output(self.widget.Outputs.learner)

# self.send_signal(
# self.test_and_score.Inputs.train_data, data_remaining, widget=self.test_and_score
# )
# self.send_signal(
# self.test_and_score.Inputs.learner, learner, widget=self.test_and_score
# )
# results = self.get_output(
# self.test_and_score.Outputs.evaluations_results, widget=self.test_and_score
# )

# print_metrics(results)

# def test_compatibility_with_predictions(self):
# """Check that the widget works with the predictions widget"""
# self.predictions = self.create_widget(OWPredictions)

# self.widget.number_of_epochs = 10
# self.widget.debias = False

# data_sample = Table("orangedemo/tests/datasets/adult_sample.pkl")
# data_remaining = Table("orangedemo/tests/datasets/adult_remaining.pkl")
# self.send_signal(self.widget.Inputs.data, data_sample)

# self.wait_until_finished(self.widget, timeout=2000000)

# model = self.get_output(self.widget.Outputs.model)

# self.send_signal(
# self.predictions.Inputs.data, data_remaining, widget=self.predictions
# )
# self.send_signal(
# self.predictions.Inputs.predictors, model, widget=self.predictions
# )
# results = self.get_output(
# self.predictions.Outputs.evaluation_results, widget=self.predictions
# )

# print_metrics(results)

# def test_model_with_predictions_and_average_impute(self):
# from Orange.widgets.evaluate.owpredictions import OWPredictions

# self.predictions = self.create_widget(OWPredictions)

# self.widget.number_of_epochs = 10
# self.widget.debias = True
# test_data = Table("C:/Users/zanme/Downloads/my_adult.pkl")

# self.send_signal(self.widget.Inputs.data, test_data)
# self.wait_until_finished(self.widget, timeout=200000)
# model = self.get_output(self.widget.Outputs.model)

# self.send_signal(self.predictions.Inputs.data, test_data)
# self.send_signal(self.predictions.Inputs.predictors, model)
# results = self.get_output(self.predictions.Outputs.evaluation_results)
# print(CA(results))
unittest.main()
1 change: 0 additions & 1 deletion orangecontrib/fairness/widgets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def wrapper(widget, input, *args, **kwargs):



#TODO: Make the fairness widgets compatible with eachother.
def check_for_reweighing_preprocessor(f):
"""A function which checks if the input to a widget is a reweighing preprocessor."""
from orangecontrib.fairness.widgets.owreweighing import ReweighingTransform
Expand Down
19 changes: 18 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from setuptools import setup, find_packages
from os import path
from os import path, walk

VERSION = "0.1.6"

Expand All @@ -10,6 +10,19 @@
except FileNotFoundError:
LONG_DESCRIPTION = ""


DATA_FILES = []

def include_documentation(local_dir, install_dir):
global DATA_FILES
doc_files = []
for dirpath, dirs, files in walk(local_dir):
doc_files.append((dirpath.replace(local_dir, install_dir),
[path.join(dirpath, f) for f in files]))
DATA_FILES.extend(doc_files)

include_documentation('doc/_build/html', 'help/orange3-fairness')

setup(
name="Orange3-Fairness",
version=VERSION,
Expand Down Expand Up @@ -41,6 +54,9 @@
entry_points={
"orange3.addon": ("Orange3-Fairness = orangecontrib.fairness",),
"orange.widgets": ("Fairness = orangecontrib.fairness.widgets",),
"orange.canvas.help": (
'html-index = orangecontrib.fairness.widgets:WIDGET_HELP_PATH',
),
},
install_requires=[
"Orange3",
Expand All @@ -54,4 +70,5 @@
"recommonmark",
]
},
data_files=DATA_FILES,
)

0 comments on commit 0c673da

Please sign in to comment.