Esempio n. 1
0
def tets_distributions():
	# not distributions
	d = numpy.ones((3,3))
	assert(mkm.is_distribution(d) == False)

	d = mkm.delta_distribution(10)
	d[1] = 1
	assert(mkm.is_distribution(d) == False)

	
	assert(mkm.is_distribution(mkm.delta_distribution(10),n=11) == False)
	assert(mkm.is_distribution(mkm.delta_distribution(10),n=10) == True)

	assert(mkm.relative_error(numpy.array([0.0001,1,1e-16]),numpy.array([0.001,1,1e-16]))>8.0)
Esempio n. 2
0
	def add_distributions(self,d):
		# vector shape
		if d.ndim == 1:
			if  mkm.is_distribution(d) == False:
				raise Exception('not a probability distribution')

			new = {0: d}
			self.distributions.append(new)
		# matrix shape
		else:
			for i in range(d.shape[0]):
				if  mkm.is_distribution(d[i,:]) == False:
					raise Exception('not a probability distribution')

				new = {0: d[i,:]}
				self.distributions.append(new)
Esempio n. 3
0
    def set_stationary(self, d):
        """ Set the stationary distribution.

		d: the stationary distribution
		"""
        if mkm.is_distribution(d) == False:
            raise Exception('not a probability distribution')

        self.sd = d
Esempio n. 4
0
	def set_stationary(self,d):
		""" Set the stationary distribution.

		d: the stationary distribution
		"""
		if  mkm.is_distribution(d) == False:
			raise Exception('not a probability distribution')

		self.sd = d
Esempio n. 5
0
    def add_iteration(self, index, t, iteration):
        """ Add an iteration for a distribution.

		In the terminology of this class the iteration for a distribution
		at time t is defined by distribution*P^{t}.

		index: index of the distribution
		t: iteration time
		iteration: the iteration
		"""
        if mkm.is_distribution(iteration) == False:
            raise Exception('not a probability distribution')

        self.distributions[index][t] = iteration
Esempio n. 6
0
    def add_distributions(self, d):
        """ Add a number of distributions to the Markov chain.

		A distribution in the sense of this class is an initial
		distribution on the state space.

			d: An ndarray where each row is a distribution
		"""
        # vector shape
        if d.ndim == 1:
            if mkm.is_distribution(d) == False:
                raise Exception('not a probability distribution')

            new = {0: d}
            self.distributions.append(new)
        # matrix shape
        else:
            for i in range(d.shape[0]):
                if mkm.is_distribution(d[i, :]) == False:
                    raise Exception('not a probability distribution')

                new = {0: d[i, :]}
                self.distributions.append(new)
Esempio n. 7
0
	def add_iteration(self,index,t,iteration):
		""" Add an iteration for a distribution.

		In the terminology of this class the iteration for a distribution
		at time t is defined by distribution*P^{t}.

		index: index of the distribution
		t: iteration time
		iteration: the iteration
		"""
		if  mkm.is_distribution(iteration) == False:
			raise Exception('not a probability distribution')

		self.distributions[index][t] = iteration
Esempio n. 8
0
	def add_distributions(self,d):
		""" Add a number of distributions to the Markov chain.

		A distribution in the sense of this class is an initial
		distribution on the state space.

			d: An ndarray where each row is a distribution
		"""
		# vector shape
		if d.ndim == 1:
			if  mkm.is_distribution(d) == False:
				raise Exception('not a probability distribution')

			new = {0: d}
			self.distributions.append(new)
		# matrix shape
		else:
			for i in range(d.shape[0]):
				if  mkm.is_distribution(d[i,:]) == False:
					raise Exception('not a probability distribution')

				new = {0: d[i,:]}
				self.distributions.append(new)
Esempio n. 9
0
	def add_iteration(self,index,t,iteration):
		if  mkm.is_distribution(iteration) == False:
			raise Exception('not a probability distribution')

		self.distributions[index][t] = iteration
Esempio n. 10
0
	def set_stationary_distribution(self,d):
		if  mkm.is_distribution(d) == False:
			raise Exception('not a probability distribution')

		self.sd = d