How to create one Comparison Sample record

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

How to create one Comparison Sample record

Post by Jack Harich »

Slow and steady progress here, learning a lot. I expect once I more fully understand Ventity, it will be a stellar ABM tool for the problem I’m working on, the best available. Its overall design strikes me as highly innovative, flexible, and amazingly powerful, considering it's a visual declarative ABM language.

I’ve got a problem. In action Create Sample Records I’m using a Process List to walk the Politicians for that country and create one Comparison Sample per record in the Process List. Each call from the Process List triggers Create One Comparison Sample Record. The problem is how do I pass the triggered action the PoliticianID?

I tried creating referencing Politicians in Country, which is Politician[Country]. But the elements in that reference do not include PoliticianID.

The Comparison Sample records are created at startup for each voter. Then for each election, a voters walks Media Memes using a Process List, and accumulates data about politicians, by updating its Comparison Sample records. When done, the next step is the Support Decision action. There we simply use a Process List to sort the Comparison Sample records by average attractiveness descending. The first record is the most attractive politician. That becomes a voter’s politician supported.
Attachments
RDem3.zip
(130.17 KiB) Downloaded 277 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to create one Comparison Sample record

Post by tomfid »

I'd suggest the following:
- put the Create One Sample Rec action in the Politician
- set the Invoker reference type to Voter
- the Parent will be the Politician, so you have both pieces of info needed
- the trigger in the Create Sample Recs process list will invoke RefPolitician.Create One Sample Rec

