此文件是 TPOT 库的一部分。
TPOT 当前版本由 Cedars-Sinai 的以下人员开发:- Pedro Henrique Ribeiro (https://github.com/perib, https://www.linkedin.com/in/pedro-ribeiro/) - Anil Saini (anil.saini@cshs.org) - Jose Hernandez (jgh9094@gmail.com) - Jay Moran (jay.moran@cshs.org) - Nicholas Matsumoto (nicholas.matsumoto@cshs.org) - Hyunjun Choi (hyunjun.choi@cshs.org) - Gabriel Ketron (gabriel.ketron@cshs.org) - Miguel E. Hernandez (miguel.e.hernandez@cshs.org) - Jason Moore (moorejh28@gmail.com)
TPOT 最初版本主要由宾夕法尼亚大学的以下人员开发:- Randal S. Olson (rso@randalolson.com) - Weixuan Fu (weixuanf@upenn.edu) - Daniel Angell (dpa34@drexel.edu) - Jason Moore (moorejh28@gmail.com) - 以及许多其他慷慨的开源贡献者
TPOT 是自由软件:您可以根据自由软件基金会发布的 GNU 宽通用公共许可证(许可证的第 3 版或您选择的任何更高版本)的条款重新分发和/或修改它。
分发 TPOT 是希望它会有用,但没有任何担保;甚至不包含适销性或特定用途适用性的默示担保。详情请参见 GNU 宽通用公共许可证。
您应该已随 TPOT 收到一份 GNU 宽通用公共许可证的副本。如果未收到,请参阅 https://gnu.ac.cn/licenses/。
UnionPipeline
基类:SearchSpace
源代码位于 tpot/search_spaces/pipelines/union.py
| class UnionPipeline(SearchSpace):
def __init__(self, search_spaces : List[SearchSpace] ) -> None:
"""
Takes in a list of search spaces. will produce a pipeline of Sequential length. Each step in the pipeline will correspond to the the search space provided in the same index.
"""
self.search_spaces = search_spaces
def generate(self, rng=None):
rng = np.random.default_rng(rng)
return UnionPipelineIndividual(self.search_spaces, rng=rng)
|
__init__(search_spaces)
接收一个搜索空间列表。将生成一个 Sequential 长度的管道。管道中的每个步骤将对应于在相同索引中提供的搜索空间。
源代码位于 tpot/search_spaces/pipelines/union.py
| def __init__(self, search_spaces : List[SearchSpace] ) -> None:
"""
Takes in a list of search spaces. will produce a pipeline of Sequential length. Each step in the pipeline will correspond to the the search space provided in the same index.
"""
self.search_spaces = search_spaces
|
UnionPipelineIndividual
基类:SklearnIndividual
接收一个搜索空间列表。每个空间都是一个 SearchSpaces 列表。将生成一个 FeatureUnion 管道。管道中的每个步骤将对应于在相同索引中提供的搜索空间。最终生成的管道将是管道中各步骤的 FeatureUnion。
源代码位于 tpot/search_spaces/pipelines/union.py
| class UnionPipelineIndividual(SklearnIndividual):
"""
Takes in a list of search spaces. each space is a list of SearchSpaces.
Will produce a FeatureUnion pipeline. Each step in the pipeline will correspond to the the search space provided in the same index.
The resulting pipeline will be a FeatureUnion of the steps in the pipeline.
"""
def __init__(self, search_spaces : List[SearchSpace], rng=None) -> None:
super().__init__()
self.search_spaces = search_spaces
self.pipeline = []
for space in self.search_spaces:
self.pipeline.append(space.generate(rng))
def mutate(self, rng=None):
rng = np.random.default_rng(rng)
step = rng.choice(self.pipeline)
return step.mutate(rng)
def crossover(self, other, rng=None):
#swap a random step in the pipeline with the corresponding step in the other pipeline
rng = np.random.default_rng(rng)
cx_funcs = [self._crossover_node, self._crossover_swap_node]
rng.shuffle(cx_funcs)
for cx_func in cx_funcs:
if cx_func(other, rng):
return True
return False
def _crossover_swap_node(self, other, rng):
rng = np.random.default_rng(rng)
idx = rng.integers(1,len(self.pipeline))
self.pipeline[idx], other.pipeline[idx] = other.pipeline[idx], self.pipeline[idx]
return True
def _crossover_node(self, other, rng):
rng = np.random.default_rng(rng)
crossover_success = False
for idx in range(len(self.pipeline)):
if rng.random() < 0.5:
if self.pipeline[idx].crossover(other.pipeline[idx], rng):
crossover_success = True
return crossover_success
def export_pipeline(self, **kwargs):
return sklearn.pipeline.make_union(*[step.export_pipeline(**kwargs) for step in self.pipeline])
def unique_id(self):
l = [step.unique_id() for step in self.pipeline]
l = ["FeatureUnion"] + l
return TupleIndex(tuple(l))
|