Crate neuro_divergent_core

Crate neuro_divergent_core 

Source
Expand description

§Neuro-Divergent Core

High-performance neural forecasting library for Rust, built on the ruv-FANN foundation. This crate provides the core abstractions, traits, and data structures needed for advanced time series forecasting with neural networks.

§Features

  • Type-safe Neural Networks: Built on ruv-FANN with generic floating-point support
  • Time Series Data Structures: Efficient handling of temporal data with exogenous variables
  • Memory-safe Operations: Rust’s ownership model ensures memory safety without garbage collection
  • Parallel Processing: Built-in support for multi-threaded training and inference
  • Comprehensive Error Handling: Detailed error types for robust error management
  • Flexible Configuration: Builder patterns and configuration systems for easy setup

§Architecture

The library is organized into several key modules:

  • traits: Core traits that define the forecasting model interface
  • data: Time series data structures and preprocessing utilities
  • error: Comprehensive error handling types
  • integration: Integration layer with ruv-FANN neural networks
  • config: Configuration management and builder patterns

§Quick Start

use neuro_divergent_core::prelude::*;
use chrono::{DateTime, Utc};

// Create a time series dataset
let mut dataset = TimeSeriesDatasetBuilder::new()
    .with_target_column("value")
    .with_time_column("timestamp")
    .with_unique_id_column("series_id")
    .build()?;

// Configure a forecasting model
let config = ModelConfigBuilder::new()
    .with_horizon(12)
    .with_input_size(24)
    .build()?;

§Integration with ruv-FANN

This library extends ruv-FANN’s neural network capabilities with time series-specific functionality:

use neuro_divergent_core::integration::NetworkAdapter;
use ruv_fann::Network;

// Create a ruv-FANN network
let network = Network::new(&[24, 64, 32, 12])?;

// Wrap it with our adapter for time series forecasting
let adapter = NetworkAdapter::from_network(network)
    .with_input_preprocessor(/* ... */)
    .with_output_postprocessor(/* ... */);

Re-exports§

pub use crate::config::*;
pub use crate::data::*;
pub use crate::error::*;
pub use crate::integration::*;
pub use crate::traits::*;

Modules§

aggregations
arity
binary
chunkedarray
Traits and utilities for temporal data.
cloud
Interface with cloud storage through the object_store crate.
config
Configuration management and builder patterns for neuro-divergent.
consts
data
Time series data structures and processing utilities.
datatypes
Data types supported by Polars.
default_arrays
dt
error
Comprehensive error handling for the neuro-divergent library.
expr
fill_null
full
gather
gather_skip_nulls
integration
Integration layer with ruv-FANN neural networks.
null
predicates
prelude
Commonly used types and traits for convenient importing
read_impl
series
slice
sort
sum_f64
traits
Core traits that define the forecasting model interface.
udf
utils
zip

Macros§

config_error
Convenience macros for error creation
data_error
Create a data error with the given message
df
polars_bail
polars_ensure
polars_err
polars_warn
training_error
Create a training error with the given message

Structs§