The analogy is social media. If I want to set up a relationship with someone on Facebook, I
- scan for someone interesting (process list, I am the invoker and parent, the someone is the refPerson)
- trigger a friend request to the refPerson
- they approve the request and create the relationship (Create action, they are the Parent, I'm the invoker)
This pattern is pretty common, so creating a simpler way to do it is on the long term wish list.
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

Thanks for your help. I never thought of doing it this way!

I created a new action Create One Sample Record in Politician. Then, in the voter’s Create Sample Records action, I edited the trigger to call refPolitician.Create One Sample Record.

Looking at action owned by Politician, Create One Sample Record, the Invoker was Politician. That’s wrong and the app is in an inconsistent state. When a trigger calls an action, why isn’t the Invoker automatically set correctly and is unchangeable? Perhaps because different entity type invokers can call the same action. But there is no way to manually set different invoker Entity Preference while a simulation is running, so only one setting is realistically possible, if I understand this correctly.

So on Create One Sample Record, I changed Invoker from Politician to Voter. This action is a Create. Now I was able to set all three surrogate attributes needing setting.

But now I get two errors: “Generated code at (1078, 83) 'GeneratedCode.ozjCAxcBJL.voter' does not contain a definition for 'politicianid' and no extension method 'politicianid' accepting a first argument of type 'GeneratedCode.ozjCAxcBJL.voter' could be found (are you missing a using directive or an assembly reference?) (context: creating; create new comparison_sample reference, in action_create_one_sample_record_voter)”
Attachments
RDem3.zip
(130.82 KiB) Downloaded 339 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to create one Comparison Sample record

Post by tomfid »

The proximate cause is that you're using Invoker.PoliticianID to initialize the politician attribute in the Create One Sample action.
2023-03-17_14-31-10.png
2023-03-17_14-31-10.png (49.62 KiB) Viewed 19333 times
I'm guessing this happened because you did the following:
- create the Create action; since it's in the Politician, Parent=Invoker=Politician
- start initializing the newComparison... states
- inadvertently grab the PoliticianID from the Invoker
- later, remember to change the Invoker type to Voter
At this point, the Invoker.PoliticianID surrogate is invalid, but Ventity doesn't catch that, hence the generated code error. Very easy mistake to make.

The more cosmic cause is that the GUI is steering you the wrong way, and the documentation is insufficient to provide better guidance. For comparison, here's my modified version:
RDem3c2.zip
(17.41 KiB) Downloaded 315 times
2023-03-17_14-37-47.png
2023-03-17_14-37-47.png (44.75 KiB) Viewed 19333 times
Notice that I've used references (gray) instead of surrogates (blue) as the info sources for initializing the newComparisons. A reference is a pointer to a variable somewhere else, whereas a surrogate is a local proxy for the variable. The rules are a bit arcane:

Attribute

Initialize it (create only): surrogate

If you want to change it: surrogate

If you want to use it: reference

Unless you already have the surrogate, in which case you could use that

Stock

Initialize it (create only): surrogate

Change it: reference, with a local flow

Use it: reference

Other variable types

Always a reference (can't presently initialize constants, though that would be convenient)

The GUI (often wrongly) steers you toward surrogates. For example, when writing an expression for an attribute, it is likely to suggest Parent<bullet>Attribute rather than Parent.Attribute, though most of the time you want the latter. Similarly, when you drag an attribute from the invoker or parent reference, you generally get a surrogate, unless you use the <control> key modifier to get a reference. The reference should really be the default. The solution (for now) is to apply some persistence to get past the default offering.
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

That fixed the problem. Your guess as to the procedure for how it happened is correct. <lament on> But still, I would expect Ventity to keep itself in a consistent state when a user enters a value for Action to Invoke, just like it does when you rename entities, etc. Otherwise, there are too many things for a user to do manually. After all, this is a declarative language.<end lament>

Love your phrase “The more cosmic cause is….” and awareness the doc could be better.
Notice that I've used references (gray) instead of surrogates (blue) ….
Surrogates are never defined in the doc. Only 4 results are found in a search one "surrogate". Only one result is not an Example. This is Defining Entity Types > Create a New Entity Type > Actions. The closest it come to a definition is “The surrogate is not a reference to any chameleon or its color; instead, it is a construct that lives entirely within the action. You can see it listed on the attributes tab of the action inspector:” That doesn’t mean anything to me. Thus, I wonder if “surrogate” refers to the way they are handled in the code under the declarative framework. Perhaps a more user-friendly descriptive word or phrase would be better? Why not just call them attributes that may need to be set? That’s how they are treated.

The top of the Actions doc page says:
Note: On any of the action tabs, you can create surrogate links by dragging and dropping a variable on to the page. You can suppress the creation of surrogates and instead create ghosts by holding the Cntrl key while dragging and dropping a variable.
Ghosts? I tried this and it produced what look like shadow attributes. Without holding down Control, I get blue attributes. These apparently can be used just fine to set the 3 “surrogates” that need their values set.

Now I have a new problem. The Country diagram has a trigger that invokes action Reset Comparison Table. The action is intended to reset the values of two auxiliaries in the Comparison Sample to zero. But when I drag the two to the diagram from refComparison Sample, they appear in green as shadow variables. They cannot be changed. I have the same problem on action Survey Media Memes, where I need to use refMedia Meme attractiveness to accumulate to Comparison Sample total attractiveness, and increment count by one.

Regarding “The rules are a bit arcane:” I really don’t understand these. They do sound like rules that will cause me, and others, a lot of trouble if not fully understood, so thanks for taking the time to list them.
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

Whoops, forgot to include the latest model.
Attachments
RDem3.zip
(258.56 KiB) Downloaded 297 times
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

More on this. While awaiting a reply, I’ve been studying Ventity models, documentation, and videos. I’ve also been working on how RDem can realistically model political system polarization endogenously, an enticing challenge. If the model can do this, it will gain lots of credibility in the eyes of political scientists. I think I have a realistic approach that’s supported by the literature.

In sample model BassArray7, I discovered a shadow stock that was changed. So, in RDem3 in entity Comparison Sample I changed total attractiveness and count to stocks. It appears that exogenous auxiliaries cannot be changed during a run. Then in action Reset Comparison Sample I used flows to reset the stocks to zero. That solved the problem I was having in that action.

A problem remains. In action Survey Media Memes, trying to create a reference for Companion Sample, the editor wanted Value to Match for Comparison SampleID. I don’t have that. Instead, I need to get the record using the Media Meme's Country, Voter, and Politician. So I triggered action Survey One Media Meme. This uses a Process List with a filter using Media Meme's Country, Voter, and Politician.

But there’s a problem. In the Process List filter, we have “refComparison Sample.Country == Invoker.Country && refComparison Sample.Voter == Invoker.VoterID” so far. But we need to set refComparison Sample.Politician to Media Meme.PoliticianID. But we don’t have a reference to the Media Meme record the invoking action was processing. How can I get that?

Thanks once again for your gracious assistance!
Attachments
RDem3.zip
(260.1 KiB) Downloaded 321 times
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

With a little pondering of alternatives, I got a little further on this. We need PoliticianID in Survey One Media Meme. So I added attribute temp politicianID to Voter, set it in Survey Media Memes, and used it in the filter in Survey One Media Meme. Seems to work.

Then I added temp attractiveness to Voter, set it in Survey Media Memes, and used it on the diagram in Survey One Media Meme. But now I get the error: "Generated code at (1651, 45) Unexpected character '●' (context: initializing; action invocation, in action_survey_one_media_meme_voter)"
Attachments
RDem3.zip
(260.55 KiB) Downloaded 299 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to create one Comparison Sample record

Post by tomfid »

Jack Harich wrote: Fri Mar 17, 2023 11:58 pm Now I have a new problem. The Country diagram has a trigger that invokes action Reset Comparison Table. The action is intended to reset the values of two auxiliaries in the Comparison Sample to zero. But when I drag the two to the diagram from refComparison Sample, they appear in green as shadow variables. They cannot be changed. I have the same problem on action Survey Media Memes, where I need to use refMedia Meme attractiveness to accumulate to Comparison Sample total attractiveness, and increment count by one.
This is due to the last of the rules:
Other variable types

Always a reference (can't presently initialize constants, though that would be convenient)
You can't change an auxiliary or flow because it has no persistent existence. As in normal integration, all flow/aux values are calculated on the fly and can be reduced to functions of state variables.

If you need to change a value from an action, it should be a stock reference. Then you can change it with a flow. Bear in mind that flows in an action are discrete events, so they have the same units as the stock, and you don't need to divide by time step or any other time constant. Therefore your change equation might look like:

changeFlow = desiredStock - currentStock
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to create one Comparison Sample record

Post by tomfid »

Jack Harich wrote: Fri Mar 17, 2023 11:58 pm That fixed the problem. Your guess as to the procedure for how it happened is correct. <lament on> But still, I would expect Ventity to keep itself in a consistent state when a user enters a value for Action to Invoke, just like it does when you rename entities, etc. Otherwise, there are too many things for a user to do manually. After all, this is a declarative language.<end lament>
This is ticketed for a fix.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to create one Comparison Sample record

Post by tomfid »

Jack Harich wrote: Sat Mar 18, 2023 10:55 am A problem remains. In action Survey Media Memes, trying to create a reference for Companion Sample, the editor wanted Value to Match for Comparison SampleID. I don’t have that. Instead, I need to get the record using the Media Meme's Country, Voter, and Politician. So I triggered action Survey One Media Meme. This uses a Process List with a filter using Media Meme's Country, Voter, and Politician.
I haven't looked at it yet, but I think the solution may be to make [Country,Voter,Politician] the key to the Comparison. You can do this by checking the "key" box in the attributes. Then delete the default ID attribute. This may break subcollections (though you'll be able to repair those in the imminent release).
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to create one Comparison Sample record

Post by tomfid »

Jack Harich wrote: Sat Mar 18, 2023 2:30 pm But now I get the error: "Generated code at (1651, 45) Unexpected character '●' (context: initializing; action invocation, in action_survey_one_media_meme_voter)"
This is most likely another instance of problems from linking to a surrogate instead of an action. Take a look at your attribute expressions and try replacing <bullet> with a .
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

Even more on this. Previously when I encountered errors I usually could see no way forward, so I posted here. But lately, due to my learning more and more about Ventity, I'm starting to be able to find ways forward.

That has occurred here. I changed from an attribute to a stock for temp attractiveness, since it's numeric. Now I'm getting no errors. Currently I'm laboriously checking results data to see that the correct calculations were made and the right data is where it needs to be. So for now, don't work on this. I'm doing that! Thanks.
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

Wow Tom, thanks for all the careful feedback. I'm proceeding in a forward direction!
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

I've encountered an error I can't seem to fix: "Generated code at (1782, 86) Unexpected character '●' (context: creating; action invocation, in action_create_one_belief_meme_voter)"

By the time I saw your previous reply involving a large '●', I had solved the problem and there was no need to edit the large dot. But before and now, I never did edit a large dot. They are set automatically by Ventity.

On Voter, Sample Media Memes, and Create One Belief Meme you will see what seems to me to be an awkward and brittle way to pass data to the Create action. Is there a better way? It's also awkward to use stocks as variables, as you can see. To set a stock's value the flow equation has be new stock value = input - present stock value.
Attachments
RDem3.zip
(267.11 KiB) Downloaded 313 times
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

About the awkward way to pass data. I was using 3 temp values in Voter to pass data along a call chain to Create One Belief Meme. I've changed this to using one temp value, that of Media MemeID. The 2 errors persist.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to create one Comparison Sample record

Post by tomfid »

First issue is bullet notation in the three attributes in Create One Belief Meme.

Second issue - more rules. When you have a surrogate (blue) stock, as in a create action, you can initialize it directly, without using a flow.

In any other action context you'll only have access to references (gray) to stocks - that's when you need a flow.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to create one Comparison Sample record

Post by tomfid »

RDem3d2.zip
(25.81 KiB) Downloaded 344 times
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

Thanks so much. That solved the problem. Now I've encountered two problems.

Looking at the results spreadsheet, the first problem is in Voter politician supported. All are P1. This is set by action Support Decision using Politician Comparison. If you look at Politician Comparison in the spreadsheet, maximum average attractiveness says all voters should support P2. In theory, the action should do this and set voter politician supported correctly.

The second problem deals with action Choose Election Winner. This would be a Process List using Voter[Country, politician supported]. If you examine that table in the spreadsheet, for this run it has one row (If the first problem is solved there will often be more than one.) with Country, politician supported, Count. The information we need to determine the winner is there. We simply filter on the country, sort descending by Count, and the first record is the winner.

But in action Choose Election Winner, we must first create a reference for er[Country, politician supported]. This requires setting Value to Match for both partitions, Country and politician supported. But we only want to set it for Country.

I tried “” for the match for politician supported to imply doesn’t matter. I even tried “ANY”. Leaving it empty results in error “Missing condition for ‘politician supported’ attribute.”

This is the same problem we encountered before. In your “This turns out to be a pretty tricky task” solution, in model Vote 2, action Determine Winner used a complex approach that I still cannot understand. Thus, I’m trying to find another solution.

An alternative I’ve not tried is copying every record in Voter[Country, politician supported] to an unpartitioned table, say an entity named Voter Politician Supported. Then as I said earlier, “We simply filter on the country, sort descending by Count, and the first record is the winner.” But this is a hack, and I hesitate. Thanks!
Attachments
RDem3.zip
(266.56 KiB) Downloaded 312 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to create one Comparison Sample record

Post by tomfid »

I've only looked briefly, but I think what's happening here is that Accumulate Politician Comparison is iterating over the same set of comparisons for all voters, because it's looking at the top-level collection [].

I think what you want instead is:
- create a Belief Meme subcollection by [voter,politician]
- add an aggregate for average attractiveness
- delete the Accumulate Politician Comparison action
- delete the Politician Comparison entitytype
- in the Support Decision, add a reference to Belief Meme[politician,voter] - I'd call it "My Comparisons" or something like that
- in the Support Decision, change Collection to Process to that reference (My Comparisons)
- sort by refMeme.average attractiveness
- set Parent<.>Politician Supported to refMeme.average attractiveness

Using the Belief Meme subcollection directly should save a couple layers of actions and intermediate storage.
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

What a clever idea! Thanks. I hope to learn how to think like this, to naturally see the many ways to use Ventity.

I removed the Politician Comparison entity and all use of it. Then I added Belief Meme [Country, Politician, Voter] and added an aggregate for Average attractiveness. Then I added a reference to it in Support Decision.

But there’s a problem. When editing the reference, we must supply Value to Match for Country, Politician, and Voter. We know Country and Voter, but we don’t know Politician. That is what we’re trying to determine. I’ve run into this before. If Value to Match would accept “*” or “ANY” or “” for doesn’t matter, then we’d have the rows we need, I think.

The attached model is in this state. It has one error for the missing condition.
Attachments
RDem3.zip
(262.92 KiB) Downloaded 275 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to create one Comparison Sample record

Post by tomfid »

Jack Harich wrote: Mon Mar 20, 2023 4:39 pm But there’s a problem. When editing the reference, we must supply Value to Match for Country, Politician, and Voter. We know Country and Voter, but we don’t know Politician. That is what we’re trying to determine. I’ve run into this before. If Value to Match would accept “*” or “ANY” or “” for doesn’t matter, then we’d have the rows we need, I think.
My mistake. The Belief Meme subcollection should be by [country,voter]. Then iterating over the entries that match the voter will yield the Belief Meme with the politician having highest attractiveness.
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

Thanks, gave it a try. Created Belief Meme [Country, Voter]. But now I’m getting this error: “expected (context: VentityRuntimeModel_GC; constructor, in collection_of_voter)”.

But will this really average attractiveness per politician?
Attachments
RDem3.zip
(262.65 KiB) Downloaded 298 times
Jack Harich
Senior Member
Posts: 68
Joined: Wed Sep 15, 2004 9:01 pm
Vensim version: DSS

Re: How to create one Comparison Sample record

Post by Jack Harich »

Very good news. Worked on this. Eventually thought of closing and reopening the model. The error vanished.

But we still have the challenge of how to implement a voter's Support Decision.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to create one Comparison Sample record

Post by tomfid »

Do as I mean, not as I say apparently.

It turns out that you do need the Comparison entity, not for storage, but because you can't iterate over a subcollection (you can only iterate over the subcollection members). So, you need the comparison entity to extract the average attractiveness; then you iterate over the Comparisons.

This runs, but appears to have some other issue I haven't investigated yet.
RDem3e3.zip
(24.5 KiB) Downloaded 320 times
Post Reply