[ 
https://issues.apache.org/jira/browse/METRON-640?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15815163#comment-15815163
 ] 

ASF GitHub Bot commented on METRON-640:
---------------------------------------

Github user cestella commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/403#discussion_r95378128
  
    --- Diff: 
metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/StringFunctions.java
 ---
    @@ -284,4 +287,36 @@ private static Object fill(FillDirection direction, 
Object inputObject, Object f
         }
         return 
org.apache.commons.lang.StringUtils.rightPad(input,requiredLength,fill);
       }
    +
    +  @Stellar( namespace="STRING"
    +          , name="ENTROPY"
    +          , description = "Computes the base-2 shannon entropy of a string"
    +          , params = { "input - String" }
    +          , returns = "The base-2 shannon entropy of the string.  The unit 
of this is bits."
    +  )
    +  public static class Entropy extends BaseStellarFunction {
    +    @Override
    +    public Object apply(List<Object> strings) {
    +      /*
    +      Shannon entropy is defined as follows:
    +      \Eta(X) = - \sum(p(x_i)*log_2(p(x_i)), i=0, n-1) where x_i are 
distinct characters in the string.
    +       */
    +      Map<Character, Integer> frequency = new HashMap<>();
    +      String input = (String)strings.get(0);
    --- End diff --
    
    Good catch; I did an `IllegalArgumentException`


> Add a Stellar function to compute shannon entropy for strings
> -------------------------------------------------------------
>
>                 Key: METRON-640
>                 URL: https://issues.apache.org/jira/browse/METRON-640
>             Project: Metron
>          Issue Type: Improvement
>            Reporter: Casey Stella
>
> A common feature used for models (especially DGA models) is shannon entropy 
> of strings.  We should have the ability to compute it in stellar.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to