Algorithm-Classifier-IsolationForest

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

# Record the captured configuration where the module can read it at load
# time.  Generated before WriteMakefile so ExtUtils::MakeMaker's lib/ scan
# picks it up for blib and install.  Not in MANIFEST: it is per-install
# state, never shipped.
my $bf_path = 'lib/Algorithm/Classifier/IsolationForest/BuildFlags.pm';
open my $bf_fh, '>', $bf_path
	or die "Makefile.PL: can't write $bf_path: $!";
print $bf_fh <<"BUILDFLAGS";
package Algorithm::Classifier::IsolationForest::BuildFlags;

# AUTOGENERATED by Makefile.PL -- do not edit and do not add to MANIFEST.
# Records per-install C build configuration; regenerate by re-running
# `perl Makefile.PL` (with IF_* environment variables as desired).

use strict;
use warnings;

=head1 NAME

Algorithm::Classifier::IsolationForest::BuildFlags - C build flags captured at configure time

lib/Algorithm/Classifier/IsolationForest.pm  view on Meta::CPAN

		my $use_prebuilt
			= $prebuilt
			&& !$ENV{IF_RUNTIME_BUILD}
			&& !$ENV{IF_INSTALL_BUILD}
			&& $opt eq $def_opt
			&& $arch eq $def_arch
			&& $no_omp == $def_no_omp;

		# Inline::C hashes the C source to decide whether to rebuild but
		# does NOT include CCFLAGS / OPTIMIZE in that hash.  Without the
		# tag below, toggling IF_NATIVE/IF_ARCH/IF_OPT (or editing the
		# optimisation flags here) would silently reuse a cached binary
		# built with stale flags.  Embedding the active flags as a leading
		# comment forces the hash to differ when they change.  The OpenMP
		# and serial builds get distinct tags so they cache to separate
		# artefacts.
		my $omp_tag    = "/* if_build: openmp $opt_level */\n";
		my $serial_tag = "/* if_build: serial $opt_level */\n";

		if ( $ENV{IF_INSTALL_BUILD} ) {

lib/Algorithm/Classifier/IsolationForest.pm  view on Meta::CPAN

string) and returns it -- an instance of whichever class the prototype's
C<class> field names, so like C<load()> this is a single entry point for
both model types.  Croaks on any validation failure; a munger-bearing
prototype compiles its plan here, so a bogus munger spec dies at
creation (and needs Algorithm::ToNumberMunger installed).

C<%overrides> merge over the prototype's C<params> block -- per-run
knobs like C<seed> -- and are held to the same per-class whitelist.
Overriding the schema itself (feature_names, feature_descriptions,
mungers, missing, impute_with, schema_version, schema_description)
croaks: the schema is the prototype's, full stop; edit the prototype.

    my $oif = Algorithm::Classifier::IsolationForest->new_from_prototype(
        $proto_json,
        seed => 42,
    );

=cut

sub new_from_prototype {
	my ( $class, $proto, %overrides ) = @_;

	$proto = $class->validate_prototype($proto);
	my $which  = $proto->{class};
	my $schema = $proto->{schema};

	for my $k ( sort keys %overrides ) {
		croak "new_from_prototype: '$k' is part of the prototype's schema and may not "
			. "be overridden; edit the prototype instead"
			if $k
			=~ /\A(?:feature_names|feature_descriptions|mungers|missing|impute_with|schema_version|schema_description)\z/;
		croak "new_from_prototype: unknown override '$k' for a $which prototype (allowed: "
			. join( ', ', sort keys %{ $PROTO_PARAM_KEYS{$which} } ) . ')'
			unless $PROTO_PARAM_KEYS{$which}{$k};
	}

	my %args = (
		%{ $proto->{params} || {} },
		%overrides,

lib/Algorithm/Classifier/IsolationForest.pm  view on Meta::CPAN

schema (feature_names, feature_descriptions, mungers, missing policy)
plus its current tuning knobs.  This closes the loop -- extract a
prototype from a good model and periodically create fresh models with an
identical schema, the natural retrain workflow -- and means hand-writing
a prototype is never mandatory.

Croaks when the model has no C<feature_names>: a prototype's variable
schema needs named variables.  A model with no recorded
C<schema_version> / C<schema_description> (fitted before prototype
support, or without the knobs) gets placeholder values, since both are
required in the file -- edit them in and bump from there.  C<seed> and
C<max_depth> resolved at fit time are not emitted; pass such per-run
knobs as overrides when creating from the prototype.

    my $proto_json = $iforest->to_prototype;

=cut

sub to_prototype {
	my ($self) = @_;
	croak "to_prototype: this model has no feature_names; a prototype's variable " . "schema needs named features"

lib/Algorithm/Classifier/IsolationForest/App/Command/proto.pm  view on Meta::CPAN


sub description {
	'Works with model prototypes: small JSON documents holding the variable
schema (feature names, per-feature descriptions, munger specs, missing
policy), a user-owned schema_version and schema_description, and
optionally the tuning knobs.  `iforest fit --prototype` and
`iforest stream --prototype` create models from one; see PROTOTYPES in
the Algorithm::Classifier::IsolationForest POD for the file format.

--from-model extracts a prototype from a saved model, closing the loop:
pull the schema and knobs out of a good model, edit the metadata, and
create fresh models from it.  A model with no recorded schema_version /
schema_description gets placeholder values to edit in.

--check validates a prototype file and prints a summary of what it
describes, exiting non-zero when the file is not a valid prototype.

Exactly one of --from-model or --check must be given.
';
} ## end sub description

sub validate {
	my ( $self, $opt, $args ) = @_;



( run in 0.566 second using v1.01-cache-2.11-cpan-995e09ba956 )