Skip to content

Commit

Permalink
fix resample
Browse files Browse the repository at this point in the history
  • Loading branch information
valer1435 committed Aug 7, 2023
1 parent 6f265ff commit d3da621
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
5 changes: 4 additions & 1 deletion fedot/api/api_utils/api_params_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from golem.core.optimisers.genetic.operators.inheritance import GeneticSchemeTypesEnum
from golem.core.optimisers.genetic.operators.mutation import MutationTypesEnum

from fedot.core.composer.gp_composer.specific_operators import parameter_change_mutation, boosting_mutation
from fedot.core.composer.gp_composer.specific_operators import parameter_change_mutation, boosting_mutation, \
add_resample_mutation
from fedot.core.constants import AUTO_PRESET_NAME
from fedot.core.repository.tasks import TaskTypesEnum
from fedot.core.utils import default_fedot_data_dir
Expand Down Expand Up @@ -135,5 +136,7 @@ def _get_default_mutations(task_type: TaskTypesEnum, params) -> Sequence[Mutatio
# TODO remove workaround after boosting mutation fix
if task_type == TaskTypesEnum.ts_forecasting:
mutations.append(partial(boosting_mutation, params=params))
else:
mutations.append(add_resample_mutation)

return mutations
11 changes: 11 additions & 0 deletions fedot/core/composer/gp_composer/specific_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ def boosting_mutation(pipeline: Pipeline, requirements, graph_gen_params, **kwar
return pipeline


def add_resample_mutation(pipeline: Pipeline, **kwargs):
resample_node = PipelineNode('resample')

p_nodes = [p_node for p_node in pipeline.primary_nodes]
pipeline.add_node(resample_node)

for node in p_nodes:
pipeline.connect_nodes(resample_node, node)
return pipeline


def choose_new_model(boosting_model_candidates: List[str]) -> str:
""" Since 'linear' and 'dtreg' operations are suitable for solving the problem
and they are simpler than others, they are preferred """
Expand Down
15 changes: 14 additions & 1 deletion fedot/core/pipelines/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from copy import deepcopy
from datetime import timedelta
from os import PathLike
from typing import Optional, Tuple, Union, Sequence
from typing import Optional, Tuple, Union, Sequence, List

import func_timeout
from golem.core.dag.graph import Graph
Expand Down Expand Up @@ -327,6 +327,19 @@ def root_node(self) -> Optional[PipelineNode]:
raise ValueError(f'{ERROR_PREFIX} More than 1 root_nodes in pipeline')
return root[0]

@property
def primary_nodes(self) -> List[PipelineNode]:
"""Finds pipelines sink-node
Returns:
the final predictor-node
"""
if not self.nodes:
return []
primary_nodes = [node for node in self.nodes
if not node.nodes_from]
return primary_nodes

def pipeline_for_side_task(self, task_type: TaskTypesEnum) -> 'Pipeline':
"""Returns pipeline formed from the last node solving the given problem and all its parents
Expand Down
8 changes: 5 additions & 3 deletions fedot/core/pipelines/verification_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ def has_correct_location_of_resample(pipeline: Pipeline):
is_resample_primary = True
else:
is_not_resample_primary = True
if node.name == 'resample':
raise ValueError(
f'{ERROR_PREFIX} Pipeline can have only one resample operation located in start of the pipeline')
else:
if node.name == 'resample':
raise ValueError(
f'{ERROR_PREFIX} Pipeline can have only one resample operation located in start of the pipeline')
if is_resample_primary and is_not_resample_primary:
raise ValueError(
f'{ERROR_PREFIX} Pipeline can have only one resample operation located in start of the pipeline')
return True


def get_wrong_links(ts_to_table_operations: list, ts_data_operations: list, non_ts_data_operations: list,
Expand Down

0 comments on commit d3da621

Please sign in to comment.