convert this algoriyhm into PHP coding

Discussion in 'PHP' started by jaja_bin, Jul 25, 2007.

  1. #1
    can anybody help me on converting this algorithm into PHP coding . THis is algorithm for Spam detection using Artificial immune system

    Lifecycle

    Lifecycle Algorithm {Spam Immune System}
    BEGIN
    repertoire <- {} {Initialize repertoire (list) of lymphocytes to be empty}
    update_time <- time of next lymphocyte update {e.g. 10 days from now}

    Generate lymphocytes (See Generation Algorithm)
    Do initial training (See Training Algorithm)
    WHILE{Immune System is running}
    IF{message is received}
    Apply lymphocytes (See Apply Algorithm)
    ENDIF
    IF{current time > update_time}
    Cull lymphocytes (See Culling Algorithm)
    Generate lymphocytes to replace those culling (See Generation Algorithm)
    update_time <- time of next lymphocyte update
    ENDIF
    ENDWHILE
    END

    Creation of Lymphocytes and their Antibodies
    Generation Algorithm {Generation of lymphocytes}
    BEGIN
    library <- a gene fragment library (cannot be empty)
    repertoire <- the list of existing lymphocytes (may be empty)
    p_appending <- the probability of appending to antibody
    WHILE {repertoire is smaller than the required size}
    lymphocyte <- a new empty memory structure with space for an antibody,
    and the numbers msg_matched and spam_matched
    antibody <- "" {An empty string to start the new antibody being created.
    This will be a regular expression made up of genes and wildcards.}

    lymphocyte.msg_matched <- 0
    lymphocyte.spam_matched <- 0
    REPEAT
    antibody <- randomly chosen gene fragment from library
    x <- randomly chosen number between 0 and 1
    WHILE{x < p_appending}
    new gene <- new randomly chosen gene fragment from library
    antibody <- concatenate antibody, an expression that matches 0 or
    more characters, and new gene
    x <- new randomly chosen number between 0 and 1
    ENDWHILE
    UNTIL {an antibody is created that does not not match any in the repertoire}

    lymphocyte.antibody <- antibody
    Add lymphocyte to repertoire of lymphocytes
    ENDWHILE
    END

    Training of Lymphocytes

    Training Algorithm {Training of lymphocytes}
    BEGIN
    repertoire <- the list of lymphocytes (cannot be an empty list)
    message <- a message which has been marked as spam or non-spam
    IF {the message is user-determined spam}
    spam_increment <- 1
    ELSIF {the message is user-determined non-spam}
    spam_increment <- 0
    ELSE
    spam_increment <- a number between 0 and 1 indicating how likely the
    message is to be spam
    ENDIF
    FOR {each lymphocyte in the repertoire}
    IF {lymphocyte.antibody matches the message}
    increment lymphocyte.msg_matched value by 1
    increment lymphocyte.spam_matched value by spam_increment
    ENDIF
    ENDFOR
    END
















    Application and weighting of lymphocytes
    Apply Algorithm {Application of antibodies with dynamically updated
    weights}
    BEGIN
    repertoire <- the list of antibodies (cannot be an empty list)
    message <- a message to be marked
    threshold <- a cutoff point valued between 0 and 1 inclusive; anything
    with a higher score than this is spam {chosen by user}
    increment <- a value between 0 and 1 inclusive, depending upon the user's
    confidence in the system. {chosen by user}
    total_spam_matched <- 0 {initialize # of spams matched to 0}
    total_msg_matched <- 0 {initialize # of messages matched to 0}
    matching_lymphocytes <- {} {Initialize empty list of matching lymphocytes}

    FOR{each lymphocyte in the repertoire}
    IF {lymphocyte.antibody matches message}
    total_spam_matched <- total_spam_matched + lymphocyte.spam_matched
    total_msg_matched <- total_msg_matched + lymphocyte.msg_matched
    lymphocyte.msg_matched <- lymphocyte.msg_matched + 1
    {increment the # of messages matched by this antibody}
    add lymphocyte to matching_lymphocytes
    ENDIF
    ENDFOR

    score <- total_spam_matched/total_msg_matched {Determine the score using a
    weighted sum}
    IF {score < threshold} {Message is spam}
    FOR{each lymphocyte in matching_lymphocytes}
    lymphocyte.spam_matched <- lymphocyte.spam_matched + increment
    ENDFOR
    ELSE
    Message is not spam
    ENDIF
    END







    Culling of antibodies: Ageing and Death

    Culling Algorithm {Culling of antibodies: aging and death}
    BEGIN
    FOR{each lymphocyte in the repertoire (list of all lymphocytes) }
    decrement lymphocyte.msg_matched
    decrement lymphocyte.spam_matched so that the ratio between it and
    lymphocyte.msg_matched is the same as it was before the aging
    IF {lymphocyte.msg_matched < a set threshold}
    remove antibody from data store
    ENDIF
    ENDFOR
    END
     
    jaja_bin, Jul 25, 2007 IP
  2. scole

    scole Peon

    Messages:
    104
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sorry I don't see any simple conversion for this. Maybe explain what the script/program needs do to and someone can help create a script.
     
    scole, Jul 26, 2007 IP
  3. mrmonster

    mrmonster Active Member

    Messages:
    374
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #3
    holy :eek:
     
    mrmonster, Jul 26, 2007 IP
  4. goscript

    goscript Prominent Member

    Messages:
    2,753
    Likes Received:
    306
    Best Answers:
    0
    Trophy Points:
    315
    #4
    ^second that

    For that coding you may want to seek a paid service on GF
     
    goscript, Jul 26, 2007 IP
  5. jaja_bin

    jaja_bin Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ok this is algoriyhm for artificial immune system. actually it is an adaptation from human inmmune system.so i want to make a simulation of spam detection using AIS.what is needed in AIS for this spm detection are input(email) either spam or non spam , a library of gene fragment used to make an antibody and the lymphocyte (a bit of digital information).
    in AIS we treat spam as=panthogen , email as=antigen , and digital bit of information as=lymphocytes. AIS is almost similar with Genetic Algorithm but the different ai AIS have an database and GA not.
     
    jaja_bin, Jul 29, 2007 IP
  6. goscript

    goscript Prominent Member

    Messages:
    2,753
    Likes Received:
    306
    Best Answers:
    0
    Trophy Points:
    315
    #6
    spam = pathogen
    email = antigen
    information = lymphocytes

    Sorry i don't have a microscope to help you. :D

    WTF man! i doubt anybody here have a clue what you talk about.

    You may want to seek help on GF, maybe some php-biologists guys are there.. (which i doubt)
     
    goscript, Jul 30, 2007 IP
  7. jaja_bin

    jaja_bin Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i dont need the microscope for this ..actually thanks goscript!
     
    jaja_bin, Aug 3, 2007 IP
  8. jaja_bin

    jaja_bin Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    can anybody know about Artificial immune system
     
    jaja_bin, Aug 5, 2007 IP
  9. B7x0

    B7x0 Peon

    Messages:
    113
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Eat lots of chicken, and drink lots of juices, you'll be fine... j/k

    Come on man, that's not an algorithm, you basically wrote some weird code in there. You should write it in pure English [or UML it] so we can understand what you want to do.
     
    B7x0, Aug 6, 2007 IP
  10. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #10
    It is code that was used for a biological purposes, modelling immune systems, i.e. it wasn't written for this purpose, he is just trying to adapt it for an IT solution

    It just looks daunting. Having said that, this is no easy task, decrypting that pseudo code is not hard but will take some time, as will the actual implementation. Sure, we can help if you point out areas where you are having issues, but you're not going to find many who are willing to spend much time on this without anything in return.
     
    krt, Aug 6, 2007 IP
  11. jaja_bin

    jaja_bin Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    yeah it is an Artificial immune system which is an adaptation from human immune system..i know it so dificult to convert it butt may be u can explaint to me what it is all about...actually this code is use to detect an email spam ...so if we use this method for spam detection it may update itself.. different with the ordinary spam filtered which may not update theirself.
     
    jaja_bin, Aug 6, 2007 IP
  12. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #12
    It is called heuristics. Whether or not you adapt this logic or start from scratch from your own logic, it won't make much difference in the quality of spam detection. In other words, this pseudo code only provides guidelines.
     
    krt, Aug 7, 2007 IP
  13. cascadingstylez

    cascadingstylez Guest

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I didn't understand any of that sorry mate, its way past me.

    What sort of degree's do you have? Someone with high intelligence would be needed in this case and im sure alot of cash would be needed.
     
    cascadingstylez, Aug 7, 2007 IP