Brian Hann > DateTime-Event-Predict-0.01_04 > DateTime::Event::Predict

Download:
DateTime-Event-Predict-0.01_04.tgz

Dependencies

Annotate this POD

Module Version: 0.01_03   Source  

NAME ^

DateTime::Event::Predict - Predict new dates from a set of dates

SYNOPSIS ^

Given a set of dates this module will predict the next date or dates to follow.

  use DateTime::Event::Predict;

  my $dtp = DateTime::Event::Predict->new(
      profile => {
          buckets => ['day_of_week'],
      },
  );

  # Add today's date: 2009-12-17
  my $date = new DateTime->today();
  $dtp->add_date($date);

  # Add the previous 14 days
  for  (1 .. 14) {
      my $new_date = $date->clone->add(
          days => ($_ * -1),
      );

      $dtp->add_date($new_date);
  }

  # Predict the next date
  my $predicted_date = $dtp->predict;

  print $predicted_date->ymd;

  # 2009-12-18

Here we create a new DateTime object with today's date (it being December 17th, 2009 currently). We then use add_date to add it onto the list of dates that DateTime::Event::Predict (DTP) will use to make the prediction.

Then we take the 14 previous days (December 16-2) and them on to same list one by one. This gives us a good set to make a prediction out of.

Finally we call predict which returns a DateTime object representing the date that DTP has calculated will come next.

HOW IT WORKS ^

Predicting the future is not easy, as anyone except, perhaps, Nostradamus will tell you. Events can occur with perplexing randomness and discerning any pattern in the noise is nigh unpossible.

However, if you have a set of data to work with that you know for certain contains some sort of regularity, and you have enough information to discover that regularity, then making predictions from that set can be possible. The main issue with our example above is the tuning we did with this sort of information.

When you configure your instance of DTP, you will have to tell what sorts of date-parts to keep track of so that it has a good way of making a prediction. Date-parts can be things like "day of the week", "day of the year", "is a weekend day", "week on month", "month of year", differences between dates counted by "week", or "month", etc. Dtpredict will collect these identifiers from all the provided dates into "buckets" for processing later on.

EXAMPLES ^

Predicting Easter
Predicting

METHODS ^

new

Constructor

        my $dtp = DateTime::Event::Predict->new();

dates

Arguments: none | \@dates

Return value: \@dates

Called with no argument this method will return an arrayref to the list of the dates currently in the instance.

Called with an arrayref to a list of DateTime objects (\@dates) this method will set the dates for this instance to \@dates.

add_date

Arguments: $date

Return value:

Adds a date on to the list of dates in the instance, where $date is a DateTime object.

profile

Arguments: $profile

Set the profile for which date-parts will be

  # Pass in preset profile by its alias
  $dtp->profile( profile => 'default' );
  $dtp->profile( profile => 'holiday' );

  # Create a new profile
  my $profile = new DateTime::Event::Predict::Profile(
      buckets => [qw/ minute hour day_of_week day_of_month /],
  );

  $dtp->profile( profile => $profile );

Provided profiles

The following profiles are provided for use by-name:

predict

Arguments: %options

Return Value: $next_date | @next_dates

Predict the next date(s) from the dates supplied.

  my $predicted_date = $dtp->predict();

If list context predict returns a list of all the predictions, sorted by their probability:

  my @predicted_dates = $dtp->predict();

The number of prediction can be limited with the max_predictions option.

Possible options

  $dtp->predict(
      max_predictions => 4, # Once 4 predictions are found, return back
      callbacks => [
          sub { return ($_->second % 4) ? 0 : 1 } # Only predict dates with second values that are divisible by four.
      ],
  );
max_predictions

Maximum number of predictions to find.

callbacks

Arrayref of subroutine callbacks. If any of them return a false value the date will not be returned as a prediction.

train

Train this instance of DTP

TODO ^

AUTHOR ^

Brian Hann, <brian.hann at gmail.com>

BUGS ^

Please report any bugs or feature requests to bug-datetime-event-predict at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DateTime-Event-Predict. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc DateTime::Event::Predict

You can also look for information at:

COPYRIGHT & LICENSE ^

Copyright 2009 Brian Hann, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO ^

DateTime, DateTime::Event::Predict::Profile

syntax highlighting: