Commit 9e16c926 authored by Miniskar, Narasinga Rao's avatar Miniskar, Narasinga Rao 🏄🏿
Browse files

Added one dimension with combination

parent cfc74598
......@@ -15,6 +15,7 @@ from numpy import random
import pdb
import argparse
import shlex
import itertools
from deffe_utils import *
class DeffeRandomSampling:
......@@ -120,14 +121,41 @@ class DeffeRandomSampling:
base_params.append(param.base)
seq = [ base_params.copy() ]
count = 0
params_list = []
comb_params_list = []
comb_params_values = []
for index, (param, param_values, pindex, permutation_index) in enumerate(params):
count += len(param_values)
print(f"Index:{index} PVs:{param_values} Count:{len(param_values)}")
for vindex, val in enumerate(param_values):
if base_params[index] != vindex:
obase = base_params.copy()
obase[index] = vindex
seq.append(obase)
if param.onedim_combination:
comb_params_list.append(index)
comb_params_values.append([i for i in range(len(param_values))])
else:
params_list.append(index)
if len(comb_params_values) > 0:
comb_list = list(itertools.product(*comb_params_values))
for comb in comb_list:
comb_params = base_params.copy()
for eindex, index in enumerate(comb_params_list):
(param, param_values, pindex, permutation_index) = params[index]
comb_params[index] = comb[eindex]
for index in params_list:
(param, param_values, pindex, permutation_index) = params[index]
count += len(param_values)
print(f"Index:{index} PVs:{param_values} Count:{len(param_values)}")
for vindex, val in enumerate(param_values):
if base_params[index] != vindex:
obase = comb_params.copy()
obase[index] = vindex
seq.append(obase)
else:
for index in params_list:
(param, param_values, pindex, permutation_index) = params[index]
count += len(param_values)
print(f"Index:{index} PVs:{param_values} Count:{len(param_values)}")
for vindex, val in enumerate(param_values):
if base_params[index] != vindex:
obase = base_params.copy()
obase[index] = vindex
seq.append(obase)
seq = np.array([ self.parameters.EncodePermutationFromArray(x) for x in seq])
np.random.shuffle(seq)
return seq
......
......@@ -41,6 +41,8 @@ def IsFloat(x):
"^[-+]? (?: (?: \d* \. \d+ ) | (?: \d+ \.? ) )(?: [Ee] [+-]? \d+ ) ?$"
)
float_re = re.compile(float_pattern, re.VERBOSE)
if type(x) == bool:
return False
if IsNumber(x):
return True
if float_re.findall(x):
......
......@@ -54,6 +54,11 @@ class DeffeConfigValues:
sub_values = [prefix+str(i)+postfix for i in range(start, end, inc)]
values_extract.extend(sub_values)
else:
#if type(value) == str and value.lower() == 'true':
# values_extract.append(True)
#elif type(value) == str and value.lower() == 'false':
# values_extract.append(False)
#else:
values_extract.append(os.path.expandvars(value))
def ExtractValues(self, values, delim=','):
......@@ -83,12 +88,19 @@ class DeffeConfigKnob:
self.map = self.name
self.base = None
self.groups_configured = False
self.onedim_combination = False
if "map" in data:
self.map = data["map"]
if "values" in data:
self.values = DeffeConfigValues(data["values"])
if "base" in data:
self.base =data['base']
if "onedim_combination" in data:
onedim_combination = data['onedim_combination']
if type(onedim_combination) == str and onedim_combination.lower() == 'true':
self.onedim_combination = True
else:
self.onedim_combination = data['onedim_combination']
if "groups" in data:
self.groups = DeffeConfigValues(data["groups"]).values
self.groups_configured = True
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment