Esempio n. 1
0
      //--------------------------------------------------------------------------------
      void svm_problem::load(std::istream& inStream)
      {
	int s = 0;
	inStream >> s >> n_dims_;
  
	if (recover_)
	  for (size_t i = 0; i != x_.size(); ++i)
	    delete [] x_[i];

	y_.resize(s, 0);
	x_.resize(s, 0);

	inStream.ignore(1);
	nta::binary_load(inStream, y_);
	
	for (int i = 0; i < size(); ++i) {

#if defined(NTA_PLATFORM_win32) && defined(_MSC_VER)
          x_[i] = (float*) _aligned_malloc(4*n_dims(), 16);
#else
	  x_[i] = new feature_type[n_dims()];
#endif

          std::fill(x_[i], x_[i] + n_dims(), (float) 0);
	  nta::binary_load(inStream, x_[i], x_[i] + n_dims());
	}
      }
Esempio n. 2
0
//------------------------------------------------------------------------------
void svm_model::print() const {
  std::cout << "n classes = " << n_class() << " n sv = " << size()
            << " n dims = " << n_dims() << std::endl;

  std::cout << "Support vectors: " << std::endl;
  for (size_t i = 0; i != sv.size(); ++i) {
    for (int j = 0; j != n_dims(); ++j)
      std::cout << sv[i][j] << " ";
    std::cout << std::endl;
  }

  std::cout << "Support vector coefficients: " << std::endl;
  for (size_t i = 0; i != sv_coef.size(); ++i) {
    for (int j = 0; j != size(); ++j)
      std::cout << sv_coef[i][j] << " ";
    std::cout << std::endl;
  }

  std::cout << "Rho: " << std::endl;
  for (size_t i = 0; i != rho.size(); ++i)
    std::cout << rho[i] << " ";
  std::cout << std::endl;

  if (!probA.empty()) {
    std::cout << "Probabilities A: " << std::endl;
    for (size_t i = 0; i != probA.size(); ++i)
      std::cout << probA[i] << " ";
    std::cout << std::endl;

    std::cout << "Probabilities B: " << std::endl;
    for (size_t i = 0; i != probB.size(); ++i)
      std::cout << probB[i] << " ";
    std::cout << std::endl;
  }
}
Esempio n. 3
0
//------------------------------------------------------------------------------
void svm_problem::load(std::istream &inStream) {
  int s = 0;
  inStream >> s >> n_dims_;

  if (recover_)
    for (size_t i = 0; i != x_.size(); ++i)
      delete[] x_[i];

  y_.resize(s, 0);
  x_.resize(s, nullptr);

  inStream.ignore(1);
  nupic::binary_load(inStream, y_);

  for (int i = 0; i < size(); ++i) {
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
    x_[i] = (float *)_aligned_malloc(4 * n_dims(), 16);
#else
    x_[i] = new feature_type[n_dims()];
#endif

    std::fill(x_[i], x_[i] + n_dims(), (float)0);
    nupic::binary_load(inStream, x_[i], x_[i] + n_dims());
  }
}
Esempio n. 4
0
//------------------------------------------------------------------------------
int svm_problem::persistent_size() const {
  stringstream b;

  b << size() << " " << n_dims() << " ";

  return b.str().size() + y_.size() * sizeof(label_type) +
         size() * n_dims() * sizeof(feature_type) + 1;
}
Esempio n. 5
0
      //--------------------------------------------------------------------------------
      int svm_model::persistent_size() const
      {
	stringstream b;
	b << n_class() << " "
	  << size() << " " 
	  << n_dims() << " ";
	
	int n = b.str().size();
	
	n += sv.size() * n_dims() * sizeof(float) + 1;
	
	{
	  stringstream b2;
	  for (size_t i = 0; i < sv_coef.size(); ++i) {
	    for (int j = 0; j < size(); ++j) 
	      b2 << sv_coef[i][j] << " ";
	  }
	  n += b2.str().size();
	}

	{ 
	  stringstream b2;
          b2 << rho << " ";
	  n += b2.str().size();
	}

	{ 
	  stringstream b2;
          b2 << label << " ";
	  n += b2.str().size();
	}

	{ 
	  stringstream b2;
          b2 << n_sv << " ";
	  n += b2.str().size();
	}

	{ 
	  stringstream b2;
          b2 << probA << " ";
	  n += b2.str().size();
	}

	{ 
	  stringstream b2;
          b2 << probB << " ";
	  n += b2.str().size();
	}

	{ 
	  stringstream b2;
          b2 << w << " ";
	  n += b2.str().size();
	}

	return n;
      }
