Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2-dim tuple for noise #176

Closed
lorenzoreus opened this issue Jan 28, 2019 · 6 comments
Closed

2-dim tuple for noise #176

lorenzoreus opened this issue Jan 28, 2019 · 6 comments

Comments

@lorenzoreus
Copy link

Dear Oscar,

I'm trying to implement a process for 2 variables in the price interpolation scheme.
Specifically I want to have a noise with a simultaneous but different movement for each variable.
The DiscreteDistribution only allows a vector (N,1) of posibble values for the N possible realizations. But I need to specify a matrix of (N,2) size to include all posibble values. Is it somehow possible to create a noise for DynamicPriceInterpolation in this case?

Thanks!

@odow
Copy link
Owner

odow commented Jan 28, 2019

The answer is just to create a vector of the Cartesian product of the discrete random variables.

# Support and probabilities of first random variable:
support_A = [1, 2, 3]
probability_A = [0.5, 0.2, 0.3]

# Support and probabilities of second random variable:
support_B = [5, 6]
probability_B = [0.5, 0.5]

# Vector of joint-supports:
supports = [(a, b) for a in support_A for b in support_B]

# Assuming that the random variables are independent
probabilities = [a * b for a in probability_A for b in probability_B]

# Form a discrete distribution
noise_distribution = DiscreteDistribution(supports, probability)

# Now the argument `noise` in the `dynamics` function will be a tuple `(a, b)`.

@lorenzoreus
Copy link
Author

Thanks Oscar!
Following the same approach if I want to add this noise as a tuple. how do operations work?
For example if I have

function modeldynamics(price,noise)
a1=price+noise
return a1
end
HOw price is defined? Is it also a tuple or an array? Is the + adding tuples componentwise?
i) How should I enter min_price? As an array or tuple?
ii) How do I call the component of this price in the SDDPmodel ?
iii) Something that applies for one-dim price process too. Can I write a constraint in terms of the price? I've only seen example where prices are in the @stageobjective with the syntax "price->"

Thanks for everything! I really appreaciate your help.

@odow
Copy link
Owner

odow commented Jan 28, 2019

HOw price is defined? Is it also a tuple or an array?

The riverchain example demonstrates N-dimensional prices. In particular

return (t,i) -> DynamicPriceInterpolation(
dynamics = (p,w) -> ar2price(p, w, t, i),
initial_price = (pbar, pbar),
min_price = (minprice, minprice),
max_price = (maxprice, maxprice),
noise = NOISES

Is the + adding tuples componentwise?

This isn't defined in Julia. It will error. You have to do it yourself.

i) How should I enter min_price? As an array or tuple?

See first comment.

ii) How do I call the component of this price in the SDDPmodel ?

It will be passed in as a tuple, so access it like a tuple.

@stageobjective(sp,
price -> sum(
valley_chain[i].spill_cost * spill[i] for i in 1:N
) - price[1] * generation_quantity
)

iii) Something that applies for one-dim price process too. Can I write a constraint in terms of the price? I've only seen example where prices are in the @stageobjective with the syntax "price->"

Unfortunately, this is never allowed. One key assumption that we make in our paper is that price is independent of the states and actions in the model.

If you mean put a constraint in price (e.g., clamp(price, 0, 1)), then this is allowed in some circumstances. It gets a bit tricky, but you need to ensure that concavity of the LP is maintained through this price mapping. In general, constraints such as this clamp destroy that concavity. Caveat emptor. It's up to you if this is a problem. If it isn't you'll get a good heuristic with no guarantee of global optimality.

@lorenzoreus
Copy link
Author

Thanks oscar. Very clear explanations.

And one last question related to this issue of price interpolation scheme
Can I somehow keep the current price (not the price at the next stage that includes the noise) as a state variable? I need to use this value, which is known at stage t, in a constraint.

@odow
Copy link
Owner

odow commented Feb 3, 2019

I need to use this value, which is known at stage t, in a constraint.

In almost all cases, you can't use the price in a constraint (that is, a JuMP @constraint constraint). The library purposefully excludes this possibility.

If you need to use the price in the prior stage in the price dynamics (for example, an auto-regressive process with lag two), you can augment the price-state dimension so it is a tuple of (price[t], price[t-1]).

@lorenzoreus
Copy link
Author

ok! thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants