Code Monkey home page Code Monkey logo

eigen-qp's People

Contributors

jarredbarber 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

Watchers

 avatar  avatar  avatar

eigen-qp's Issues

Basic usage

Hi.
Thanks for great library.

I start to use this library, but have trouble.
I want to solve least square Ax=b under constraint Ex โ‰ฆ (1,1,1....), all variables are under 1.

Code is following.

void test()
{
    // construct Ax = b
    const int32_t numSample = 128;
    Eigen::SparseMatrix<double> A;
    Eigen::VectorXd b;
    A.resize(numSample,3);
    b.resize(numSample);
    for(int32_t sn=0;sn<numSample;++sn)
    {
        // something funtion
        const float x = float(sn)/float(numSample);
        const float y = 2.5f * x * x + 2.4f * x + 2.3f;
        //
        A.insert(sn,0) = x * x;
        A.insert(sn,1) = x;
        A.insert(sn,2) = 1.0f;
        b(sn) = y;
    }
    A.makeCompressed();
    
    // Make constraint. All coeffs are under 1. (Ex<I)
    // https://scicomp.stackexchange.com/a/11588
    Eigen::MatrixXd Q = A.transpose() * A;
    Eigen::VectorXd c = -A.transpose() * b;
    Eigen::MatrixXd A2;
    Eigen::VectorXd b2;
    A2.resize(3,3);
    b2.resize(3);
    A2.setIdentity();
    b2.setOnes();
    //
    Eigen::VectorXd x;
    x.resize(3);
    EigenQP::quadprog(Q, c, A2, b2, x);
    std::cout << x << std::endl;
}

I get x as (2.5,2.4,2.3). But this is not constraint.
And "b2.setOnes();" rewrite to "b2 << 10.0,10.0,10.0;", I got x as (0.106648, 0.355828, 0.216527).
Totally bad results, I might did bad operation, bud I can't figure out it.

Thanks.

Solver Produces Incorrect Solutions

I have attached a minimal example that demonstrates issues with quadprog.

The solution to this QP should be equal to the value of c, but quadprog sets x to nan.

#include "eigen-qp.hpp"
#include <Eigen/Core>
#include <iostream>
using namespace std;

int main(int argc, char **argv){
   Eigen::Matrix<double, 2,1> x;
   Eigen::Matrix<double, 2,2> Q = 2*Eigen::Matrix<double, 2,2>::Identity();
   Eigen::Matrix<double, 2,1> c = 2*Eigen::Matrix<double, 2,1>::Random();
   Eigen::Matrix<double, 2,2> A; A << 0,0,0,0; 
   
   Eigen::Matrix<double, 2,1> b; b << 1.0,1.0;
   
   EigenQP::quadprog(Q,c,A,b,x);
   cout << x << endl;

}

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.