summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ricky/param/probabilities.py21
-rw-r--r--ricky/param/probability.py9
-rw-r--r--ricky/params.py18
3 files changed, 15 insertions, 33 deletions
diff --git a/ricky/param/probabilities.py b/ricky/param/probabilities.py
deleted file mode 100644
index d109b18..0000000
--- a/ricky/param/probabilities.py
+++ /dev/null
@@ -1,21 +0,0 @@
-from ricky.param.probability import Probability
-import sys
-class Probabilities:
- def __init__(self, *args):
- self._values = args
- def __iter__(self):
- return iter(self._values)
- def __len__(self):
- return len(self._values)
- def __str__(self):
- return str(self._values)
- def __getitem__(self, i):
- return self._values[i]
- def search(self, s):
- for i in self:
- if str(s) in i.value:
- return i
- @classmethod
- def from_dict(cls, *args):
- probabilities = map(lambda x: Probability(**x), args);
- return cls(*probabilities);
diff --git a/ricky/param/probability.py b/ricky/param/probability.py
deleted file mode 100644
index 0d27b70..0000000
--- a/ricky/param/probability.py
+++ /dev/null
@@ -1,9 +0,0 @@
-class Probability(dict):
- def __init__(self, **kwargs):
- super(Probability, self).__init__(**kwargs)
- self.value = kwargs["value"]
- self.weight = kwargs["weight"]
- def __getattr__(self, attr):
- return self.get(attr)
- __setattr__= dict.__setitem__
- __delattr__= dict.__delitem__
diff --git a/ricky/params.py b/ricky/params.py
index c5595d4..4f91776 100644
--- a/ricky/params.py
+++ b/ricky/params.py
@@ -18,10 +18,22 @@ class Params(object):
"""string representation"""
return pprint.pformat(self.as_dict())
- def randomize(self):
- """assign random values to all params, taking into account weight"""
+ def randomize(
+ self,
+ probabilities=None,
+ probabilities_local=False
+ ):
+ """assign random values to all params
+ if using a probabilities.json file, weight is taken
+ into account"""
+ if probabilities:
+ probabilities = self._load_probabilities(probabilities)
+ else if probabilities_local:
+ probabilities = self._load_probabilities(probabilities_local)
+ else:
+ probabilities = {}
for param in self._params:
- param.randomize()
+ param.randomize(probability=probabilities.get(param.name))
@property
def api(self):