Ignore:
Timestamp:
Nov 29, 2010 5:26:46 PM (10 years ago)
Author:
jwatson
Message:

Adding two options to the runef and runph pysp scripts, to facilitate scenario downsampling - the case where you have a big tree, but you don't want to use it all.

The options are:
--scenario-tree-downsample-fraction=X
--scenario-tree-random-seed

The options are fairly self-explanatory - the only possible nuance is that the downsample fraction is the fraction of scenarios retained.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pysp/trunk/coopr/pysp/scenariotree.py

    r3218 r3261  
    1616
    1717from math import fabs
     18
     19import random
    1820
    1921from coopr.pyomo import *
     
    654656            probability = probability * tree_node._conditional_probability
    655657         scenario._probability = probability
     658
     659   #
     660   # utility for automatically selecting a proportion of scenarios from the
     661   # tree to retain, eliminating the rest.
     662   #
     663
     664   def downsample(self, fraction_to_retain, random_seed, verbose=False):
     665
     666      random.seed(random_seed)
     667
     668      random_sequence=range(0,len(self._scenarios))
     669      random.shuffle(random_sequence)
     670
     671      number_to_retain = max(int(round(float(len(random_sequence)*fraction_to_retain))), 1)
     672
     673      scenario_bundle_list = []
     674      for i in range(0,number_to_retain):
     675         scenario_bundle_list.append(self._scenarios[random_sequence[i]]._name)
     676
     677      if verbose is True:
     678         print "Downsampling scenario tree - retained scenarios: "+str(scenario_bundle_list)
     679
     680      self.compress(scenario_bundle_list)
     681
    656682
    657683   #
Note: See TracChangeset for help on using the changeset viewer.