def get_pb(self, result=None):
        if not isinstance(result, NeuralNetworkProto):
            result = NeuralNetworkProto()
        result.id_name = self._id_name
        for f_cls in self.function_cls:
            result.function_cls.append(f_cls.get_cls_name())
        for _f in self.functions:
            result.functions.append(_f.get_pb())
        for in_label, (out_label, id_name) in self._inputs.items():
            ioM = IOMappingProto()
            ioM.in_label = in_label
            ioM.out_label = out_label
            ioM.df_id_name = id_name
            result.input_mapping.append(ioM)
        for in_label, (out_label, id_name) in self.output_mapping.items():
            ioM = IOMappingProto()
            ioM.in_label = in_label
            ioM.out_label = out_label
            ioM.df_id_name = id_name
            result.output_mapping.append(ioM)
        result.output_ntss.v.extend(
            [value2pb(v) for v in self.output_targets.items()])

        result.attr.extend(
            [attr2pb(key, value) for key, value in self.attr.items()])
        result.attr.append(attr2pb(self.arg_INPUTS, self.input_mapping))
        return result
Example #2
0
    def get_pb(self, result=None):
        if not isinstance(result, CompareClassProto):
            result = CompareClassProto()

        result.attr.append(
            attr2pb(self.arg_PRIMARY_OBJECTIVE, self.primary_objective))
        result.attr.append(attr2pb(self.arg_PRIMARY_ALPHA, self.primary_alpha))
        result.attr.append(
            attr2pb(self.arg_PRIMARY_THRESHOLD, self.primary_threshold))
        result.attr.append(
            attr2pb(self.secondary_objectives, self.secondary_objectives))
        return result
Example #3
0
 def get_pb(self, result=None) -> InitializerProto:
     if not isinstance(result, InitializerProto):
         result = InitializerProto()
     result.cls_name = self.__class__.__name__
     result.attr.extend(
         [attr2pb(key, value) for key, value in self.attr.items()])
     return result
Example #4
0
 def get_pb(self, result=None):
     if not isinstance(result, RegularisationProto):
         result = RegularisationProto()
     result.cls_name = self.__class__.__name__
     result.attr.extend(
         [attr2pb(key, value) for key, value in self.attr.items()])
     return result
Example #5
0
 def __copy__(self):
   result = self.__class__.__new__(self.__class__)
   result._id_name = self._id_name
   result.input_mapping = dict(self.input_mapping)
   result.variables = [v.__copy__() for v in self.variables]
   result.attr = dict([pb2attr(attr2pb(key, value)) for key, value in self.attr.items()])
   return result
Example #6
0
 def get_pb(self, result=None):
   if not isinstance(result, DatasetProto):
     result = DatasetProto()
   result = super(UncorrelatedSupervised, self).get_pb(result)
   if self.train_X is not None: result.attr_val.append(attr2pb('train_X', self.train_X))
   if self.train_Y is not None: result.attr_val.append(attr2pb('train_Y', self.train_Y))
   if self.test_X is not None: result.attr_val.append(attr2pb('test_X', self.test_X))
   if self.test_Y is not None: result.attr_val.append(attr2pb('test_Y', self.test_Y))
   if self.valid_X is not None: result.attr_val.append(attr2pb('valid_X', self.valid_X))
   if self.valid_Y is not None: result.attr_val.append(attr2pb('valid_Y', self.valid_Y))
   result.attr_val.append(attr2pb('len', self.len))
   result.attr_val.append(attr2pb('idx', self.idx))
   result.attr_val.append(attr2pb('state', self.state))
   return result
 def recombine(self, other):
     result = WeightAgnosticIndividual.__new__(WeightAgnosticIndividual)
     result.metrics = dict()
     result.attr = dict(
         [pb2attr(attr2pb(key, value)) for key, value in self.attr.items()])
     result._data_nts = {
         label: (nts.__copy__(), id_name)
         for label, (nts, id_name) in self._data_nts.items()
     }
     result._losses = list(self._losses)
     result.loss = self.loss
     result._networks = self.network.recombine(other.network)
     result.network = result._networks[0]
     result._id_name = self.getNewName()
     return [result]
