Skip to main content

This project is an extension of the wisardpkg library and provides additional machine learning models based on the WiSARD architecture, including symbolic capabilities. It offers implementations of WiSARD-based models with high performance, easy installation, and a unified usage pattern.

Project description

Symbolicwisardpkg

Description:

This project is an extension of the wisardpkg library that expands the WiSARD ecosystem by introducing new models and functionalities while preserving the original design principles of simplicity, performance, and ease of use.

The library provides machine learning models based on the WiSARD architecture, supporting supervised, unsupervised, and semi-supervised learning paradigms. In addition to the classical WiSARD model, this project introduces neuro-symbolic extensions that enable the direct incorporation of symbolic knowledge into weightless neural networks.

The following WiSARD-based models are made available:

  • WiSARD: the classical weightless neural network model based on RAM memories.

  • SWiSARD: a neuro-symbolic extension of WiSARD that allows the direct insertion of logical rules into discriminators, enabling hybrid learning from rules and examples.

  • ClusWiSARD: a clustering-based WiSARD model for unsupervised learning.

to install:

python:


pip install symbolicwisardpkg

Works to pyhton3.

If you are on Linux and not in a virtual environment, you may need to run as superuser.

obs:

To install on windows platform you can use anaconda and do:


python -m pip install symbolicwisardpkg

to uninstall:


pip uninstall symbolicwisardpkg

to import:

python:

import symbolicwisardpkg as wp

to use:

WiSARD

WiSARD with bleaching by default:

python:

# load input data, just zeros and ones  

X = [

      [1,1,1,0,0,0,0,0],

      [1,1,1,1,0,0,0,0],

      [0,0,0,0,1,1,1,1],

      [0,0,0,0,0,1,1,1]

    ]



# load label data, which must be a string array

y = [

      "cold",

      "cold",

      "hot",

      "hot"

    ]





addressSize = 3     # number of addressing bits in the ram

ignoreZero  = False # optional; causes the rams to ignore the address 0



# False by default for performance reasons,

# when True, WiSARD prints the progress of train() and classify()

verbose = True



wsd = wp.Wisard(addressSize, ignoreZero=ignoreZero, verbose=verbose)







# train using the input data

wsd.train(X,y)



# classify some data

out = wsd.classify(X)



# the output of classify is a string list in the same sequence as the input

for i,d in enumerate(X):

    print(out[i],d)

SWiSARD

SWiSARD with bleaching by default:

python:

# load input data, just zeros and ones  

X = [

      [1,1,1,0,0,0,0,0],

      [1,1,1,1,0,0,0,0],

      [0,0,0,0,1,1,1,1],

      [0,0,0,0,0,1,1,1]

    ]



# load label data, which must be a string array

y = [

      "cold",

      "cold",

      "hot",

      "hot"

    ]



addressSize = 3     # number of addressing bits in the ram

ignoreZero  = False # optional; causes the rams to ignore the address 0

verbose = True      # optional; prints the progress of train() and classify()



wsd = wp.Wisard(addressSize, ignoreZero=ignoreZero, verbose=verbose)



# Add symbolic rules to discriminators

# variableIndexes maps variable names to indices in the input vector

# Example: if the vector has 8 positions [0,1,2,3,4,5,6,7], we can name:

# - x0 for index 0, x1 for index 1, etc.



# Add rule for class "cold": (x0 * x1) + (x0 * x2)

# This means: (position 0 AND position 1) OR (position 0 AND position 2)

variableIndexes_cold = {

    "x0": 0,  # first position of the vector

    "x1": 1,  # second position of the vector

    "x2": 2   # third position of the vector

}

rule_cold = "(x0 * x1) + (x0 * x2)"  # boolean expression: * = AND, + = OR, ! = NOT

alpha = 10  # rule weight (the higher, the more influence the rule has)



wsd.addRule("cold", variableIndexes_cold, rule_cold, alpha)



# Add rule for class "hot": (x4 * x5) + (x5 * x6)

variableIndexes_hot = {

    "x4": 4,

    "x5": 5,

    "x6": 6

}

rule_hot = "(x4 * x5) + (x5 * x6)"

wsd.addRule("hot", variableIndexes_hot, rule_hot, alpha)



# Train using trainWithRules (considers rules during training)

wsd.trainWithRules(X, y)



# Classify using classifyWithRules (considers rules during classification)

out = wsd.classifyWithRules(X)



# the output of classifyWithRules is a string list in the same sequence as the input

for i, d in enumerate(X):

    print(out[i], d)

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

symbolicwisardpkg-1.0.1.tar.gz (137.7 kB view details)

Uploaded Source

Built Distribution

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

symbolicwisardpkg-1.0.1-cp312-cp312-win_amd64.whl (231.9 kB view details)

Uploaded CPython 3.12Windows x86-64

File details

Details for the file symbolicwisardpkg-1.0.1.tar.gz.

File metadata

  • Download URL: symbolicwisardpkg-1.0.1.tar.gz
  • Upload date:
  • Size: 137.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for symbolicwisardpkg-1.0.1.tar.gz
Algorithm Hash digest
SHA256 30b3cc2eba23c14f8b895c48b1e51b622549ca039f052c307276eb2e487c6e13
MD5 e90b1abc0acf8b704877a4766d901ba0
BLAKE2b-256 906715fcf7191278a0338a0edeb9208450aeda193827c13e30a5c90a79587bab

See more details on using hashes here.

File details

Details for the file symbolicwisardpkg-1.0.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for symbolicwisardpkg-1.0.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fe316eb67f8eb58180f689ca72bddde461e12ef9175c8dbc606e2a6c53f6a7e1
MD5 4e10d343e9c5e715a7968885dbd8443e
BLAKE2b-256 5a64bcdb4b346f7cd68e27b87ac3e86452c1155bb4b4d9a7434f813bc29e553a

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