dwavesystems / dwavesystems/dwave-optimization

Consider adding categorical variables

Open
#436 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
31
Forks
36
Avg merge
16h 55m
Merged PRs (30d)
8

Description

### Example

Say one wants to model choosing between four different stocks, each with an expected return and a volatility. One might currently model it like
```python
model = Model()

expected_return = model.constant([...])
volatility = model.constant([...])

stock = model.integer(lower_bound=0, upper_bound=3)

stock_return = expected_return[stock]
stock_volatility = volatility[stock]
```
This works OK but `stock` isn't really modelling an integer variable in the sense that the ordering of the stocks in the relevant arrays does not hold any semantic meaning.

### Feature Request

In such cases a user might wish to use a [categorical variable](https://en.wikipedia.org/wiki/Categorical_variable). This might have a similar API
```python
model = Model()

expected_return = model.constant([...])
volatility = model.constant([...])

stock = model.categorical(num_categories=4)

stock_return = expected_return[stock]
stock_volatility = volatility[stock]
```
but semantically the solver would not consider the variable to be ordered.

### Other thoughts

This needs more thought, but something like
```python
stock = model.categorical(["a", "b", "c"]) # takes values in [0, 1, 2] as usual
stock == stock.category("a") # equivalent to stock == model.constant(0)
```
might be convenient. Or might just introduce a mess.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.