跳到内容

元组索引

此文件是 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 宽通用公共许可证(GNU Lesser General Public License)的条款重新分发和/或修改它,您可以选择使用该许可证的第三版,或任何后续版本。

分发 TPOT 的目的是希望它能有用,但不提供任何担保;甚至不提供适销性或特定用途适用性的默示担保。更多详情请参阅 GNU 宽通用公共许可证(GNU Lesser General Public License)。

您应该已经随 TPOT 收到了 GNU 宽通用公共许可证(GNU Lesser General Public License)的副本。如果没有,请参阅 https://gnu.ac.cn/licenses/

TupleIndex

TPOT 使用元组(tuple)为某些流水线搜索空间创建唯一 ID。然而,元组有时无法与 pandas 索引正确交互。这个类是对元组的包装,允许它在字典中用作键,而不会被视为可迭代对象。

另一种替代方案是让唯一 ID 返回一个字符串,但这不适用于 graphpipeline,graphpipeline 需要一个特殊对象。这个类允许线性流水线包含图流水线,同时仍能在字典中用作键。

源代码位于 tpot/search_spaces/tuple_index.py
class TupleIndex():
    """
    TPOT uses tuples to create a unique id for some pipeline search spaces. However, tuples sometimes don't interact correctly with pandas indexes.
    This class is a wrapper around a tuple that allows it to be used as a key in a dictionary, without it being an itereable.

    An alternative could be to make unique id return a string, but this would not work with graphpipelines, which require a special object.
    This class allows linear pipelines to contain graph pipelines while still being able to be used as a key in a dictionary.

    """
    def __init__(self, tup):
        self.tup = tup

    def __eq__(self,other) -> bool:
        return self.tup == other

    def __hash__(self) -> int:
        return self.tup.__hash__()

    def __str__(self) -> str:
        return self.tup.__str__()

    def __repr__(self) -> str:
        return self.tup.__repr__()