Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Implement Negative Selection Algorithm | Artificial Immune Systems
Bio-Inspired Algorithms

bookChallenge: Implement Negative Selection Algorithm

Task

Swipe to start coding

In this challenge, you will implement a basic negative selection algorithm (NSA) for anomaly detection.
This algorithm is inspired by the human immune system, which learns to distinguish between self (normal) and non-self (foreign) patterns.

You are given a list of self_patterns representing normal data.
Your task is to implement two core functions:

  1. Generate detectors: in the generate_detectors function, you must:
    • Generate random candidate patterns.
    • Check if the candidate pattern is in the self_set.
    • Only add the candidate to the detectors set if it is not a "self" pattern.
  2. Classify patterns: in the classify_patterns function, you must:
    • Check each pattern from the test_patterns list.
    • If the pattern is in the self_set, classify it as 'self'.
    • Else, if the pattern is in the detector_set, classify it as 'non-self'.
    • Otherwise (if it is not "self" and not in the generated detector list), classify it as 'non-self'.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 4
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain this in simpler terms?

What are some examples related to this topic?

How does this information apply to real-life situations?

close

Awesome!

Completion rate improved to 6.25

bookChallenge: Implement Negative Selection Algorithm

Swipe to show menu

Task

Swipe to start coding

In this challenge, you will implement a basic negative selection algorithm (NSA) for anomaly detection.
This algorithm is inspired by the human immune system, which learns to distinguish between self (normal) and non-self (foreign) patterns.

You are given a list of self_patterns representing normal data.
Your task is to implement two core functions:

  1. Generate detectors: in the generate_detectors function, you must:
    • Generate random candidate patterns.
    • Check if the candidate pattern is in the self_set.
    • Only add the candidate to the detectors set if it is not a "self" pattern.
  2. Classify patterns: in the classify_patterns function, you must:
    • Check each pattern from the test_patterns list.
    • If the pattern is in the self_set, classify it as 'self'.
    • Else, if the pattern is in the detector_set, classify it as 'non-self'.
    • Otherwise (if it is not "self" and not in the generated detector list), classify it as 'non-self'.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 4
single

single

some-alt