Unable to determine the winner of an election process

A place for Ventity software questions & answers
Post Reply
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Unable to determine the winner of an election process

Post by Jack Harich »

In Ventity I’m trying to model an election process. Countries have Politicians and Voters. An election occurs. Each voter has an attribute for politician supported. Now the modeling challenge is to find the PoliticianID of the winning politician.

I created a new collection Voter [politician supported]. Then in the Politician inspector I created a new reference for supporters, with target Voter [politician supported] and Value to Match PoliticianID. That allows dragging the Count of that reference to the Politician diagram, which creates the shadow variable supporter count. A graph demonstrates the variable is behaving correctly.

But now I’m unable to figure out how to find the PoliticianID with the max supporter count. That would be the election winner. The Country diagram needs this information.

Looking at aggregate functions, what I don’t see is a function that returns the group Value to Match of a collection that has the Max of the collection groups. That would seem to be useful if I understand all this correctly.

All this indicates I’m having great difficultly learning Ventity. I’ve studied the Help doc, Help videos, and Juan Garcia’s first book on Agent-Based Modeling and Simulation. But I simply cannot grasp how to accomplish modeling tasks like the problem I’ve described here. Are there any other learning sources? Are tutors available? Etc. I’m very open to suggestions. My background is I’m an intermediate level user of Vensim and have extensive OO programming experience in Java (long ago, was certified) and JavaScript (two years ago). Thanks!
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Unable to determine the winner of an election process

Post by tomfid »

This turns out to be a pretty tricky task. A solution is attached.
Vote 2 (2).zip
(16.96 KiB) Downloaded 379 times
The model uses a Process List action to rank the politicians by votes received, and assigns the winning PoliticianID to an attribute in the Country.

The Process List uses an internal stock as a local counter to determine whether it's processing the winner (count=1) or a later loser (count>1).

Voters also use a Process List to pick a politician to vote for (currently at random).

This might be a lot easier to solve if you could create collections of subcollections, or run a Process List action directly over a set of subcollections. Even better might be to have a Find() function that could select a single entity by some value or attribute combination.

I think this is hard because it's pretty far outside what people are normally using Ventity for.
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: Unable to determine the winner of an election process

Post by Jack Harich »

This is fantastic, thanks. Looking it over, it's such an elaborate workaround that I can't understand it yet.

One understanding problem is I don't see where a voter's election choice is randomly set. This would occur in the Pick Politician action. Here refPolitician.PoliticianID is used to set Parent.politician supported. I don't see any randomness here. I even searched the entire set of folders for the model for the word "random" with no results.
I think this is hard because it's pretty far outside what people are normally using Ventity for.
That could be because Ventity can't do what they need easily. Use cases would be:
  • Given these policies and constrains, which scenario attains the highest sales? As opposed to what are the max sales possible?
  • In this forecast, which salesperson does the best, second best, etc? As opposed to what is the max expected?
  • In this set of drug formulations and trials, which formulation gives the best results? As opposed to what is the best trial outcome possible?
Changing the subject:
Even better might be to have a Find() function that could select a single entity by some value or attribute combination.
Yes! Entity instances are much like a relational database table and its rows. A general purpose query function would be quite useful. Think of the many users who would benefit, and the many applications of Ventity that would now be possible, if I understand this correctly.

For my problem of finding the PoliticianID in the auxiliary variable "Voter by politican supported count," I wonder if "GetCategory(collection reference, variable)" could be used. This:
Sorts collection by variable. Generates a list of the collection, then looks up those that match the parameters set by the variable. Returns all of these values. GetCategory is the most efficient method for processing a list of variables. This function can only be used in an Action, and to use it you'll need to have a collection already created which you reference via the collection entity name (as it appears in the Model Overview), and the variable by which you're sorting the collection.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Unable to determine the winner of an election process

Post by tomfid »

where a voter's election choice is randomly set
pick politician.png
pick politician.png (44.35 KiB) Viewed 5274 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Unable to determine the winner of an election process

Post by tomfid »

That could be because Ventity can't do what they need easily.
Chicken, meet egg?
Use cases would be:

Given these policies and constrains, which scenario attains the highest sales? As opposed to what are the max sales possible?

In this forecast, which salesperson does the best, second best, etc? As opposed to what is the max expected?

In this set of drug formulations and trials, which formulation gives the best results? As opposed to what is the best trial outcome possible?
I think there are two things going on here. Most of the time, these questions are answered by comparing multiple runs. But it's legit in Ventity to wonder about individual entities. So, this implies two needs: a findEntity() function that's easier than Process List, and ability to pick and inspect particular runs out of multi-run ensembles (especially sensitivity runs).
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Unable to determine the winner of an election process

Post by tomfid »

I wonder if "GetCategory(collection reference, variable)" could be used.
GetCategory solves problems like assigning people to named income categories (low,mid,high) based on numeric income values.

You could potentially hack that to have "winner" and "loser" categories, and set the numeric threshold for winner to the winning number of votes, but you'd still need an action to do that, so I don't think it would be more transparent.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Unable to determine the winner of an election process

Post by tomfid »

Entity instances are much like a relational database table and its rows.
Very much so. However, the database analogy is also partly the source of the challenge here. The functionality needed is a lot like a SQL subquery, which is also pretty arcane.
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: Unable to determine the winner of an election process

Post by Jack Harich »

Just wanted to say I've further evaluated your solution. This is tremendously helpful, thanks once more. I'm now proceeding to continue building the model.

