Code Monkey home page Code Monkey logo

cvxr_tutorial's Introduction

=======

CVXR Tutorial

This is the bookdown for the CVXR tutorial at useR! 2019.

Preparatory Steps

  1. Clone this repo or download this repo as one master zip file.

  2. Open the file _book/index.html in your browser.

  3. Ensure that you follow the steps outlined in Chapter 2: Getting Started to be ready for the tutorial.

If you want a single markdown file with all the code, you will find it in the extra/code folder.

We are happy to see you at useR! 2019, Toulouse!

cvxr_tutorial's People

Contributors

anqif avatar bnaras avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cvxr_tutorial's Issues

Incorrect Solution for Exercise 6.4.4

Issue

Given the problem stated "Fit OLS with just the following order constraints on β: β_i≤β_{i+1} for i=1,…,4 and β_i≥β_{i+1} for i=5,…,p.", the solution should have beta_1 <= beta_2 ... beta4_ <= beta_5 and beta_5 >= beta_6 ... beta_9 >= beta_10.

However, the solution given doesn't satisfy this requirement.

D1 <- D2 <- diag(0, p)
D1[1:5, 1:5] <- 1; D2[5:p, 5:p] <- 1;
D3 <- D4 <- diag(0, p - 1)
D3[1:4, 1:4] <- 1; D4[5:(p-1), 5:(p-1)] <- 1;
constraints = list(D3 %*% diff(D1 %*% beta) >= 0, D4 %*% diff(D2 %*% beta) <= 0)
problem4 <- Problem(objective, constraints)
ex4 <- solve(problem4)
betaEstimate <- ex4$getValue(beta)

results in

beta_1 -3.9025328
beta_2 -2.9683386
beta_3 -1.8234267
beta_4 -1.1562133
beta_5 0.0753986
beta_6 0.9224317
beta_7 1.8799511
beta_8 3.1107020
beta_9 4.1086503
beta_10 5.0947592

Potential Solution

I believe something akin to the below would satisfy the constraints of the problem as stated.

# generate (p-1) x p matrix for both constraints
# beta_1 <= beta_2 implies beta_2 - beta_1 >= 0, etc.
# and beta_5 >= beta_6 implies beta_5 - beta_6 >= 0, etc.
ones <- diag(1, p)
d1 <- ones[-1, ] - ones[-10,]
d1[-(1:4),] <- 0
d2 <- ones[-10,] - ones[-1,]
d2[1:4,] <- 0
d <- d1 + d2

constraints <- list(d %*% beta >= 0)
problem <- Problem(objective, constraints)
result <- solve(problem1)
result$getValue(beta)

has a result of

beta_1 -4.124667
beta_2 -2.731246
beta_3 -1.739471
beta_4 -1.456388
beta_5 2.823590
beta_6 2.823590
beta_7 2.823590
beta_8 2.823590
beta_9 2.823590
beta_10 2.823590

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.