Пример #1
0
 bool init()
 {
     V_ = FromEigen(v);
     dd_ErrorType error = dd_NoError;
     /*dd_rowset redset,impl_linset;
     dd_rowindex newpos;
     dd_MatrixCanonicalize(&V_, &impl_linset, &redset, &newpos, &error);
     if(error != dd_NoError)
     {
         std::cout << ("can not reduce matrix") << std::endl;
     }
     fprintf(stdout, "\nRedundant rows: ");
     set_fwrite(stdout, redset);
     fprintf(stdout, "\n");
     set_free(redset);
     set_free(impl_linset);
     free(newpos);
     error = dd_NoError;*/
     H_= dd_DDMatrix2Poly(V_, &error);
     if(error != dd_NoError)
     {
         if(dd_debug)
             std::cout << ("numerical instability in cddlib. ill formed polytope") << std::endl;
     }
     else
     {
         init_= true;
         b_A = dd_CopyInequalities(H_);
         // get equalities and add them as complementary inequality constraints
         long elem;
         std::vector<long> eq_rows;
         for(elem=1;elem<=(long)(b_A->linset[0]);++elem)
         {
             if (set_member(elem,b_A->linset))
                eq_rows.push_back(elem);
         }
         int rowsize = (int)b_A->rowsize;
         A = matrix_t (rowsize + eq_rows.size(), (int)b_A->colsize-1);
         b = vector_t (rowsize + eq_rows.size());
         for(int i=0; i < rowsize; ++i)
         {
             b(i) = (value_type)(*(b_A->matrix[i][0]));
             for(int j=1; j < b_A->colsize; ++j)
             {
                 A(i, j-1) = -(value_type)(*(b_A->matrix[i][j]));
             }
         }
         int i = 0;
         for(std::vector<long int>::const_iterator cit = eq_rows.begin();
             cit != eq_rows.end(); ++cit, ++i)
         {
             b(rowsize + i) = -b((int)(*cit));
             A(rowsize + i) = -A((int)(*cit));
         }
     }
     return init_;
 }
Пример #2
0
void make_test_predict(bool async)
{
    auto estimator = train_estimator();
    estimator->predicted_quantiles(mkcol({0.5, 0.9}));
    const auto X = get_X();
    const auto threads = async ? 3 : 1;
    const auto y_resp = estimator->predict(X, threads);
    assert_equal(X.n_rows, y_resp.n_rows, SPOT);
    assert_equal(2u, y_resp.n_cols, SPOT);
    auto y_exp = matrix_t(X.n_rows, 2u);
    for (std::size_t i=0; i<X.n_rows; ++i) {
        y_exp.row(i) = mkrow({5.5, 7.5});
    }
    assert_equal_containers(y_exp, y_resp, SPOT);
}
Пример #3
0
	vector< vector <Type> > transpose(const vector< vector<Type> >& matrix)
	{
		//if empty, return a new empty
		if(matrix.size() == 0)
			return vector< vector<int> >();

		//safety check
		for(unsigned i = 0, size=matrix[0].size(); i < matrix.size(); i++)
			if(matrix[i].size() != size)
				throw Exception("Matrix with differing row sizes! " + matrix[i].size());

		vector< vector<Type> > matrix_t(matrix[0].size(), vector<Type>(matrix.size()));

		for(unsigned i = 0; i < matrix.size(); i++)
			for(unsigned j = 0; j < matrix[i].size(); j++)
				matrix_t[j][i] = matrix[i][j];

		return matrix_t;
	}
Пример #4
0
System::System(int dimension) {
    dim = dimension;
    vars.resize(dimension);
    v_tmp.resize(dimension);
    dfdt.resize(dim);
    for (int i=0; i<4; i++)
        _rk4[i].resize(dimension);
    jacobian = matrix_t(dim, dim);
    ode_explicit_pair = std::make_pair ([this](const state_t & state,
                                               state_t &out, const double time) -> void {
                                            this->rhs(state, out, time);
                                        },[this](const state_t & state,
                                                 matrix_t &out, const double time, state_t &dfdt) -> void {
                                            this->jac(state, out, time, dfdt);
                                        });
    stepper_kind = STEPPER_RK4;
    rhs_b = boost::bind(&System::rhs, this, _1, _2, _3);
    rhs_combined_b = boost::bind(&System::rhs_combined, this, _1, _2, _3);
    rhs_implicit_active = rhs_b;
}