AggregationContext
AnonymousScanOptions
Arc
A thread-safe reference-counting pointer. ‘Arc’ stands for ‘Atomically Reference Counted’.
ArrowField
Represents Arrow’s metadata of a “column”.
ArrowSchema
An ordered sequence of Fields with associated Metadata.
BatchedParquetReader
BinaryChunkedBuilder
BinaryType
BooleanChunkedBuilder
BooleanType
Bounds
BoundsIter
BrotliLevel
CategoricalType
ChainedThen
Utility struct for the when-then-otherwise expression.
ChainedWhen
Utility struct for the when-then-otherwise expression.
ChunkedArray
ChunkedArray
CsvReader
Create a new DataFrame by reading a csv file.
CsvWriter
Write a DataFrame to csv.
CsvWriterOptions
DataFrame
A contiguous growable collection of Series that have the same length.
DateTime
ISO 8601 combined date and time with time zone.
DateType
DatetimeArgs
Arguments used by datetime in order to produce an Expr of Datetime
DatetimeType
Duration
DurationArgs
Arguments used by duration in order to produce an Expr of Duration
DurationType
DynamicGroupOptions
Field
Characterizes the name and the DataType of a column.
FieldsMapper
FileMetaData
Metadata for a Parquet file.
Flat
Float32Type
Float64Type
GroupBy
Returned by a group_by operation on a DataFrame. This struct supports several aggregations.
GroupsIdx
Indexes of the groups, the first index is stored separately. this make sorting fast.
GroupsProxyIter
GroupsProxyParIter
GzipLevel
Int8Type
Int16Type
Int32Type
Int64Type
JoinArgs
JoinBuilder
JoinOptions
JsonLineReader
JsonReader
Reads JSON in one of the formats in JsonFormat into a DataFrame.
JsonWriter
Writes a DataFrame to JSON.
LazyCsvReader
LazyFrame
Lazy abstraction over an eager DataFrame. It really is an abstraction over a logical plan. The methods of this struct will incrementally modify a logical plan until output is requested (via collect).
LazyGroupBy
Utility struct for lazy group_by operation.
LazyJsonLineReader
ListBinaryChunkedBuilder
ListBooleanChunkedBuilder
ListNameSpace
Specialized expressions for Series of DataType::List.
ListPrimitiveChunkedBuilder
ListType
ListUtf8ChunkedBuilder
Logical
Maps a logical type to a a chunked array implementation of the physical type. This saves a lot of compiler bloat and allows us to reuse functionality.
MeltArgs
Arguments for [DataFrame::melt] function
Nested
Network
A feedforward neural network
NetworkBuilder
Builder for creating neural networks with a fluent API
NoNull
Just a wrapper structure. Useful for certain impl specializations This is for instance use to implement impl<T> FromIterator<T::Native> for NoNull<ChunkedArray<T>> as Option<T::Native> was already implemented: impl<T> FromIterator<Option<T::Native>> for ChunkedArray<T>
Null
The literal Null
OptState
State of the allowed optimizations
ParquetReader
Read Apache parquet format into a DataFrame.
ParquetWriteOptions
ParquetWriter
Write a DataFrame to parquet format
PhysicalIoHelper
Wrapper struct that allow us to use a PhysicalExpr in polars-io.
PrimitiveChunkedBuilder
RollingCovOptions
RollingGroupOptions
RollingQuantileParams
RollingVarParams
ScanArgsAnonymous
ScanArgsParquet
Schema
A map from field/column name (String) to the type of that field/column (DataType)
SerializeOptions
Options to serialize logical types to CSV.
Series
Series
SlicedGroups
SortMultipleOptions
SortOptions
SpecialEq
Wrapper type that has special equality properties depending on the inner type specialization
StrptimeOptions
StructArray
A StructArray is a nested Array with an optional validity representing multiple Array with the same number of rows.
StructChunked
This is logical type StructChunked that dispatches most logic to the fields implementations
StructNameSpace
Specialized expressions for Struct dtypes.
Then
Utility struct for the when-then-otherwise expression.
TimeType
TrainingData
UInt8Type
UInt16Type
UInt32Type
UInt64Type
UnionArgs
UserDefinedFunction
Represents a user-defined function
Utc
The UTC time zone. This is the most efficient time zone when you don’t need the local time. It is also used as an offset (which is also a dummy type).
Utf8ChunkedBuilder
Utf8Type
When
Utility struct for the when-then-otherwise expression.
Window
Represents a window in time
ZstdLevel
Represents a valid zstd compression level.

Enums§

ActivationFunction
Activation functions available for neurons
AggExpr
AnyValue
ArrowDataType
The set of supported logical types in this crate.
ArrowTimeUnit
The time units defined in Arrow.
BooleanFunction
ClosedWindow
CsvEncoding
DataType
Excluded
Expr
Expressions that can be used in various contexts. Queries consist of multiple expressions. When using the polars lazy API, don’t construct an Expr directly; instead, create one using the functions in the polars_lazy::dsl module. See that module’s docs for more info.
FillNullStrategy
FunctionExpr
GroupByMethod
GroupsIndicator
GroupsProxy
JoinType
JoinValidation
JsonFormat
The format to use to write the DataFrame to JSON: Json (a JSON array) or JsonLines (each row output on a separate line). In either case, each row is serialized as a JSON object whose keys are the column names and whose values are the row’s corresponding values.
Label
LiteralValue
LogicalPlan
NullValues
Operator
ParallelStrategy
ParquetCompression
PolarsError
QuantileInterpolOptions
QuoteStyle
StartBy
TimeUnit
UniqueKeepStrategy
WindowMapping
WindowType

Constants§

DESCRIPTION
Library description
IDX_DTYPE
NAME
Library name
NULL
VERSION
Library version information

Statics§

BOOLEAN_RE
FLOAT_RE
INTEGER_RE

Traits§

