Kent Johsnon writes<div>&quot;<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">This class has a lot of responsibilities:<br>- create applicants<br>- create institutions<br>
- run a single match<br>- run multiple matches<br>- calculate statistics on the result of multiple matches<br>A principle of object-oriented design is that a class should have a<br>single responsibility. I would break your class up a bit using<br>
multiple classes, perhaps.&quot;</span></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">I am trying to do what you recomend, as much as makes sense to me, but that is why I ask the question so I should consider your answer.</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">This is what I hear you saying, (I don&#39;t mean to represent them as sub-classes but more how they would operate on each other) Should I consider making Institutions) a subclass of (Make Institutions)? I can&#39;t think of anything that would make sense to inherit.</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">class Simulation:</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">    class Create Institutions:</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">        class Institutions:</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">    class create Applicants:</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">        class Applicants:</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">    class Match:</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">    class Multi Match:</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">I add I am thinking</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">class Simulation:</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">    def__init__:(self, results, stats.....repeat..)</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">    def create_applicants():</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">        class Applicants</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">    def creat_institutions():</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">        class Institutions</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">    def one_simulation(): # one or more</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">        create_applicants()</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">        create_institutions()</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">        class Match()</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">        class Results</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">    def repeat_simulation()</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">        repeat one_simulations</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">        class Results</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br>
</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">After writing this out I now think you are right, more classes. Which means I really need to play with function objects to understand how they are passed down the layers</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">Simulation(GPA = random.gauss(50, 10), repeat = 100.....)</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">    MakeApplicants(GPA)</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">        Applicants(GPA)  # I need to make sure the GPA is calculated at each applicant not back at Simulation.</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">DaveA </span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">ask if it will always be random.gauss? No, I would like it to be anything from a constant to a much more complex function) </span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">DaveA</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">&quot;<span class="Apple-style-span" style="font-size: 13px; ">I would caution you that each instance of RepeatMatch will then hold lots of the other members, so keeping them around could be expensive&quot;</span></span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">This means they stay in memory? Is there a way to know how much room a instance takes up, in memory or hard drive?</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">I could serialize them a save them to a sqlite when done with a simulation correct? How is a questions for later.</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">&quot;<span class="Apple-style-span" style="font-size: 13px; ">worried that you might find my responses too complex&quot;</span></span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">I am kinda working in a vacuum, with respect to python programing. Complex and difficult are ok, The challenge is not knowing what I don&#39;t know. I need to practice with function objects and run a few experiments still to make sureI understand them.</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">DaveA and Kent Thanks for all your help, Vincent</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">To add a little more to what I am doing I am using CherryPy to host this simulation. So the GPA function and other simulation variables can be entered in a html form and passed to the Simulation class. Then I am calculating results as well as using matplotlib to make some plots, these results and plots then get show. I think I have most of the CherryPy stuff figured out once I have the Simulations class setup to do the whole thing. The only part with CherryPy I am still working on is displaying progress on the browser as the simulations runs, it can take several minutes.</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div>Thanks<br>Vincent Davis<br>720-301-3003<br>
<br><br><div class="gmail_quote">On Sun, Nov 1, 2009 at 6:02 AM, Dave Angel <span dir="ltr">&lt;<a href="mailto:davea@ieee.org">davea@ieee.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">Vincent Davis wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I ask this question in part because of a fee remarks from another question I<br>
ask &quot;class attribute to initiate more classes&quot;<br>
<br>
Basically I am simulation the process of applicants to schools and trying to<br>
ask/answer some questions like &quot;what conditions do you need to have an<br>
optimal solution&quot; Oh and to learn python. I basically had it working as a<br>
script rather than using a class structure but it was very inflexible and I<br>
still needed to learn about classes.<br>
<br>
What I have these classes<br>
class Applicant: has lots of attributes (self.gpa = random.gauss(50, 10)<br>
about the Applicant and def() defining how/why an applicant applies to an<br>
institution,<br>
<br>
class Institution: Lots of attributes (self.quality = random.gauss(50,<br>
10)) about the Institution and def() defining how the institution considers<br>
the applicant.<br>
<br>
class Match: this defines the interaction of the population of Applicants<br>
and Institutions, i.e. the rules of the game and returns the outcome i.e.<br>
which Applicants went to which Institutions.<br>
<br>
As of now I have been running 1 Match at a time. Which is to say generate<br>
8000 instances of Applicant and 300 instances of Institution and then run<br>
the match Match(app_list, inst_list) and I do this with a short script.<br>
<br>
So now I need to implement my monte-carlo. By that I mean that i want to set<br>
some of the initial condition such as GPA, and Quality and basically re-run<br>
the what I descried above, (generate applicant, institutions, match them)<br>
 Then save the results.<br>
<br>
So my plan way to make a new class. This class would define the Applicant<br>
characteristics &quot;self.gpa = random.gauss(mean, SD)&quot; and the<br>
institutions self.quality = random.gauss(mean, sd)<br>
<br>
so it would look something like this<br>
<br>
<br>
class RepeatMatch:<br>
    def __int__(self, app_mean, app_sd, inst_mean, inst_sd, match_ repeat)<br>
        self.app_mean = app_mean<br>
        ……..<br>
        self.match_repeat = match_repeat<br>
<br>
   def makeApplicants():<br>
<br>
   def makeInstitutions():<br>
<br>
   def runMatches(self)<br>
   # runs the match match_repeat number of times, saves results<br>
<br>
# then I calculate some characteristics of the results<br>
<br>
    def ratio_dist():<br>
         # returns the Mean and sd of GPA/Quality<br>
END OF CODE<br>
<br>
Does it make sense to do it this way? Is there a better/alternative way of<br>
thinking about this. In the end I want to compare the results of repeated<br>
simulations &quot;RepeatMatch(50,2….) Compared to RepeatMatch(50,15….)&quot;<br>
This is way I had ask the earlier question &quot;class attribute to initiate more<br>
classes&quot;<br>
<br>
Thanks<br>
Vincent Davis<br>
<br>
  <br>
</blockquote></div></div>
I worried that you might find my responses too complex, but nobody else has responded, and it&#39;s been almost a day.<br>
<br>
I don&#39;t see anything wrong with your approach.  Since you&#39;re going to do multiple sets of data, it makes sense for an instance of a class (RepeatMatch) to hold the data for one such run.  In your original sample, it didn&#39;t make sense to me, but of course I didn&#39;t know where you were heading.  So I would add in instance attributes such as  self.applicants=[]  to your __init__() method of RepeatMatch.  (I suspect you&#39;re planning to do exactly that)<br>

<br>
I would caution you that each instance of RepeatMatch will then hold lots of the other members, so keeping them around could be expensive. So when run_matches() finishes its analysis, it might want to delete its lists of raw data (eg. self.applicants).  But other choices exist, and you can decide that when you see how the whole thing fits together.  Perhaps you&#39;ll only have one such instance at a time.  But if you&#39;re going to do multiple things with the results, you may want this object to hang onto the results, but throw away the raw data when all the necessary results have been calculated.<br>

<br>
Are you sure that the only distribution you&#39;re going to use is random.gauss() ?  If so, then you only need to pass mean and stddev to the RepeatMatch constructor, as you&#39;re doing.  But if you might need to compare that distribution with a different one, then you might want to use a function object, as I tried to describe earlier.<br>

<br>
<br>
HTH<br>
DaveA<br>
</blockquote></div><br></div>