473,618 Members | 3,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[Python] Matrix convergence

Hi all,

I'm trying to check whether a (stochastic/transition) matrix
converges, i.e. a function/method that will return True if the input
matrix sequence shows convergence and False otherwise. The background
is a Markov progress, so the special thing about the transition matrix
is the values of elements in each row add up to be 1. Fail to find any
relevant build-in methods in Python...

Currently the standard theorem on convergence in Markov chain
literature is involved with the properties of aperiodic and
connectivity, which I'm not able to implement with Python either...
Therefore I'm actually also looking for alternative conditions to
check for convergence, and am willing to sacrifice a little bit of
precision.

If you have any ideas/suggestions on how to examine the convergence of
a matrix in general or specifically about this kind of matrices, and
are willing to share, that'd be really great.

Thx!

Zz

Sep 30 '07 #1
2 5834
On Sep 30, 3:10 pm, Zhengzheng Pan <panzhengzh...@ gmail.comwrote:
I'm trying to check whether a (stochastic/transition) matrix
converges, i.e. a function/method that will return True if the input
matrix sequence shows convergence and False otherwise. The background
is a Markov progress, so the special thing about the transition matrix
is the values of elements in each row add up to be 1. Fail to find any
relevant build-in methods in Python...
I'm not sure exactly what you want here. Do you have a single
transition matrix, or a `matrix sequence'? Can I assume that you're
working with a time-homogeneous Markov chain with a finite state
space? And that the function should take the transition matrix, and
should return True if and only if there's a unique limiting
distribution for the Markov process, independent of starting state?
Or have I misunderstood?

What's the typical number of states? Thousands? Millions?

Can you explain why you're unable to implement detection of
periodicity and connectivity (is this the same as irreducibility) ?
Are there technical problems, or just conceptual problems?

Detecting irreducibility ought to be straightforward : form the
directed graph corresponding to the transition matrix (one vertex per
state, an edge from i to j iff the corresponding entry in the
transition matrix is nonzero) and apply Tarjan's algorithm (google
it!), which detects strongly connected components: if there's a
single strongly connected component consisting of the entire graph
then the Markov process is irreducible. Figuring out the period
shouldn't be too hard either---I have a feeling that it ought to be
possible to adapt Tarjan's algorithm to detect the period: label the
vertices of the graph by depth (Tarjan's algorithm is essentially a
depth-first traversal of the graph), and every time Tarjan's algorithm
detects a cycle, comparing depths will give you a multiple of the
period; taking the gcd of all these multiples should give the period
itself.

An alternative, quick and dirty way (quick for the human, not the
computer!) would be just to compute some large power of the transition
matrix and eyeball it to see if all columns are identical. If so, the
process converges.
Thx!
Ur wlcm!

Mark

Sep 30 '07 #2
Zhengzheng Pan <pa***********@ gmail.comwrites :
Hi all,

I'm trying to check whether a (stochastic/transition) matrix
converges, i.e. a function/method that will return True if the input
matrix sequence shows convergence and False otherwise. The background
is a Markov progress, so the special thing about the transition matrix
is the values of elements in each row add up to be 1. Fail to find any
relevant build-in methods in Python...

Currently the standard theorem on convergence in Markov chain
literature is involved with the properties of aperiodic and
connectivity, which I'm not able to implement with Python either...
Therefore I'm actually also looking for alternative conditions to
check for convergence, and am willing to sacrifice a little bit of
precision.

If you have any ideas/suggestions on how to examine the convergence of
a matrix in general or specifically about this kind of matrices, and
are willing to share, that'd be really great.
Do you mean you have an n x n stochastic matrix T and you're trying to find
out whether the sequence T^j converges?

Let A = (I + T)^(n-1) and B = T^((n-1)^2+1). Powers of matrices are easy
to compute using repeated squaring.

i and j are in the same class iff A_{ij} 0 and A_{ji} 0. A class
containing state i is recurrent iff A_{ij} = 0 for all j not in the class.

A recurrent class containing state i is aperiodic iff
B_{ij} 0 for all j in the class.

T^j converges iff all recurrent classes are aperiodic. Thus the test
can be written as follows:
For each i, either there is some j for which A_{ij} 0 but A_{ji} = 0,
or there is no j for which A_{ij} 0 but B_{ij} = 0.
--
Robert Israel is****@math.MyU niversitysIniti als.ca
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia Vancouver, BC, Canada
Sep 30 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
18983
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
699
33828
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
3
1958
by: Paul Keating | last post by:
I have a very simple COM server written in Python that is trying to return a two-dimensional array 268 x 20. The values it contains are some small integers, some short (<29 character) Unicode strings, and None. To isolate the problem I have taken out the code that builds the matrix from real data, and just substituted a literal tuple of tuples, like this: class AtlasSecurity:
2
2105
by: quadric | last post by:
Hi, I have an application that requires that Python initiate and mediate a live and iterative conversation between an external application (in which Python is embedded) and an external Excel spreadsheet. Python will have to pass info to the spreadsheet, spreadsheet will make calculations, Python will obtain results and pass back to application, application will evaluate results of spreadsheet calculations and create new set of data and
5
2810
by: C. Barnes | last post by:
Hi, I'm in the process of writing a Python linear algebra module. The current targeted interface is: http://oregonstate.edu/~barnesc/temp/linalg/ The interface was originally based on Raymond Hettinger's Matfunc . However, it has evolved so that now it
25
5731
by: abhinav | last post by:
Hello guys, I am a novice in python.I have to implement a full fledged mail server ..But i am not able to choose the language.Should i go for C(socket API) or python for this project? What are the advantages of one over the other in implementing this server.which language will be easier? What are the performance issues?In what language are mail servers generally written?
10
3277
by: jantod | last post by:
I think there might be something wrong with the implementation of modulus. Negative float values close to 0.0 break the identity "0 <= abs(a % b) < abs(b)". print 0.0 % 2.0 # => 0.0 print -1e-010 % 2.0 # =>1.9999999999 which is correct, but:
0
2802
by: DarrenWeber | last post by:
# Copyright (C) 2007 Darren Lee Weber # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY...
1
15241
by: dazzler | last post by:
Hi! I have problem with numpy, multiplying with an inversed matrix will crash python :( this works fine: from numpy import matrix A = matrix(,]) B = matrix(,]) print A.I #inverse matrix
0
8150
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8650
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8593
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8303
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6098
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2582
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.