AnonymousScan
ArgAgg
Argmin/ Argmax
ArrayCollectIterExt
ArrayFromIter
ArrayFromIterDtype
AsBinary
AsList
AsRefDataType
AsUtf8
BinaryNameSpaceImpl
BinaryUdfOutputField
ChunkAgg
Aggregation operations.
ChunkAggSeries
Aggregations that return Series of unit length. Those can be used in broadcasting operations.
ChunkAnyValue
ChunkApply
Fastest way to do elementwise operations on a ChunkedArray<T> when the operation is cheaper than branching due to null checking.
ChunkApplyKernel
Apply kernels on the arrow array chunks in a ChunkedArray.
ChunkBytes
ChunkCast
Cast ChunkedArray<T> to ChunkedArray<N>
ChunkCompare
Compare Series and ChunkedArray’s and get a boolean mask that can be used to filter rows.
ChunkExpandAtIndex
Create a new ChunkedArray filled with values at that index.
ChunkExplode
Explode/ flatten a List or Utf8 Series
ChunkFillNullValue
Replace None values with a value
ChunkFilter
Filter values by a boolean mask.
ChunkFull
Fill a ChunkedArray with one value.
ChunkFullNull
ChunkQuantile
Quantile and median aggregation.
ChunkReverse
Reverse a ChunkedArray<T>
ChunkSet
Create a ChunkedArray with new values by index or by boolean mask. Note that these operations clone data. This is however the only way we can modify at mask or index level as the underlying Arrow arrays are immutable.
ChunkShift
ChunkShiftFill
Shift the values of a ChunkedArray by a number of periods.
ChunkSort
Sort operations on ChunkedArray.
ChunkTake
ChunkTakeUnchecked
ChunkUnique
Get unique values in a ChunkedArray
ChunkVar
Variance and standard deviation aggregation.
ChunkZip
Combine two ChunkedArray based on some predicate.
ChunkedBuilder
ChunkedCollectInferIterExt
ChunkedCollectIterExt
ChunkedSet
CrossJoin
DataFrameJoinOps
DataFrameOps
DateMethods
DatetimeMethods
Deserialize
A data structure that can be deserialized from any data format supported by Serde.
DurationMethods
Float
Generic trait for floating point numbers
FromData
FromDataBinary
FromDataUtf8
FunctionOutputField
GetAnyValue
IndexOfSchema
This trait exists to be unify the API of polars Schema and arrows Schema
IndexToUsize
InitHashMaps
InitHashMaps2
IntoGroupsProxy
Used to create the tuples for a group_by operation.
IntoLazy
IntoSeries
Used to convert a ChunkedArray, &dyn SeriesTrait and Series into a Series.
IntoVec
IsFloat
Safety
JoinDispatch
LazyFileListReader
Reads LazyFrame from a filesystem or a cloud storage. Supports glob patterns.
LhsNumOps
ListBuilderTrait
ListFromIter
ListNameSpaceImpl
Literal
LogicalType
MutableBitmapExtension
NamedFrom
NamedFromOwned
NewChunkedArray
NumOpsDispatch
NumericNative
PartitionedAggregation
PhysicalExpr
Take a DataFrame and evaluate the expressions. Implement this for Column, lt, eq, etc
PolarsArray
PolarsDataType
Safety
PolarsFloatType
PolarsIntegerType
PolarsIterator
A PolarsIterator is an iterator over a ChunkedArray which contains polars types. A PolarsIterator must implement ExactSizeIterator and DoubleEndedIterator.
PolarsMonthEnd
PolarsMonthStart
PolarsNumericType
PolarsRound
PolarsTemporalGroupby
PolarsTruncate
PolarsUpsample
QuantileAggSeries
RenameAliasFn
SerReader
SerWriter
Serialize
A data structure that can be serialized into any data format supported by Serde.
SeriesBinaryUdf
A wrapper trait for any binary closure Fn(Series, Series) -> PolarsResult<Series>
SeriesJoin
SeriesMethods
SeriesSealed
SeriesTrait
SeriesUdf
A wrapper trait for any closure Fn(Vec<Series>) -> PolarsResult<Series>
SlicedArray
Utility trait to slice concrete arrow arrays whilst keeping their concrete type. E.g. don’t return Box<dyn Array>.
StaticArray
TemporalMethods
TimeMethods
TrainingAlgorithm
Main trait for training algorithms
UdfSchema
Utf8Methods
ValueSize
VarAggSeries
VecHash

Functions§

