Skip to main content

No project description provided

Project description

ml_functions: A Machine Learning Functions Package

Overview

The ml_functions package provides a collection of Python functions designed for various machine learning tasks. The package currently includes:

  • convolution2d: Perform 2D cross-correlation between an input matrix and a kernel.
  • transpose: Transpose a 2D matrix.
  • window1d: Generate a list of windows from a 1D array or list.

Installation

This package uses Poetry for dependency management. To install the package, first, ensure you have Poetry installed.

Then, run:

poetry install

This package is also available on pypi: https://pypi.org/project/ml-functions/

Usage

convolution2d

Perform 2D cross-correlation.

The convolution2d function slides a kernel over the input matrix, computes the element-wise product of the kernel and the corresponding sub-matrix at each position, and sums up these products. It utilizes nested loops to iterate over the rows and columns of the output matrix, extracting sub-matrices from the input matrix and performing element-wise multiplication with the kernel.

Image Feature Extraction:

Convolution operations are fundamental to Convolutional Neural Networks (CNNs). Before feeding an image into a CNN, it might be preprocessed using various kernels to extract features like edges, textures, and corners. For instance, you might use a Sobel filter (used in edge detection to detect brightness changes) to detect edges in an image.

from ml_functions import convolution2d
result = convolution2d(
    input_matrix: np.ndarray, kernel: np.ndarray, stride: int = 1)

transpose2d

Transposes a 2D matrix.

Matrix Operations in Neural Networks:

While designing neural networks, especially fully connected layers or when visualizing certain types of data, you may need to transpose weight matrices or the input matrix itself to match the required shape for matrix multiplication.

For example, if you have an input vector x of shape (m, 1) and weight matrix W of shape (n, m), then before you perform the dot product (an operation performed by each artificial neuron in the network), you might need to transpose W to make it of shape (m, n).

from ml_functions import transpose2d
result = transpose2d(input_matrix: list[list[int]])

window1d

Generate a list of windows from a 1D array or list.

Time Series Analysis:

When working with time series data, it's often necessary to break the series down into smaller overlapping or non-overlapping windows for analysis. This is particularly useful for tasks like anomaly detection, where you'd want to compute statistics like mean and standard deviation for local windows to identify anomalies. With this function you can change the size of the window, how it changes with each iteration (shift), and how many steps to take before generating the next window (stride).

from ml_functions import window1d
result = window1d(
    input_array: list | np.ndarray, size: int, shift: int = 1, stride: int = 1)

Tests

Basic tests for the functions in the package are included in the tests directory. Each function has corresponding test cases that are designed to verify the accuracy and efficiency of the functions under different circumstances. Error testing has yet to be added.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ml_functions-0.1.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ml_functions-0.1.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file ml_functions-0.1.1.tar.gz.

File metadata

  • Download URL: ml_functions-0.1.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.0 Darwin/21.6.0

File hashes

Hashes for ml_functions-0.1.1.tar.gz
Algorithm Hash digest
SHA256 45be733964a7fb84262a2ff9203c11e03d2a274496adb1318555d022c8707dc9
MD5 5add88227969935c8b6ef1f055e04d68
BLAKE2b-256 fe98f5dc8edfeda0d1cdcb2e060cb3b26efc749e6cce9b3e3e9681c28550fd9c

See more details on using hashes here.

File details

Details for the file ml_functions-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ml_functions-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.0 Darwin/21.6.0

File hashes

Hashes for ml_functions-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 520bd9d986e56d0c20ff763ecddcc4542f9d31bad0168d219d57cd29b4758b56
MD5 7d968c94fd2e8cbd96dea3c08d353f4f
BLAKE2b-256 6a99128ab07728765f51ceb3ccf691bbd60a66bd03b94f02db95b278fb536e29

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page