473,473 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Fastest Way To Iterate Over A Probability Simplex

Hello,

Let's say a probability vector of dimension d is x_1, ..., x_d, where
each one is a non-negative term, and they all sum up to 1. Now I'd like
to iterate over all probability vectors, but this is impossible, since
they're uncountable. So instead, let's say I want to iterate over all
such vectors under the constraint that the granularity of each component
is at most some delta.

To make things pythonesque, here's the interface:
<interface>
class simplex:
def __init__(self, dim, delta):
...

def __iter__(self):
...

def next(self):
...
</interface>

The problem is, what's a fast implementation? I tried something simple,
and it is slooooooooooooow. If anyone can think of something clever, I'd
love to hear it.

Many Thanks,

Efrat
May 22 '07 #1
2 2798
On May 22, 11:19 am, Efrat Regev:
I want to iterate over all
such vectors under the constraint that the granularity of
each component is at most some delta.
You can think of this like your sum is an integer>=1 and the single
"probabilities" are integers>=1 So given the sum, like 6, you can find
all the parts of it, and then find all the permutations of such parts.
Eppstein has given code for the parts of an integer, and you can can
find the iterable permutations code on the cookbook. But the number of
such possible vectors grows very quickly...

http://aspn.activestate.com/ASPN/Coo.../Recipe/218332
http://aspn.activestate.com/ASPN/Coo.../Recipe/474124

Bye,
bearophile

May 22 '07 #2
be************@lycos.com wrote:
On May 22, 11:19 am, Efrat Regev:
>I want to iterate over all
such vectors under the constraint that the granularity of
each component is at most some delta.

You can think of this like your sum is an integer>=1 and the single
"probabilities" are integers>=1 So given the sum, like 6, you can find
all the parts of it, and then find all the permutations of such parts.
Eppstein has given code for the parts of an integer, and you can can
find the iterable permutations code on the cookbook. But the number of
such possible vectors grows very quickly...

http://aspn.activestate.com/ASPN/Coo.../Recipe/218332
http://aspn.activestate.com/ASPN/Coo.../Recipe/474124

Bye,
bearophile
Many thanks. I modified the recipes you attached some, and it works much
better. Nice and informative answer!
May 22 '07 #3

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

Similar topics

2
by: Andreas Schmitt | last post by:
Hi, Sorry for posting in German before, totally forgot about that when I was pasting this in here from another German newsgroup I was writing to, trying to get help I am programming a simple...
60
by: Julie | last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB) for a given string. The files are unindexed and unsorted, and for the purposes of my immediate requirements, can't...
2
by: trullox | last post by:
do you have the simplex algorithm? the code in php please.... :o) tnk trullox :o)
5
by: John A Grandy | last post by:
In 2.0 what is the fastest way to iterate through an element set in a read-only forward-only XMLDocument ? For example , load the key/value pairs in the following xml doc into a hashtable : ...
0
by: semkiw_t | last post by:
I'm looking for implementaction Simplex Algorithm in PHP. Do you have the simplex algorithm? the code in php please.... :o)
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
24
by: ThunderMusic | last post by:
Hi, The subject says it all... I want to use a byte and use it as byte* so I can increment the pointer to iterate through it. What is the fastest way of doing so in C#? Thanks ThunderMusic
1
by: femi ojo | last post by:
pls i am novice to programmes and am giving an assignment to solve a transportation problem using simplex method and i need to write a programmes on it due to the large variables how can i do this.
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.