Esempio n. 6
0
//------------------------------------------------------------------------------
void svm_problem::save(std::ostream &outStream) const {
  outStream << size() << " " << n_dims() << " ";

  nupic::binary_save(outStream, y_);

  for (int i = 0; i < size(); ++i)
    nupic::binary_save(outStream, x_[i], x_[i] + n_dims());
  outStream << " ";
}
Esempio n. 7
0
//------------------------------------------------------------------------------
void svm_model::save(std::ostream &outStream) const {
  outStream << n_class() << " " << size() << " " << n_dims() << " ";

  for (auto &elem : sv)
    nupic::binary_save(outStream, elem, elem + n_dims());
  outStream << " ";

  for (auto &elem : sv_coef)
    for (int j = 0; j < size(); ++j)
      outStream << elem[j] << " ";

  outStream << rho << ' ' << label << ' ' << n_sv << ' ' << probA << ' '
            << probB << ' ' << w << ' ';
}
Esempio n. 8
0
      //--------------------------------------------------------------------------------
      void svm_model::load(std::istream& inStream)
      {
	int n_class = 0, l = 0;
	inStream >> n_class >> l >> n_dims_; 

        if (sv_mem == NULL) {

          for (size_t i = 0; i < sv.size(); ++i)
            delete [] sv[i];

        } else {

          delete [] sv_mem;
          sv_mem = NULL;
        }

#if defined(NTA_PLATFORM_win32) && defined(_MSC_VER)
        sv_mem = (float*) _aligned_malloc(4 * l * n_dims(), 16);
#else
        sv_mem = new float [l * n_dims()];
#endif

        std::fill(sv_mem, sv_mem + l * n_dims(), (float)0);

	sv.resize(l, 0);
	inStream.ignore(1);
	for (int i = 0; i < l; ++i) {
	  sv[i] = sv_mem + i * n_dims();
	  nta::binary_load(inStream, sv[i], sv[i] + n_dims());
	}

	for (size_t i = 0; i < sv_coef.size(); ++i)
	  delete [] sv_coef[i];
  
	sv_coef.resize(n_class-1, 0);
	for (int i = 0; i < n_class-1; ++i) {
	  sv_coef[i] = new float [l];
	  for (int j = 0; j < l; ++j) 
	    inStream >> sv_coef[i][j];
	} 
  
        inStream >> rho
                 >> label
                 >> n_sv
                 >> probA
                 >> probB
                 >> w;
      }
Esempio n. 9
0
      //--------------------------------------------------------------------------------
      void svm_model::load(std::istream& inStream)
      {
	int n_class = 0, l = 0;
	inStream >> n_class >> l >> n_dims_; 

        if (sv_mem == nullptr) {

          for (auto & elem : sv)
            delete [] elem;

        } else {

          delete [] sv_mem;
          sv_mem = nullptr;
        }

#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
        sv_mem = (float*) _aligned_malloc(4 * l * n_dims(), 16);
#else
        sv_mem = new float [l * n_dims()];
#endif

        std::fill(sv_mem, sv_mem + l * n_dims(), (float)0);

	sv.resize(l, nullptr);
	inStream.ignore(1);
	for (int i = 0; i < l; ++i) {
	  sv[i] = sv_mem + i * n_dims();
	  nupic::binary_load(inStream, sv[i], sv[i] + n_dims());
	}

	for (auto & elem : sv_coef)
	  delete [] elem;
  
	sv_coef.resize(n_class-1, nullptr);
	for (int i = 0; i < n_class-1; ++i) {
	  sv_coef[i] = new float [l];
	  for (int j = 0; j < l; ++j) 
	    inStream >> sv_coef[i][j];
	} 
  
        inStream >> rho
                 >> label
                 >> n_sv
                 >> probA
                 >> probB
                 >> w;
      }
Esempio n. 10
0
      //--------------------------------------------------------------------------------
      void svm_problem01::save(std::ostream& outStream) const
      {
	outStream << size() << " " << n_dims() << " " << threshold_ << " ";
  
	nta::binary_save(outStream, y_);
	nta::binary_save(outStream, nnz_);
	
	for (int i = 0; i < size(); ++i) 
	  nta::binary_save(outStream, x_[i], x_[i] + nnz_[i]);
	outStream << " ";
      }
Esempio n. 11
0
      //--------------------------------------------------------------------------------
      void svm_model::save(std::ostream& outStream) const
      {
	outStream << n_class() << " "
		  << size() << " " 
		  << n_dims() << " ";
  
	for (size_t i = 0; i < sv.size(); ++i) 
	  nta::binary_save(outStream, sv[i], sv[i] + n_dims());
	outStream << " ";
  
	for (size_t i = 0; i < sv_coef.size(); ++i) 
	  for (int j = 0; j < size(); ++j) 
	    outStream << sv_coef[i][j] << " ";
  
        outStream << rho << ' '
                  << label << ' '
                  << n_sv << ' '
                  << probA << ' '
                  << probB << ' '
                  << w << ' ';
      }
Esempio n. 12
0
//------------------------------------------------------------------------------
int svm_problem01::persistent_size() const {
  stringstream b;
  b << size() << " " << n_dims() << " " << threshold_ << " ";
  int n = b.str().size();

  n += y_.size() * sizeof(float);
  n += nnz_.size() * sizeof(int);

  for (int i = 0; i != size(); ++i)
    n += nnz_[i] * sizeof(feature_type);

  return n + 1;
}