def frequencyTailoredPatternSearchTest(createTestFile=False): pattern = Pattern( SeqOperator(PrimitiveEventStructure("DRIV", "a"), PrimitiveEventStructure("MSFT", "b"), PrimitiveEventStructure("CBRL", "c")), AndCondition( GreaterThanCondition(Variable("a", lambda x: x["Opening Price"]), Variable("b", lambda x: x["Opening Price"])), GreaterThanCondition(Variable("b", lambda x: x["Opening Price"]), Variable("c", lambda x: x["Opening Price"]))), timedelta(minutes=360)) # frequencyDict = {"MSFT": 256, "DRIV": 257, "CBRL": 1} pattern.set_statistics({ StatisticsTypes.ARRIVAL_RATES: [0.01454418928322895, 0.016597077244258872, 0.012421711899791231] }) eval_params = TreeBasedEvaluationMechanismParameters( optimizer_params=StatisticsDeviationAwareOptimizerParameters( tree_plan_params=TreePlanBuilderParameters( TreePlanBuilderTypes.SORT_BY_FREQUENCY_LEFT_DEEP_TREE), statistics_collector_params=StatisticsCollectorParameters( statistics_types=[StatisticsTypes.ARRIVAL_RATES])), storage_params=DEFAULT_TESTING_EVALUATION_MECHANISM_SETTINGS. storage_params) runTest('frequencyTailored1', [pattern], createTestFile, eval_mechanism_params=eval_params, events=nasdaqEventStream)
def frequencyPatternSearch2Test(createTestFile=False): pattern = Pattern( SeqOperator(PrimitiveEventStructure("LOCM", "a"), PrimitiveEventStructure("AMZN", "b"), PrimitiveEventStructure("AAPL", "c")), AndCondition( SmallerThanCondition(Variable("a", lambda x: x["Opening Price"]), Variable("b", lambda x: x["Opening Price"])), SmallerThanCondition(Variable("b", lambda x: x["Opening Price"]), Variable("c", lambda x: x["Opening Price"]))), timedelta(minutes=5)) pattern.set_statistics( {StatisticsTypes.ARRIVAL_RATES: [0.0076, 0.0153, 0.0159]}) eval_params = TreeBasedEvaluationMechanismParameters( optimizer_params=StatisticsDeviationAwareOptimizerParameters( tree_plan_params=TreePlanBuilderParameters( TreePlanBuilderTypes.SORT_BY_FREQUENCY_LEFT_DEEP_TREE), statistics_collector_params=StatisticsCollectorParameters( statistics_types=[StatisticsTypes.ARRIVAL_RATES])), storage_params=DEFAULT_TESTING_EVALUATION_MECHANISM_SETTINGS. storage_params) runTest("frequency2", [pattern], createTestFile, eval_mechanism_params=eval_params)
def frequencyPatternSearch6Test(createTestFile=False): pattern = Pattern( SeqOperator(PrimitiveEventStructure("AAPL", "a1"), PrimitiveEventStructure("LOCM", "b1"), PrimitiveEventStructure("AAPL", "a2"), PrimitiveEventStructure("LOCM", "b2"), PrimitiveEventStructure("AAPL", "a3"), PrimitiveEventStructure("LOCM", "b3")), TrueCondition(), timedelta(minutes=7)) pattern.set_statistics({ StatisticsTypes.ARRIVAL_RATES: [0.0159, 0.0076, 0.0159, 0.0076, 0.0159, 0.0076] }) # {"AAPL": 460, "LOCM": 219} eval_params = TreeBasedEvaluationMechanismParameters( optimizer_params=StatisticsDeviationAwareOptimizerParameters( tree_plan_params=TreePlanBuilderParameters( TreePlanBuilderTypes.SORT_BY_FREQUENCY_LEFT_DEEP_TREE), statistics_collector_params=StatisticsCollectorParameters( statistics_types=[StatisticsTypes.ARRIVAL_RATES])), storage_params=DEFAULT_TESTING_EVALUATION_MECHANISM_SETTINGS. storage_params) runTest("frequency6", [pattern], createTestFile, eval_mechanism_params=eval_params)
def __init__( self, tree_plan_params: TreePlanBuilderParameters = TreePlanBuilderParameters( TreePlanBuilderTypes.INVARIANT_AWARE_GREEDY_LEFT_DEEP_TREE), statistics_collector_params: StatisticsCollectorParameters = StatisticsCollectorParameters(), statistics_updates_wait_time: timedelta = DefaultConfig. STATISTICS_UPDATES_WAIT_TIME): super().__init__(OptimizerTypes.INVARIANT_AWARE_OPTIMIZER, tree_plan_params, statistics_collector_params, statistics_updates_wait_time)
def __init__( self, tree_plan_params: TreePlanBuilderParameters = TreePlanBuilderParameters( ), statistics_collector_params: StatisticsCollectorParameters = StatisticsCollectorParameters(), statistics_updates_wait_time: timedelta = DefaultConfig. STATISTICS_UPDATES_WAIT_TIME): super().__init__(OptimizerTypes.TRIVIAL_OPTIMIZER, tree_plan_params, statistics_collector_params, statistics_updates_wait_time)
def __init__( self, opt_type: OptimizerTypes = DefaultConfig.DEFAULT_OPTIMIZER_TYPE, tree_plan_params: TreePlanBuilderParameters = TreePlanBuilderParameters( ), statistics_collector_params: StatisticsCollectorParameters = StatisticsCollectorParameters(), statistics_updates_wait_time: timedelta = DefaultConfig. STATISTICS_UPDATES_WAIT_TIME): self.type = opt_type self.tree_plan_params = tree_plan_params self.statistics_collector_params = statistics_collector_params self.statistics_updates_time_window = statistics_updates_wait_time # None disabled any adaptive functionality
def __init__( self, tree_plan_params: TreePlanBuilderParameters = TreePlanBuilderParameters( ), statistics_collector_params: StatisticsCollectorParameters = StatisticsCollectorParameters(), statistics_updates_wait_time: timedelta = DefaultConfig. STATISTICS_UPDATES_WAIT_TIME, deviation_threshold: float = DefaultConfig. DEVIATION_OPTIMIZER_THRESHOLD): super().__init__(OptimizerTypes.STATISTICS_DEVIATION_AWARE_OPTIMIZER, tree_plan_params, statistics_collector_params, statistics_updates_wait_time) statistics_types = statistics_collector_params.statistics_types if isinstance(statistics_types, StatisticsTypes): statistics_types = [statistics_types] self.statistics_types = statistics_types self.deviation_threshold = deviation_threshold
def zStreamPatternSearchTest(createTestFile=False): pattern = Pattern( SeqOperator(PrimitiveEventStructure("MSFT", "a"), PrimitiveEventStructure("DRIV", "b"), PrimitiveEventStructure("ORLY", "c"), PrimitiveEventStructure("CBRL", "d")), AndCondition( AndCondition( SmallerThanCondition(Variable("a", lambda x: x["Peak Price"]), Variable("b", lambda x: x["Peak Price"])), AndCondition( SmallerThanCondition( Variable("b", lambda x: x["Peak Price"]), Variable("c", lambda x: x["Peak Price"])))), SmallerThanCondition(Variable("c", lambda x: x["Peak Price"]), Variable("d", lambda x: x["Peak Price"]))), timedelta(minutes=3)) selectivityMatrix = [[1.0, 0.9457796098355941, 1.0, 1.0], [0.9457796098355941, 1.0, 0.15989723367389616, 1.0], [1.0, 0.15989723367389616, 1.0, 0.9992557393942864], [1.0, 1.0, 0.9992557393942864, 1.0]] arrivalRates = [ 0.016597077244258872, 0.01454418928322895, 0.013917884481558803, 0.012421711899791231 ] pattern.set_statistics({ StatisticsTypes.SELECTIVITY_MATRIX: selectivityMatrix, StatisticsTypes.ARRIVAL_RATES: arrivalRates }) eval_params = TreeBasedEvaluationMechanismParameters( optimizer_params=StatisticsDeviationAwareOptimizerParameters( tree_plan_params=TreePlanBuilderParameters( TreePlanBuilderTypes.ZSTREAM_BUSHY_TREE), statistics_collector_params=StatisticsCollectorParameters( statistics_types=[ StatisticsTypes.ARRIVAL_RATES, StatisticsTypes.SELECTIVITY_MATRIX ])), storage_params=DEFAULT_TESTING_EVALUATION_MECHANISM_SETTINGS. storage_params) runTest('zstream1', [pattern], createTestFile, eval_mechanism_params=eval_params, events=nasdaqEventStream)
from adaptive.optimizer.OptimizerFactory import StatisticsDeviationAwareOptimizerParameters, \ InvariantsAwareOptimizerParameters, TrivialOptimizerParameters from plan.TreePlanBuilderFactory import TreePlanBuilderParameters, TreeCostModels, StatisticsTypes from plan.TreePlanBuilderTypes import TreePlanBuilderTypes from adaptive.statistics.StatisticsCollectorFactory import StatisticsCollectorParameters from tree.PatternMatchStorage import TreeStorageParameters DEFAULT_TREE_STORAGE_PARAMETERS = TreeStorageParameters( sort_storage=False, clean_up_interval=10, prioritize_sorting_by_timestamp=True) """ Default testing statistics collector settings """ DEFAULT_TESTING_STATISTICS_COLLECTOR_SELECTIVITY_AND_ARRIVAL_RATES_STATISTICS = \ StatisticsCollectorParameters(statistics_types=[StatisticsTypes.SELECTIVITY_MATRIX, StatisticsTypes.ARRIVAL_RATES]) """ Default testing tree builder settings """ DEFAULT_BASIC_TESTING_TREE_BUILDER = \ TreePlanBuilderParameters(TreePlanBuilderTypes.GREEDY_LEFT_DEEP_TREE, TreeCostModels.INTERMEDIATE_RESULTS_TREE_COST_MODEL) DEFAULT_TESTING_INVARIANT_AWARE_GREEDY_TREE_BUILDER = \ TreePlanBuilderParameters(TreePlanBuilderTypes.INVARIANT_AWARE_GREEDY_LEFT_DEEP_TREE, TreeCostModels.INTERMEDIATE_RESULTS_TREE_COST_MODEL) DEFAULT_TESTING_INVARIANT_AWARE_ZSTREAM_BUSHY_TREE_BUILDER = \ TreePlanBuilderParameters(TreePlanBuilderTypes.INVARIANT_AWARE_ZSTREAM_BUSHY_TREE, TreeCostModels.INTERMEDIATE_RESULTS_TREE_COST_MODEL) """