Skip to main content

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

  • Python
  • Pymoo
  • Pandas
  • Numpy

Quick-Start Guide

Installation

  1. Install MCD with: pip install decode-mcd
  2. 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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

decode-mcd-2024.2.22rc0.tar.gz (35.3 kB view hashes)

Uploaded Source

Built Distribution

decode_mcd-2024.2.22rc0-py3-none-any.whl (26.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page