_join_suffix_name
_sort_or_hash_inner
all
Selects all columns. Shorthand for col("*").
apply_binary
Like map_binary, but used in a group_by-aggregation context.
apply_multiple
Apply a function/closure over the groups of multiple columns. This should only be used in a group_by aggregation.
as_struct
Take several expressions and collect them into a StructChunked.
avg
Find the mean of all the values in the column named name. Alias for mean.
binary_expr
Compute op(l, r) (or equivalently l op r). l and r must have types compatible with the Operator.
cast
Casts the column given by Expr to a different type.
check_projected_arrow_schema
Checks if the projected columns are equal
check_projected_schema
Checks if the projected columns are equal
check_projected_schema_impl
clip
Clamp underlying values to the min and max values.
clip_max
Clamp underlying values to the max value.
clip_min
Clamp underlying values to the min value.
coalesce
Folds the expressions from left to right keeping the first non-null values.
col
Create a Column Expression based on a column name.
collect_all
Collect all LazyFrame computations.
cols
Select multiple columns by name.
concat
Concat multiple LazyFrames vertically.
concat_expr
concat_list
Concat lists entries.
count
Count expression.
cum_fold_exprs
Accumulate over multiple columns horizontally / row wise.
cum_reduce_exprs
Accumulate over multiple columns horizontally / row wise.
date_range
Create a DatetimeChunked from a given start and end date and a given interval.
datetime
Construct a column of Datetime from the provided DatetimeArgs.
datetime_to_timestamp_ms
datetime_to_timestamp_ns
datetime_to_timestamp_us
default_join_ids
dtype_col
Select multiple columns by dtype.
dtype_cols
Select multiple columns by dtype.
duration
Construct a column of Duration from the provided DurationArgs
first
First column in DataFrame.
fmt_group_by_column
fold_exprs
Accumulate over multiple columns horizontally / row wise.
get_reader_bytes
get_sequential_row_statistics
Compute remaining_rows_to_read to be taken per file up front, so we can actually read concurrently/parallel
group_by_values
Different from group_by_windows, where define window buckets and search which values fit that pre-defined bucket, this function defines every window based on the: - timestamp (lower bound) - timestamp + period (upper bound) where timestamps are the individual values in the array time
group_by_windows
Based on the given Window, which has an
in_nanoseconds_window
indexes_to_usizes
is_not_null
A column which is false wherever expr is null, true elsewhere.
is_null
A column which is true wherever expr is null, false elsewhere.
last
Last column in DataFrame.
lit
Create a Literal Expression from L. A literal expression behaves like a column that contains a single distinct value.
map_binary
Apply a closure on the two columns that are evaluated from Expr a and Expr b.
map_list_multiple
Apply a function/closure over multiple columns once the logical plan get executed.
map_multiple
Apply a function/closure over multiple columns once the logical plan get executed.
materialize_projection
max
Find the maximum of all the values in the column named name. Shorthand for col(name).max().
mean
Find the mean of all the values in the column named name. Shorthand for col(name).mean().
median
Find the median of all the values in the column named name. Shorthand for col(name).median().
merge_dtypes
min
Find the minimum of all the values in the column named name. Shorthand for col(name).min().
not
Negates a boolean column.
private_left_join_multiple_keys
quantile
Find a specific quantile of all the values in the column named name.
reduce_exprs
Analogous to Iterator::reduce.
repeat
Create a column of length n containing n copies of the literal value. Generally you won’t need this function, as lit(value) already represents a column containing only value whose length is automatically set to the correct number of rows.
resolve_homedir
sum
Sum all the values in the column named name. Shorthand for col(name).sum().
ternary_expr
time_range
Create a TimeChunked from a given start and end date and a given interval.
unix_time
when
Start a when-then-otherwise expression.

Type Aliases§

AllowedOptimizations
AllowedOptimizations
Array1
one-dimensional array
Array2
two-dimensional array
ArrayRef
ArrayView1
one-dimensional array view
ArrayView2
two-dimensional array view
BinaryChunked
BooleanChunked
BorrowIdxItem
ChunkId
[ChunkIdx, DfIdx]
ChunkJoinIds
ChunkJoinOptIds
DateChunked
DatetimeChunked
DurationChunked
DynArgs
FileMetaDataRef
FillNullLimit
Float32Chunked
Float64Chunked
GetOutput
GroupsSlice
Every group is indicated by an array where the
IdxArr
IdxCa
IdxItem
IdxSize
The type used by polars to index data.
IdxType
InnerJoinIds
Int8Chunked
Int16Chunked
Int32Chunked
Int64Chunked
LargeBinaryArray
LargeListArray
LargeStringArray
LeftJoinIds
ListChunked
PathIterator
PlHashMap
PlHashSet
PlIdHashMap
This hashmap uses an IdHasher
PlIndexMap
PlIndexSet
PolarsResult
SchemaRef
TimeChunked
TimeZone
UInt8Chunked
UInt16Chunked
UInt32Chunked
UInt64Chunked
Utf8Chunked

Derive Macros§

Deserialize
Serialize