[rules-users] [drools-fusion] Detecting a Trend in Data
Wolfgang Laun
wolfgang.laun at gmail.com
Mon Nov 4 01:24:13 EST 2013
To keep it simple,
declare Trend
List entries
int lastValue
bool hot
end
One rule creates a new Trend with a single entry if there is a new Entry:
rule newTrend
when
$e: Entry(...)
not Trend
then
create Trend with $e in entries, insert
end
Two to extend or rewind a Trend:
rule extendTrend
when
$t: Trend( $lv: lastValue )
$e: Entry( $value: value >= $lv ) // or >
then
extend Trend, modify Trend
end
rule rewindTrend
when
$t: Trend( $lv: lastValue )
$e: Entry( $value: value < $lv ) // or <=
then
clear entries, add $e, modify Trend
end
One to discover a "hot" trend:
rule discoverHotTrend
when
$t: Trend( ! $hot, entries.size >= LIMIT )
then
hot becomes true, modify Trend
end
I always opt for a simple solution so that I can understand it ;-)
-W
On 03/11/2013, Davide Sottara <dsotty at gmail.com> wrote:
> Quick ideas (not tested):
>
> 1) Detect an always increasing trend:
> ensure that no previous value - possibly scoped by a sliding window - is
> greater than the current
>
> $current : MyPoint( $val : value )
> not MyPoint( value > $val, this before $current ) over window:length(3)
>
>
> 2) A more robust approach, allowing for some noise:
> create a custom accumulate function that computes a (linear) regression
> and returns a
> data structure with the basic output parameters (regression
> coefficients, confidence intervals, etc..)
> You would then constrain on that... something like
>
> when
> LinearRegressionData( k > .... ) from accumulate ( $x : MyPoints()
> over window:length(3),
>
> myCustomLinearRegressionAccumulateFunction $x ) )
> then
>
> Other options might be possible
> Davide
>
>
>
>
>
> On 11/03/2013 10:21 AM, code4dc wrote:
>> Hey guys,
>>
>> I am trying to come up with a way to get Drools to detect a trend in a
>> dataset. The data is very basic and looks something like this:
>> (each row represents an object in the WM)
>> Time Value
>> 10:00 1
>> 11:00 2
>> 12:00 3
>> 01:00 1
>> 02:00 3
>> 04:00 4
>> 05:00 5
>> 06:00 3
>>
>> I want to set up a rule that detects when there is an upward trend in the
>> value for 3(configurable) or more consecutive data points.
>>
>> It's easy to set up a rule to detect when there is a two consecutive rows
>> and the 2nd one has a higher value. But how can I set up a rule to detect
>> when there are multiple consecutive rows each with a higher value than
>> the
>> previous one?
>>
>> Any ideas are welcome(even if they are not complete!).
>>
>> Thanks
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://drools.46999.n3.nabble.com/drools-fusion-Detecting-a-Trend-in-Data-tp4026609.html
>> Sent from the Drools: User forum mailing list archive at Nabble.com.
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list