Example #8
0
 def mutate(self, prob):
     result = ClassifierIndividualOPACDG.__new__(ClassifierIndividualOPACDG)
     result.metrics = dict()
     result.attr = dict(
         [pb2attr(attr2pb(key, value)) for key, value in self.attr.items()])
     result._data_nts = {
         label: (nts.__copy__(), id_name)
         for label, (nts, id_name) in self._data_nts.items()
     }
     result._losses = list(self._losses)
     result.loss = self.loss
     result.network = self.network.mutate(prob=prob)[0]
     result._networks = [result.network]
     result._id_name = self.getNewName()
     return [result]
Example #9
0
 def get_pb(self, result=None):
     """
 Convert the in individual into a protobuf object.
 :param result: optional result protobuf object to modify
 :return: protobuf object (IndividualProto)
 """
     if not isinstance(result, IndividualProto):
         result = IndividualProto()
     result.cls_name = self.__class__.__name__
     result.id_name = self._id_name
     result.metrics.extend([
         IndividualProto.MetricProto(id_name=key, value=value)
         for key, value in self.metrics.items()
     ])
     result.attr.extend(
         [attr2pb(key, value) for key, value in self.attr.items()])
     return result
Example #10
0
 def get_pb(self, result=None) -> FunctionProto:
   """
   Convert the object into a protobuf object.
   :param result: optional result protobuf to modify; if None, one is created
   :return: protobuf object (FunctionProto)
   """
   if not isinstance(result, FunctionProto):
     result = FunctionProto()
   result.class_name = self.get_cls_name()
   result.id_name = self._id_name
   for input_label, (output_label, df_obj) in self.input_mapping.items():
     input_proto = IOMappingProto()
     input_proto.in_label = input_label
     input_proto.out_label = output_label
     input_proto.df_id_name = df_obj
     result.input_mapping.append(input_proto)
   result.variables.extend([v.get_pb() for v in self.variables])
   result.attr.extend([attr2pb(key, value) for key, value in self.attr.items()])
   return result
Example #11
0
 def distinct_copy(self):
   result = NeuralNetwork.__new__(NeuralNetwork)
   result._id_name = self.id_name
   result.function_cls = list(self.function_cls)
   result.output_targets = dict([(label, value.__copy__()) for label, value in self.output_targets.items()])
   result._inputs = dict(self._inputs)
   result.output_mapping = dict(self.output_mapping)
   result.functions = list()
   function_mapping = dict()
   for _f in self.functions:
     new_f = Function.__new__(Function)
     new_f.__setstate__(_f.get_pb())
     new_f._id_name = new_f.getNewName(new_f)
     result.functions.append(new_f)
     function_mapping[_f.id_name] = new_f.id_name
   for _f in result.functions:
     for key, (v1, old_f_id) in _f.input_mapping.items():
       _f.input_mapping[key] = (v1, function_mapping.get(old_f_id, old_f_id))
   for in_label, (out_label, f_id) in result.output_mapping.items():
     result.output_mapping[in_label] = (out_label, function_mapping.get(f_id, f_id))
   result.variable_pool = dict([(key, list(value_l)) for key, value_l in self.variable_pool.items()])
   result.attr = dict([pb2attr(attr) for attr in [attr2pb(key, value) for key, value in self.attr.items()]])
   return result
    def __copy__(self):
        result = WeightAgnosticNeuralNetwork.__new__(
            WeightAgnosticNeuralNetwork)
        result.input_mapping = {
            key: (l0, v.__copy__(), l1)
            for key, (l0, v, l1) in self.input_mapping.items()
        }
        result.output_targets = {
            key: ts.__copy__()
            for key, ts in self.output_targets.items()
        }
        result.function_cls = list(self.function_cls)
        result._inputs = {k: (v0, v1) for k, (v0, v1) in self._inputs.items()}
        result.output_mapping = {
            k: (v0, v1)
            for k, (v0, v1) in self.output_mapping.items()
        }
        result.functions = [f.__copy__() for f in self.functions]
        result.attr = dict(
            [pb2attr(attr2pb(key, value)) for key, value in self.attr.items()])

        self._id_name = self.getNewName()
        return result