alnurali / cvxstoc

Disciplined convex stochastic programming. For the cvxstoc home page, please see:
http://alnurali.github.io/cvxstoc/
31 stars 11 forks source link

I checked out the sample on paper: Disciplined Convex Stochastic Programming. No error, but no results. #11

Open zyFan68 opened 2 years ago

zyFan68 commented 2 years ago

EXSAMPLE

from cvxpy.constraints import nonpos
from cvxpy.constraints.nonpos import NonNeg, NonPos
from cvxstoc import expectation, prob
from cvxstoc import NormalRandomVariable, prob
from cvxpy.expressions.variable import Variable
from cvxpy.atoms import *
from cvxpy import Minimize, Maximize, Problem
import numpy
import cvxpy as cp
from cvxstoc.random_variable import RandomVariableFactory

n = 10
numpy.random.seed(1)
c = numpy.random.randn(n)
P, q, r = numpy.eye(n), numpy.random.randn(n), numpy.random.randn()
mu, Sigma = numpy.zeros(n), 0.1*numpy.eye(n)
omega = RandomVariableFactory().create_normal_rv(mu, Sigma)
m, eta = 100, 0.95

x = cp.Variable(n)
yield_constr = expectation(omega.T @ q + r, m) <= 1-eta
p = cp.Problem(cp.Minimize(x.T @ c), [yield_constr])
result = p.solve(verbose = True)
print(x.value)

TERMINAL

PS I:\zyf> & D:/Anaconda/envs/cvx/python.exe i:/zyf/sample.py
D:\Anaconda\envs\cvx\lib\site-packages\pymc\MCMC.py:81: UserWarning: Instantiating a Model object directly is deprecated. We recommend passing variables directly to the Model subclass.
  warnings.warn(message)
===============================================================================
                                     CVXPY
                                    v1.1.13
===============================================================================
(CVXPY) Oct 09 03:16:18 PM: Your problem has 10 variables, 1 constraints, and 10 parameters.
(CVXPY) Oct 09 03:16:18 PM: It is compliant with the following grammars: DCP, DQCP
(CVXPY) Oct 09 03:16:18 PM: CVXPY will first compile your problem; then, it will invoke a numerical solver to obtain a solution.
-------------------------------------------------------------------------------
                                  Compilation
-------------------------------------------------------------------------------
(CVXPY) Oct 09 03:16:18 PM: Compiling problem (target solver=ECOS).
(CVXPY) Oct 09 03:16:18 PM: Reduction chain: Dcp2Cone -> CvxAttr2Constr -> ConeMatrixStuffing -> ECOS
(CVXPY) Oct 09 03:16:18 PM: Applying reduction Dcp2Cone
(CVXPY) Oct 09 03:16:18 PM: Applying reduction CvxAttr2Constr
(CVXPY) Oct 09 03:16:18 PM: Applying reduction ConeMatrixStuffing

There will be no error, but the result can not be obtained. I want to ask what might be wrong and whether this is a common problem. Looking forward to your reply. Thank you! @alnurali @SteveDiamond

SteveDiamond commented 2 years ago

cvxstoc is deprecated in favor of https://github.com/cvxgrp/osmm

zyFan68 commented 2 years ago

cvxstoc is deprecated in favor of https://github.com/cvxgrp/osmm

OK! Thanks!