File: vectorSpace.cpp

package info (click to toggle)
mldemos 0.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,224 kB
  • ctags: 46,525
  • sloc: cpp: 306,887; ansic: 167,718; ml: 126; sh: 109; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 871 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "vectorSpace.hpp"
#include <boost/foreach.hpp>

namespace AG
{
namespace Data{

void random_init_vector_space(VectorSpace & vs, unsigned int num_vectors, unsigned int dimensions, double max_value)
{
	for (unsigned int vid = 0 ; vid < num_vectors; vid++)
	{
		Vect v(dimensions);
		for (unsigned int i=0; i < dimensions; i++)
			v(i) = rand() / (double)RAND_MAX * max_value;
		vs.push_back(v);
	}
}

std::ostream& operator << (std::ostream& os,  VectorSpace & vs)
{
	unsigned int i = 0;
	BOOST_FOREACH(Vect v, vs)
	{
		os << "[" << i << "]: ";
		BOOST_FOREACH(Vect::value_type  value, v)
				os << value << " ";
		os << std::endl;
		i++;
	}

	return os;
}

std::ostream& operator << (std::ostream& os,  Vect & v)
{
	BOOST_FOREACH(Vect::value_type  value, v)
			os << value << " ";
	os << std::endl;

	return os;
}
};
};