In my design of the model, several places will need to extract info from collections, in a manner beyond what Sum, Average, Min, Max, Average, etc. provide. I need to extract entities.

GetCategory seems to offers this. However, the documentation is out of synch with version 4.8. Here autotype brings up "GetCategory(entitytype, value, category)" which disagrees with the documentation that I posted in the above post, which says "GetCategory(collection reference, variable)". Is value an expression? Is category a partition name? Does GetCategory return new instances or pointers to the instances in the collection? It sure would help to see more elaborate documentation. I've not seen any model use examples.

Is there a way to get a random subset from a collection? This allows an agent to get a small representative sample, then use that while the larger collection can change.

It sure would help to have the equivalent of the SQL SELECT Statement. Having used that a lot in JavaScript on the back end, I guess I tend to think in those terms when designing an agent-based model, since an entity is a table, entity instances are rows, and attributes are foreign keys. It's been a while, so I may be rusty on my terms.

Thanks!
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Unable to determine the winner of an election process

Post by tomfid »

Right - we tend to say
entityType=table
entity (instance)=row
attributes might be keys, or just categorical data, but any time you create a subcollection on an attribute it becomes a key to that subcollection
subcollections are basically GROUP BY
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Unable to determine the winner of an election process

Post by tomfid »

I can think of 2 ways to get a random sample:
- use a process list action to assign some attribute value to the collection the agent is interested in
- assign each entity a random value and use GetCategory to put those above some threshold in the sample
These are pretty similar, but it would be interesting to see if there's a performance difference.

Process List basically gives you SELECT capability, because you can add Filter criteria, which are like the WHERE clause.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Unable to determine the winner of an election process

Post by tomfid »

The GetCategory tooltip is screwed up and the documentation is too thin to build a working example from scratch I think.

Here's an example of use to separate people into quintiles by some value and calculate quintile aggregates.
GetCategory via Person 1.zip
(14.07 KiB) Downloaded 404 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Unable to determine the winner of an election process

Post by tomfid »

In this example, each person triggers an action to run GetCategory on themself. I only do this intermittently, based on a timer in the Model, because it's a somewhat expensive operation. It's also possible to use a Process List for this.

Also note that the Quintile entitytype, which defines the lower bounds of the categories, is special in that the names Category Name and Category Value have to be present for the function to work.

Process List is probably the easiest way to go if you just wanted something like a random subset of the population.
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: Unable to determine the winner of an election process

Post by Jack Harich »

Thanks Tom for putting together a good example of how to apply Get Category. Sure is a fancy graph of Person Value! Again this shows off the awesome power of a certain tool named Ventity and use of random values.

We see soooo much randomness in real world problems, so I really like your ubiquitous use of randomness in your models and videos. Below are unrandomized and randomized versions of the graph. The first was obtained by removing RandomNormal(0,1) in the flow Person.change. But now I'm wondering why in the first graph the values all grow to one, but say flatish in the second graph. What does the variable name "brate" mean on the Person diagram?

Taking a look, I agree. Process List will do the job beautifully.
Attachments
Ventity Graph of Value not randomized.png
Ventity Graph of Value not randomized.png (117.55 KiB) Viewed 5107 times
Ventity Graph of Value.png
Ventity Graph of Value.png (306.96 KiB) Viewed 5107 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Unable to determine the winner of an election process

Post by tomfid »

"brate" is short for "b rate" - i.e. a rate constant named 'b'.

What you're seeing with randomness off is the logistic model, dx/dt = b*x*(1-x). Since x,b > 0, it can only go up. The RandomNormal turns it into the logistic transform of a random walk, bounded between 0 and 1.
rob_n
Senior Member
Posts: 53
Joined: Thu Feb 22, 2018 6:12 pm
Vensim version: DSS

Re: Unable to determine the winner of an election process

Post by rob_n »

I love this example. In Tom's example model, a Person's Value varies between 1 and 0. We can think of the extremes as pro/con, right/left, red/blue, etc. The change function has the tendency to "polarize" the population, as evidenced by the thinning out of the middle quintiles.
Picture1.png
Picture1.png (60.19 KiB) Viewed 5014 times
We can normalize the quintile populations by the total population to get the population fraction in each quintile, x. We could calculate an information theoretic measure like entropy (S = -sum_i x_i ln x_i, where i is the quartile index).

In Ventity how would we perform this sum? (I can't see how to do an Aggregation of an Aggregation).
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Unable to determine the winner of an election process

Post by tomfid »

It's true that you can't currently aggregate an aggregate, because we don't have collections of collections.

The workaround is to map the subcollection values back to a regular entity, and aggregate that. In this case, you could map the value by [quantile] counts back to the Quantile entitytype, compute the pln(p) component, and sum in the Quantile[] collection.

I should note that I think I called that entity "Quintile" but it's not what we normally think of as a quintile. The cuts discretize the value distribution into uniform cuts, but the population of each group is not uniform. A real quintile would be rank based, with the cut points varying such that each group has the same share of the population. That's also possible, but not what I did. So, some other name - maybe just "State" - would be better.
rob_n
Senior Member
Posts: 53
Joined: Thu Feb 22, 2018 6:12 pm
Vensim version: DSS

Re: Unable to determine the winner of an election process

Post by rob_n »

This works great. Thanks, Tom!
Picture1.png
Picture1.png (42.97 KiB) Viewed 4986 times
Picture2.png
Picture2.png (44.86 KiB) Viewed 4986 times
Post Reply