MCD generates counterfactuals that meet multiple, customizable objectives in both the feature and performance spaces.
Project description
Multiobjective-Counterfactuals-for-Design
MCD generates counterfactuals that meet multiple, customizable objectives in both the feature and performance spaces.
About The Project
Multiobjective Counterfactuals for Design (MCD) is a framework primarily intended for the generation of design alternatives that meet user-specified performance criteria while remaining within a certain region of the design space. To use MCD, you need a dataset of designs that are reasonably representative of the desired region of the design space, including performance metrics, as well as a model capable of predicting the performance metrics of a given design. MCD is model agnostic - this means that the model need not be a differentiable machine learning model, or, in fact, a machine learning model in the first place. MCD also offers high flexibility in terms of the number and 'type' of performance targets that can be specified. Performance targets can be any combination of:
- 'Continuous Targets': (e.g. I want suggested bike designs to weigh between 2 and 4 kilograms)
- 'Classification Targets': (e.g. I want suggested bike designs to be classified as dirt bikes)
- 'Probability Targets': (e.g. I want each suggested design to have a higher probability of belonging to classes A or B than of belonging to C or D)
Built With
Quick-Start Guide
Installation
- Install MCD with:
pip install decode-mcd
- Run:
import random
from pymoo.core.variable import Real
import numpy as np
from decode_mcd import DesignTargets, DataPackage, MultiObjectiveProblem, CounterfactualsGenerator, ContinuousTarget
x = np.random.random(100)
x = x.reshape(100, 1)
y = x * 100
def predict(_x):
return _x * 100 + random.random()
data_package = DataPackage(features_dataset=x,
predictions_dataset=y,
query_x=x[0].reshape(1, 1),
design_targets=DesignTargets([ContinuousTarget(label=0,
lower_bound=25,
upper_bound=75)]),
datatypes=[Real(bounds=(0, 1))])
problem = MultiObjectiveProblem(data_package=data_package,
prediction_function=lambda design: predict(design),
constraint_functions=[])
generator = CounterfactualsGenerator(problem=problem,
pop_size=10,
initialize_from_dataset=False)
generator.generate(n_generations=10)
counterfactuals = generator.sample_with_dtai(num_samples=10, gower_weight=1,
avg_gower_weight=1, cfc_weight=1,
diversity_weight=50)
print(counterfactuals)
Roadmap
- We are currently working on support for gradient-based optimization
See the open issues for a full list of proposed features (and known issues).
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE
for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for decode_mcd-2024.2.22rc0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55a87e108c3eefe1321dcc55e23c302ae28fdfd079a54e0d8a8c7423bb387196 |
|
MD5 | a6bfa5a00f4a98c0e7933c5c73105d73 |
|
BLAKE2b-256 | 088430691423e094fdf5d22dfdd958c4d4ba91603d91516d6df860901c8bc5ca |