15 of Complexity Explorer's basic tutorial. [indistinguishable - age of base...] In this session, we'll complete part 2 of our trade function in which we establish the Marginal Rate of Substitution, or MRS, and price for our agents, so that they can trade with each other Let's get started. First, open up your preferred IDE, or your Google Colab instance, and then you want to make sure your [sugarmap] that .txt file has either been uploaded, or disconnected, via your Google Drive through this [magic] function. So you import your dependencies, uh, we do our helper function uh, which is [get] distance from this one We do our resource classes, which is sugar and spice, Which says that, uh, each one grows one unit per timestep. Then we have our trader class, which is significantly longer, right, uh, where they move, uh, they eat, they possibly, uh, die, uh, and then we're working this function here, which is "trade with neighbours". So far, we've established the list of neighbour agents, that we could possibly trade with, based off the agent's vision attribute, which tells how far they can see. Then we have our Model Class, which we initiate our model. This manages, uh, the interactions of our agents, so, sugar, spice, and then trainers use this kind-of unique, [stage] random activation function. Right, the agents move, eat and die, that's what we call those functions, and then they trade with neighbours. Right? We run that from session 14, we end up with, uh, the output of the length of neighbours that each agent has [during] one timestep. Uh, so now we can delete this, uh, print statement, and now we wanna create our actual trade function. So we need to iterate through, uh, our neighbour agents. So, remember neighbour agents, uh, is a list of agent objects, and if there is, say, a trader [H] object, then we're going to call our trade function, uh, that we're abou- So we'll pass one parameter, which is the other trader agent that we wanna trade with. Add a comment, uh, just say what we're doing here, iterate through traders, right, in neighbourhood agents, but remember that the neighbouring cells is determined by the vision, uh, of that particular agent; how far they can see. Right, now we do need to account for something so we don't cull this unnecessarily, right, if the neighbour agents, uh, returns nothing, right, so it has no length, it's just an empty list, right, we don't wanna do all these other, uh, functions. We wanna end the function as is. Um, as we saw from the previous print statement, there are some neighbours that - or, there are some agents that have [unintelligible], neighbour agents, right. So, if that happens, um, if the length equals zero or, uh, then, uh, we need to return the empty list, right, and this function'll return two things: so it'll turn price, or prices, that the agents, uh, exchange their sugar and spice at, and who they traded with, so we can monitor the trade. So, if that's the case, we'll just return two empty lists. So, if "length neighbour agent = 0", then "return empty list", comma, "empty list". And now we wanna build our trade function. So this is going to be, uh, "death trade", right, and then it's gunna have two parameters; one being "self", because it's part of the trader class, and the other one, uh, being the other - uh, the other trader agency. Right? So, it's self or other. And that "other" being an agent object, uh, a trader agent object. Uh, and then, we put in our comments, right. So, "helper function". Right, that's used in trading neighbours. It's the main function we call from our model class. Uh, and then, we're gunna add - uh, again, uh, again one comment here, which is to say "other is a trader agent object". Just to emphasise that. Okay. The other thing you could do here, right, so now we've got hundreds of agents who're interacting, lots of other agents, multiple times. Um, so we're gunna add, uh, just to, uh, sanity check here, to make sure that they should be trading, and the rest of our code's working properly. Alright? So, we'll add Python's "primitive assert" function. Says, if "self . sugar" is greater than zero, and "self . spice" is greater than zero, right, then we'll do the same for the other agent. "Other . sugar" , greater than 0, "other . spice" greater than 0, then, uh, that'll allow this function to work. If it doesn't, if that assertion fails, alright, they [won't] get an error, right, and we know that there's some type of, uh, bug in our code, uh, that we need to - that we need to check on. So this is just a sanity check, to verify, uh, our code is working. Now that we've added this additional verification, inside our model, the next thing we've gotta do, is calculate the Marginal Rate of Substitution of each of our agents. Marginal Rate of Substitution comes from micro-economic theory, and determines how each agent values their sugar and spice commodity in relation to the other. Then this is then based off, uh, each agent's unique biology, which is their sugar and spice metabolism. Right? There's a great description of this, that starts on page 101 of "Growing Artificial Societies", and explains how, uh, professors Axtell and Epstein developed the rules that they have, uh, for trading inside, uh, this particular model, which we're - uh, what we're basing this off of. So we'll create a function, called, "calculate MRS". Right? As you can see here, uh, each agent object will have this function, uh, so, for "self" we'll do "self . calculate MRS", and for other, uh, they'll use their, uh, MRS function, in order to calculate their Marginal Rate of Substitution. This is - also then becomes important, it's the sense where you're building a simulation, right, just like that, [uh], you can make it say anything that you want, you can make a simulation say anything that you want. Right? So, it's important to make sure your simulations and models are built on, uh, firm theoretic foundations, and that you're not just programming something, uh, to make it produce the answer that you want. Now that we've done that, uh, we can look up here, right. So, this is our calculated MRS, right? And on - on that similar vein, we're gunna build our Cobb-Douglas function, alright? Although I showed, uh, where - uh, where a description [around internet?], can also look this up on page 97, uh, which gives a great description, uh, of the integration of Cobb - the Cobb-Douglas function, and how they, um, put it into this functional form, also in Growing Artificial Societies.