Exemplo n.º 1
0
void cheboksarovv::lab7()
{ double* a1=new double[N];
  double* a2=new double[N];
  double e=0.00000001;
   do{
       a2=v(um(A,x),b);
       a1=v(a1,umc(a2,uc(um(A,a2),a2)/uc(um(A,a2),um(A,a2))));
            }while(logik(x,a1,e));
}
Exemplo n.º 2
0
 int maximumGap(vector<int>& nums) {
     int gap = 0,
         l = INT_MAX,
         u = 0;
     for (int num: nums) {
         l = min(l, num);
         u = max(u, num);
     }
     if (l < u) {
         gap = div_(u - l, nums.size() - 1);
         vector<vector<int>> um(nums.size());
         for (int num: nums)
             um[(num - l) / gap].push_back(num);
         u = l;
         for (auto &v: um)
             if (!v.empty()) {
                 int pu = u;
                 l = INT_MAX;
                 for (int num: v) {
                     l = min(l, num);
                     u = max(u, num);
                 }
                 gap = max(gap, l - pu);
             }
     }
     return gap;
 }
Exemplo n.º 3
0
TEST(Image2D, turnOffOpenCL)
{
    if (cv::ocl::haveOpenCL())
    {
        // save the current state
        bool useOCL = cv::ocl::useOpenCL();
        bool isFormatSupported = false;

        cv::ocl::setUseOpenCL(true);
        UMat um(128, 128, CV_8UC1);

        cv::ocl::setUseOpenCL(false);
        EXPECT_NO_THROW(isFormatSupported = cv::ocl::Image2D::isFormatSupported(CV_8U, 1, true));

        if (isFormatSupported)
        {
            EXPECT_NO_THROW(cv::ocl::Image2D image(um));
        }
        else
            std::cout << "CV_8UC1 is not supported for OpenCL images. Test skipped." << std::endl;
    
        // reset state to the previous one
        cv::ocl::setUseOpenCL(useOCL);
    }
    else
        std::cout << "OpenCL runtime not found. Test skipped." << std::endl;
}
Exemplo n.º 4
0
TEST(Image2D, createAlias)
{
    if (cv::ocl::haveOpenCL())
    {
        const cv::ocl::Device & d = cv::ocl::Device::getDefault();
        int minor = d.deviceVersionMinor(), major = d.deviceVersionMajor();

        // aliases is OpenCL 1.2 extension
        if (1 < major || (1 == major && 2 <= minor))
        {
            UMat um(128, 128, CV_8UC1);
            bool isFormatSupported = false, canCreateAlias = false;

            EXPECT_NO_THROW(isFormatSupported = cv::ocl::Image2D::isFormatSupported(CV_8U, 1, false));
            EXPECT_NO_THROW(canCreateAlias = cv::ocl::Image2D::canCreateAlias(um));

            if (isFormatSupported && canCreateAlias)
            {
                EXPECT_NO_THROW(cv::ocl::Image2D image(um, false, true));
            }
            else
                std::cout << "Impossible to create alias for selected image. Test skipped." << std::endl;
        }
    }
    else
        std::cout << "OpenCL runtime not found. Test skipped" << std::endl;
}
Exemplo n.º 5
0
void
au (int qj)
{
  if (qj < 1)
    {
vq:
      ty ();
    }

  um ();

  goto vq;
}
Exemplo n.º 6
0
//-----------------------------------------------------------------------------------------
void print_usage()
{
    UsageMan um("hfprint", GETARGLIST, "<fix protocol file, use '-' for stdin>");
    um.setdesc("hfprint -- f8 protocol log printer");
    um.add('h', "help", "help, this screen");
    um.add('v', "version", "print version then exit");
    um.add('o', "offset", "bytes to skip on each line before parsing FIX message");
    um.add('s', "summary", "summary, generate message summary");
    um.add("e.g.");
    um.add("@hfprint myfix_server_protocol.log");
    um.add("@hfprint hfprint -s -o 12 myfix_client_protocol.log");
    um.add("@cat myfix_client_protocol.log | hfprint -");
    um.print(cerr);
}
Exemplo n.º 7
0
// called from the subclass destructor
void reftarget::invalidate() 
{
	pw::lockmutex lm(mutex_);
	valid_ = false;
	while (rlist_) {
		weakref *wr = rlist_;
		rlist_ = rlist_->next_;
		if (rlist_)
			rlist_->prevp_ = &rlist_;
		wr->prevp_ = 0;
		wr->next_ = 0;
		bool code = wr->invalidate1();
		if (code) {
			pw::unlockmutex um(mutex_);
			wr->invalidate2();
		}
	}
	hold_.wait();
}
Exemplo n.º 8
0
//-----------------------------------------------------------------------------------------
void print_usage()
{
	UsageMan um("seqedit", GETARGLIST, "<perist file prefix>");
	um.setdesc("seqedit -- edit next expected send/receive");
	um.add('R', "receive", "set next expected receive sequence number");
	um.add('S', "send", "set next send sequence number");
	um.add('d', "dump", "dump all the records in both the index and the data file");
	um.add('D', "rawdump", "dump all the raw data records referenced in the index");
	um.add('h', "help", "help, this screen");
	um.add('i', "index", "only dump the index not the data records");
	um.add('q', "quiet", "set the sequence numbers silently");
	um.add('v', "version", "print version, exit");
	um.add("e.g.");
	um.add("@seqedit client.DLD_TEX.TEX_DLD");
	um.add("@seqedit -R 23417 -S 2341 client.DLD_TEX.TEX_DLD");
	um.add("@seqedit -d client.DLD_TEX.TEX_DLD");
	um.add("@seqedit -D client.DLD_TEX.TEX_DLD");
	um.add("@seqedit -id client.DLD_TEX.TEX_DLD");
	um.print(cerr);
}
Exemplo n.º 9
0
// so chamar pre msm..
void pre()
{
	tab[0][0] = Num(1, 1);
	for (int i = 1; i <= 400; ++i)
	{
		// primeiro calcula outras colunas
		for (int j = 1; j <= i; ++j)
		{
			//printf("%d %d ", i, j);
			//tab[i-1][j-1].print(); printf("\n");
			tab[i][j] = Num(i, j+1)*tab[i-1][j-1];
		}
		// primeira coluna
		Num um(1, 1);
		Num soma(0, 1);
		for (int j = 1; j <= i; ++j)
		{
			soma = soma+tab[i][j];
		}
		soma.a *= -1;
		tab[i][0] = um+soma;
	}
}
Exemplo n.º 10
0
int main(int argc, char * argv[])
{
    try
    {
        std::string directory_path;
        std::string folderkey;
        std::string password;
        std::string save_as;
        std::vector<std::string> upload_file_path;
        std::string username;

        po::options_description visible("Allowed options");
        /* clang-format off */
        visible.add_options()
            ("folderkey"     , po::value<std::string>(&folderkey)      , "Folderkey to the directory where to upload")
            ("help,h"        ,                                           "Show this message.")
            ("password,p"    , po::value<std::string>(&password)       , "Password for login")
            ("path"          , po::value<std::string>(&directory_path) , "Directory path where to upload file")
            ("saveas,s"      , po::value<std::string>(&save_as)        , "Upload file with custom name.  If multiple files passed, only the first is renamed.")
            ("username,u"    , po::value<std::string>(&username)       , "Username for login")
            ("replace,r"     ,                                           "Replace file if one exists already with the same name.")
            ("autorename,a"  ,                                           "Rename the file if it exists already.")
            ;
        /* clang-format on */

        po::options_description hidden("Hidden options");
        hidden.add_options()(
                "upload_file_path",
                po::value<std::vector<std::string>>(&upload_file_path),
                "upload_file_path");

        po::positional_options_description p;
        p.add("upload_file_path", -1);

        po::options_description cmdline_options;
        cmdline_options.add(visible).add(hidden);

        po::variables_map vm;
        try
        {
            po::store(po::command_line_parser(argc, argv)
                              .options(cmdline_options)
                              .positional(p)
                              .run(),
                      vm);
            po::notify(vm);
        }
        catch (boost::program_options::error & err)
        {
            std::cout << "Error: " << err.what() << std::endl;
            ShowUsage(argv[0], visible);
            return 1;
        }

        if (vm.count("help") || !vm.count("upload_file_path")
            || !vm.count("username") || !vm.count("password"))
        {
            ShowUsage(argv[0], visible);
            return 0;
        }

        if (vm.count("replace") && vm.count("autorename"))
        {
            std::cout << "Unable to replace and autorename." << std::endl;
            ShowUsage(argv[0], visible);
            return 1;
        }

        asio::io_service io_service;

        std::map<int, std::string> summary_map;

        {
            auto http_config = mf::http::HttpConfig::Create();
            http_config->SetWorkIoService(&io_service);

            mf::api::SessionMaintainer stm(http_config);

            // Handle session token failures.
            stm.SetSessionStateChangeCallback(
                    [&io_service](mf::api::SessionState state)
                    {
                        if (boost::get<mf::api::session_state::
                                               CredentialsFailure>(&state))
                        {
                            std::cout << "Username or password incorrect."
                                      << std::endl;
                            io_service.stop();
                        }
                    });

            stm.SetLoginCredentials(
                    mf::api::credentials::Email{username, password});

            mf::uploader::UploadManager um(&stm);

            const int files_to_upload = upload_file_path.size();
            int files_uploaded = 0;
            for (auto file_id = 0; file_id < files_to_upload; ++file_id)
            {
                mf::uploader::UploadRequest request(upload_file_path[file_id]);

                if (vm.count("folderkey"))
                    request.SetTargetFolderkey(folderkey);

                if (vm.count("path"))
                    request.SetTargetFolderPath(directory_path);

                if (vm.count("saveas") && file_id == 0)
                    request.SetTargetFilename(save_as);

                if (vm.count("replace"))
                {
                    request.SetOnDuplicateAction(
                            mf::uploader::OnDuplicateAction::Replace);
                }

                if (vm.count("autorename"))
                {
                    request.SetOnDuplicateAction(
                            mf::uploader::OnDuplicateAction::AutoRename);
                }

                um.Add(request,
                       [&io_service, files_to_upload, &files_uploaded, file_id,
                        &summary_map](mf::uploader::UploadStatus status)
                       {
                           boost::apply_visitor(
                                   StatusVisitor(io_service, file_id,
                                                 files_to_upload,
                                                 &files_uploaded, &summary_map),
                                   status.state);
                       });
            }

            io_service.run();

            if (files_to_upload > 0)
            {
                int file_id = 0;
                std::cout << std::endl;
                for (auto & pair : summary_map)
                {
                    std::cout << "File " << (file_id + 1) << ": "
                              << upload_file_path[file_id] << std::endl;
                    std::cout << pair.second << std::endl;
                    ++file_id;
                }
            }
        }
    }
    catch (std::exception & e)
    {
        std::cerr << "Uncaught exception: " << e.what() << "\n";
        return 1;
    }
    catch (...)
    {
        std::cerr << "Exception of unknown type!\n";
        return 1;
    }

    return 0;
}
Exemplo n.º 11
0
int soma_tres(int *x) {
    *x += um(x) + dois(*x);
}
Exemplo n.º 12
0
int dois(int x) {
    x = 0;
    return 1 + um(&x);
}
Exemplo n.º 13
0
int main() try 
{
    // Several ways to create and initialize band matrices:

    // Create with uninitialized values
    tmv::BandMatrix<double> m1(6,6,1,2);
    for(int i=0;i<m1.nrows();i++) 
        for(int j=0;j<m1.ncols();j++) 
            if (i<=j+m1.nlo() && j<=i+m1.nhi())
                m1(i,j) = 3.*i-j*j+7.; 
    std::cout<<"m1 =\n"<<m1;
    //! m1 =
    //! 6  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    //! ( 0  0  0  10  3  -6 )
    //! ( 0  0  0  0  6  -3 )

    // Create with all 2's.
    tmv::BandMatrix<double> m2(6,6,1,3,2.);
    std::cout<<"m2 =\n"<<m2;
    //! m2 =
    //! 6  6  
    //! ( 2  2  2  2  0  0 )
    //! ( 2  2  2  2  2  0 )
    //! ( 0  2  2  2  2  2 )
    //! ( 0  0  2  2  2  2 )
    //! ( 0  0  0  2  2  2 )
    //! ( 0  0  0  0  2  2 )

    // A BandMatrix can be non-square:
    tmv::BandMatrix<double> m3(6,8,1,3,2.);
    std::cout<<"m3 =\n"<<m3;
    //! m3 =
    //! 6  8  
    //! ( 2  2  2  2  0  0  0  0 )
    //! ( 2  2  2  2  2  0  0  0 )
    //! ( 0  2  2  2  2  2  0  0 )
    //! ( 0  0  2  2  2  2  2  0 )
    //! ( 0  0  0  2  2  2  2  2 )
    //! ( 0  0  0  0  2  2  2  2 )

    // Create from given elements:
    double mm[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
    tmv::BandMatrix<double,tmv::ColMajor> m4(6,6,2,1);
    std::copy(mm,mm+20,m4.colmajor_begin());
    std::cout<<"m4 (ColMajor) =\n"<<m4;
    //! m4 (ColMajor) =
    //! 6  6  
    //! ( 1  4  0  0  0  0 )
    //! ( 2  5  8  0  0  0 )
    //! ( 3  6  9  12  0  0 )
    //! ( 0  7  10  13  16  0 )
    //! ( 0  0  11  14  17  19 )
    //! ( 0  0  0  15  18  20 )
    tmv::BandMatrix<double,tmv::RowMajor> m5(6,6,2,1);
    std::copy(mm,mm+20,m5.rowmajor_begin());
    std::cout<<"m5 (RowMajor) =\n"<<m5;
    //! m5 (RowMajor) =
    //! 6  6  
    //! ( 1  2  0  0  0  0 )
    //! ( 3  4  5  0  0  0 )
    //! ( 6  7  8  9  0  0 )
    //! ( 0  10  11  12  13  0 )
    //! ( 0  0  14  15  16  17 )
    //! ( 0  0  0  18  19  20 )
    tmv::BandMatrix<double,tmv::DiagMajor> m6(6,6,2,1);
    std::copy(mm,mm+20,m6.diagmajor_begin());
    std::cout<<"m6 (DiagMajor) =\n"<<m6;
    //! m6 (DiagMajor) =
    //! 6  6  
    //! ( 10  16  0  0  0  0 )
    //! ( 5  11  17  0  0  0 )
    //! ( 1  6  12  18  0  0 )
    //! ( 0  2  7  13  19  0 )
    //! ( 0  0  3  8  14  20 )
    //! ( 0  0  0  4  9  15 )

    // Can make from the banded portion of a regular Matrix:
    tmv::Matrix<double> xm(6,6);
    for(int i=0;i<xm.nrows();i++) 
        for(int j=0;j<xm.ncols();j++) 
            xm(i,j) = 5.*i-j*j+3.; 
    tmv::BandMatrix<double> m7(xm,3,2);
    std::cout<<"m7 =\n"<<m7;
    //! m7 =
    //! 6  6  
    //! ( 3  2  -1  0  0  0 )
    //! ( 8  7  4  -1  0  0 )
    //! ( 13  12  9  4  -3  0 )
    //! ( 18  17  14  9  2  -7 )
    //! ( 0  22  19  14  7  -2 )
    //! ( 0  0  24  19  12  3 )
    // Or from a wider BandMatrix:
    tmv::BandMatrix<double> m8(m7,3,0);
    std::cout<<"m8 =\n"<<m8;
    //! m8 =
    //! 6  6  
    //! ( 3  0  0  0  0  0 )
    //! ( 8  7  0  0  0  0 )
    //! ( 13  12  9  0  0  0 )
    //! ( 18  17  14  9  0  0 )
    //! ( 0  22  19  14  7  0 )
    //! ( 0  0  24  19  12  3 )

    // Shortcuts to Bi- and Tri-diagonal matrices:
    tmv::Vector<double> v1(5,1.);
    tmv::Vector<double> v2(6,2.);
    tmv::Vector<double> v3(5,3.);
    tmv::BandMatrix<double> m9 = LowerBiDiagMatrix(v1,v2);
    tmv::BandMatrix<double> m10 = UpperBiDiagMatrix(v2,v3);
    tmv::BandMatrix<double> m11 = TriDiagMatrix(v1,v2,v3);
    std::cout<<"LowerBiDiagMatrix(v1,v2) =\n"<<m9;
    //! LowerBiDiagMatrix(v1,v2) =
    //! 6  6  
    //! ( 2  0  0  0  0  0 )
    //! ( 1  2  0  0  0  0 )
    //! ( 0  1  2  0  0  0 )
    //! ( 0  0  1  2  0  0 )
    //! ( 0  0  0  1  2  0 )
    //! ( 0  0  0  0  1  2 )
    std::cout<<"UpperBiDiagMatrix(v2,v3) =\n"<<m10;
    //! UpperBiDiagMatrix(v2,v3) =
    //! 6  6  
    //! ( 2  3  0  0  0  0 )
    //! ( 0  2  3  0  0  0 )
    //! ( 0  0  2  3  0  0 )
    //! ( 0  0  0  2  3  0 )
    //! ( 0  0  0  0  2  3 )
    //! ( 0  0  0  0  0  2 )
    std::cout<<"TriDiagMatrix(v1,v2,v3) =\n"<<m11;
    //! TriDiagMatrix(v1,v2,v3) =
    //! 6  6  
    //! ( 2  3  0  0  0  0 )
    //! ( 1  2  3  0  0  0 )
    //! ( 0  1  2  3  0  0 )
    //! ( 0  0  1  2  3  0 )
    //! ( 0  0  0  1  2  3 )
    //! ( 0  0  0  0  1  2 )


    // Norms, etc. 

    std::cout<<"Norm1(m1) = "<<Norm1(m1)<<std::endl;
    //! Norm1(m1) = 30
    std::cout<<"Norm2(m1) = "<<Norm2(m1)<<std::endl;
    //! Norm2(m1) = 24.0314
    std::cout<<"NormInf(m1) = "<<NormInf(m1)<<std::endl;
    //! NormInf(m1) = 28
    std::cout<<"NormF(m1) = "<<NormF(m1)<<" = "<<Norm(m1)<<std::endl;
    //! NormF(m1) = 32.0312 = 32.0312
    std::cout<<"MaxAbsElement(m1) = "<<MaxAbsElement(m1)<<std::endl;
    //! MaxAbsElement(m1) = 12
    std::cout<<"Trace(m1) = "<<Trace(m1)<<std::endl;
    //! Trace(m1) = 32
    std::cout<<"Det(m1) = "<<Det(m1)<<std::endl;
    //! Det(m1) = 67635


    // Views:

    std::cout<<"m1 =\n"<<m1;
    //! m1 =
    //! 6  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    //! ( 0  0  0  10  3  -6 )
    //! ( 0  0  0  0  6  -3 )
    std::cout<<"m1.diag() = "<<m1.diag()<<std::endl;
    //! m1.diag() = 6  ( 7  9  9  7  3  -3 )
    std::cout<<"m1.diag(1) = "<<m1.diag(1)<<std::endl;
    //! m1.diag(1) = 5  ( 6  6  4  0  -6 )
    std::cout<<"m1.diag(-1) = "<<m1.diag(-1)<<std::endl;
    //! m1.diag(-1) = 5  ( 10  12  12  10  6 )
    std::cout<<"m1.subBandMatrix(0,3,0,3,1,1) =\n"<<
        m1.subBandMatrix(0,3,0,3,1,1);
    //! m1.subBandMatrix(0,3,0,3,1,1) =
    //! 3  3  
    //! ( 7  6  0 )
    //! ( 10  9  6 )
    //! ( 0  12  9 )
    std::cout<<"m1.transpose() =\n"<<m1.transpose();
    //! m1.transpose() =
    //! 6  6  
    //! ( 7  10  0  0  0  0 )
    //! ( 6  9  12  0  0  0 )
    //! ( 3  6  9  12  0  0 )
    //! ( 0  1  4  7  10  0 )
    //! ( 0  0  -3  0  3  6 )
    //! ( 0  0  0  -9  -6  -3 )

    // rowRange, colRange shrink both dimensions of the matrix to include only
    // the portions that are in those rows or columns:
    std::cout<<"m1.rowRange(0,4) =\n"<<m1.rowRange(0,4);
    //! m1.rowRange(0,4) =
    //! 4  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    std::cout<<"m1.colRange(1,4) =\n"<<m1.colRange(1,4);
    //! m1.colRange(1,4) =
    //! 5  3  
    //! ( 6  3  0 )
    //! ( 9  6  1 )
    //! ( 12  9  4 )
    //! ( 0  12  7 )
    //! ( 0  0  10 )
    std::cout<<"m1.diagRange(0,2) =\n"<<m1.diagRange(0,2);
    //! m1.diagRange(0,2) =
    //! 6  6  
    //! ( 7  6  0  0  0  0 )
    //! ( 0  9  6  0  0  0 )
    //! ( 0  0  9  4  0  0 )
    //! ( 0  0  0  7  0  0 )
    //! ( 0  0  0  0  3  -6 )
    //! ( 0  0  0  0  0  -3 )
    std::cout<<"m1.diagRange(-1,1) =\n"<<m1.diagRange(-1,1);
    //! m1.diagRange(-1,1) =
    //! 6  6  
    //! ( 7  0  0  0  0  0 )
    //! ( 10  9  0  0  0  0 )
    //! ( 0  12  9  0  0  0 )
    //! ( 0  0  12  7  0  0 )
    //! ( 0  0  0  10  3  0 )
    //! ( 0  0  0  0  6  -3 )


    // Fortran Indexing:

    tmv::BandMatrix<double,tmv::FortranStyle> fm1 = m1;
    std::cout<<"fm1 = m1 =\n"<<fm1;
    //! fm1 = m1 =
    //! 6  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    //! ( 0  0  0  10  3  -6 )
    //! ( 0  0  0  0  6  -3 )
    std::cout<<"fm1(1,1) = "<<fm1(1,1)<<std::endl;
    //! fm1(1,1) = 7
    std::cout<<"fm1(4,3) = "<<fm1(4,3)<<std::endl;
    //! fm1(4,3) = 12
    std::cout<<"fm1.subBandMatrix(1,3,1,3,1,1) =\n"<<
        fm1.subBandMatrix(1,3,1,3,1,1);
    //! fm1.subBandMatrix(1,3,1,3,1,1) =
    //! 3  3  
    //! ( 7  6  0 )
    //! ( 10  9  6 )
    //! ( 0  12  9 )
    std::cout<<"fm1.rowRange(1,4) =\n"<<fm1.rowRange(1,4);
    //! fm1.rowRange(1,4) =
    //! 4  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    std::cout<<"fm1.colRange(2,4) =\n"<<fm1.colRange(2,4);
    //! fm1.colRange(2,4) =
    //! 5  3  
    //! ( 6  3  0 )
    //! ( 9  6  1 )
    //! ( 12  9  4 )
    //! ( 0  12  7 )
    //! ( 0  0  10 )
    std::cout<<"fm1.diagRange(0,1) =\n"<<fm1.diagRange(0,1);
    //! fm1.diagRange(0,1) =
    //! 6  6  
    //! ( 7  6  0  0  0  0 )
    //! ( 0  9  6  0  0  0 )
    //! ( 0  0  9  4  0  0 )
    //! ( 0  0  0  7  0  0 )
    //! ( 0  0  0  0  3  -6 )
    //! ( 0  0  0  0  0  -3 )
    std::cout<<"fm1.diagRange(-1,0) =\n"<<fm1.diagRange(-1,0);
    //! fm1.diagRange(-1,0) =
    //! 6  6  
    //! ( 7  0  0  0  0  0 )
    //! ( 10  9  0  0  0  0 )
    //! ( 0  12  9  0  0  0 )
    //! ( 0  0  12  7  0  0 )
    //! ( 0  0  0  10  3  0 )
    //! ( 0  0  0  0  6  -3 )


    // Matrix arithmetic:

    tmv::BandMatrix<double> m1pm2 = m1 + m2;
    std::cout<<"m1 + m2 =\n"<<m1pm2;
    //! m1 + m2 =
    //! 6  6  
    //! ( 9  8  5  2  0  0 )
    //! ( 12  11  8  3  2  0 )
    //! ( 0  14  11  6  -1  2 )
    //! ( 0  0  14  9  2  -7 )
    //! ( 0  0  0  12  5  -4 )
    //! ( 0  0  0  0  8  -1 )
    // Works correctly even if matrices are stored in different order:
    tmv::BandMatrix<double> m5pm6 = m5 + m6; 
    std::cout<<"m5 + m6 =\n"<<m5pm6;
    //! m5 + m6 =
    //! 6  6  
    //! ( 11  18  0  0  0  0 )
    //! ( 8  15  22  0  0  0 )
    //! ( 7  13  20  27  0  0 )
    //! ( 0  12  18  25  32  0 )
    //! ( 0  0  17  23  30  37 )
    //! ( 0  0  0  22  28  35 )
    // Also expands the number of off-diagonals appropriately as needed:
    tmv::BandMatrix<double> m2pm4 = m2 + m4; 
    std::cout<<"m2 + m4 =\n"<<m2pm4;
    //! m2 + m4 =
    //! 6  6  
    //! ( 3  6  2  2  0  0 )
    //! ( 4  7  10  2  2  0 )
    //! ( 3  8  11  14  2  2 )
    //! ( 0  7  12  15  18  2 )
    //! ( 0  0  11  16  19  21 )
    //! ( 0  0  0  15  20  22 )

    m1 *= 2.;
    std::cout<<"m1 *= 2 =\n"<<m1;
    //! m1 *= 2 =
    //! 6  6  
    //! ( 14  12  6  0  0  0 )
    //! ( 20  18  12  2  0  0 )
    //! ( 0  24  18  8  -6  0 )
    //! ( 0  0  24  14  0  -18 )
    //! ( 0  0  0  20  6  -12 )
    //! ( 0  0  0  0  12  -6 )

    m2 += m1;
    std::cout<<"m2 += m1 =\n"<<m2;
    //! m2 += m1 =
    //! 6  6  
    //! ( 16  14  8  2  0  0 )
    //! ( 22  20  14  4  2  0 )
    //! ( 0  26  20  10  -4  2 )
    //! ( 0  0  26  16  2  -16 )
    //! ( 0  0  0  22  8  -10 )
    //! ( 0  0  0  0  14  -4 )

    tmv::Vector<double> v = xm.col(0);
    std::cout<<"v = "<<v<<std::endl;
    //! v = 6  ( 3  8  13  18  23  28 )
    std::cout<<"m1 * v = "<<m1*v<<std::endl;
    //! m1 * v = 6  ( 216  396  432  60  162  108 )
    std::cout<<"v * m1 = "<<v*m1<<std::endl;
    //! v * m1 = 6  ( 202  492  780  832  396  -768 )

    // Matrix * matrix product also expands bands appropriately:
    tmv::BandMatrix<double> m1m2 = m1 * m2; 
    std::cout<<"m1 * m2 =\n"<<m1m2;
    //! m1 * m2 =
    //! 6  6  
    //! ( 488  592  400  136  0  12 )
    //! ( 716  952  704  264  -8  -8 )
    //! ( 528  948  904  272  -56  -32 )
    //! ( 0  624  844  464  -320  -104 )
    //! ( 0  0  520  452  -80  -332 )
    //! ( 0  0  0  264  12  -96 )

    // Can mix BandMatrix with other kinds of matrices:
    std::cout<<"xm * m1 =\n"<<xm*m1;
    //! xm * m1 =
    //! 6  6  
    //! ( 82  48  -120  -348  -336  396 )
    //! ( 252  318  180  -128  -276  216 )
    //! ( 422  588  480  92  -216  36 )
    //! ( 592  858  780  312  -156  -144 )
    //! ( 762  1128  1080  532  -96  -324 )
    //! ( 932  1398  1380  752  -36  -504 )
    tmv::UpperTriMatrix<double> um(xm);
    std::cout<<"um + m1 =\n"<<um+m1;
    //! um + m1 =
    //! 6  6  
    //! ( 17  14  5  -6  -13  -22 )
    //! ( 20  25  16  1  -8  -17 )
    //! ( 0  24  27  12  -9  -12 )
    //! ( 0  0  24  23  2  -25 )
    //! ( 0  0  0  20  13  -14 )
    //! ( 0  0  0  0  12  -3 )
    tmv::LowerTriMatrix<double> lm(xm);
    lm *= m8;
    std::cout<<"lm *= m8 =\n"<<lm;
    //! lm *= m8 =
    //! 6  6  
    //! ( 9  0  0  0  0  0 )
    //! ( 80  49  0  0  0  0 )
    //! ( 252  192  81  0  0  0 )
    //! ( 534  440  252  81  0  0 )
    //! ( 744  774  500  224  49  0 )
    //! ( 954  1064  782  396  120  9 )
    tmv::DiagMatrix<double> dm(xm);
    m1 *= dm;
    std::cout<<"m1 *= dm =\n"<<m1;
    //! m1 *= dm =
    //! 6  6  
    //! ( 42  84  54  0  0  0 )
    //! ( 60  126  108  18  0  0 )
    //! ( 0  168  162  72  -42  0 )
    //! ( 0  0  216  126  0  -54 )
    //! ( 0  0  0  180  42  -36 )
    //! ( 0  0  0  0  84  -18 )
    return 0;
} catch (tmv::Error& e) {
    std::cerr<<e<<std::endl;
    return 1;
}
Exemplo n.º 14
0
void AsiMS2000::selectCommand(int commandNum)
{
  switch(commandNum)
  {
      case 0:
          accel();
          break;
      case 1:
          aalign();
          break;
      case 2:
          afcont();
          break;
      case 3:
          aflim();
          break;
      case 4:
          afocus();
          break;
      case 5:
          afset();
          break;
      case 6:
          afmove();
          break;
      case 7:
          ahome();
          break;
      case 8:
          aij();
          break;
      case 9:
          array();
          break;
      case 10:
          azero();
          break;
      case 11:
          backlash();
          break;
      case 12:
          bcustom();
          break;
      case 13:
          benable();
          break;
      case 14:
          build();
          break;
      case 15:
          cdate();
          break;
      case 16:
          cnts();
          break;
      case 17:
          customa();
          break;
      case 18:
          customb();
          break;
      case 19:
          dack();
          break;
      case 20:
          dump();
          break;
      case 21:
          ensync();
          break;
      case 22:
          epolarity();
          break;
      case 23:
          error();
          break;
      case 24:
          halt();
          break;
      case 25:
          here();
          break;
      case 26:
          home();
          break;
      case 27:
          info();
          break;
      case 28:
          joystick();
          break;
      case 29:
          jsspd();
          break;
      case 30:
          kadc();
          break;
      case 31:
          kd();
          break;
      case 32:
          ki();
          break;
      case 33:
          kp();
          break;
      case 34:
          lcd();
          break;
      case 35:
          led();
          break;
      case 36:
          lladdr();
          break;
      case 37:
          load();
          break;
      case 38:
          lock();
          break;
      case 39:
          lockrg();
          break;
      case 40:
          lockset();
          break;
      case 41:
          maintain();
          break;
      case 42:
          motctrl();
          break;
      case 43:
          move();
          break;
      case 44:
          movrel();
          break;
      case 45:
          pcros();
          break;
      case 46:
          pedal();
          break;
      case 47:
          rbmode();
          break;
      case 48:
          rdadc();
          break;
      case 49:
          rdsbyte();
          break;
      case 50:
          rdstat();
          break;
      case 51:
          relock();
          break;
      case 52:
          reset();
          break;
      case 53:
          rt();
          break;
      case 54:
          runaway();
          break;
      case 55:
          saveset();
          break;
      case 56:
          savepos();
          break;
      case 57:
          scan();
          break;
      case 58:
          scanr();
          break;
      case 59:
          scanv();
          break;
      case 60:
          secure();
          break;
      case 61:
          sethome();
          break;
      case 62:
          setlow();
          break;
      case 63:
          setup();
          break;
      case 64:
          si();
          break;
      case 65:
          speed();
          break;
      case 66:
          spin();
          break;
      case 67:
          status();
          break;
      case 68:
          stopbits();
          break;
      case 69:
          ttl();
          break;
      case 70:
          um();
          break;
      case 71:
          units();
          break;
      case 72:
          unlock();
          break;
      case 73:
          vb();
          break;
      case 74:
          vector();
          break;
      case 75:
          version();
          break;
      case 76:
          wait();
          break;
      case 77:
          where();
          break;
      case 78:
          who();
          break;
      case 79:
          wrdac();
          break;
      case 80:
          zero();
          break;
      case 81:
          z2b();
          break;
      case 82:
          zs();
          break;
      case 83:
          overshoot();
          break;
  }
}
Exemplo n.º 15
0
double ung_ssm::bsf_filter(const unsigned int nsim, arma::cube& alpha,
  arma::mat& weights, arma::umat& indices) {
  
  arma::uvec nonzero = arma::find(P1.diag() > 0);
  arma::mat L_P1(m, m, arma::fill::zeros);
  if (nonzero.n_elem > 0) {
    L_P1.submat(nonzero, nonzero) =
      arma::chol(P1.submat(nonzero, nonzero), "lower");
  }
  std::normal_distribution<> normal(0.0, 1.0);
  for (unsigned int i = 0; i < nsim; i++) {
    arma::vec um(m);
    for(unsigned int j = 0; j < m; j++) {
      um(j) = normal(engine);
    }
    alpha.slice(i).col(0) = a1 + L_P1 * um;
  }
  
  std::uniform_real_distribution<> unif(0.0, 1.0);
  arma::vec normalized_weights(nsim);
  double loglik = 0.0;
  
  if(arma::is_finite(y(0))) {
    weights.col(0) = log_obs_density(0, alpha);
    double max_weight = weights.col(0).max();
    weights.col(0) = arma::exp(weights.col(0) - max_weight);
    double sum_weights = arma::accu(weights.col(0));
    if(sum_weights > 0.0){
      normalized_weights = weights.col(0) / sum_weights;
    } else {
      return -std::numeric_limits<double>::infinity();
    }
    loglik = max_weight + std::log(sum_weights / nsim);
  } else {
    weights.col(0).ones();
    normalized_weights.fill(1.0 / nsim);
  }
  for (unsigned int t = 0; t < n; t++) {
    
    arma::vec r(nsim);
    for (unsigned int i = 0; i < nsim; i++) {
      r(i) = unif(engine);
    }
    
    indices.col(t) = stratified_sample(normalized_weights, r, nsim);
    
    arma::mat alphatmp(m, nsim);
    
    for (unsigned int i = 0; i < nsim; i++) {
      alphatmp.col(i) = alpha.slice(indices(i, t)).col(t);
    }
    
    for (unsigned int i = 0; i < nsim; i++) {
      arma::vec uk(k);
      for(unsigned int j = 0; j < k; j++) {
        uk(j) = normal(engine);
      }
      alpha.slice(i).col(t + 1) = C.col(t * Ctv) +
        T.slice(t * Ttv) * alphatmp.col(i) + R.slice(t * Rtv) * uk;
    }
    
    if ((t < (n - 1)) && arma::is_finite(y(t + 1))) {
      weights.col(t + 1) = log_obs_density(t + 1, alpha);
      
      double max_weight = weights.col(t + 1).max();
      weights.col(t + 1) = arma::exp(weights.col(t + 1) - max_weight);
      double sum_weights = arma::accu(weights.col(t + 1));
      if(sum_weights > 0.0){
        normalized_weights = weights.col(t + 1) / sum_weights;
      } else {
        return -std::numeric_limits<double>::infinity();
      }
      loglik += max_weight + std::log(sum_weights / nsim);
    } else {
      weights.col(t + 1).ones();
      normalized_weights.fill(1.0/nsim);
    }
  }
  // constant part of the log-likelihood
  switch(distribution) {
  case 0 :
    loglik += arma::uvec(arma::find_finite(y)).n_elem * norm_log_const(phi);
    break;
  case 1 : {
      arma::uvec finite_y(find_finite(y));
      loglik += poisson_log_const(y(finite_y), u(finite_y));
    } break;
  case 2 : {
    arma::uvec finite_y(find_finite(y));
    loglik += binomial_log_const(y(finite_y), u(finite_y));
  } break;
  case 3 : {
    arma::uvec finite_y(find_finite(y));
    loglik += negbin_log_const(y(finite_y), u(finite_y), phi);
  } break;
  }
  return loglik;
}
Exemplo n.º 16
0
double ung_ssm::psi_filter(const ugg_ssm& approx_model,
  const double approx_loglik, const arma::vec& scales,
  const unsigned int nsim, arma::cube& alpha, arma::mat& weights,
  arma::umat& indices) {
  
  arma::mat alphahat(m, n + 1);
  arma::cube Vt(m, m, n + 1);
  arma::cube Ct(m, m, n + 1);
  approx_model.smoother_ccov(alphahat, Vt, Ct);
  conditional_cov(Vt, Ct);
  
  std::normal_distribution<> normal(0.0, 1.0);
  
  
  for (unsigned int i = 0; i < nsim; i++) {
    arma::vec um(m);
    for(unsigned int j = 0; j < m; j++) {
      um(j) = normal(engine);
    }
    alpha.slice(i).col(0) = alphahat.col(0) + Vt.slice(0) * um;
  }
  
  std::uniform_real_distribution<> unif(0.0, 1.0);
  arma::vec normalized_weights(nsim);
  double loglik = 0.0;
  if(arma::is_finite(y(0))) {
    weights.col(0) = arma::exp(log_weights(approx_model, 0, alpha) - scales(0));
    double sum_weights = arma::accu(weights.col(0));
    if(sum_weights > 0.0){
      normalized_weights = weights.col(0) / sum_weights;
    } else {
      return -std::numeric_limits<double>::infinity();
    }
    loglik = approx_loglik + std::log(sum_weights / nsim);
  } else {
    weights.col(0).ones();
    normalized_weights.fill(1.0 / nsim);
    loglik = approx_loglik;
  }
  
  for (unsigned int t = 0; t < n; t++) {
    arma::vec r(nsim);
    for (unsigned int i = 0; i < nsim; i++) {
      r(i) = unif(engine);
    }
    indices.col(t) = stratified_sample(normalized_weights, r, nsim);
    
    arma::mat alphatmp(m, nsim);
    
    // for (unsigned int i = 0; i < nsim; i++) {
    //   alphatmp.col(i) = alpha.slice(i).col(t);
    // }
    for (unsigned int i = 0; i < nsim; i++) {
      alphatmp.col(i) = alpha.slice(indices(i, t)).col(t);
      //alpha.slice(i).col(t) = alphatmp.col(indices(i, t));
    }
    for (unsigned int i = 0; i < nsim; i++) {
      arma::vec um(m);
      for(unsigned int j = 0; j < m; j++) {
        um(j) = normal(engine);
      }
      alpha.slice(i).col(t + 1) = alphahat.col(t + 1) +
        Ct.slice(t + 1) * (alphatmp.col(i) - alphahat.col(t)) + Vt.slice(t + 1) * um;
    }
    
    if ((t < (n - 1)) && arma::is_finite(y(t + 1))) {
      weights.col(t + 1) =
        arma::exp(log_weights(approx_model, t + 1, alpha) - scales(t + 1));
      double sum_weights = arma::accu(weights.col(t + 1));
      if(sum_weights > 0.0){
        normalized_weights = weights.col(t + 1) / sum_weights;
      } else {
        return -std::numeric_limits<double>::infinity();
      }
      loglik += std::log(sum_weights / nsim);
    } else {
      weights.col(t + 1).ones();
      normalized_weights.fill(1.0 / nsim);
    }
  }
  return loglik;
}