def visitSearchSpaceObject(
         self, space: SearchSpaceObject) -> List[SearchSpaceGrid]:
     keys = space.keys
     keys_len = len(keys)
     final_choices: List[SearchSpaceGrid] = []
     for c in space.choices:
         assert keys_len == len(c)
         kvs_complex: List[List[SearchSpaceGrid]] = []
         kvs_simple: SearchSpaceGrid = {}
         for k, v in zip(keys, c):
             vspace: Union[List[SearchSpaceGrid],
                           SearchSpacePrimitive] = accept(v, self)
             if isinstance(vspace, SearchSpacePrimitive):
                 kvs_simple[k] = vspace
             else:
                 nested_vspace: List[SearchSpaceGrid] = nest_all_HPparams(
                     k, vspace)
                 if nested_vspace:
                     kvs_complex.append(nested_vspace)
         nested_space_choices: Iterable[
             Iterable[SearchSpaceGrid]] = itertools.product(*kvs_complex)
         nested_space_choices_lists: List[List[SearchSpaceGrid]] = list(
             map((lambda x: list(x)), nested_space_choices))
         nested_space_choices_filtered: List[List[SearchSpaceGrid]] = [
             ll for ll in nested_space_choices_lists if ll
         ]
         if nested_space_choices_filtered:
             chained_grids: Iterable[SearchSpaceGrid] = [
                 dict(ChainMap(*nested_choice, kvs_simple))
                 for nested_choice in nested_space_choices_filtered
             ]
             final_choices.extend(chained_grids)
         else:
             final_choices.append(kvs_simple)
     return final_choices
    def _searchSpaceList(self, space: SearchSpaceArray, *,
                         size: int) -> List[SearchSpaceGrid]:
        sub_spaces = space.items(max=size)

        param_grids: List[List[SearchSpaceGrid]] = [
            nest_all_HPparams(
                str(index), self.fixupDegenerateSearchSpaces(accept(sub,
                                                                    self)))
            for index, sub in enumerate(sub_spaces)
        ]

        param_grids_product: Iterable[
            Iterable[SearchSpaceGrid]] = itertools.product(*param_grids)
        chained_grids: List[SearchSpaceGrid] = [
            dict(ChainMap(*gridline, )) for gridline in param_grids_product
        ]

        if space.is_tuple:
            st_val = structure_type_tuple
        else:
            st_val = structure_type_list

        discriminated_grids: List[SearchSpaceGrid] = [{
            **d, structure_type_name:
            SearchSpaceConstant(st_val)
        } for d in chained_grids]

        return discriminated_grids
Example #3
0
    def visitSearchSpaceProduct(self, op:SearchSpaceProduct)->SearchSpaceGridInternalType:

        sub_spaces = op.get_indexed_spaces()

        param_grids:List[List[SearchSpaceGrid]] = [nest_all_HPparams(make_indexed_name(name, index), self.fixupDegenerateSearchSpaces(accept(space,self))) for name,index,space in sub_spaces]

        param_grids_product:Iterable[Iterable[SearchSpaceGrid]] = itertools.product(*param_grids)
        chained_grids:List[SearchSpaceGrid] = [
            dict(ChainMap(*gridline)) for gridline in param_grids_product]

        return chained_grids
Example #4
0
    def visitPlannedPipeline(self,
                             op: 'PlannedPipeline') -> List[SearchSpaceGrid]:

        param_grids: List[List[SearchSpaceGrid]] = [
            nest_all_HPparams(s.name(), s.accept(self)) for s in op.steps()
        ]

        param_grids_product: Iterable[
            Iterable[SearchSpaceGrid]] = itertools.product(*param_grids)
        chained_grids: List[SearchSpaceGrid] = [
            dict(ChainMap(*gridline)) for gridline in param_grids_product
        ]

        return chained_grids
Example #5
0
    def visitSearchSpaceDict(
            self, op: SearchSpaceDict) -> SearchSpaceGridInternalType:

        sub_spaces = op.space_dict.items()

        param_grids: List[List[SearchSpaceGrid]] = [
            nest_all_HPparams(
                name,
                self.fixupDegenerateSearchSpaces(accept(space, self)),
            ) for name, space in sub_spaces
        ]

        param_grids_product: Iterable[
            Iterable[SearchSpaceGrid]] = itertools.product(*param_grids)
        chained_grids: List[SearchSpaceGrid] = [
            dict(ChainMap(*gridline)) for gridline in param_grids_product
        ]

        discriminated_grids: List[SearchSpaceGrid] = [{
            **d, structure_type_name:
            SearchSpaceConstant(structure_type_dict)
        } for d in chained_grids]

        return discriminated_grids